OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [openrisc/] [arch/] [current/] [src/] [context.S] - Blame information for rev 838

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
##=============================================================================##
2
##      context.S
3
##
4
##      OpenRISC context switch code
5
##
6
##=============================================================================
7
## ####ECOSGPLCOPYRIGHTBEGIN####
8
## -------------------------------------------
9
## This file is part of eCos, the Embedded Configurable Operating System.
10
## Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
11
##
12
## eCos is free software; you can redistribute it and/or modify it under
13
## the terms of the GNU General Public License as published by the Free
14
## Software Foundation; either version 2 or (at your option) any later
15
## version.
16
##
17
## eCos is distributed in the hope that it will be useful, but WITHOUT
18
## ANY 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
23
## along with eCos; if not, write to the Free Software Foundation, Inc.,
24
## 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
25
##
26
## As a special exception, if other files instantiate templates or use
27
## macros or inline functions from this file, or you compile this file
28
## and link it with other works to produce a work based on this file,
29
## this file does not by itself cause the resulting work to be covered by
30
## the GNU General Public License. However the source code for this file
31
## must still be made available in accordance with section (3) of the GNU
32
## General Public License v2.
33
##
34
## This exception does not invalidate any other reasons why a work based
35
## on this file might be covered by the GNU General Public License.
36
## -------------------------------------------
37
## ####ECOSGPLCOPYRIGHTEND####
38
##=============================================================================
39
#######DESCRIPTIONBEGIN####
40
##
41
## Author(s):   Scott Furman
42
## Contributors:Piotr Skrzypek (pskrzypek@antmicro.com)
43
## Date:        2003-01-21
44
## Purpose:     OpenRISC context switch code
45
## Description: This file contains implementations of the thread context
46
##              switch routines. It also contains the longjmp() and setjmp()
47
##              routines.
48
##
49
######DESCRIPTIONEND####
50
##
51
##=============================================================================
52
 
53
#include 
54
 
55
#include 
56
#include 
57
 
58
 
59
 
60
#------------------------------------------------------------------------------
61
# hal_thread_switch_context()
62
# Switch thread contexts
63
# R3 = address of sp of next thread to execute
64
# R4 = address of sp save location of current thread
65
 
66
FUNC_START(hal_thread_switch_context)
67
        l.addi  sp,sp,-SIZEOF_OR1KREGS  # space for registers
68
 
69
        # Store General Purpose Registers (GPRs).
70
        l.sw     2 * OR1K_GPRSIZE(sp), r2
71
        l.sw     9 * OR1K_GPRSIZE(sp), r9
72
        l.sw    10 * OR1K_GPRSIZE(sp), r10
73
        l.sw    14 * OR1K_GPRSIZE(sp), r14
74
        l.sw    16 * OR1K_GPRSIZE(sp), r16
75
        l.sw    18 * OR1K_GPRSIZE(sp), r18
76
        l.sw    20 * OR1K_GPRSIZE(sp), r20
77
        l.sw    22 * OR1K_GPRSIZE(sp), r22
78
        l.sw    24 * OR1K_GPRSIZE(sp), r24
79
        l.sw    26 * OR1K_GPRSIZE(sp), r26
80
        l.sw    28 * OR1K_GPRSIZE(sp), r28
81
        l.sw    30 * OR1K_GPRSIZE(sp), r30
82
 
83
#ifndef CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM
84
 
85
        # R0 is not typically stored because it is always zero-valued,
86
        # but we store it here for consistency when examining registers
87
        # in the debugger.
88
        l.sw     0 * OR1K_GPRSIZE(sp), r0
89
 
90 790 skrzyp
        # Caller-saved temporary regs don't need to be preserved across
91 786 skrzyp
        # context switches, but we do so to make debugging easier.
92
 
93
        l.sw     3 * OR1K_GPRSIZE(sp), r3
94
        l.sw     4 * OR1K_GPRSIZE(sp), r4
95
        l.sw     5 * OR1K_GPRSIZE(sp), r5
96
        l.sw     6 * OR1K_GPRSIZE(sp), r6
97
        l.sw     7 * OR1K_GPRSIZE(sp), r7
98
        l.sw     8 * OR1K_GPRSIZE(sp), r8
99
        l.sw    11 * OR1K_GPRSIZE(sp), r11
100 790 skrzyp
        l.sw    12 * OR1K_GPRSIZE(sp), r12
101 786 skrzyp
        l.sw    13 * OR1K_GPRSIZE(sp), r13
102
        l.sw    15 * OR1K_GPRSIZE(sp), r15
103
        l.sw    17 * OR1K_GPRSIZE(sp), r17
104
        l.sw    19 * OR1K_GPRSIZE(sp), r19
105
        l.sw    21 * OR1K_GPRSIZE(sp), r21
106
        l.sw    23 * OR1K_GPRSIZE(sp), r23
107
        l.sw    25 * OR1K_GPRSIZE(sp), r25
108
        l.sw    27 * OR1K_GPRSIZE(sp), r27
109
        l.sw    29 * OR1K_GPRSIZE(sp), r29
110
        l.sw    31 * OR1K_GPRSIZE(sp), r31
111
 
112 790 skrzyp
#endif
113
 
114 786 skrzyp
        # save MAC LO and HI regs
115
        l.mfspr r5,r0,SPR_MACLO
116
        l.sw    OR1KREG_MACLO(sp),r5
117
        l.mfspr r5,r0,SPR_MACHI
118
        l.sw    OR1KREG_MACHI(sp),r5
119
 
120
 
121
#ifdef CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
122
        # Make the thread context look like an exception context if thread-
123
        # aware debugging is required. This state does not need restoring.
124
        l.sw    OR1KREG_PC(sp),r9
125
#endif
126
 
127
        l.addi  r5,sp,SIZEOF_OR1KREGS           # save SP in reg dump
128
        l.sw     1 * OR1K_GPRSIZE(sp), r5
129
 
130
        l.mfspr  r5,r0,SPR_SR                   # save SR in reg dump
131
        l.sw     OR1KREG_SR(sp), r5
132
 
133
        # Return resulting new SP to caller via second argument
134
        l.sw     0(r4), sp
135
 
136
        # Now load the destination thread by dropping through
137
        # to hal_thread_load_context...
138
FUNC_END(hal_thread_switch_context)
139
 
140
 
141
#------------------------------------------------------------------------------
142
# hal_thread_load_context()
143
# Load thread context
144
# R3 = address of sp of next thread to execute
145
# Note that this function is also the second half of hal_thread_switch_context()
146
# and is simply dropped into from it.
147
 
148
FUNC_START(hal_thread_load_context)
149
 
150
        # Copy R3 to SP
151
        l.lwz   sp, 0(r3)
152
 
153
        # Restore General Purpose Registers (GPRs).
154
        # R0 is not restored because it is always zero-valued.
155
        l.lwz   r2,   2 * OR1K_GPRSIZE(sp)
156
        l.lwz   r9,   9 * OR1K_GPRSIZE(sp)
157
        l.lwz   r10, 10 * OR1K_GPRSIZE(sp)
158
        l.lwz   r14, 14 * OR1K_GPRSIZE(sp)
159
        l.lwz   r16, 16 * OR1K_GPRSIZE(sp)
160
        l.lwz   r18, 18 * OR1K_GPRSIZE(sp)
161
        l.lwz   r20, 20 * OR1K_GPRSIZE(sp)
162
        l.lwz   r22, 22 * OR1K_GPRSIZE(sp)
163
        l.lwz   r24, 24 * OR1K_GPRSIZE(sp)
164
        l.lwz   r26, 26 * OR1K_GPRSIZE(sp)
165
        l.lwz   r28, 28 * OR1K_GPRSIZE(sp)
166
        l.lwz   r30, 30 * OR1K_GPRSIZE(sp)
167
 
168
        # Merge interrupt-enable state of new thread into
169
        # current SR
170
        load32i r5,~(SPR_SR_TEE|SPR_SR_IEE)
171
        l.mfspr r6, r0, SPR_SR
172
        l.and   r6, r5, r6
173
        l.lwz   r5,  OR1KREG_SR(sp)
174
        l.andi  r5, r5, (SPR_SR_TEE|SPR_SR_IEE)
175
        l.or    r5, r5, r6
176
        l.mtspr r0, r5, SPR_SR
177
 
178
        # Restore MAC LO and HI regs
179
        l.lwz   r5, OR1KREG_MACLO(sp)
180
        l.mtspr r0,r5,SPR_MACLO
181
        l.lwz   r5, OR1KREG_MACHI(sp)
182
        l.mtspr r0,r5,SPR_MACHI
183
 
184 790 skrzyp
#ifndef CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM
185
 
186
        # Caller-saved temporary regs don't need to be preserved across
187
        # context switches, but we do so here to make debugging
188
        # easier.
189
 
190 786 skrzyp
        l.lwz    r4,  4 * OR1K_GPRSIZE(sp)
191
        l.lwz    r5,  5 * OR1K_GPRSIZE(sp)
192
        l.lwz    r6,  6 * OR1K_GPRSIZE(sp)
193
        l.lwz    r7,  7 * OR1K_GPRSIZE(sp)
194
        l.lwz    r8,  8 * OR1K_GPRSIZE(sp)
195
        l.lwz   r11, 11 * OR1K_GPRSIZE(sp)
196 790 skrzyp
        l.lwz   r12, 12 * OR1K_GPRSIZE(sp)
197 786 skrzyp
        l.lwz   r13, 13 * OR1K_GPRSIZE(sp)
198
        l.lwz   r15, 15 * OR1K_GPRSIZE(sp)
199
        l.lwz   r17, 17 * OR1K_GPRSIZE(sp)
200
        l.lwz   r19, 19 * OR1K_GPRSIZE(sp)
201
        l.lwz   r21, 21 * OR1K_GPRSIZE(sp)
202
        l.lwz   r23, 23 * OR1K_GPRSIZE(sp)
203
        l.lwz   r25, 25 * OR1K_GPRSIZE(sp)
204
        l.lwz   r27, 27 * OR1K_GPRSIZE(sp)
205
        l.lwz   r29, 29 * OR1K_GPRSIZE(sp)
206
        l.lwz   r31, 31 * OR1K_GPRSIZE(sp)
207
 
208
#endif
209
 
210
        # If this is the first time we're running a thread, R3
211
        # contains the argument to the thread entry point function,
212
        # So we always have to restore it even though it's a callee-saved
213
        # register.
214
        l.lwz    r3,  3 * OR1K_GPRSIZE(sp)
215
 
216
        # Finally, restore target thread's true SP
217
        l.lwz   sp,   1 * OR1K_GPRSIZE(sp)
218
 
219
        l.jr    lr
220 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
221 786 skrzyp
        l.nop                                   # delay slot - must be nop
222 838 skrzyp
#endif
223 786 skrzyp
 
224
FUNC_END(hal_thread_load_context)
225
 
226
#------------------------------------------------------------------------------
227
# HAL longjmp, setjmp implementations
228
# hal_setjmp saves only callee-saved registers into buffer supplied in r3:
229
#       1,2,9,10,13,15,17,19,21,23,25,27,29,31
230
# Note: These definitions are repeated in hal_arch.h. If changes are required
231
# remember to update both sets.
232
 
233
#define CYGARC_JMP_BUF_R1        0
234
#define CYGARC_JMP_BUF_R2        1
235
#define CYGARC_JMP_BUF_R9        2
236
#define CYGARC_JMP_BUF_R10       3
237
#define CYGARC_JMP_BUF_R12       4
238
#define CYGARC_JMP_BUF_R14       5
239
#define CYGARC_JMP_BUF_R16       6
240
#define CYGARC_JMP_BUF_R18       7
241
#define CYGARC_JMP_BUF_R20       8
242
#define CYGARC_JMP_BUF_R22       9
243
#define CYGARC_JMP_BUF_R24      10
244
#define CYGARC_JMP_BUF_R26      11
245
#define CYGARC_JMP_BUF_R28      12
246
#define CYGARC_JMP_BUF_R30      13
247
 
248
#define CYGARC_JMP_BUF_SIZE     14
249
 
250
#define jmpbuf_regsize 4
251
 
252
FUNC_START(hal_setjmp)
253
        # Store General Purpose Registers (GPRs).
254
        # R0 is not stored because it is always zero-valued.
255
        # Caller-saved registers are not stored
256
        l.sw    CYGARC_JMP_BUF_R1  * OR1K_GPRSIZE(r3), r1
257
        l.sw    CYGARC_JMP_BUF_R2  * OR1K_GPRSIZE(r3), r2
258
        l.sw    CYGARC_JMP_BUF_R9  * OR1K_GPRSIZE(r3), r9
259
        l.sw    CYGARC_JMP_BUF_R10 * OR1K_GPRSIZE(r3), r10
260
        l.sw    CYGARC_JMP_BUF_R12 * OR1K_GPRSIZE(r3), r12
261
        l.sw    CYGARC_JMP_BUF_R14 * OR1K_GPRSIZE(r3), r14
262
        l.sw    CYGARC_JMP_BUF_R16 * OR1K_GPRSIZE(r3), r16
263
        l.sw    CYGARC_JMP_BUF_R18 * OR1K_GPRSIZE(r3), r18
264
        l.sw    CYGARC_JMP_BUF_R20 * OR1K_GPRSIZE(r3), r20
265
        l.sw    CYGARC_JMP_BUF_R22 * OR1K_GPRSIZE(r3), r22
266
        l.sw    CYGARC_JMP_BUF_R24 * OR1K_GPRSIZE(r3), r24
267
        l.sw    CYGARC_JMP_BUF_R26 * OR1K_GPRSIZE(r3), r26
268
        l.sw    CYGARC_JMP_BUF_R28 * OR1K_GPRSIZE(r3), r28
269
        l.sw    CYGARC_JMP_BUF_R30 * OR1K_GPRSIZE(r3), r30
270
        l.movhi rv, 0
271
        l.jr    lr
272 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
273 786 skrzyp
        l.nop                   # delay slot
274 838 skrzyp
#endif
275
 
276 786 skrzyp
FUNC_END(hal_setjmp)
277
 
278
 
279
FUNC_START(hal_longjmp)
280
        l.lwz    r1, CYGARC_JMP_BUF_R1  * OR1K_GPRSIZE(r3)
281
        l.lwz    r2, CYGARC_JMP_BUF_R2  * OR1K_GPRSIZE(r3)
282
        l.lwz    r9, CYGARC_JMP_BUF_R9  * OR1K_GPRSIZE(r3)
283
        l.lwz   r10, CYGARC_JMP_BUF_R10 * OR1K_GPRSIZE(r3)
284
        l.lwz   r12, CYGARC_JMP_BUF_R12 * OR1K_GPRSIZE(r3)
285
        l.lwz   r14, CYGARC_JMP_BUF_R14 * OR1K_GPRSIZE(r3)
286
        l.lwz   r16, CYGARC_JMP_BUF_R16 * OR1K_GPRSIZE(r3)
287
        l.lwz   r18, CYGARC_JMP_BUF_R18 * OR1K_GPRSIZE(r3)
288
        l.lwz   r20, CYGARC_JMP_BUF_R20 * OR1K_GPRSIZE(r3)
289
        l.lwz   r22, CYGARC_JMP_BUF_R22 * OR1K_GPRSIZE(r3)
290
        l.lwz   r24, CYGARC_JMP_BUF_R24 * OR1K_GPRSIZE(r3)
291
        l.lwz   r26, CYGARC_JMP_BUF_R26 * OR1K_GPRSIZE(r3)
292
        l.lwz   r28, CYGARC_JMP_BUF_R28 * OR1K_GPRSIZE(r3)
293
        l.lwz   r30, CYGARC_JMP_BUF_R30 * OR1K_GPRSIZE(r3)
294
        l.movhi rv, 0
295
        l.or    rv, rv, r4
296
        l.jr    lr
297 838 skrzyp
#ifdef CYGHWR_BRANCH_SLOT_IMPLEMENTED
298 786 skrzyp
        l.nop                   # delay slot
299 838 skrzyp
#endif
300
 
301 786 skrzyp
FUNC_END(hal_longjmp)
302
 
303
 
304
#------------------------------------------------------------------------------
305
# end of context.S

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.