blob: 3dedb923011bc328bc76cdb45694447d73217d8f [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
Olivier Deprezc8f6a672022-01-13 13:44:53 +00002 * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <asm_macros.S>
8
9 .globl tftf_vector
10
Sandrine Bailleuxa43b0032019-01-14 14:04:32 +010011/*
12 * Exception vector code for unhandled exceptions.
13 * Print a crash dump on the UART and loops forever.
14 */
Sandrine Bailleuxe7604492019-01-14 09:37:28 +010015.macro unhandled_exception name
16 vector_entry \name
Sandrine Bailleuxa43b0032019-01-14 14:04:32 +010017 b crash_dump
Sandrine Bailleuxe7604492019-01-14 09:37:28 +010018 end_vector_entry \name
19.endm
20
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020021vector_base tftf_vector
Sandrine Bailleux8b170a22019-01-11 18:47:26 +010022
23 /*
24 * Current EL with SP0 : 0x0 - 0x200.
25 */
Daniel Boulby08798ac2021-04-06 14:30:19 +010026unhandled_exception sync_exception_sp_el0
27unhandled_exception irq_sp_el0
28unhandled_exception fiq_sp_el0
29unhandled_exception serror_sp_el0
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020030
Sandrine Bailleux8b170a22019-01-11 18:47:26 +010031 /*
32 * Current EL with SPx : 0x200 - 0x400.
33 */
Olivier Deprezc8f6a672022-01-13 13:44:53 +000034vector_entry sync_spx
35 b sync_exception_vector_entry
36end_vector_entry sync_spx
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020037
Daniel Boulby08798ac2021-04-06 14:30:19 +010038vector_entry irq_sp_elx
Sandrine Bailleuxd1019672019-01-11 18:39:24 +010039 b irq_vector_entry
Daniel Boulby08798ac2021-04-06 14:30:19 +010040end_vector_entry irq_sp_elx
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020041
Daniel Boulby08798ac2021-04-06 14:30:19 +010042unhandled_exception fiq_sp_elx
43unhandled_exception serror_sp_elx
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020044
Sandrine Bailleux8b170a22019-01-11 18:47:26 +010045 /*
46 * Lower EL using AArch64 : 0x400 - 0x600.
47 */
Daniel Boulby08798ac2021-04-06 14:30:19 +010048unhandled_exception sync_exception_aarch64
49unhandled_exception irq_aarch64
50unhandled_exception fiq_aarch64
51unhandled_exception serror_aarch64
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020052
Sandrine Bailleux8b170a22019-01-11 18:47:26 +010053 /*
54 * Lower EL using AArch32 : 0x600 - 0x800.
55 */
Daniel Boulby08798ac2021-04-06 14:30:19 +010056unhandled_exception sync_exception_aarch32
57unhandled_exception irq_aarch32
58unhandled_exception fiq_aarch32
59unhandled_exception serror_aarch32
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020060
Sandrine Bailleuxd1019672019-01-11 18:39:24 +010061.macro save_gp_regs
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020062 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 Bailleuxd1019672019-01-11 18:39:24 +010076 stp x28, x29, [sp, #0xe0]
Sandrine Bailleuxa43b0032019-01-14 14:04:32 +010077 /* We push xzr simply to keep the stack 16-byte aligned. */
78 stp x30, xzr, [sp, #0xf0]
Sandrine Bailleuxd1019672019-01-11 18:39:24 +010079.endm
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020080
Sandrine Bailleuxd1019672019-01-11 18:39:24 +010081.macro restore_gp_regs
Sandrine Bailleuxa43b0032019-01-14 14:04:32 +010082 ldp x30, xzr, [sp, #0xf0]
Sandrine Bailleuxd1019672019-01-11 18:39:24 +010083 ldp x28, x29, [sp, #0xe0]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020084 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 Bailleuxd1019672019-01-11 18:39:24 +010098.endm
99
Olivier Deprezc8f6a672022-01-13 13:44:53 +0000100func 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
1110: restore_gp_regs
112 add sp, sp, #0x100
113 eret
114endfunc sync_exception_vector_entry
115
Sandrine Bailleuxd1019672019-01-11 18:39:24 +0100116func irq_vector_entry
117 sub sp, sp, #0x100
118 save_gp_regs
119 bl tftf_irq_handler_dispatcher
120 restore_gp_regs
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200121 add sp, sp, #0x100
Sandrine Bailleuxd1019672019-01-11 18:39:24 +0100122 eret
123endfunc irq_vector_entry
Sandrine Bailleuxa43b0032019-01-14 14:04:32 +0100124
125func 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
137endfunc crash_dump