forked from NienfengYao/armv8-bare-metal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector.S
294 lines (257 loc) · 5.84 KB
/
vector.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/* -*- mode: asm; coding:utf-8 -*- */
/************************************************************************/
/* OS kernel sample */
/* Copyright 2014 Takeharu KATO */
/* */
/* Exception vector */
/* */
/************************************************************************/
#define ASM_FILE 1
#include "exception.h"
.section ".text.boot"
.macro build_trapframe exc_type
/*
* store generic registers from (x29,x30) pair to (x1,x2) pair.
*/
stp x29, x30, [sp, #-16]!
stp x27, x28, [sp, #-16]!
stp x25, x26, [sp, #-16]!
stp x23, x24, [sp, #-16]!
stp x21, x22, [sp, #-16]!
stp x19, x20, [sp, #-16]!
stp x17, x18, [sp, #-16]!
stp x15, x16, [sp, #-16]!
stp x13, x14, [sp, #-16]!
stp x11, x12, [sp, #-16]!
stp x9, x10, [sp, #-16]!
stp x7, x8, [sp, #-16]!
stp x5, x6, [sp, #-16]!
stp x3, x4, [sp, #-16]!
stp x1, x2, [sp, #-16]!
/*
* Store (spsr, x0)
*/
mrs x21, spsr_el1
stp x21, x0, [sp, #-16]!
/*
* Allocate a room for sp_el0 and store elr
*/
mrs x21, elr_el1
stp xzr, x21, [sp, #-16]!
/*
* store exception type and esr
*/
mov x21, #(\exc_type)
mrs x22, esr_el1
stp x21, x22, [sp, #-16]!
.endm
.macro store_traped_sp
mrs x21, sp_el0
str x21, [sp, #EXC_EXC_SP_OFFSET]
.endm
.macro call_common_trap_handler
mov x0, sp
bl common_trap_handler
.endm
.macro store_nested_sp
mov x21, sp
add x21, x21, #EXC_FRAME_SIZE
str x21, [sp, #EXC_EXC_SP_OFFSET]
.endm
.macro restore_traped_sp
ldr x21, [sp, #EXC_EXC_SP_OFFSET]
msr sp_el0, x21
.endm
.macro restore_trapframe
/*
* Drop exception type, esr,
*/
add sp, sp, #16
/*
* Drop exception stack pointer and restore elr_el1
*/
ldp x21, x22, [sp], #16
msr elr_el1, x22
/*
* Retore spsr and x0
*/
ldp x21, x0, [sp], #16
msr spsr_el1, x21
/*
* Restore generic registers from (x29,x30) pair to (x1,x2) pair.
*/
ldp x1, x2, [sp], #16
ldp x3, x4, [sp], #16
ldp x5, x6, [sp], #16
ldp x7, x8, [sp], #16
ldp x9, x10, [sp], #16
ldp x11, x12, [sp], #16
ldp x13, x14, [sp], #16
ldp x15, x16, [sp], #16
ldp x17, x18, [sp], #16
ldp x19, x20, [sp], #16
ldp x21, x22, [sp], #16
ldp x23, x24, [sp], #16
ldp x25, x26, [sp], #16
ldp x27, x28, [sp], #16
ldp x29, x30, [sp], #16
eret
.endm
/*
* Exception vectors.
*/
vector_table_align
.globl vectors
vectors:
/*
* Current EL with SP0
*/
vector_entry_align
b _curr_el_sp0_sync /* Synchronous */
vector_entry_align
b _curr_el_sp0_irq /* IRQ/vIRQ */
vector_entry_align
b _curr_el_sp0_fiq /* FIQ/vFIQ */
vector_entry_align
b _curr_el_sp0_serror /* SError/vSError */
/*
* Current EL with SPx
*/
vector_entry_align
b _curr_el_spx_sync /* Synchronous */
vector_entry_align
b _curr_el_spx_irq /* IRQ/vIRQ */
vector_entry_align
b _curr_el_spx_fiq /* FIQ/vFIQ */
vector_entry_align
b _curr_el_spx_serror /* SError/vSError */
/*
* Lower EL using AArch64
*/
vector_entry_align
b _lower_el_aarch64_sync
vector_entry_align
b _lower_el_aarch64_irq
vector_entry_align
b _lower_el_aarch64_fiq
vector_entry_align
b _lower_el_aarch64_serror
/*
* Lower EL using AArch32
*/
vector_entry_align
b _lower_el_aarch32_sync
vector_entry_align
b _lower_el_aarch32_irq
vector_entry_align
b _lower_el_aarch32_fiq
vector_entry_align
b _lower_el_aarch32_serror
text_align
_curr_el_sp0_sync:
build_trapframe AARCH64_EXC_SYNC_SP0
store_traped_sp
call_common_trap_handler
restore_traped_sp
restore_trapframe
text_align
_curr_el_sp0_irq:
build_trapframe AARCH64_EXC_IRQ_SP0
store_traped_sp
call_common_trap_handler
restore_traped_sp
restore_trapframe
text_align
_curr_el_sp0_fiq:
build_trapframe AARCH64_EXC_FIQ_SP0
store_traped_sp
call_common_trap_handler
restore_traped_sp
restore_trapframe
text_align
_curr_el_sp0_serror:
build_trapframe AARCH64_EXC_SERR_SP0
store_traped_sp
call_common_trap_handler
restore_traped_sp
restore_trapframe
text_align
_curr_el_spx_sync:
build_trapframe AARCH64_EXC_SYNC_SPX
store_nested_sp
call_common_trap_handler
restore_trapframe
text_align
_curr_el_spx_irq:
build_trapframe AARCH64_EXC_IRQ_SPX
store_nested_sp
call_common_trap_handler
restore_trapframe
text_align
_curr_el_spx_fiq:
build_trapframe AARCH64_EXC_FIQ_SPX
store_nested_sp
call_common_trap_handler
restore_trapframe
text_align
_curr_el_spx_serror:
build_trapframe AARCH64_EXC_SERR_SPX
store_nested_sp
call_common_trap_handler
restore_trapframe
text_align
_lower_el_aarch64_sync:
build_trapframe AARCH64_EXC_SYNC_AARCH64
store_traped_sp
call_common_trap_handler
restore_traped_sp
restore_trapframe
text_align
_lower_el_aarch64_irq:
build_trapframe AARCH64_EXC_IRQ_AARCH64
store_traped_sp
call_common_trap_handler
restore_traped_sp
restore_trapframe
text_align
_lower_el_aarch64_fiq:
build_trapframe AARCH64_EXC_FIQ_AARCH64
store_traped_sp
call_common_trap_handler
restore_traped_sp
restore_trapframe
text_align
_lower_el_aarch64_serror:
build_trapframe AARCH64_EXC_SERR_AARCH64
store_traped_sp
call_common_trap_handler
restore_traped_sp
restore_trapframe
text_align
_lower_el_aarch32_sync:
build_trapframe AARCH64_EXC_SYNC_AARCH32
store_traped_sp
call_common_trap_handler
restore_traped_sp
restore_trapframe
text_align
_lower_el_aarch32_irq:
build_trapframe AARCH64_EXC_IRQ_AARCH32
store_traped_sp
call_common_trap_handler
restore_traped_sp
restore_trapframe
text_align
_lower_el_aarch32_fiq:
build_trapframe AARCH64_EXC_FIQ_AARCH32
store_traped_sp
call_common_trap_handler
restore_traped_sp
restore_trapframe
text_align
_lower_el_aarch32_serror:
build_trapframe AARCH64_EXC_SERR_AARCH32
store_traped_sp
call_common_trap_handler
restore_traped_sp
restore_trapframe