Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, Arm Limited. All rights reserved. |
| 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 | */ |
Daniel Boulby | 08798ac | 2021-04-06 14:30:19 +0100 | [diff] [blame^] | 34 | unhandled_exception sync_exception_sp_elx |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 35 | |
Daniel Boulby | 08798ac | 2021-04-06 14:30:19 +0100 | [diff] [blame^] | 36 | vector_entry irq_sp_elx |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 37 | b irq_vector_entry |
Daniel Boulby | 08798ac | 2021-04-06 14:30:19 +0100 | [diff] [blame^] | 38 | end_vector_entry irq_sp_elx |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 39 | |
Daniel Boulby | 08798ac | 2021-04-06 14:30:19 +0100 | [diff] [blame^] | 40 | unhandled_exception fiq_sp_elx |
| 41 | unhandled_exception serror_sp_elx |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 42 | |
Sandrine Bailleux | 8b170a2 | 2019-01-11 18:47:26 +0100 | [diff] [blame] | 43 | /* |
| 44 | * Lower EL using AArch64 : 0x400 - 0x600. |
| 45 | */ |
Daniel Boulby | 08798ac | 2021-04-06 14:30:19 +0100 | [diff] [blame^] | 46 | unhandled_exception sync_exception_aarch64 |
| 47 | unhandled_exception irq_aarch64 |
| 48 | unhandled_exception fiq_aarch64 |
| 49 | unhandled_exception serror_aarch64 |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 50 | |
Sandrine Bailleux | 8b170a2 | 2019-01-11 18:47:26 +0100 | [diff] [blame] | 51 | /* |
| 52 | * Lower EL using AArch32 : 0x600 - 0x800. |
| 53 | */ |
Daniel Boulby | 08798ac | 2021-04-06 14:30:19 +0100 | [diff] [blame^] | 54 | unhandled_exception sync_exception_aarch32 |
| 55 | unhandled_exception irq_aarch32 |
| 56 | unhandled_exception fiq_aarch32 |
| 57 | unhandled_exception serror_aarch32 |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 58 | |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 59 | .macro save_gp_regs |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 60 | stp x0, x1, [sp, #0x0] |
| 61 | stp x2, x3, [sp, #0x10] |
| 62 | stp x4, x5, [sp, #0x20] |
| 63 | stp x6, x7, [sp, #0x30] |
| 64 | stp x8, x9, [sp, #0x40] |
| 65 | stp x10, x11, [sp, #0x50] |
| 66 | stp x12, x13, [sp, #0x60] |
| 67 | stp x14, x15, [sp, #0x70] |
| 68 | stp x16, x17, [sp, #0x80] |
| 69 | stp x18, x19, [sp, #0x90] |
| 70 | stp x20, x21, [sp, #0xa0] |
| 71 | stp x22, x23, [sp, #0xb0] |
| 72 | stp x24, x25, [sp, #0xc0] |
| 73 | stp x26, x27, [sp, #0xd0] |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 74 | stp x28, x29, [sp, #0xe0] |
Sandrine Bailleux | a43b003 | 2019-01-14 14:04:32 +0100 | [diff] [blame] | 75 | /* We push xzr simply to keep the stack 16-byte aligned. */ |
| 76 | stp x30, xzr, [sp, #0xf0] |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 77 | .endm |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 78 | |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 79 | .macro restore_gp_regs |
Sandrine Bailleux | a43b003 | 2019-01-14 14:04:32 +0100 | [diff] [blame] | 80 | ldp x30, xzr, [sp, #0xf0] |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 81 | ldp x28, x29, [sp, #0xe0] |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 82 | ldp x26, x27, [sp, #0xd0] |
| 83 | ldp x24, x25, [sp, #0xc0] |
| 84 | ldp x22, x23, [sp, #0xb0] |
| 85 | ldp x20, x21, [sp, #0xa0] |
| 86 | ldp x18, x19, [sp, #0x90] |
| 87 | ldp x16, x17, [sp, #0x80] |
| 88 | ldp x14, x15, [sp, #0x70] |
| 89 | ldp x12, x13, [sp, #0x60] |
| 90 | ldp x10, x11, [sp, #0x50] |
| 91 | ldp x8, x9, [sp, #0x40] |
| 92 | ldp x6, x7, [sp, #0x30] |
| 93 | ldp x4, x5, [sp, #0x20] |
| 94 | ldp x2, x3, [sp, #0x10] |
| 95 | ldp x0, x1, [sp, #0x0] |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 96 | .endm |
| 97 | |
| 98 | func irq_vector_entry |
| 99 | sub sp, sp, #0x100 |
| 100 | save_gp_regs |
| 101 | bl tftf_irq_handler_dispatcher |
| 102 | restore_gp_regs |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 103 | add sp, sp, #0x100 |
Sandrine Bailleux | d101967 | 2019-01-11 18:39:24 +0100 | [diff] [blame] | 104 | eret |
| 105 | endfunc irq_vector_entry |
Sandrine Bailleux | a43b003 | 2019-01-14 14:04:32 +0100 | [diff] [blame] | 106 | |
| 107 | func crash_dump |
| 108 | /* Save general-purpose registers on the stack. */ |
| 109 | sub sp, sp, #0x100 |
| 110 | save_gp_regs |
| 111 | |
| 112 | /* Save original stack pointer value on the stack. */ |
| 113 | add x1, sp, #0x100 |
| 114 | str x1, [sp, #0xf8] |
| 115 | |
| 116 | /* Print the saved CPU context on the UART. */ |
| 117 | mov x0, sp |
| 118 | b print_exception |
| 119 | endfunc crash_dump |