Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
Olivier Deprez | c8f6a67 | 2022-01-13 13:44:53 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2018-2022, Arm Limited. All rights reserved. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <asm_macros.S> |
| 8 | |
| 9 | .globl tftf_vector |
| 10 | |
Sandrine Bailleux | a43b003 | 2019-01-14 14:04:32 +0100 | [diff] [blame] | 11 | /* |
| 12 | * Exception vector code for unhandled exceptions. |
| 13 | * Print a crash dump on the UART and loops forever. |
| 14 | */ |
Sandrine Bailleux | e760449 | 2019-01-14 09:37:28 +0100 | [diff] [blame] | 15 | .macro unhandled_exception name |
| 16 | vector_entry \name |
Sandrine Bailleux | a43b003 | 2019-01-14 14:04:32 +0100 | [diff] [blame] | 17 | b crash_dump |
Sandrine Bailleux | e760449 | 2019-01-14 09:37:28 +0100 | [diff] [blame] | 18 | end_vector_entry \name |
| 19 | .endm |
| 20 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 21 | vector_base tftf_vector |
Sandrine Bailleux | 8b170a2 | 2019-01-11 18:47:26 +0100 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | * Current EL with SP0 : 0x0 - 0x200. |
| 25 | */ |
Daniel Boulby | 08798ac | 2021-04-06 14:30:19 +0100 | [diff] [blame] | 26 | unhandled_exception sync_exception_sp_el0 |
| 27 | unhandled_exception irq_sp_el0 |
| 28 | unhandled_exception fiq_sp_el0 |
| 29 | unhandled_exception serror_sp_el0 |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 30 | |
Sandrine Bailleux | 8b170a2 | 2019-01-11 18:47:26 +0100 | [diff] [blame] | 31 | /* |
| 32 | * Current EL with SPx : 0x200 - 0x400. |
| 33 | */ |
Olivier Deprez | c8f6a67 | 2022-01-13 13:44:53 +0000 | [diff] [blame^] | 34 | vector_entry sync_spx |
| 35 | b sync_exception_vector_entry |
| 36 | end_vector_entry sync_spx |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 37 | |
Daniel Boulby | 08798ac | 2021-04-06 14:30:19 +0100 | [diff] [blame] | 38 | vector_entry irq_sp_elx |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 39 | b irq_vector_entry |
Daniel Boulby | 08798ac | 2021-04-06 14:30:19 +0100 | [diff] [blame] | 40 | end_vector_entry irq_sp_elx |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 41 | |
Daniel Boulby | 08798ac | 2021-04-06 14:30:19 +0100 | [diff] [blame] | 42 | unhandled_exception fiq_sp_elx |
| 43 | unhandled_exception serror_sp_elx |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 44 | |
Sandrine Bailleux | 8b170a2 | 2019-01-11 18:47:26 +0100 | [diff] [blame] | 45 | /* |
| 46 | * Lower EL using AArch64 : 0x400 - 0x600. |
| 47 | */ |
Daniel Boulby | 08798ac | 2021-04-06 14:30:19 +0100 | [diff] [blame] | 48 | unhandled_exception sync_exception_aarch64 |
| 49 | unhandled_exception irq_aarch64 |
| 50 | unhandled_exception fiq_aarch64 |
| 51 | unhandled_exception serror_aarch64 |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 52 | |
Sandrine Bailleux | 8b170a2 | 2019-01-11 18:47:26 +0100 | [diff] [blame] | 53 | /* |
| 54 | * Lower EL using AArch32 : 0x600 - 0x800. |
| 55 | */ |
Daniel Boulby | 08798ac | 2021-04-06 14:30:19 +0100 | [diff] [blame] | 56 | unhandled_exception sync_exception_aarch32 |
| 57 | unhandled_exception irq_aarch32 |
| 58 | unhandled_exception fiq_aarch32 |
| 59 | unhandled_exception serror_aarch32 |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 60 | |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 61 | .macro save_gp_regs |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 62 | stp x0, x1, [sp, #0x0] |
| 63 | stp x2, x3, [sp, #0x10] |
| 64 | stp x4, x5, [sp, #0x20] |
| 65 | stp x6, x7, [sp, #0x30] |
| 66 | stp x8, x9, [sp, #0x40] |
| 67 | stp x10, x11, [sp, #0x50] |
| 68 | stp x12, x13, [sp, #0x60] |
| 69 | stp x14, x15, [sp, #0x70] |
| 70 | stp x16, x17, [sp, #0x80] |
| 71 | stp x18, x19, [sp, #0x90] |
| 72 | stp x20, x21, [sp, #0xa0] |
| 73 | stp x22, x23, [sp, #0xb0] |
| 74 | stp x24, x25, [sp, #0xc0] |
| 75 | stp x26, x27, [sp, #0xd0] |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 76 | stp x28, x29, [sp, #0xe0] |
Sandrine Bailleux | a43b003 | 2019-01-14 14:04:32 +0100 | [diff] [blame] | 77 | /* We push xzr simply to keep the stack 16-byte aligned. */ |
| 78 | stp x30, xzr, [sp, #0xf0] |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 79 | .endm |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 80 | |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 81 | .macro restore_gp_regs |
Sandrine Bailleux | a43b003 | 2019-01-14 14:04:32 +0100 | [diff] [blame] | 82 | ldp x30, xzr, [sp, #0xf0] |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 83 | ldp x28, x29, [sp, #0xe0] |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 84 | ldp x26, x27, [sp, #0xd0] |
| 85 | ldp x24, x25, [sp, #0xc0] |
| 86 | ldp x22, x23, [sp, #0xb0] |
| 87 | ldp x20, x21, [sp, #0xa0] |
| 88 | ldp x18, x19, [sp, #0x90] |
| 89 | ldp x16, x17, [sp, #0x80] |
| 90 | ldp x14, x15, [sp, #0x70] |
| 91 | ldp x12, x13, [sp, #0x60] |
| 92 | ldp x10, x11, [sp, #0x50] |
| 93 | ldp x8, x9, [sp, #0x40] |
| 94 | ldp x6, x7, [sp, #0x30] |
| 95 | ldp x4, x5, [sp, #0x20] |
| 96 | ldp x2, x3, [sp, #0x10] |
| 97 | ldp x0, x1, [sp, #0x0] |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 98 | .endm |
| 99 | |
Olivier Deprez | c8f6a67 | 2022-01-13 13:44:53 +0000 | [diff] [blame^] | 100 | func sync_exception_vector_entry |
| 101 | sub sp, sp, #0x100 |
| 102 | save_gp_regs |
| 103 | mov x19, sp |
| 104 | bl tftf_sync_exception_handler |
| 105 | cbnz x0, 0f |
| 106 | mov x0, x19 |
| 107 | /* Save original stack pointer value on the stack */ |
| 108 | add x1, x0, #0x100 |
| 109 | str x1, [x0, #0xf8] |
| 110 | b print_exception |
| 111 | 0: restore_gp_regs |
| 112 | add sp, sp, #0x100 |
| 113 | eret |
| 114 | endfunc sync_exception_vector_entry |
| 115 | |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 116 | func irq_vector_entry |
| 117 | sub sp, sp, #0x100 |
| 118 | save_gp_regs |
| 119 | bl tftf_irq_handler_dispatcher |
| 120 | restore_gp_regs |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 121 | add sp, sp, #0x100 |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 122 | eret |
| 123 | endfunc irq_vector_entry |
Sandrine Bailleux | a43b003 | 2019-01-14 14:04:32 +0100 | [diff] [blame] | 124 | |
| 125 | func crash_dump |
| 126 | /* Save general-purpose registers on the stack. */ |
| 127 | sub sp, sp, #0x100 |
| 128 | save_gp_regs |
| 129 | |
| 130 | /* Save original stack pointer value on the stack. */ |
| 131 | add x1, sp, #0x100 |
| 132 | str x1, [sp, #0xf8] |
| 133 | |
| 134 | /* Print the saved CPU context on the UART. */ |
| 135 | mov x0, sp |
| 136 | b print_exception |
| 137 | endfunc crash_dump |