50928e75815a082310be204c5292bd72a9ce4733
[reactos.git] / include / asm / kxarm.h
1
2
3 #ifdef _MSC_VER
4
5 /* Globals */
6 GBLS AreaName
7 GBLS FuncName
8 GBLS PrologName
9 GBLS FuncEndName
10 AreaName SETS "|.text|"
11
12 MACRO
13 TEXTAREA
14 AREA |.text|,ALIGN=2,CODE,READONLY
15 AreaName SETS "|.text|"
16 MEND
17
18 MACRO
19 NESTED_ENTRY $Name
20 FuncName SETS "$Name"
21 PrologName SETS "$Name":CC:"_Prolog"
22 FuncEndName SETS "$Name":CC:"_end"
23 AREA |.pdata|,ALIGN=2,PDATA
24 ALIGN 2
25 EXPORT $FuncName [FUNC]
26 $FuncName
27 ROUT
28 MEND
29
30 MACRO
31 PROLOG_END
32 $PrologName
33 MEND
34
35 MACRO
36 ENTRY_END $Name
37 $FuncEndName
38 MEND
39
40 MACRO
41 LEAF_ENTRY $Name
42 FuncName SETS "$Name"
43 PrologName SETS "Invalid Prolog"
44 FuncEndName SETS "$Name":CC:"_end"
45 ALIGN 2
46 EXPORT $FuncName [FUNC]
47 $FuncName
48 ROUT
49 MEND
50
51 MACRO
52 LEAF_END $Name
53 $FuncEndName
54 MEND
55
56 MACRO
57 TRAP_PROLOG $Abort
58 fixme
59 MEND
60
61 MACRO
62 SYSCALL_PROLOG $Abort
63 fixme
64 MEND
65
66 MACRO
67 TRAP_EPILOG $SystemCall
68 fixme
69 MEND
70
71 #else
72
73 /* Compatibility define */
74 #define EQU .equ
75
76 .macro IMPORT Name
77 /* Ignore */
78 .endm
79
80 .macro TEXTAREA
81 .section .text, "rx"
82 .align 2
83 .endm
84
85 .macro NESTED_ENTRY Name
86 FuncName .equ &Name
87 PrologName .equ &Name&_Prolog
88 FuncEndName .equ &Name&_end
89 .global &FuncName
90 .align 2
91 .func &FuncName
92 &FuncName:
93 .endm
94
95 .macro PROLOG_END
96 \PrologName:
97 .endm
98
99 .macro ENTRY_END Name
100 &FuncEndName:
101 .endfunc
102 .endm
103
104 .macro TRAP_PROLOG Abort
105 //
106 // Fixup lr
107 //
108 .if \Abort
109 sub lr, lr, #8
110 .else
111 sub lr, lr, #4
112 .endif
113
114 // Save the bottom 4 registers
115 stmdb sp, {r0-r3}
116
117 // Save the abort lr, sp, spsr, cpsr
118 mov r0, lr
119 mov r1, sp
120 mrs r2, cpsr
121 mrs r3, spsr
122
123 // Switch to SVC mode
124 bic r2, r2, #CPSR_MODES
125 orr r2, r2, #CPSR_SVC_MODE
126 msr cpsr_c, r2
127
128 // Save the SVC sp before we modify it
129 mov r2, sp
130
131 // Make space for the trap frame
132 sub sp, sp, #TrapFrameLength
133
134 // Save abt32 state
135 str r0, [sp, #TrPc]
136 str lr, [sp, #TrSvcLr]
137 str r2, [sp, #TrSvcSp]
138
139 // Restore the saved SPSR
140 msr spsr_all, r3
141
142 // Restore our 4 registers
143 ldmdb r1, {r0-r3}
144
145 // Build trap frame
146 // FIXME: Change to stmdb later
147 str r0, [sp, #TrR0]
148 str r1, [sp, #TrR1]
149 str r2, [sp, #TrR2]
150 str r3, [sp, #TrR3]
151 str r4, [sp, #TrR4]
152 str r5, [sp, #TrR5]
153 str r6, [sp, #TrR6]
154 str r7, [sp, #TrR7]
155 str r8, [sp, #TrR8]
156 str r9, [sp, #TrR9]
157 str r10, [sp, #TrR10]
158 str r11, [sp, #TrR11]
159 str r12, [sp, #TrR12]
160 mov r12, sp
161 add r12, r12, #TrUserSp
162 stm r12, {sp, lr}^
163 mrs r0, spsr_all
164 str r0, [sp, #TrSpsr]
165 ldr r0, =0xBADB0D00
166 str r0, [sp, #TrDbgArgMark]
167 .endm
168
169 .macro SYSCALL_PROLOG
170 // Make space for the trap frame
171 sub sp, sp, #TrapFrameLength
172
173 // Build trap frame
174 // FIXME: Change to stmdb later
175 str r0, [sp, #TrR0]
176 str r1, [sp, #TrR1]
177 str r2, [sp, #TrR2]
178 str r3, [sp, #TrR3]
179 str r4, [sp, #TrR4]
180 str r5, [sp, #TrR5]
181 str r6, [sp, #TrR6]
182 str r7, [sp, #TrR7]
183 str r8, [sp, #TrR8]
184 str r9, [sp, #TrR9]
185 str r10, [sp, #TrR10]
186 str r11, [sp, #TrR11]
187 str r12, [sp, #TrR12]
188 mov r12, sp
189 add r12, r12, #TrUserSp
190 stm r12, {sp, lr}^
191 str sp, [sp, #TrSvcSp]
192 str lr, [sp, #TrPc]
193 mrs r0, spsr_all
194 str r0, [sp, #TrSpsr]
195 ldr r0, =0xBADB0D00
196 str r0, [sp, #TrDbgArgMark]
197 .endm
198
199 .macro TRAP_EPILOG SystemCall
200 // ASSERT(TrapFrame->DbgArgMark == 0xBADB0D00)
201 ldr r0, [sp, #TrDbgArgMark]
202 ldr r1, =0xBADB0D00
203 cmp r0, r1
204 bne 1f
205
206 // Get the SPSR and restore it
207 ldr r0, [sp, #TrSpsr]
208 msr spsr_all, r0
209
210 // Restore the registers
211 // FIXME: Use LDMIA later
212 mov r0, sp
213 add r0, r0, #TrUserSp
214 ldm r0, {sp, lr}^
215 ldr r0, [sp, #TrR0]
216 ldr r1, [sp, #TrR1]
217 ldr r2, [sp, #TrR2]
218 ldr r3, [sp, #TrR3]
219 ldr r4, [sp, #TrR4]
220 ldr r5, [sp, #TrR5]
221 ldr r6, [sp, #TrR6]
222 ldr r7, [sp, #TrR7]
223 ldr r8, [sp, #TrR8]
224 ldr r9, [sp, #TrR9]
225 ldr r10, [sp, #TrR10]
226 ldr r11, [sp, #TrR11]
227 ldr r12, [sp, #TrR12]
228
229 // Restore program execution state
230 .if \SystemCall
231 ldr lr, [sp, #TrPc]
232 add sp, sp, #TrapFrameLength
233 movs pc, lr
234 .else
235 add sp, sp, #TrSvcSp
236 ldmia sp, {sp, lr, pc}^
237 .endif
238 1:
239 b .
240 .endm
241
242 #endif
243
244