frame.h revision 1.4 1 /* $NetBSD: frame.h,v 1.4 2002/10/18 21:32:59 bjh21 Exp $ */
2
3 /*
4 * Copyright (c) 1994-1997 Mark Brinicombe.
5 * Copyright (c) 1994 Brini.
6 * All rights reserved.
7 *
8 * This code is derived from software written for Brini by Mark Brinicombe
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by Brini.
21 * 4. The name of the company nor the name of the author may be used to
22 * endorse or promote products derived from this software without specific
23 * prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * RiscBSD kernel project
38 *
39 * frame.h
40 *
41 * Stack frames structures
42 *
43 * Created : 30/09/94
44 */
45
46 #ifndef _ARM32_FRAME_H_
47 #define _ARM32_FRAME_H_
48
49 #include <arm/frame.h> /* Common ARM stack frames */
50
51 #ifndef _LOCORE
52
53 /*
54 * System stack frames.
55 */
56
57 typedef struct irqframe {
58 unsigned int if_spsr;
59 unsigned int if_r0;
60 unsigned int if_r1;
61 unsigned int if_r2;
62 unsigned int if_r3;
63 unsigned int if_r4;
64 unsigned int if_r5;
65 unsigned int if_r6;
66 unsigned int if_r7;
67 unsigned int if_r8;
68 unsigned int if_r9;
69 unsigned int if_r10;
70 unsigned int if_r11;
71 unsigned int if_r12;
72 unsigned int if_usr_sp;
73 unsigned int if_usr_lr;
74 unsigned int if_svc_sp;
75 unsigned int if_svc_lr;
76 unsigned int if_pc;
77 } irqframe_t;
78
79 #define clockframe irqframe
80
81 /*
82 * Switch frame
83 * Pushed onto the stack at the start of cpu_switch()
84 */
85
86 struct switchframe {
87 int sf_spl;
88 u_int sf_r4;
89 u_int sf_r5;
90 u_int sf_r6;
91 u_int sf_r7;
92 u_int sf_r8;
93 u_int sf_r9;
94 u_int sf_r10;
95 u_int sf_fp;
96 u_int sf_sp;
97 u_int sf_pc; /* return address from cpu_switch() */
98 u_int sf_scp;
99 };
100
101 /*
102 * Stack frame. Used during stack traces (db_trace.c)
103 */
104 struct frame {
105 u_int fr_fp;
106 u_int fr_sp;
107 u_int fr_lr;
108 u_int fr_pc;
109 };
110
111 #ifdef _KERNEL
112 void validate_trapframe __P((trapframe_t *, int));
113 #endif /* _KERNEL */
114
115 #else /* _LOCORE */
116
117 /*
118 * ASM macros for pushing and pulling trapframes from the stack
119 *
120 * These macros are used to handle the irqframe and trapframe structures
121 * defined above.
122 */
123
124 /*
125 * PUSHFRAME - macro to push a trap frame on the stack in the current mode
126 * Since the current mode is used, the SVC lr field is not defined.
127 *
128 * NOTE: r13 and r14 are stored separately as a work around for the
129 * SA110 rev 2 STM^ bug
130 */
131
132 #define PUSHFRAME \
133 str lr, [sp, #-4]!; /* Push the return address */ \
134 sub sp, sp, #(4*17); /* Adjust the stack pointer */ \
135 stmia sp, {r0-r12}; /* Push the user mode registers */ \
136 add r0, sp, #(4*13); /* Adjust the stack pointer */ \
137 stmia r0, {r13-r14}^; /* Push the user mode registers */ \
138 mov r0, r0; /* NOP for previous instruction */ \
139 mrs r0, spsr_all; /* Put the SPSR on the stack */ \
140 str r0, [sp, #-4]!;
141
142 /*
143 * PULLFRAME - macro to pull a trap frame from the stack in the current mode
144 * Since the current mode is used, the SVC lr field is ignored.
145 */
146
147 #define PULLFRAME \
148 ldr r0, [sp], #0x0004; /* Get the SPSR from stack */ \
149 msr spsr_all, r0; \
150 ldmia sp, {r0-r14}^; /* Restore registers (usr mode) */ \
151 mov r0, r0; /* NOP for previous instruction */ \
152 add sp, sp, #(4*17); /* Adjust the stack pointer */ \
153 ldr lr, [sp], #0x0004; /* Pull the return address */
154
155 /*
156 * PUSHFRAMEINSVC - macro to push a trap frame on the stack in SVC32 mode
157 * This should only be used if the processor is not currently in SVC32
158 * mode. The processor mode is switched to SVC mode and the trap frame is
159 * stored. The SVC lr field is used to store the previous value of
160 * lr in SVC mode.
161 *
162 * NOTE: r13 and r14 are stored separately as a work around for the
163 * SA110 rev 2 STM^ bug
164 */
165
166 #define PUSHFRAMEINSVC \
167 stmdb sp, {r0-r3}; /* Save 4 registers */ \
168 mov r0, lr; /* Save xxx32 r14 */ \
169 mov r1, sp; /* Save xxx32 sp */ \
170 mrs r3, spsr; /* Save xxx32 spsr */ \
171 mrs r2, cpsr; /* Get the CPSR */ \
172 bic r2, r2, #(PSR_MODE); /* Fix for SVC mode */ \
173 orr r2, r2, #(PSR_SVC32_MODE); \
174 msr cpsr_c, r2; /* Punch into SVC mode */ \
175 mov r2, sp; /* Save SVC sp */ \
176 str r0, [sp, #-4]!; /* Push return address */ \
177 str lr, [sp, #-4]!; /* Push SVC lr */ \
178 str r2, [sp, #-4]!; /* Push SVC sp */ \
179 msr spsr_all, r3; /* Restore correct spsr */ \
180 ldmdb r1, {r0-r3}; /* Restore 4 regs from xxx mode */ \
181 sub sp, sp, #(4*15); /* Adjust the stack pointer */ \
182 stmia sp, {r0-r12}; /* Push the user mode registers */ \
183 add r0, sp, #(4*13); /* Adjust the stack pointer */ \
184 stmia r0, {r13-r14}^; /* Push the user mode registers */ \
185 mov r0, r0; /* NOP for previous instruction */ \
186 mrs r0, spsr_all; /* Put the SPSR on the stack */ \
187 str r0, [sp, #-4]!
188
189 /*
190 * PULLFRAMEFROMSVCANDEXIT - macro to pull a trap frame from the stack
191 * in SVC32 mode and restore the saved processor mode and PC.
192 * This should be used when the SVC lr register needs to be restored on
193 * exit.
194 */
195
196 #define PULLFRAMEFROMSVCANDEXIT \
197 ldr r0, [sp], #0x0004; /* Get the SPSR from stack */ \
198 msr spsr_all, r0; /* restore SPSR */ \
199 ldmia sp, {r0-r14}^; /* Restore registers (usr mode) */ \
200 mov r0, r0; /* NOP for previous instruction */ \
201 add sp, sp, #(4*15); /* Adjust the stack pointer */ \
202 ldmia sp, {sp, lr, pc}^ /* Restore lr and exit */
203
204 #endif /* _LOCORE */
205
206 #endif /* _ARM32_FRAME_H_ */
207
208 /* End of frame.h */
209