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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [mips/] [arch/] [v2_0/] [src/] [context.S] - Blame information for rev 307

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
##=============================================================================##
2
##      context.S
3
##
4
##      MIPS 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 Red Hat, 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 version.
15
##
16
## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
17
## WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19
## for more details.
20
##
21
## You should have received a copy of the GNU General Public License along
22
## with eCos; if not, write to the Free Software Foundation, Inc.,
23
## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24
##
25
## As a special exception, if other files instantiate templates or use macros
26
## or inline functions from this file, or you compile this file and link it
27
## with other works to produce a work based on this file, this file does not
28
## by itself cause the resulting work to be covered by the GNU General Public
29
## License. However the source code for this file must still be made available
30
## in accordance with section (3) of the GNU General Public License.
31
##
32
## This exception does not invalidate any other reasons why a work based on
33
## this file might be covered by the GNU General Public License.
34
##
35
## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
36
## at http://sources.redhat.com/ecos/ecos-license/
37
## -------------------------------------------
38
#####ECOSGPLCOPYRIGHTEND####
39
##=============================================================================
40
#######DESCRIPTIONBEGIN####
41
##
42
## Author(s):   nickg
43
## Contributors:        nickg
44
## Date:        1998-04-27
45
## Purpose:     MIPS context switch code
46
## Description: This file contains implementations of the thread context
47
##              switch routines. It also contains the longjmp() and setjmp()
48
##              routines.
49
##
50
######DESCRIPTIONEND####
51
##
52
##=============================================================================
53
 
54
#include 
55
 
56
#include 
57
 
58
#ifdef at
59
#undef at
60
#endif
61
 
62
#------------------------------------------------------------------------------
63
# hal_thread_switch_context
64
# Switch thread contexts
65
# A0 = address of sp of next thread to execute
66
# A1 = address of sp save location of current thread
67
 
68
        .global hal_thread_switch_context
69
hal_thread_switch_context:
70
 
71
        addi    sp,sp,-mipsreg_size     # space for registers
72
 
73
        # store GPRs
74
        .set    noat
75
#ifndef CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM
76
        sgpr    0,sp
77
        sgpr    1,sp
78
        sgpr    2,sp
79
        sgpr    3,sp
80
        sgpr    4,sp
81
        sgpr    5,sp
82
        sgpr    6,sp
83
        sgpr    7,sp
84
        sgpr    8,sp
85
        sgpr    9,sp
86
        sgpr    10,sp
87
        sgpr    11,sp
88
        sgpr    12,sp
89
        sgpr    13,sp
90
        sgpr    14,sp
91
        sgpr    15,sp
92
        sgpr    24,sp
93
        sgpr    25,sp
94
        sgpr    28,sp   # == GP
95
#endif
96
        sgpr    16,sp
97
        sgpr    17,sp
98
        sgpr    18,sp
99
        sgpr    19,sp
100
        sgpr    20,sp
101
        sgpr    21,sp
102
        sgpr    22,sp
103
        sgpr    23,sp
104
#       sgpr    26,sp   # == K0
105
#       sgpr    27,sp   # == K1
106
#       sgpr    29,sp   # == SP
107
        sgpr    30,sp   # == FP
108
        sgpr    31,sp   # == RA
109
        spc     $31,sp  # == PC (to help with debugging)
110
        .set    at
111
 
112
#ifndef CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM
113
 
114
        mflo    t0                              # save LO and HI regs
115
        mfhi    t1
116
        slo     t0,sp
117
        shi     t1,sp
118
 
119
#endif
120
 
121
        hal_fpu_save_callee     sp
122
 
123
#ifndef CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM
124
 
125
        hal_fpu_save_caller     sp
126
 
127
#endif
128
 
129
        addi    t0,sp,mipsreg_size              # save SP in reg dump
130
        ssp     t0,sp
131
 
132
        mfc0    t1,status                       # Save status register
133
        sw      t1,mipsreg_sr(sp)
134
 
135
        sw      sp,0(a1)                        # save sp in save loc
136
 
137
        # Now load the destination thread by dropping through
138
        # to hal_thread_load_context
139
 
140
#------------------------------------------------------------------------------
141
# hal_thread_load_context
142
# Load thread context
143
# A0 = address of sp of next thread to execute
144
# Note that this function is also the second half of hal_thread_switch_context
145
# and is simply dropped into from it.
146
 
147
        .global hal_thread_load_context
148
hal_thread_load_context:
149
 
150
        lw      sp,0(a0)                        # load new SP directly
151
 
152
#ifndef CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM
153
 
154
        hal_fpu_load_caller sp
155
 
156
#endif
157
 
158
        hal_fpu_load_callee sp
159
 
160
#ifndef CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM
161
 
162
        lw      t0,mipsreg_hi(sp)               # load HI and LO regs
163
        lw      t1,mipsreg_lo(sp)
164
        mthi    t0
165
        mtlo    t1
166
 
167
#endif
168
 
169
        # load GPRs
170
        .set    noat
171
#       lgpr    0,sp
172
        lgpr    4,sp    # A0, must load for thread startup
173
#ifndef CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM
174
        lgpr    1,sp
175
        lgpr    2,sp
176
        lgpr    3,sp
177
        lgpr    5,sp
178
        lgpr    6,sp
179
        lgpr    7,sp
180
        lgpr    8,sp
181
        lgpr    9,sp
182
        lgpr    10,sp
183
        lgpr    11,sp
184
        lgpr    12,sp
185
        lgpr    13,sp
186
        lgpr    14,sp
187
        lgpr    15,sp
188
        lgpr    24,sp
189
        lgpr    25,sp
190
#endif
191
        lgpr    16,sp
192
        lgpr    17,sp
193
        lgpr    18,sp
194
        lgpr    19,sp
195
        lgpr    20,sp
196
        lgpr    21,sp
197
        lgpr    22,sp
198
        lgpr    23,sp
199
#       lgpr    26,sp   # == K0
200
#       lgpr    27,sp   # == K1
201
#       lgpr    28,sp   # == GP
202
#       lgpr    29,sp   # == SP
203
        lgpr    30,sp   # == FP
204
        lgpr    31,sp   # == RA
205
        .set    at
206
 
207
        lw      a2,mipsreg_sr(sp)               # A2 = saved SR
208
        lsp     sp,sp                           # SP = saved SP
209
 
210
        hal_cpu_int_merge a2                    # Merge with current SR
211
 
212
        jr      ra                              # return via ra
213
        nop                                     # delay slot - must be nop
214
 
215
#------------------------------------------------------------------------------
216
# HAL longjmp, setjmp implementations
217
# hal_setjmp saves only to callee save registers 16-23, 28, 30, 31[ra], 29[sp]
218
# into buffer supplied in a0[arg0]
219
# Note: These definitions are repeated in hal_arch.h. If changes are required
220
# remember to update both sets.
221
 
222
#define CYGARC_JMP_BUF_SP        0
223
#define CYGARC_JMP_BUF_R16       1
224
#define CYGARC_JMP_BUF_R17       2
225
#define CYGARC_JMP_BUF_R18       3
226
#define CYGARC_JMP_BUF_R19       4
227
#define CYGARC_JMP_BUF_R20       5
228
#define CYGARC_JMP_BUF_R21       6
229
#define CYGARC_JMP_BUF_R22       7
230
#define CYGARC_JMP_BUF_R23       8
231
#define CYGARC_JMP_BUF_R28       9
232
#define CYGARC_JMP_BUF_R30      10
233
#define CYGARC_JMP_BUF_R31      11
234
 
235
#define CYGARC_JMP_BUF_SIZE     12
236
 
237
// FIXME: The follwing restricts us to using only 32 bit registers
238
// in jump buffers. If/when we move to a full 64 bit architecture,
239
// this will need to change, as will the instructions that we use to
240
// save and restore them.
241
 
242
#define jmpbuf_regsize 4
243
 
244
        .globl  hal_setjmp
245
        .ent    hal_setjmp
246
hal_setjmp:
247
        sw      $31,CYGARC_JMP_BUF_R31*jmpbuf_regsize(a0)       # ra (link)
248
        sw      $30,CYGARC_JMP_BUF_R30*jmpbuf_regsize(a0)
249
        sw      $28,CYGARC_JMP_BUF_R28*jmpbuf_regsize(a0)       # gp, optimize out?
250
        sw      $23,CYGARC_JMP_BUF_R23*jmpbuf_regsize(a0)
251
        sw      $22,CYGARC_JMP_BUF_R22*jmpbuf_regsize(a0)
252
        sw      $21,CYGARC_JMP_BUF_R21*jmpbuf_regsize(a0)
253
        sw      $20,CYGARC_JMP_BUF_R20*jmpbuf_regsize(a0)
254
        sw      $19,CYGARC_JMP_BUF_R19*jmpbuf_regsize(a0)
255
        sw      $18,CYGARC_JMP_BUF_R18*jmpbuf_regsize(a0)
256
        sw      $17,CYGARC_JMP_BUF_R17*jmpbuf_regsize(a0)
257
        sw      $16,CYGARC_JMP_BUF_R16*jmpbuf_regsize(a0)
258
        sw      sp,CYGARC_JMP_BUF_SP*jmpbuf_regsize(a0) # $29
259
        li      v0,0
260
        jr      ra
261
        nop                     # delay slot
262
        .end hal_setjmp
263
 
264
        .globl  hal_longjmp
265
        .ent    hal_longjmp
266
hal_longjmp:
267
        lw      $31,CYGARC_JMP_BUF_R31*jmpbuf_regsize(a0)       # ra (link)
268
        lw      $30,CYGARC_JMP_BUF_R30*jmpbuf_regsize(a0)
269
        lw      $28,CYGARC_JMP_BUF_R28*jmpbuf_regsize(a0)       # gp, optimize out?
270
        lw      $23,CYGARC_JMP_BUF_R23*jmpbuf_regsize(a0)
271
        lw      $22,CYGARC_JMP_BUF_R22*jmpbuf_regsize(a0)
272
        lw      $21,CYGARC_JMP_BUF_R21*jmpbuf_regsize(a0)
273
        lw      $20,CYGARC_JMP_BUF_R20*jmpbuf_regsize(a0)
274
        lw      $19,CYGARC_JMP_BUF_R19*jmpbuf_regsize(a0)
275
        lw      $18,CYGARC_JMP_BUF_R18*jmpbuf_regsize(a0)
276
        lw      $17,CYGARC_JMP_BUF_R17*jmpbuf_regsize(a0)
277
        lw      $16,CYGARC_JMP_BUF_R16*jmpbuf_regsize(a0)
278
        lw      sp,CYGARC_JMP_BUF_SP*jmpbuf_regsize(a0) # $29
279
        move    v0,a1
280
        jr      ra
281
        nop                     # delay slot
282
        .end hal_longjmp
283
 
284
 
285
#------------------------------------------------------------------------------
286
# end of context.S

powered by: WebSVN 2.1.0

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