blob: 210dd3e4281db7e60ed7a8794d38eb7a72363893 [file] [log] [blame]
nabkah01002e5692022-10-10 12:36:46 +01001/*
AlexeiFedorov2f30f102023-03-13 19:37:46 +00002 * Copyright (c) 2022-2023, Arm Limited. All rights reserved.
nabkah01002e5692022-10-10 12:36:46 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <asm_macros.S>
8
9 .globl realm_vector
10
11/*
12 * Exception vector code for unhandled exceptions.
13 * Print a crash dump on the UART and loops forever.
14 */
15.macro unhandled_exception name
16 vector_entry \name
AlexeiFedorov2f30f102023-03-13 19:37:46 +000017 b crash_dump
nabkah01002e5692022-10-10 12:36:46 +010018 end_vector_entry \name
19.endm
20
21vector_base realm_vector
22
23 /*
24 * Current EL with SP0 : 0x0 - 0x200.
25 */
26unhandled_exception sync_sp0
27unhandled_exception irq_sp0
28unhandled_exception fiq_sp0
29unhandled_exception serr_sp0
30
31 /*
32 * Current EL with SPx : 0x200 - 0x400.
33 */
34vector_entry sync_spx
35 b sync_exception_vector_entry
36end_vector_entry sync_spx
37
38vector_entry irq_spx
39 b interrupt_vector_entry
40end_vector_entry irq_spx
41
42vector_entry fiq_spx
43 b interrupt_vector_entry
44end_vector_entry fiq_spx
45
46unhandled_exception serr_spx
47
48 /*
49 * Lower EL using AArch64 : 0x400 - 0x600.
50 */
51unhandled_exception sync_a64
52unhandled_exception irq_a64
53unhandled_exception fiq_a64
54unhandled_exception serr_a64
55
56 /*
57 * Lower EL using AArch32 : 0x600 - 0x800.
58 */
59unhandled_exception sync_a32
60unhandled_exception irq_a32
61unhandled_exception fiq_a32
62unhandled_exception serr_a32
63
64.macro save_gp_regs
65 stp x0, x1, [sp, #0x0]
66 stp x2, x3, [sp, #0x10]
67 stp x4, x5, [sp, #0x20]
68 stp x6, x7, [sp, #0x30]
69 stp x8, x9, [sp, #0x40]
70 stp x10, x11, [sp, #0x50]
71 stp x12, x13, [sp, #0x60]
72 stp x14, x15, [sp, #0x70]
73 stp x16, x17, [sp, #0x80]
74 stp x18, x19, [sp, #0x90]
75 stp x20, x21, [sp, #0xa0]
76 stp x22, x23, [sp, #0xb0]
77 stp x24, x25, [sp, #0xc0]
78 stp x26, x27, [sp, #0xd0]
79 stp x28, x29, [sp, #0xe0]
80 /* We push xzr simply to keep the stack 16-byte aligned. */
81 stp x30, xzr, [sp, #0xf0]
82.endm
83
84.macro restore_gp_regs
85 ldp x30, xzr, [sp, #0xf0]
86 ldp x28, x29, [sp, #0xe0]
87 ldp x26, x27, [sp, #0xd0]
88 ldp x24, x25, [sp, #0xc0]
89 ldp x22, x23, [sp, #0xb0]
90 ldp x20, x21, [sp, #0xa0]
91 ldp x18, x19, [sp, #0x90]
92 ldp x16, x17, [sp, #0x80]
93 ldp x14, x15, [sp, #0x70]
94 ldp x12, x13, [sp, #0x60]
95 ldp x10, x11, [sp, #0x50]
96 ldp x8, x9, [sp, #0x40]
97 ldp x6, x7, [sp, #0x30]
98 ldp x4, x5, [sp, #0x20]
99 ldp x2, x3, [sp, #0x10]
100 ldp x0, x1, [sp, #0x0]
101.endm
102
103func sync_exception_vector_entry
104 sub sp, sp, #0x100
105 save_gp_regs
106 mov x19, sp
107 bl tftf_sync_exception_handler
108 cbnz x0, 0f
AlexeiFedorov2f30f102023-03-13 19:37:46 +0000109 mov x0, x19
nabkah01002e5692022-10-10 12:36:46 +0100110 /* Save original stack pointer value on the stack */
111 add x1, x0, #0x100
112 str x1, [x0, #0xf8]
Arunachalam Ganapathy5f0afde2023-11-20 12:05:50 +0000113 b realm_print_exception
nabkah01002e5692022-10-10 12:36:46 +01001140: restore_gp_regs
115 add sp, sp, #0x100
116 eret
117endfunc sync_exception_vector_entry
118
119func interrupt_vector_entry
120 sub sp, sp, #0x100
121 save_gp_regs
122 bl realm_interrupt_handler
123 restore_gp_regs
124 add sp, sp, #0x100
125 eret
126endfunc interrupt_vector_entry
127
128func crash_dump
129 /* Save general-purpose registers on the stack. */
130 sub sp, sp, #0x100
131 save_gp_regs
132
133 /* Save original stack pointer value on the stack. */
134 add x1, sp, #0x100
135 str x1, [sp, #0xf8]
136
137 /* Print the saved CPU context on the UART. */
138 mov x0, sp
Arunachalam Ganapathy5f0afde2023-11-20 12:05:50 +0000139 b realm_print_exception
nabkah01002e5692022-10-10 12:36:46 +0100140endfunc crash_dump