frame.h revision 1.26 1 1.26 matt /* $NetBSD: frame.h,v 1.26 2012/07/31 08:01:30 matt Exp $ */
2 1.1 reinoud
3 1.1 reinoud /*
4 1.1 reinoud * Copyright (c) 1994-1997 Mark Brinicombe.
5 1.1 reinoud * Copyright (c) 1994 Brini.
6 1.1 reinoud * All rights reserved.
7 1.1 reinoud *
8 1.1 reinoud * This code is derived from software written for Brini by Mark Brinicombe
9 1.1 reinoud *
10 1.1 reinoud * Redistribution and use in source and binary forms, with or without
11 1.1 reinoud * modification, are permitted provided that the following conditions
12 1.1 reinoud * are met:
13 1.1 reinoud * 1. Redistributions of source code must retain the above copyright
14 1.1 reinoud * notice, this list of conditions and the following disclaimer.
15 1.1 reinoud * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 reinoud * notice, this list of conditions and the following disclaimer in the
17 1.1 reinoud * documentation and/or other materials provided with the distribution.
18 1.1 reinoud * 3. All advertising materials mentioning features or use of this software
19 1.1 reinoud * must display the following acknowledgement:
20 1.1 reinoud * This product includes software developed by Brini.
21 1.1 reinoud * 4. The name of the company nor the name of the author may be used to
22 1.1 reinoud * endorse or promote products derived from this software without specific
23 1.1 reinoud * prior written permission.
24 1.1 reinoud *
25 1.1 reinoud * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 1.1 reinoud * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 1.1 reinoud * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 1.1 reinoud * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 1.1 reinoud * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 1.1 reinoud * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 1.1 reinoud * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.1 reinoud * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.1 reinoud * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.1 reinoud * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.1 reinoud * SUCH DAMAGE.
36 1.1 reinoud *
37 1.1 reinoud * RiscBSD kernel project
38 1.1 reinoud *
39 1.1 reinoud * frame.h
40 1.1 reinoud *
41 1.1 reinoud * Stack frames structures
42 1.1 reinoud *
43 1.1 reinoud * Created : 30/09/94
44 1.1 reinoud */
45 1.1 reinoud
46 1.1 reinoud #ifndef _ARM32_FRAME_H_
47 1.1 reinoud #define _ARM32_FRAME_H_
48 1.1 reinoud
49 1.1 reinoud #include <arm/frame.h> /* Common ARM stack frames */
50 1.1 reinoud
51 1.1 reinoud #ifndef _LOCORE
52 1.1 reinoud
53 1.1 reinoud /*
54 1.1 reinoud * System stack frames.
55 1.1 reinoud */
56 1.1 reinoud
57 1.1 reinoud typedef struct irqframe {
58 1.1 reinoud unsigned int if_spsr;
59 1.1 reinoud unsigned int if_r0;
60 1.1 reinoud unsigned int if_r1;
61 1.1 reinoud unsigned int if_r2;
62 1.1 reinoud unsigned int if_r3;
63 1.1 reinoud unsigned int if_r4;
64 1.1 reinoud unsigned int if_r5;
65 1.1 reinoud unsigned int if_r6;
66 1.1 reinoud unsigned int if_r7;
67 1.1 reinoud unsigned int if_r8;
68 1.1 reinoud unsigned int if_r9;
69 1.1 reinoud unsigned int if_r10;
70 1.1 reinoud unsigned int if_r11;
71 1.1 reinoud unsigned int if_r12;
72 1.1 reinoud unsigned int if_usr_sp;
73 1.1 reinoud unsigned int if_usr_lr;
74 1.25 matt unsigned int if_fill;
75 1.1 reinoud unsigned int if_svc_sp;
76 1.1 reinoud unsigned int if_svc_lr;
77 1.1 reinoud unsigned int if_pc;
78 1.1 reinoud } irqframe_t;
79 1.1 reinoud
80 1.12 cube struct clockframe {
81 1.12 cube struct irqframe cf_if;
82 1.12 cube };
83 1.1 reinoud
84 1.1 reinoud /*
85 1.16 skrll * Switch frame.
86 1.16 skrll *
87 1.16 skrll * Should be a multiple of 8 bytes for dumpsys.
88 1.1 reinoud */
89 1.1 reinoud
90 1.1 reinoud struct switchframe {
91 1.1 reinoud u_int sf_r4;
92 1.1 reinoud u_int sf_r5;
93 1.1 reinoud u_int sf_r6;
94 1.1 reinoud u_int sf_r7;
95 1.16 skrll u_int sf_sp;
96 1.5 bjh21 u_int sf_pc;
97 1.1 reinoud };
98 1.1 reinoud
99 1.1 reinoud /*
100 1.1 reinoud * Stack frame. Used during stack traces (db_trace.c)
101 1.1 reinoud */
102 1.1 reinoud struct frame {
103 1.1 reinoud u_int fr_fp;
104 1.1 reinoud u_int fr_sp;
105 1.1 reinoud u_int fr_lr;
106 1.1 reinoud u_int fr_pc;
107 1.1 reinoud };
108 1.1 reinoud
109 1.1 reinoud #ifdef _KERNEL
110 1.21 matt void validate_trapframe(trapframe_t *, int);
111 1.1 reinoud #endif /* _KERNEL */
112 1.1 reinoud
113 1.1 reinoud #else /* _LOCORE */
114 1.1 reinoud
115 1.7 scw #include "opt_compat_netbsd.h"
116 1.7 scw #include "opt_execfmt.h"
117 1.7 scw #include "opt_multiprocessor.h"
118 1.17 matt #include "opt_cpuoptions.h"
119 1.15 thorpej #include "opt_arm_debug.h"
120 1.26 matt #include "opt_cputypes.h"
121 1.7 scw
122 1.17 matt #include <machine/cpu.h>
123 1.17 matt
124 1.7 scw /*
125 1.18 matt * This macro is used by DO_AST_AND_RESTORE_ALIGNMENT_FAULTS to process
126 1.18 matt * any pending softints.
127 1.18 matt */
128 1.18 matt #ifdef __HAVE_FAST_SOFTINTS
129 1.18 matt #define DO_PENDING_SOFTINTS \
130 1.19 matt ldr r0, [r4, #CI_INTR_DEPTH]/* Get current intr depth */ ;\
131 1.19 matt teq r0, #0 /* Test for 0. */ ;\
132 1.21 matt bne 10f /* skip softints if != 0 */ ;\
133 1.19 matt ldr r0, [r4, #CI_CPL] /* Get current priority level */;\
134 1.18 matt ldr r1, [r4, #CI_SOFTINTS] /* Get pending softint mask */ ;\
135 1.20 matt movs r0, r1, lsr r0 /* shift mask by cpl */ ;\
136 1.20 matt blne _C_LABEL(dosoftints) /* dosoftints(void) */ ;\
137 1.18 matt 10:
138 1.18 matt #else
139 1.18 matt #define DO_PENDING_SOFTINTS /* nothing */
140 1.18 matt #endif
141 1.18 matt
142 1.18 matt /*
143 1.7 scw * AST_ALIGNMENT_FAULT_LOCALS and ENABLE_ALIGNMENT_FAULTS
144 1.7 scw * These are used in order to support dynamic enabling/disabling of
145 1.7 scw * alignment faults when executing old a.out ARM binaries.
146 1.17 matt *
147 1.17 matt * Note that when ENABLE_ALIGNMENTS_FAULTS finishes r4 will contain
148 1.17 matt * pointer to the cpu's cpu_info. DO_AST_AND_RESTORE_ALIGNMENT_FAULTS
149 1.17 matt * relies on r4 being preserved.
150 1.7 scw */
151 1.14 manu #ifdef EXEC_AOUT
152 1.17 matt #define AST_ALIGNMENT_FAULT_LOCALS \
153 1.17 matt .Laflt_cpufuncs: ;\
154 1.17 matt .word _C_LABEL(cpufuncs)
155 1.17 matt
156 1.7 scw /*
157 1.7 scw * This macro must be invoked following PUSHFRAMEINSVC or PUSHFRAME at
158 1.7 scw * the top of interrupt/exception handlers.
159 1.7 scw *
160 1.7 scw * When invoked, r0 *must* contain the value of SPSR on the current
161 1.7 scw * trap/interrupt frame. This is always the case if ENABLE_ALIGNMENT_FAULTS
162 1.7 scw * is invoked immediately after PUSHFRAMEINSVC or PUSHFRAME.
163 1.7 scw */
164 1.7 scw #define ENABLE_ALIGNMENT_FAULTS \
165 1.7 scw and r0, r0, #(PSR_MODE) /* Test for USR32 mode */ ;\
166 1.7 scw teq r0, #(PSR_USR32_MODE) ;\
167 1.17 matt GET_CURCPU(r4) /* r4 = cpuinfo */ ;\
168 1.7 scw bne 1f /* Not USR mode skip AFLT */ ;\
169 1.17 matt ldr r1, [r4, #CI_CURPCB] /* get curpcb from cpu_info */ ;\
170 1.17 matt ldr r1, [r1, #PCB_FLAGS] /* Fetch curpcb->pcb_flags */ ;\
171 1.17 matt tst r1, #PCB_NOALIGNFLT ;\
172 1.7 scw beq 1f /* AFLTs already enabled */ ;\
173 1.7 scw ldr r2, .Laflt_cpufuncs ;\
174 1.17 matt ldr r1, [r4, #CI_CTRL] /* Fetch control register */ ;\
175 1.7 scw mov r0, #-1 ;\
176 1.7 scw mov lr, pc ;\
177 1.7 scw ldr pc, [r2, #CF_CONTROL] /* Enable alignment faults */ ;\
178 1.7 scw 1:
179 1.7 scw
180 1.7 scw /*
181 1.7 scw * This macro must be invoked just before PULLFRAMEFROMSVCANDEXIT or
182 1.17 matt * PULLFRAME at the end of interrupt/exception handlers. We know that
183 1.17 matt * r4 points to cpu_info since that is what ENABLE_ALIGNMENT_FAULTS did
184 1.17 matt * for use.
185 1.7 scw */
186 1.7 scw #define DO_AST_AND_RESTORE_ALIGNMENT_FAULTS \
187 1.18 matt DO_PENDING_SOFTINTS ;\
188 1.8 scw ldr r0, [sp] /* Get the SPSR from stack */ ;\
189 1.17 matt mrs r5, cpsr /* save CPSR */ ;\
190 1.18 matt orr r1, r5, #(IF32_bits) ;\
191 1.11 scw msr cpsr_c, r1 /* Disable interrupts */ ;\
192 1.7 scw and r0, r0, #(PSR_MODE) /* Returning to USR mode? */ ;\
193 1.7 scw teq r0, #(PSR_USR32_MODE) ;\
194 1.7 scw bne 3f /* Nope, get out now */ ;\
195 1.18 matt 1: ldr r1, [r4, #CI_ASTPENDING] /* Pending AST? */ ;\
196 1.18 matt teq r1, #0x00000000 ;\
197 1.7 scw bne 2f /* Yup. Go deal with it */ ;\
198 1.17 matt ldr r1, [r4, #CI_CURPCB] /* Get current PCB */ ;\
199 1.17 matt ldr r0, [r1, #PCB_FLAGS] /* Fetch curpcb->pcb_flags */ ;\
200 1.17 matt tst r0, #PCB_NOALIGNFLT ;\
201 1.7 scw beq 3f /* Keep AFLTs enabled */ ;\
202 1.17 matt ldr r1, [r4, #CI_CTRL] /* Fetch control register */ ;\
203 1.7 scw ldr r2, .Laflt_cpufuncs ;\
204 1.7 scw mov r0, #-1 ;\
205 1.7 scw bic r1, r1, #CPU_CONTROL_AFLT_ENABLE /* Disable AFLTs */ ;\
206 1.7 scw adr lr, 3f ;\
207 1.7 scw ldr pc, [r2, #CF_CONTROL] /* Set new CTRL reg value */ ;\
208 1.17 matt /* NOTREACHED */ \
209 1.7 scw 2: mov r1, #0x00000000 ;\
210 1.17 matt str r1, [r4, #CI_ASTPENDING] /* Clear astpending */ ;\
211 1.18 matt bic r5, r5, #(IF32_bits) ;\
212 1.17 matt msr cpsr_c, r5 /* Restore interrupts */ ;\
213 1.7 scw mov r0, sp ;\
214 1.11 scw bl _C_LABEL(ast) /* ast(frame) */ ;\
215 1.18 matt orr r0, r5, #(IF32_bits) /* Disable IRQs */ ;\
216 1.11 scw msr cpsr_c, r0 ;\
217 1.11 scw b 1b /* Back around again */ ;\
218 1.7 scw 3:
219 1.7 scw
220 1.14 manu #else /* !EXEC_AOUT */
221 1.7 scw
222 1.17 matt #define AST_ALIGNMENT_FAULT_LOCALS
223 1.17 matt
224 1.17 matt #define ENABLE_ALIGNMENT_FAULTS GET_CURCPU(r4)
225 1.7 scw
226 1.7 scw #define DO_AST_AND_RESTORE_ALIGNMENT_FAULTS \
227 1.18 matt DO_PENDING_SOFTINTS ;\
228 1.8 scw ldr r0, [sp] /* Get the SPSR from stack */ ;\
229 1.17 matt mrs r5, cpsr /* save CPSR */ ;\
230 1.18 matt orr r1, r5, #(IF32_bits) ;\
231 1.11 scw msr cpsr_c, r1 /* Disable interrupts */ ;\
232 1.7 scw and r0, r0, #(PSR_MODE) /* Returning to USR mode? */ ;\
233 1.7 scw teq r0, #(PSR_USR32_MODE) ;\
234 1.7 scw bne 2f /* Nope, get out now */ ;\
235 1.17 matt 1: ldr r1, [r4, #CI_ASTPENDING] /* Pending AST? */ ;\
236 1.7 scw teq r1, #0x00000000 ;\
237 1.7 scw beq 2f /* Nope. Just bail */ ;\
238 1.17 matt mov r1, #0x00000000 ;\
239 1.17 matt str r1, [r4, #CI_ASTPENDING] /* Clear astpending */ ;\
240 1.18 matt bic r5, r5, #(IF32_bits) ;\
241 1.17 matt msr cpsr_c, r5 /* Restore interrupts */ ;\
242 1.7 scw mov r0, sp ;\
243 1.11 scw bl _C_LABEL(ast) /* ast(frame) */ ;\
244 1.18 matt orr r0, r5, #(IF32_bits) /* Disable IRQs */ ;\
245 1.11 scw msr cpsr_c, r0 ;\
246 1.17 matt b 1b ;\
247 1.7 scw 2:
248 1.14 manu #endif /* EXEC_AOUT */
249 1.7 scw
250 1.15 thorpej #ifdef ARM_LOCK_CAS_DEBUG
251 1.15 thorpej #define LOCK_CAS_DEBUG_LOCALS \
252 1.15 thorpej .L_lock_cas_restart: ;\
253 1.15 thorpej .word _C_LABEL(_lock_cas_restart)
254 1.15 thorpej
255 1.15 thorpej #if defined(__ARMEB__)
256 1.15 thorpej #define LOCK_CAS_DEBUG_COUNT_RESTART \
257 1.15 thorpej ble 99f ;\
258 1.15 thorpej ldr r0, .L_lock_cas_restart ;\
259 1.15 thorpej ldmia r0, {r1-r2} /* load ev_count */ ;\
260 1.15 thorpej adds r2, r2, #1 /* 64-bit incr (lo) */ ;\
261 1.15 thorpej adc r1, r1, #0 /* 64-bit incr (hi) */ ;\
262 1.15 thorpej stmia r0, {r1-r2} /* store ev_count */
263 1.15 thorpej #else /* __ARMEB__ */
264 1.15 thorpej #define LOCK_CAS_DEBUG_COUNT_RESTART \
265 1.15 thorpej ble 99f ;\
266 1.15 thorpej ldr r0, .L_lock_cas_restart ;\
267 1.15 thorpej ldmia r0, {r1-r2} /* load ev_count */ ;\
268 1.15 thorpej adds r1, r1, #1 /* 64-bit incr (lo) */ ;\
269 1.15 thorpej adc r2, r2, #0 /* 64-bit incr (hi) */ ;\
270 1.15 thorpej stmia r0, {r1-r2} /* store ev_count */
271 1.15 thorpej #endif /* __ARMEB__ */
272 1.15 thorpej #else /* ARM_LOCK_CAS_DEBUG */
273 1.15 thorpej #define LOCK_CAS_DEBUG_LOCALS /* nothing */
274 1.15 thorpej #define LOCK_CAS_DEBUG_COUNT_RESTART /* nothing */
275 1.15 thorpej #endif /* ARM_LOCK_CAS_DEBUG */
276 1.15 thorpej
277 1.15 thorpej #define LOCK_CAS_CHECK_LOCALS \
278 1.15 thorpej .L_lock_cas: ;\
279 1.15 thorpej .word _C_LABEL(_lock_cas) ;\
280 1.15 thorpej .L_lock_cas_end: ;\
281 1.15 thorpej .word _C_LABEL(_lock_cas_end) ;\
282 1.15 thorpej LOCK_CAS_DEBUG_LOCALS
283 1.15 thorpej
284 1.15 thorpej #define LOCK_CAS_CHECK \
285 1.15 thorpej ldr r0, [sp] /* get saved PSR */ ;\
286 1.15 thorpej and r0, r0, #(PSR_MODE) /* check for SVC32 mode */ ;\
287 1.15 thorpej teq r0, #(PSR_SVC32_MODE) ;\
288 1.15 thorpej bne 99f /* nope, get out now */ ;\
289 1.15 thorpej ldr r0, [sp, #(IF_PC)] ;\
290 1.15 thorpej ldr r1, .L_lock_cas_end ;\
291 1.15 thorpej cmp r0, r1 ;\
292 1.15 thorpej bge 99f ;\
293 1.15 thorpej ldr r1, .L_lock_cas ;\
294 1.15 thorpej cmp r0, r1 ;\
295 1.15 thorpej strgt r1, [sp, #(IF_PC)] ;\
296 1.15 thorpej LOCK_CAS_DEBUG_COUNT_RESTART ;\
297 1.15 thorpej 99:
298 1.15 thorpej
299 1.1 reinoud /*
300 1.1 reinoud * ASM macros for pushing and pulling trapframes from the stack
301 1.1 reinoud *
302 1.1 reinoud * These macros are used to handle the irqframe and trapframe structures
303 1.1 reinoud * defined above.
304 1.1 reinoud */
305 1.1 reinoud
306 1.1 reinoud /*
307 1.1 reinoud * PUSHFRAME - macro to push a trap frame on the stack in the current mode
308 1.1 reinoud * Since the current mode is used, the SVC lr field is not defined.
309 1.26 matt */
310 1.26 matt
311 1.26 matt #ifdef CPU_SA110
312 1.26 matt /*
313 1.1 reinoud * NOTE: r13 and r14 are stored separately as a work around for the
314 1.1 reinoud * SA110 rev 2 STM^ bug
315 1.1 reinoud */
316 1.26 matt #define PUSHUSERREGS \
317 1.26 matt stmia sp, {r0-r12}; /* Push the user mode registers */ \
318 1.26 matt add r0, sp, #(4*13); /* Adjust the stack pointer */ \
319 1.26 matt stmia r0, {r13-r14}^ /* Push the user mode registers */
320 1.26 matt #else
321 1.26 matt #define PUSHUSERREGS \
322 1.26 matt stmia sp, {r0-r14}^ /* Push the user mode registers */
323 1.26 matt #endif
324 1.1 reinoud
325 1.1 reinoud #define PUSHFRAME \
326 1.1 reinoud str lr, [sp, #-4]!; /* Push the return address */ \
327 1.25 matt sub sp, sp, #(4*18); /* Adjust the stack pointer */ \
328 1.26 matt PUSHUSERREGS; /* Push the user mode registers */ \
329 1.24 matt mov r0, r0; /* NOP for previous instruction */ \
330 1.25 matt mrs r0, spsr_all; /* Get the SPSR */ \
331 1.25 matt str r0, [sp, #-4]! /* Push the SPSR on the stack */
332 1.1 reinoud
333 1.1 reinoud /*
334 1.1 reinoud * PULLFRAME - macro to pull a trap frame from the stack in the current mode
335 1.1 reinoud * Since the current mode is used, the SVC lr field is ignored.
336 1.1 reinoud */
337 1.1 reinoud
338 1.1 reinoud #define PULLFRAME \
339 1.25 matt ldr r0, [sp], #0x0004; /* Pop the SPSR from stack */ \
340 1.24 matt msr spsr_all, r0; \
341 1.24 matt ldmia sp, {r0-r14}^; /* Restore registers (usr mode) */ \
342 1.24 matt mov r0, r0; /* NOP for previous instruction */ \
343 1.25 matt add sp, sp, #(4*18); /* Adjust the stack pointer */ \
344 1.25 matt ldr lr, [sp], #0x0004 /* Pop the return address */
345 1.1 reinoud
346 1.1 reinoud /*
347 1.1 reinoud * PUSHFRAMEINSVC - macro to push a trap frame on the stack in SVC32 mode
348 1.1 reinoud * This should only be used if the processor is not currently in SVC32
349 1.1 reinoud * mode. The processor mode is switched to SVC mode and the trap frame is
350 1.1 reinoud * stored. The SVC lr field is used to store the previous value of
351 1.1 reinoud * lr in SVC mode.
352 1.1 reinoud *
353 1.1 reinoud * NOTE: r13 and r14 are stored separately as a work around for the
354 1.1 reinoud * SA110 rev 2 STM^ bug
355 1.1 reinoud */
356 1.1 reinoud
357 1.25 matt #ifdef _ARM_ARCH_6
358 1.25 matt #define SET_CPSR_MODE(tmp, mode) \
359 1.25 matt cps #(mode)
360 1.25 matt #else
361 1.25 matt #define SET_CPSR_MODE(tmp, mode) \
362 1.25 matt mrs tmp, cpsr; /* Get the CPSR */ \
363 1.25 matt bic tmp, tmp, #(PSR_MODE); /* Fix for SVC mode */ \
364 1.25 matt orr tmp, tmp, #(mode); \
365 1.25 matt msr cpsr_c, tmp /* Punch into SVC mode */
366 1.25 matt #endif
367 1.25 matt
368 1.1 reinoud #define PUSHFRAMEINSVC \
369 1.1 reinoud stmdb sp, {r0-r3}; /* Save 4 registers */ \
370 1.1 reinoud mov r0, lr; /* Save xxx32 r14 */ \
371 1.1 reinoud mov r1, sp; /* Save xxx32 sp */ \
372 1.3 thorpej mrs r3, spsr; /* Save xxx32 spsr */ \
373 1.25 matt SET_CPSR_MODE(r2, PSR_SVC32_MODE); \
374 1.1 reinoud mov r2, sp; /* Save SVC sp */ \
375 1.1 reinoud str r0, [sp, #-4]!; /* Push return address */ \
376 1.1 reinoud str lr, [sp, #-4]!; /* Push SVC lr */ \
377 1.1 reinoud str r2, [sp, #-4]!; /* Push SVC sp */ \
378 1.25 matt sub sp, sp, #4; /* Keep stack aligned */ \
379 1.1 reinoud msr spsr_all, r3; /* Restore correct spsr */ \
380 1.1 reinoud ldmdb r1, {r0-r3}; /* Restore 4 regs from xxx mode */ \
381 1.1 reinoud sub sp, sp, #(4*15); /* Adjust the stack pointer */ \
382 1.26 matt PUSHUSERREGS; /* Push the user mode registers */ \
383 1.24 matt mov r0, r0; /* NOP for previous instruction */ \
384 1.25 matt mrs r0, spsr_all; /* Get the SPSR */ \
385 1.25 matt str r0, [sp, #-4]! /* Push the SPSR onto the stack */
386 1.1 reinoud
387 1.1 reinoud /*
388 1.1 reinoud * PULLFRAMEFROMSVCANDEXIT - macro to pull a trap frame from the stack
389 1.1 reinoud * in SVC32 mode and restore the saved processor mode and PC.
390 1.1 reinoud * This should be used when the SVC lr register needs to be restored on
391 1.1 reinoud * exit.
392 1.1 reinoud */
393 1.1 reinoud
394 1.1 reinoud #define PULLFRAMEFROMSVCANDEXIT \
395 1.25 matt ldr r0, [sp], #0x0004; /* Pop the SPSR from stack */ \
396 1.24 matt msr spsr_all, r0; /* restore SPSR */ \
397 1.24 matt ldmia sp, {r0-r14}^; /* Restore registers (usr mode) */ \
398 1.24 matt mov r0, r0; /* NOP for previous instruction */ \
399 1.25 matt add sp, sp, #(4*16); /* Adjust the stack pointer */ \
400 1.1 reinoud ldmia sp, {sp, lr, pc}^ /* Restore lr and exit */
401 1.1 reinoud
402 1.2 simonb #endif /* _LOCORE */
403 1.1 reinoud
404 1.1 reinoud #endif /* _ARM32_FRAME_H_ */
405