@@ -13,6 +13,103 @@ mod entry {
13
13
".weak _DYNAMIC" ,
14
14
".hidden _DYNAMIC" ,
15
15
".globl _start" ,
16
+
17
+ // Good only for the EL1
18
+ " __exception_common:" ,
19
+
20
+ "str x29, [sp, #-16]!" ,
21
+ "stp x27, x28, [sp, #-16]!" ,
22
+ "stp x25, x26, [sp, #-16]!" ,
23
+ "stp x23, x24, [sp, #-16]!" ,
24
+ "stp x21, x22, [sp, #-16]!" ,
25
+ "stp x19, x20, [sp, #-16]!" ,
26
+ "stp x17, x18, [sp, #-16]!" ,
27
+ "stp x15, x16, [sp, #-16]!" ,
28
+ "stp x13, x14, [sp, #-16]!" ,
29
+ "stp x11, x12, [sp, #-16]!" ,
30
+ "stp x9, x10, [sp, #-16]!" ,
31
+ "stp x7, x8, [sp, #-16]!" ,
32
+ "stp x5, x6, [sp, #-16]!" ,
33
+ "stp x3, x4, [sp, #-16]!" ,
34
+ "stp x1, x2, [sp, #-16]!" ,
35
+
36
+ "add sp, sp, #-16" ,
37
+
38
+ "mrs x2, spsr_el1" ,
39
+ "mrs x1, elr_el1" ,
40
+ "stp x1, x2, [sp, #-16]!" ,
41
+
42
+ "str x0, [sp, #-16]!" ,
43
+
44
+ "mrs x2, tpidr_el1" ,
45
+ "add x1, sp, #38*8" ,
46
+ "stp x1, x2, [sp, #32]" ,
47
+
48
+ "mov x0, sp" ,
49
+ "bl exception_handler" ,
50
+
51
+ "ldr x1, [sp, #40]" ,
52
+ "msr tpidr_el1, x1" ,
53
+
54
+ "add sp, sp, #16" ,
55
+
56
+ "ldp x1, x2, [sp], #16" ,
57
+ "msr elr_el1, x1" ,
58
+ "msr spsr_el1, x2" ,
59
+
60
+ "add sp, sp, #16" ,
61
+
62
+ "ldp x1, x2, [sp], #16" ,
63
+ "ldp x3, x4, [sp], #16" ,
64
+ "ldp x5, x6, [sp], #16" ,
65
+ "ldp x7, x8, [sp], #16" ,
66
+ "ldp x9, x10, [sp], #16" ,
67
+ "ldp x11, x12, [sp], #16" ,
68
+ "ldp x13, x14, [sp], #16" ,
69
+ "ldp x15, x16, [sp], #16" ,
70
+ "ldp x17, x18, [sp], #16" ,
71
+ "ldp x19, x20, [sp], #16" ,
72
+ "ldp x21, x22, [sp], #16" ,
73
+ "ldp x23, x24, [sp], #16" ,
74
+ "ldp x25, x26, [sp], #16" ,
75
+ "ldp x27, x28, [sp], #16" ,
76
+ "ldr x29, [sp], #16" ,
77
+ "ldp lr, x0, [sp], #16" ,
78
+
79
+ "eret" ,
80
+
81
+ ".macro EXCEPTION_ENTRY source, kind" ,
82
+ ".align 7" ,
83
+ " stp lr, x0, [sp, #-16]!" ,
84
+ " mov x0, \\ source" ,
85
+ " movk x0, \\ kind, lsl #16" ,
86
+ " b __exception_common" ,
87
+ ".endm" ,
88
+
89
+ // Vector table must be aligned to a 2KB boundary
90
+ ".balign 0x800" ,
91
+ " _vector_table_el1:" ,
92
+ // Target and source at same exception level with source SP = SP_EL0
93
+ " EXCEPTION_ENTRY #0x0, #0x0" , // Synchronous exception
94
+ " EXCEPTION_ENTRY #0x0, #0x1" , // IRQ
95
+ " EXCEPTION_ENTRY #0x0, #0x2" , // FIQ
96
+ " EXCEPTION_ENTRY #0x0, #0x3" , // SError
97
+ // Target and source at same exception level with source SP = SP_ELx
98
+ " EXCEPTION_ENTRY #0x1, #0x0 // Synchronous exception" ,
99
+ " EXCEPTION_ENTRY #0x1, #0x1 // IRQ" ,
100
+ " EXCEPTION_ENTRY #0x1, #0x2 // FIQ" ,
101
+ " EXCEPTION_ENTRY #0x1, #0x3 // SError" ,
102
+ // Source is at lower exception level running on AArch64
103
+ " EXCEPTION_ENTRY #0x2, #0x0" , // Synchronous exception
104
+ " EXCEPTION_ENTRY #0x2, #0x1" , // IRQ
105
+ " EXCEPTION_ENTRY #0x2, #0x2" , // FIQ
106
+ " EXCEPTION_ENTRY #0x2, #0x3" , // SError
107
+ // Source is at lower exception level running on AArch32
108
+ " EXCEPTION_ENTRY #0x3, #0x0" , // Synchronous exception
109
+ " EXCEPTION_ENTRY #0x3, #0x1" , // IRQ
110
+ " EXCEPTION_ENTRY #0x3, #0x2" , // FIQ
111
+ " EXCEPTION_ENTRY #0x3, #0x3" , // SError
112
+
16
113
"_start:" ,
17
114
"mov x19, x0" ,
18
115
"adrp x1, {stack}" ,
@@ -27,6 +124,12 @@ mod entry {
27
124
"msr CPACR_EL1, x0" ,
28
125
"isb" ,
29
126
127
+ // Set up the vector table.
128
+ "adrp x3, _vector_table_el1,
129
+ " add x3, x3, : lo12: _vector_table_el1,
130
+ "msr VBAR_EL1, x3,
131
+ " isb,
132
+
30
133
"adrp x0, __ehdr_start" ,
31
134
"add x0, x0, :lo12:__ehdr_start" ,
32
135
"mov x1, x0" ,
@@ -35,6 +138,7 @@ mod entry {
35
138
"bl {relocate}" ,
36
139
"mov x0, x19" ,
37
140
"b {entry}" ,
141
+
38
142
relocate = sym minimal_rt:: reloc:: relocate,
39
143
stack = sym STACK ,
40
144
entry = sym crate :: entry,
0 commit comments