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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 786 skrzyp
// #===========================================================================
2
// #
3
// #    context.S
4
// #
5
// #    FUJITSU 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, 2004 Free Software Foundation, 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
16
// version.
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21
// for more details.
22
//
23
// You should have received a copy of the GNU General Public License
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
26
//
27
// As a special exception, if other files instantiate templates or use
28
// macros or inline functions from this file, or you compile this file
29
// and link it with other works to produce a work based on this file,
30
// this file does not by itself cause the resulting work to be covered by
31
// the GNU General Public License. However the source code for this file
32
// must still be made available in accordance with section (3) of the GNU
33
// General Public License v2.
34
//
35
// This exception does not invalidate any other reasons why a work based
36
// on this file might be covered by the GNU General Public License.
37
// -------------------------------------------
38
// ####ECOSGPLCOPYRIGHTEND####
39
// #===========================================================================
40
// ######DESCRIPTIONBEGIN####
41
// #
42
// # Author(s):    nickg, gthomas
43
// # Contributors: nickg, gthomas
44
// # Date:         1998-09-15
45
// # Purpose:      FUJITSU 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 "frv.inc"
57
 
58
        .text
59
 
60
// ----------------------------------------------------------------------------
61
//  hal_thread_switch_context(new, old)
62
//  Switch thread contexts
63
//  new = address of context of next thread to execute
64
//  old = address of context save location of current thread
65
//  thread state is saved on the current stack
66
 
67
        .globl  hal_thread_switch_context
68
hal_thread_switch_context:
69
        subi    sp,_TS_size,sp          // Space for saved frame
70
        sti     gr2,@(sp,_TS_GPR2)       // Save registers
71
        sti     gr3,@(sp,_TS_GPR3)
72
        sti     gr4,@(sp,_TS_GPR4)
73
        sti     gr5,@(sp,_TS_GPR5)
74
        sti     gr6,@(sp,_TS_GPR6)
75
        sti     gr7,@(sp,_TS_GPR7)
76
        sti     gr8,@(sp,_TS_GPR8)
77
        sti     gr9,@(sp,_TS_GPR9)
78
        sti     gr10,@(sp,_TS_GPR10)
79
        sti     gr11,@(sp,_TS_GPR11)
80
        sti     gr12,@(sp,_TS_GPR12)
81
        sti     gr13,@(sp,_TS_GPR13)
82
        sti     gr14,@(sp,_TS_GPR14)
83
        sti     gr15,@(sp,_TS_GPR15)
84
        sti     gr16,@(sp,_TS_GPR16)
85
        sti     gr17,@(sp,_TS_GPR17)
86
        sti     gr18,@(sp,_TS_GPR18)
87
        sti     gr19,@(sp,_TS_GPR19)
88
        sti     gr20,@(sp,_TS_GPR20)
89
        sti     gr21,@(sp,_TS_GPR21)
90
        sti     gr22,@(sp,_TS_GPR22)
91
        sti     gr23,@(sp,_TS_GPR23)
92
        sti     gr24,@(sp,_TS_GPR24)
93
        sti     gr25,@(sp,_TS_GPR25)
94
        sti     gr26,@(sp,_TS_GPR26)
95
        sti     gr27,@(sp,_TS_GPR27)
96
        sti     gr28,@(sp,_TS_GPR28)
97
        sti     gr29,@(sp,_TS_GPR29)
98
        sti     gr30,@(sp,_TS_GPR30)
99
        sti     gr31,@(sp,_TS_GPR31)
100
#if _NGPR != 32
101
#ifdef CYGINT_HAL_FRV_ARCH_FR400
102
        movsg   HSR0,gr5
103
        srli    gr5,#10,gr5
104
        andicc  gr5,#1,gr0,icc0
105
        bne     icc0,0,1f
106
#endif
107
        sti     gr32,@(sp,_TS_GPR32)
108
        sti     gr33,@(sp,_TS_GPR33)
109
        sti     gr34,@(sp,_TS_GPR34)
110
        sti     gr35,@(sp,_TS_GPR35)
111
        sti     gr36,@(sp,_TS_GPR36)
112
        sti     gr37,@(sp,_TS_GPR37)
113
        sti     gr38,@(sp,_TS_GPR38)
114
        sti     gr39,@(sp,_TS_GPR39)
115
        sti     gr40,@(sp,_TS_GPR40)
116
        sti     gr41,@(sp,_TS_GPR41)
117
        sti     gr42,@(sp,_TS_GPR42)
118
        sti     gr43,@(sp,_TS_GPR43)
119
        sti     gr44,@(sp,_TS_GPR44)
120
        sti     gr45,@(sp,_TS_GPR45)
121
        sti     gr46,@(sp,_TS_GPR46)
122
        sti     gr47,@(sp,_TS_GPR47)
123
        sti     gr48,@(sp,_TS_GPR48)
124
        sti     gr49,@(sp,_TS_GPR49)
125
        sti     gr50,@(sp,_TS_GPR50)
126
        sti     gr51,@(sp,_TS_GPR51)
127
        sti     gr52,@(sp,_TS_GPR52)
128
        sti     gr53,@(sp,_TS_GPR53)
129
        sti     gr54,@(sp,_TS_GPR54)
130
        sti     gr55,@(sp,_TS_GPR55)
131
        sti     gr56,@(sp,_TS_GPR56)
132
        sti     gr57,@(sp,_TS_GPR57)
133
        sti     gr58,@(sp,_TS_GPR58)
134
        sti     gr59,@(sp,_TS_GPR59)
135
        sti     gr60,@(sp,_TS_GPR60)
136
        sti     gr61,@(sp,_TS_GPR61)
137
        sti     gr62,@(sp,_TS_GPR62)
138
        sti     gr63,@(sp,_TS_GPR63)
139
1:
140
#endif
141
        movsg   psr,gr4
142
        sti     gr4,@(sp,_TS_PSR)
143
        movsg   lr,gr4
144
        sti     gr4,@(sp,_TS_PC)
145
        movsg   ccr,gr4
146
        sti     gr4,@(sp,_TS_CCR)
147
        movsg   lcr,gr4
148
        sti     gr4,@(sp,_TS_LCR)
149
        movsg   cccr,gr4
150
        sti     gr4,@(sp,_TS_CCCR)
151
        addi    sp,_TS_size,gr4
152
        sti     gr4,@(sp,_TS_SP)
153
        sti     sp,@(gr9,0)             // Pointer to saved context
154
 
155
        # Now load the destination thread by dropping through
156
        # to hal_thread_load_context
157
 
158
// ----------------------------------------------------------------------------
159
//  hal_thread_load_context(new)
160
//  Load thread context
161
//  new = address of context of next thread to execute
162
//  Note that this function is also the second half of
163
//  hal_thread_switch_context and is simply dropped into from it.
164
 
165
        .globl  hal_thread_load_context
166
hal_thread_load_context:
167
        ldi     @(gr8,0),sp             // Saved context
168
        ldi     @(sp,_TS_PSR),gr8
169
        setlos  #~_PSR_ET,gr9           // Turn off exceptions
170
        and     gr8,gr9,gr8
171
        setlos  #_PSR_PS|_PSR_S,gr9     // Stay in supervisor mode
172
        or      gr8,gr9,gr8
173
        movgs   gr8,psr
174
        ldi     @(sp,_TS_PC),gr8
175
        movgs   gr8,pcsr
176
        ldi     @(sp,_TS_CCR),gr8
177
        movgs   gr8,ccr
178
        ldi     @(sp,_TS_LCR),gr8
179
        movgs   gr8,lcr
180
        ldi     @(sp,_TS_CCCR),gr8
181
        movgs   gr8,cccr
182
#if _NGPR != 32
183
#ifdef CYGINT_HAL_FRV_ARCH_FR400
184
        movsg   HSR0,gr5
185
        srli    gr5,#10,gr5
186
        andicc  gr5,#1,gr0,icc0
187
        bne     icc0,0,1f
188
#endif
189
        ldi     @(sp,_TS_GPR32),gr32
190
        ldi     @(sp,_TS_GPR33),gr33
191
        ldi     @(sp,_TS_GPR34),gr34
192
        ldi     @(sp,_TS_GPR35),gr35
193
        ldi     @(sp,_TS_GPR36),gr36
194
        ldi     @(sp,_TS_GPR37),gr37
195
        ldi     @(sp,_TS_GPR38),gr38
196
        ldi     @(sp,_TS_GPR39),gr39
197
        ldi     @(sp,_TS_GPR40),gr40
198
        ldi     @(sp,_TS_GPR41),gr41
199
        ldi     @(sp,_TS_GPR42),gr42
200
        ldi     @(sp,_TS_GPR43),gr43
201
        ldi     @(sp,_TS_GPR44),gr44
202
        ldi     @(sp,_TS_GPR45),gr45
203
        ldi     @(sp,_TS_GPR46),gr46
204
        ldi     @(sp,_TS_GPR47),gr47
205
        ldi     @(sp,_TS_GPR48),gr48
206
        ldi     @(sp,_TS_GPR49),gr49
207
        ldi     @(sp,_TS_GPR50),gr50
208
        ldi     @(sp,_TS_GPR51),gr51
209
        ldi     @(sp,_TS_GPR52),gr52
210
        ldi     @(sp,_TS_GPR53),gr53
211
        ldi     @(sp,_TS_GPR54),gr54
212
        ldi     @(sp,_TS_GPR55),gr55
213
        ldi     @(sp,_TS_GPR56),gr56
214
        ldi     @(sp,_TS_GPR57),gr57
215
        ldi     @(sp,_TS_GPR58),gr58
216
        ldi     @(sp,_TS_GPR59),gr59
217
        ldi     @(sp,_TS_GPR60),gr60
218
        ldi     @(sp,_TS_GPR61),gr61
219
        ldi     @(sp,_TS_GPR62),gr62
220
        ldi     @(sp,_TS_GPR63),gr63
221
1:
222
#endif
223
        ldi     @(sp,_TS_GPR2),gr2       // Restore registers
224
        ldi     @(sp,_TS_GPR3),gr3
225
        ldi     @(sp,_TS_GPR4),gr4
226
        ldi     @(sp,_TS_GPR5),gr5
227
        ldi     @(sp,_TS_GPR6),gr6
228
        ldi     @(sp,_TS_GPR7),gr7
229
        ldi     @(sp,_TS_GPR8),gr8
230
        ldi     @(sp,_TS_GPR9),gr9
231
        ldi     @(sp,_TS_GPR10),gr10
232
        ldi     @(sp,_TS_GPR11),gr11
233
        ldi     @(sp,_TS_GPR12),gr12
234
        ldi     @(sp,_TS_GPR13),gr13
235
        ldi     @(sp,_TS_GPR14),gr14
236
        ldi     @(sp,_TS_GPR15),gr15
237
        ldi     @(sp,_TS_GPR16),gr16
238
        ldi     @(sp,_TS_GPR17),gr17
239
        ldi     @(sp,_TS_GPR18),gr18
240
        ldi     @(sp,_TS_GPR19),gr19
241
        ldi     @(sp,_TS_GPR20),gr20
242
        ldi     @(sp,_TS_GPR21),gr21
243
        ldi     @(sp,_TS_GPR22),gr22
244
        ldi     @(sp,_TS_GPR23),gr23
245
        ldi     @(sp,_TS_GPR24),gr24
246
        ldi     @(sp,_TS_GPR25),gr25
247
        ldi     @(sp,_TS_GPR26),gr26
248
        ldi     @(sp,_TS_GPR27),gr27
249
        ldi     @(sp,_TS_GPR28),gr28
250
        ldi     @(sp,_TS_GPR29),gr29
251
        ldi     @(sp,_TS_GPR30),gr30
252
        ldi     @(sp,_TS_GPR31),gr31
253
        ldi     @(sp,_TS_SP),sp
254
        rett    #0
255
 
256
// ----------------------------------------------------------------------------
257
//  HAL longjmp, setjmp implementations - based on newlib
258
//    Register      jmpbuf offset
259
//    R16-R31       0x0-0x03c
260
//    R48-R63       0x40-0x7c
261
//    FR16-FR31     0x80-0xbc
262
//    FR48-FR63     0xc0-0xfc
263
//    LR            0x100
264
//    SP            0x104
265
//    FP            0x108
266
//
267
// R8 contains the pointer to jmpbuf
268
 
269
        .text
270
        .global hal_setjmp
271
        .type   hal_setjmp,@function
272
hal_setjmp:
273
        stdi    gr16, @(gr8,0)
274
        stdi    gr18, @(gr8,8)
275
        stdi    gr20, @(gr8,16)
276
        stdi    gr22, @(gr8,24)
277
        stdi    gr24, @(gr8,32)
278
        stdi    gr26, @(gr8,40)
279
        stdi    gr28, @(gr8,48)
280
        stdi    gr30, @(gr8,56)
281
#if _NGPR != 32
282
#ifdef CYGINT_HAL_FRV_ARCH_FR400
283
        movsg   HSR0,gr5
284
        srli    gr5,#10,gr5
285
        andicc  gr5,#1,gr0,icc0
286
        bne     icc0,0,1f
287
#endif
288
        stdi    gr48, @(gr8,64)
289
        stdi    gr50, @(gr8,72)
290
        stdi    gr52, @(gr8,80)
291
        stdi    gr54, @(gr8,88)
292
        stdi    gr56, @(gr8,96)
293
        stdi    gr58, @(gr8,104)
294
        stdi    gr60, @(gr8,112)
295
        stdi    gr62, @(gr8,120)
296
1:
297
#endif
298
 
299
#if _NFPR != 0
300
        stdfi   fr16, @(gr8,128)
301
        stdfi   fr18, @(gr8,136)
302
        stdfi   fr20, @(gr8,144)
303
        stdfi   fr22, @(gr8,152)
304
        stdfi   fr24, @(gr8,160)
305
        stdfi   fr26, @(gr8,168)
306
        stdfi   fr28, @(gr8,176)
307
        stdfi   fr30, @(gr8,184)
308
#if _NFPR != 32
309
#ifdef CYGINT_HAL_FRV_ARCH_FR400
310
        movsg   HSR0,gr5
311
        srli    gr5,#11,gr5
312
        andicc  gr5,#1,gr0,icc0
313
        bne     icc0,0,1f
314
#endif
315
        stdfi   fr48, @(gr8,192)
316
        stdfi   fr50, @(gr8,200)
317
        stdfi   fr52, @(gr8,208)
318
        stdfi   fr54, @(gr8,216)
319
        stdfi   fr56, @(gr8,224)
320
        stdfi   fr58, @(gr8,232)
321
        stdfi   fr60, @(gr8,240)
322
        stdfi   fr62, @(gr8,248)
323
1:
324
#endif
325
#endif
326
 
327
        movsg   lr, gr4
328
        sti     gr4, @(gr8,256)
329
        sti     sp, @(gr8,260)
330
        sti     fp, @(gr8,264)
331
 
332
        mov     gr0,gr8
333
        ret
334
.Lend1:
335
        .size   hal_setjmp,.Lend1-hal_setjmp
336
 
337
        .global hal_longjmp
338
        .type   hal_longjmp,@function
339
hal_longjmp:
340
#if _NFPR != 0
341
        lddfi   @(gr8,128), fr16
342
        lddfi   @(gr8,136), fr18
343
        lddfi   @(gr8,144), fr20
344
        lddfi   @(gr8,152), fr22
345
        lddfi   @(gr8,160), fr24
346
        lddfi   @(gr8,168), fr26
347
        lddfi   @(gr8,176), fr28
348
        lddfi   @(gr8,184), fr30
349
#if _NFPR != 32
350
#ifdef CYGINT_HAL_FRV_ARCH_FR400
351
        movsg   HSR0,gr5
352
        srli    gr5,#11,gr5
353
        andicc  gr5,#1,gr0,icc0
354
        bne     icc0,0,1f
355
#endif
356
        lddfi   @(gr8,192), fr48
357
        lddfi   @(gr8,200), fr50
358
        lddfi   @(gr8,208), fr52
359
        lddfi   @(gr8,216), fr54
360
        lddfi   @(gr8,224), fr56
361
        lddfi   @(gr8,232), fr58
362
        lddfi   @(gr8,240), fr60
363
        lddfi   @(gr8,248), fr62
364
1:
365
#endif
366
#endif
367
 
368
#if _NGPR != 32
369
#ifdef CYGINT_HAL_FRV_ARCH_FR400
370
        movsg   HSR0,gr5
371
        srli    gr5,#10,gr5
372
        andicc  gr5,#1,gr0,icc0
373
        bne     icc0,0,1f
374
#endif
375
        lddi    @(gr8,64), gr48
376
        lddi    @(gr8,72), gr50
377
        lddi    @(gr8,80), gr52
378
        lddi    @(gr8,88), gr54
379
        lddi    @(gr8,96), gr56
380
        lddi    @(gr8,104), gr58
381
        lddi    @(gr8,112), gr60
382
        lddi    @(gr8,120), gr62
383
1:
384
#endif
385
        lddi    @(gr8,0), gr16
386
        lddi    @(gr8,8), gr18
387
        lddi    @(gr8,16), gr20
388
        lddi    @(gr8,24), gr22
389
        lddi    @(gr8,32), gr24
390
        lddi    @(gr8,40), gr26
391
        lddi    @(gr8,48), gr28
392
        lddi    @(gr8,56), gr30
393
 
394
 
395
        ldi     @(gr8,256), gr4
396
        movgs   gr4,lr
397
 
398
        ldi     @(gr8,260), sp
399
        ldi     @(gr8,264), fp
400
 
401
# Value to return is in r9.  If zero, return 1
402
        cmp     gr9, gr0, icc0
403
        setlos  #1, gr8
404
        ckne    icc0, cc4
405
        cmov    gr9, gr8, cc4, 1
406
        ret
407
.Lend2:
408
        .size   hal_longjmp,.Lend2-hal_longjmp2
409
 
410
// ----------------------------------------------------------------------------
411
//  end of context.S

powered by: WebSVN 2.1.0

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