[CRT/OLDNAMES]
[reactos.git] / reactos / 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 #define CR 13
72 #define LF 10
73 #define NUL 0
74
75 #define ASCII dcb
76
77 MACRO
78 UNIMPLEMENTED $Name
79 MEND
80
81 #else
82
83 /* Compatibility define */
84 #define EQU .equ
85
86 .macro IMPORT Name
87 /* Ignore */
88 .endm
89
90 .macro TEXTAREA
91 .section .text, "rx"
92 .align 2
93 .endm
94
95 .macro NESTED_ENTRY Name
96 FuncName .equ &Name
97 PrologName .equ &Name&_Prolog
98 FuncEndName .equ &Name&_end
99 .global &FuncName
100 .align 2
101 .func &FuncName
102 &FuncName:
103 .endm
104
105 .macro PROLOG_END
106 \PrologName:
107 .endm
108
109 .macro ENTRY_END Name
110 &FuncEndName:
111 .endfunc
112 .endm
113
114 .macro TRAP_PROLOG Abort
115 //
116 // Fixup lr
117 //
118 .if \Abort
119 sub lr, lr, #8
120 .else
121 sub lr, lr, #4
122 .endif
123
124 // Save the bottom 4 registers
125 stmdb sp, {r0-r3}
126
127 // Save the abort lr, sp, spsr, cpsr
128 mov r0, lr
129 mov r1, sp
130 mrs r2, cpsr
131 mrs r3, spsr
132
133 // Switch to SVC mode
134 bic r2, r2, #CPSR_MODES
135 orr r2, r2, #CPSR_SVC_MODE
136 msr cpsr_c, r2
137
138 // Save the SVC sp before we modify it
139 mov r2, sp
140
141 // Make space for the trap frame
142 sub sp, sp, #TrapFrameLength
143
144 // Save abt32 state
145 str r0, [sp, #TrPc]
146 str lr, [sp, #TrSvcLr]
147 str r2, [sp, #TrSvcSp]
148
149 // Restore the saved SPSR
150 msr spsr_all, r3
151
152 // Restore our 4 registers
153 ldmdb r1, {r0-r3}
154
155 // Build trap frame
156 // FIXME: Change to stmdb later
157 str r0, [sp, #TrR0]
158 str r1, [sp, #TrR1]
159 str r2, [sp, #TrR2]
160 str r3, [sp, #TrR3]
161 str r4, [sp, #TrR4]
162 str r5, [sp, #TrR5]
163 str r6, [sp, #TrR6]
164 str r7, [sp, #TrR7]
165 str r8, [sp, #TrR8]
166 str r9, [sp, #TrR9]
167 str r10, [sp, #TrR10]
168 str r11, [sp, #TrR11]
169 str r12, [sp, #TrR12]
170 mov r12, sp
171 add r12, r12, #TrUserSp
172 stm r12, {sp, lr}^
173 mrs r0, spsr_all
174 str r0, [sp, #TrSpsr]
175 ldr r0, =0xBADB0D00
176 str r0, [sp, #TrDbgArgMark]
177 .endm
178
179 .macro SYSCALL_PROLOG
180 // Make space for the trap frame
181 sub sp, sp, #TrapFrameLength
182
183 // Build trap frame
184 // FIXME: Change to stmdb later
185 str r0, [sp, #TrR0]
186 str r1, [sp, #TrR1]
187 str r2, [sp, #TrR2]
188 str r3, [sp, #TrR3]
189 str r4, [sp, #TrR4]
190 str r5, [sp, #TrR5]
191 str r6, [sp, #TrR6]
192 str r7, [sp, #TrR7]
193 str r8, [sp, #TrR8]
194 str r9, [sp, #TrR9]
195 str r10, [sp, #TrR10]
196 str r11, [sp, #TrR11]
197 str r12, [sp, #TrR12]
198 mov r12, sp
199 add r12, r12, #TrUserSp
200 stm r12, {sp, lr}^
201 str sp, [sp, #TrSvcSp]
202 str lr, [sp, #TrPc]
203 mrs r0, spsr_all
204 str r0, [sp, #TrSpsr]
205 ldr r0, =0xBADB0D00
206 str r0, [sp, #TrDbgArgMark]
207 .endm
208
209 .macro TRAP_EPILOG SystemCall
210 // ASSERT(TrapFrame->DbgArgMark == 0xBADB0D00)
211 ldr r0, [sp, #TrDbgArgMark]
212 ldr r1, =0xBADB0D00
213 cmp r0, r1
214 bne 1f
215
216 // Get the SPSR and restore it
217 ldr r0, [sp, #TrSpsr]
218 msr spsr_all, r0
219
220 // Restore the registers
221 // FIXME: Use LDMIA later
222 mov r0, sp
223 add r0, r0, #TrUserSp
224 ldm r0, {sp, lr}^
225 ldr r0, [sp, #TrR0]
226 ldr r1, [sp, #TrR1]
227 ldr r2, [sp, #TrR2]
228 ldr r3, [sp, #TrR3]
229 ldr r4, [sp, #TrR4]
230 ldr r5, [sp, #TrR5]
231 ldr r6, [sp, #TrR6]
232 ldr r7, [sp, #TrR7]
233 ldr r8, [sp, #TrR8]
234 ldr r9, [sp, #TrR9]
235 ldr r10, [sp, #TrR10]
236 ldr r11, [sp, #TrR11]
237 ldr r12, [sp, #TrR12]
238
239 // Restore program execution state
240 .if \SystemCall
241 ldr lr, [sp, #TrPc]
242 add sp, sp, #TrapFrameLength
243 movs pc, lr
244 .else
245 add sp, sp, #TrSvcSp
246 ldmia sp, {sp, lr, pc}^
247 .endif
248 1:
249 b .
250 .endm
251
252 #endif
253
254