1 |
1254 |
phoenix |
##=============================================================================
|
2 |
|
|
##
|
3 |
|
|
## context.S
|
4 |
|
|
##
|
5 |
|
|
## PowerPC context switch code
|
6 |
|
|
##
|
7 |
|
|
##=============================================================================
|
8 |
|
|
#####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
## -------------------------------------------
|
10 |
|
|
## This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
12 |
|
|
##
|
13 |
|
|
## eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
## the terms of the GNU General Public License as published by the Free
|
15 |
|
|
## Software Foundation; either version 2 or (at your option) any later version.
|
16 |
|
|
##
|
17 |
|
|
## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
## WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
## for more details.
|
21 |
|
|
##
|
22 |
|
|
## You should have received a copy of the GNU General Public License along
|
23 |
|
|
## with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
##
|
26 |
|
|
## As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
## or inline functions from this file, or you compile this file and link it
|
28 |
|
|
## with other works to produce a work based on this file, this file does not
|
29 |
|
|
## by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
## License. However the source code for this file must still be made available
|
31 |
|
|
## in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
##
|
33 |
|
|
## This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
## this file might be covered by the GNU General Public License.
|
35 |
|
|
##
|
36 |
|
|
## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
## at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
## -------------------------------------------
|
39 |
|
|
#####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
##=============================================================================
|
41 |
|
|
#######DESCRIPTIONBEGIN####
|
42 |
|
|
##
|
43 |
|
|
## Author(s): nickg
|
44 |
|
|
## Contributors: nickg
|
45 |
|
|
## Date: 1998-04-27
|
46 |
|
|
## Purpose: PowerPC context switch code
|
47 |
|
|
## Description: This file contains implementations of the thread context
|
48 |
|
|
## switch routines. It also contains the longjmp() and setjmp()
|
49 |
|
|
## routines.
|
50 |
|
|
##
|
51 |
|
|
######DESCRIPTIONEND####
|
52 |
|
|
##
|
53 |
|
|
##=============================================================================
|
54 |
|
|
|
55 |
|
|
#include
|
56 |
|
|
|
57 |
|
|
#include
|
58 |
|
|
#include
|
59 |
|
|
|
60 |
|
|
#------------------------------------------------------------------------------
|
61 |
|
|
# Configure to use either a minimal or maximal thread state
|
62 |
|
|
|
63 |
|
|
#ifdef CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM
|
64 |
|
|
|
65 |
|
|
#define MIN_SAVE_REG 13
|
66 |
|
|
#define MAX_SAVE_REG 31
|
67 |
|
|
|
68 |
|
|
.macro save_special
|
69 |
|
|
.endm
|
70 |
|
|
|
71 |
|
|
.macro load_special
|
72 |
|
|
.endm
|
73 |
|
|
#else
|
74 |
|
|
|
75 |
|
|
#define MIN_SAVE_REG 6
|
76 |
|
|
#define MAX_SAVE_REG 31
|
77 |
|
|
|
78 |
|
|
.macro save_special
|
79 |
|
|
mfxer r6
|
80 |
|
|
mfctr r7
|
81 |
|
|
stw r6,CYGARC_PPCREG_XER(sp)
|
82 |
|
|
stw r7,CYGARC_PPCREG_CTR(sp)
|
83 |
|
|
.endm
|
84 |
|
|
|
85 |
|
|
.macro load_special
|
86 |
|
|
lwz r6,CYGARC_PPCREG_XER(sp)
|
87 |
|
|
lwz r7,CYGARC_PPCREG_CTR(sp)
|
88 |
|
|
mtxer r6
|
89 |
|
|
mtctr r7
|
90 |
|
|
.endm
|
91 |
|
|
|
92 |
|
|
#endif
|
93 |
|
|
|
94 |
|
|
#ifdef CYGHWR_HAL_POWERPC_FPU
|
95 |
|
|
#ifdef CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM
|
96 |
|
|
|
97 |
|
|
#define MIN_CONTEXT_SAVE_FREG 14
|
98 |
|
|
#define MAX_CONTEXT_SAVE_FREG 31
|
99 |
|
|
|
100 |
|
|
#else
|
101 |
|
|
|
102 |
|
|
#define MIN_CONTEXT_SAVE_FREG 0
|
103 |
|
|
#define MAX_CONTEXT_SAVE_FREG 31
|
104 |
|
|
|
105 |
|
|
#endif
|
106 |
|
|
#endif
|
107 |
|
|
|
108 |
|
|
#------------------------------------------------------------------------------
|
109 |
|
|
# hal_thread_switch_context
|
110 |
|
|
# Switch thread contexts
|
111 |
|
|
# R3 = address of sp of next thread to execute
|
112 |
|
|
# R4 = address of sp save location of current thread
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
FUNC_START(hal_thread_switch_context)
|
116 |
|
|
mr r5,sp # R5 = saved stack pointer
|
117 |
|
|
subi sp,sp,CYGARC_PPC_CONTEXT_SIZE # space for state
|
118 |
|
|
|
119 |
|
|
# Save registers MIN..MAX
|
120 |
|
|
.set _reg,MIN_SAVE_REG
|
121 |
|
|
.rept MAX_SAVE_REG+1-MIN_SAVE_REG
|
122 |
|
|
stw _reg,(CYGARC_PPCREG_REGS+_reg*4)(sp)
|
123 |
|
|
.set _reg,_reg+1
|
124 |
|
|
.endr
|
125 |
|
|
|
126 |
|
|
#ifdef CYGHWR_HAL_POWERPC_FPU
|
127 |
|
|
# Save floating point MIN..MAX
|
128 |
|
|
.set _freg, MIN_CONTEXT_SAVE_FREG
|
129 |
|
|
.rept MAX_CONTEXT_SAVE_FREG+1-MIN_CONTEXT_SAVE_FREG
|
130 |
|
|
stfd _freg,(CYGARC_PPCREG_FREGS+_freg*8)(sp)
|
131 |
|
|
.set _freg, _freg+1
|
132 |
|
|
.endr
|
133 |
|
|
#endif
|
134 |
|
|
|
135 |
|
|
stw r0,CYGARC_PPCREG_REGS+0*4(sp) # R0
|
136 |
|
|
stw r5,CYGARC_PPCREG_REGS+1*4(sp) # R5 = real SP, save in R1 slot
|
137 |
|
|
stw r2,CYGARC_PPCREG_REGS+2*4(sp) # R2 = TOC
|
138 |
|
|
|
139 |
|
|
# CR cannot be treated as a special register since GCC will only
|
140 |
|
|
# do partial restore of CR at function exit, depending on which
|
141 |
|
|
# of CR2, CR3, and CR4 have been used in the given function.
|
142 |
|
|
mfcr r5 # save CR.
|
143 |
|
|
stw r5,CYGARC_PPCREG_CR(sp)
|
144 |
|
|
|
145 |
|
|
#ifdef CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
|
146 |
|
|
# Make the thread context look like an exception context if thread-
|
147 |
|
|
# aware debugging is required. This state does not need restoring.
|
148 |
|
|
mflr r5
|
149 |
|
|
stw r5,CYGARC_PPCREG_PC(sp) # pc of caller
|
150 |
|
|
#endif
|
151 |
|
|
|
152 |
|
|
mfmsr r5
|
153 |
|
|
stw r5,CYGARC_PPCREG_MSR(sp)# msr (or PS)
|
154 |
|
|
|
155 |
|
|
save_special # save special regs
|
156 |
|
|
|
157 |
|
|
mflr r5 # save LR == return link for this fn
|
158 |
|
|
stw r5,CYGARC_PPCREG_LR(sp)
|
159 |
|
|
|
160 |
|
|
stw sp,0(r4) # save SP into save location
|
161 |
|
|
|
162 |
|
|
# Now load the destination thread by dropping through
|
163 |
|
|
# to hal_thread_load_context
|
164 |
|
|
|
165 |
|
|
#------------------------------------------------------------------------------
|
166 |
|
|
# hal_thread_load_context
|
167 |
|
|
# Load thread context
|
168 |
|
|
# R3 = address of sp of next thread to execute
|
169 |
|
|
# Note that this function is also the second half of hal_thread_switch_context
|
170 |
|
|
# and is simply dropped into from it.
|
171 |
|
|
|
172 |
|
|
FUNC_START(hal_thread_load_context)
|
173 |
|
|
|
174 |
|
|
lwz sp,0(r3) # load state directly into SP
|
175 |
|
|
|
176 |
|
|
load_special # load special registers
|
177 |
|
|
|
178 |
|
|
lwz r5,CYGARC_PPCREG_CR(sp) # restore CR
|
179 |
|
|
mtcr r5
|
180 |
|
|
|
181 |
|
|
lwz r5,CYGARC_PPCREG_LR(sp) # get LR as set as return link
|
182 |
|
|
mtlr r5
|
183 |
|
|
|
184 |
|
|
# Load registers MIN..MAX
|
185 |
|
|
.set _reg,MIN_SAVE_REG
|
186 |
|
|
.rept MAX_SAVE_REG+1-MIN_SAVE_REG
|
187 |
|
|
lwz _reg,(CYGARC_PPCREG_REGS+_reg*4)(sp)
|
188 |
|
|
.set _reg,_reg+1
|
189 |
|
|
.endr
|
190 |
|
|
|
191 |
|
|
#ifdef CYGHWR_HAL_POWERPC_FPU
|
192 |
|
|
# Load floating registers MIN..MAX
|
193 |
|
|
.set _freg, MIN_CONTEXT_SAVE_FREG
|
194 |
|
|
.rept MAX_CONTEXT_SAVE_FREG+1-MIN_CONTEXT_SAVE_FREG
|
195 |
|
|
lfd _freg,(CYGARC_PPCREG_FREGS+_freg*8)(sp)
|
196 |
|
|
.set _freg,_freg+1
|
197 |
|
|
.endr
|
198 |
|
|
#endif
|
199 |
|
|
|
200 |
|
|
lwz r3,CYGARC_PPCREG_MSR(sp) # merge interrupt state
|
201 |
|
|
hal_cpu_int_merge r3
|
202 |
|
|
|
203 |
|
|
lwz r0,CYGARC_PPCREG_REGS+0*4(sp) # R0
|
204 |
|
|
lwz r2,CYGARC_PPCREG_REGS+2*4(sp) # R2 = TOC
|
205 |
|
|
lwz r3,CYGARC_PPCREG_REGS+3*4(sp) # load r3
|
206 |
|
|
|
207 |
|
|
lwz sp,CYGARC_PPCREG_REGS+1*4(sp) # finally restore true SP
|
208 |
|
|
|
209 |
|
|
blr # jump to LR
|
210 |
|
|
|
211 |
|
|
#------------------------------------------------------------------------------
|
212 |
|
|
# HAL longjmp, setjmp implementations
|
213 |
|
|
# hal_setjmp saves only to callee save registers 13-31, r1[sp],r2, cr[2-4]
|
214 |
|
|
# and lr into buffer supplied in r3[arg0]
|
215 |
|
|
|
216 |
|
|
FUNC_START(hal_setjmp)
|
217 |
|
|
mfcr r5
|
218 |
|
|
stw r5, CYGARC_JMPBUF_CR(r3)
|
219 |
|
|
mflr r5
|
220 |
|
|
stw r5, CYGARC_JMPBUF_LR(r3)
|
221 |
|
|
stw r31,CYGARC_JMPBUF_R31(r3)
|
222 |
|
|
stw r30,CYGARC_JMPBUF_R30(r3)
|
223 |
|
|
stw r29,CYGARC_JMPBUF_R29(r3)
|
224 |
|
|
stw r28,CYGARC_JMPBUF_R28(r3)
|
225 |
|
|
stw r27,CYGARC_JMPBUF_R27(r3)
|
226 |
|
|
stw r26,CYGARC_JMPBUF_R26(r3)
|
227 |
|
|
stw r25,CYGARC_JMPBUF_R25(r3)
|
228 |
|
|
stw r24,CYGARC_JMPBUF_R24(r3)
|
229 |
|
|
stw r23,CYGARC_JMPBUF_R23(r3)
|
230 |
|
|
stw r22,CYGARC_JMPBUF_R22(r3)
|
231 |
|
|
stw r21,CYGARC_JMPBUF_R21(r3)
|
232 |
|
|
stw r20,CYGARC_JMPBUF_R20(r3)
|
233 |
|
|
stw r19,CYGARC_JMPBUF_R19(r3)
|
234 |
|
|
stw r18,CYGARC_JMPBUF_R18(r3)
|
235 |
|
|
stw r17,CYGARC_JMPBUF_R17(r3)
|
236 |
|
|
stw r16,CYGARC_JMPBUF_R16(r3)
|
237 |
|
|
stw r15,CYGARC_JMPBUF_R15(r3)
|
238 |
|
|
stw r14,CYGARC_JMPBUF_R14(r3)
|
239 |
|
|
stw r13,CYGARC_JMPBUF_R13(r3)
|
240 |
|
|
#ifdef CYGHWR_HAL_POWERPC_FPU
|
241 |
|
|
stfd f31,CYGARC_JMPBUF_F31(r3)
|
242 |
|
|
stfd f30,CYGARC_JMPBUF_F30(r3)
|
243 |
|
|
stfd f29,CYGARC_JMPBUF_F29(r3)
|
244 |
|
|
stfd f28,CYGARC_JMPBUF_F28(r3)
|
245 |
|
|
stfd f27,CYGARC_JMPBUF_F27(r3)
|
246 |
|
|
stfd f26,CYGARC_JMPBUF_F26(r3)
|
247 |
|
|
stfd f25,CYGARC_JMPBUF_F25(r3)
|
248 |
|
|
stfd f24,CYGARC_JMPBUF_F24(r3)
|
249 |
|
|
stfd f23,CYGARC_JMPBUF_F23(r3)
|
250 |
|
|
stfd f22,CYGARC_JMPBUF_F22(r3)
|
251 |
|
|
stfd f21,CYGARC_JMPBUF_F21(r3)
|
252 |
|
|
stfd f20,CYGARC_JMPBUF_F20(r3)
|
253 |
|
|
stfd f19,CYGARC_JMPBUF_F19(r3)
|
254 |
|
|
stfd f18,CYGARC_JMPBUF_F18(r3)
|
255 |
|
|
stfd f17,CYGARC_JMPBUF_F17(r3)
|
256 |
|
|
stfd f16,CYGARC_JMPBUF_F16(r3)
|
257 |
|
|
stfd f15,CYGARC_JMPBUF_F15(r3)
|
258 |
|
|
stfd f14,CYGARC_JMPBUF_F14(r3)
|
259 |
|
|
#endif
|
260 |
|
|
stw r2, CYGARC_JMPBUF_R2(r3) # TOC, optimize out?
|
261 |
|
|
stw sp, CYGARC_JMPBUF_SP(r3)
|
262 |
|
|
li r3,0 # return 0
|
263 |
|
|
blr
|
264 |
|
|
|
265 |
|
|
# hal_longjmp loads state from r3[arg0] and returns
|
266 |
|
|
# to the setjmp caller with r4[arg1] as return value
|
267 |
|
|
|
268 |
|
|
FUNC_START(hal_longjmp)
|
269 |
|
|
lwz r5,CYGARC_JMPBUF_CR(r3)
|
270 |
|
|
mtcr r5
|
271 |
|
|
lwz r5,CYGARC_JMPBUF_LR(r3)
|
272 |
|
|
mtlr r5
|
273 |
|
|
lwz r31,CYGARC_JMPBUF_R31(r3)
|
274 |
|
|
lwz r30,CYGARC_JMPBUF_R30(r3)
|
275 |
|
|
lwz r29,CYGARC_JMPBUF_R29(r3)
|
276 |
|
|
lwz r28,CYGARC_JMPBUF_R28(r3)
|
277 |
|
|
lwz r27,CYGARC_JMPBUF_R27(r3)
|
278 |
|
|
lwz r26,CYGARC_JMPBUF_R26(r3)
|
279 |
|
|
lwz r25,CYGARC_JMPBUF_R25(r3)
|
280 |
|
|
lwz r24,CYGARC_JMPBUF_R24(r3)
|
281 |
|
|
lwz r23,CYGARC_JMPBUF_R23(r3)
|
282 |
|
|
lwz r22,CYGARC_JMPBUF_R22(r3)
|
283 |
|
|
lwz r21,CYGARC_JMPBUF_R21(r3)
|
284 |
|
|
lwz r20,CYGARC_JMPBUF_R20(r3)
|
285 |
|
|
lwz r19,CYGARC_JMPBUF_R19(r3)
|
286 |
|
|
lwz r18,CYGARC_JMPBUF_R18(r3)
|
287 |
|
|
lwz r17,CYGARC_JMPBUF_R17(r3)
|
288 |
|
|
lwz r16,CYGARC_JMPBUF_R16(r3)
|
289 |
|
|
lwz r15,CYGARC_JMPBUF_R15(r3)
|
290 |
|
|
lwz r14,CYGARC_JMPBUF_R14(r3)
|
291 |
|
|
lwz r13,CYGARC_JMPBUF_R13(r3)
|
292 |
|
|
#ifdef CYGHWR_HAL_POWERPC_FPU
|
293 |
|
|
lfd f31,CYGARC_JMPBUF_F31(r3)
|
294 |
|
|
lfd f30,CYGARC_JMPBUF_F30(r3)
|
295 |
|
|
lfd f29,CYGARC_JMPBUF_F29(r3)
|
296 |
|
|
lfd f28,CYGARC_JMPBUF_F28(r3)
|
297 |
|
|
lfd f27,CYGARC_JMPBUF_F27(r3)
|
298 |
|
|
lfd f26,CYGARC_JMPBUF_F26(r3)
|
299 |
|
|
lfd f25,CYGARC_JMPBUF_F25(r3)
|
300 |
|
|
lfd f24,CYGARC_JMPBUF_F24(r3)
|
301 |
|
|
lfd f23,CYGARC_JMPBUF_F23(r3)
|
302 |
|
|
lfd f22,CYGARC_JMPBUF_F22(r3)
|
303 |
|
|
lfd f21,CYGARC_JMPBUF_F21(r3)
|
304 |
|
|
lfd f20,CYGARC_JMPBUF_F20(r3)
|
305 |
|
|
lfd f19,CYGARC_JMPBUF_F19(r3)
|
306 |
|
|
lfd f18,CYGARC_JMPBUF_F18(r3)
|
307 |
|
|
lfd f17,CYGARC_JMPBUF_F17(r3)
|
308 |
|
|
lfd f16,CYGARC_JMPBUF_F16(r3)
|
309 |
|
|
lfd f15,CYGARC_JMPBUF_F15(r3)
|
310 |
|
|
lfd f14,CYGARC_JMPBUF_F14(r3)
|
311 |
|
|
#endif
|
312 |
|
|
lwz r2, CYGARC_JMPBUF_R2(r3)
|
313 |
|
|
lwz sp, CYGARC_JMPBUF_SP(r3)
|
314 |
|
|
mr r3,r4 # return r4[arg1]
|
315 |
|
|
blr
|
316 |
|
|
|
317 |
|
|
#------------------------------------------------------------------------------
|
318 |
|
|
# end of context.S
|