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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
##=============================================================================
2
##
3
##      context.S
4
##
5
##      FR30 context switch and longjmp setjmp 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, 2007 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):   larsi
43
## Contributors:larsi
44
## Date:        2006-06-03
45
## Purpose:     fr30 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
#include 
59
 
60
#------------------------------------------------------------------------------
61
# function declaration macro
62
 
63
#define FUNC_START(name)                        \
64
        .globl name;                            \
65
name:
66
 
67
#------------------------------------------------------------------------------
68
# hal_thread_switch_context
69
# Switch thread contexts
70
#
71
# a timer interrupt should have caused this function to be called
72
# so interrupts are forbidden and we are in SSP mode (S flag=1)
73
#
74
# R4 and R5 contain our arguments.
75
# R5 is _fspptr_ (old USP), R4 is _tspptr_ (new USP).
76
# @(SSP) has the return address of the call to this function.
77
# In @(SSP,4) the PS and in @(SSP,8) the PC are saved by hardware.
78
# Before we RETI, we have to switch S flag in CCR to 0
79
# to use SSP for returning. Interrupts have to be
80
# reenabled before returning, but this is done by restoring PS.
81
 
82
 
83
    .globl  hal_thread_switch_context
84
hal_thread_switch_context:
85
 
86
# at first switch to USP (set bit 5 in CCR in PS)
87
    st      r0,     @-r15       ; push last_trap, cannot guarantee that it is
88
                                ; the right value, but that should not matter
89
                                ; as it is only for GDB
90
    st      mdl,    @-r15
91
    st      mdh,    @-r15
92
 
93
    st      r0,     @-r15       ; store usp
94
 
95
    st      r0,     @-r15       ; store ssp
96
    st      rp,     @-r15
97
    st      tbr,    @-r15
98
    st      ps,     @-r15
99
    st      rp,     @-r15       ; rp is our new pc when load_context executes
100
 
101
    st      r15,    @-r15       ; store original r15 here
102
 
103
    stm1    (r8, r9, r10, r11, r12, r13, r14)
104
    stm0    (r0, r1, r2, r3 , r4 , r5 , r6 , r7)
105
 
106
# we should be finished saving context here
107
 
108
    st      r15,    @r5         ; store pointer to saved context
109
 
110
#------------------------------------------------------------------------------
111
# hal_thread_load_context
112
# Load thread context
113
.globl  hal_thread_load_context
114
hal_thread_load_context:
115
 
116
    ld      @r4,     r15
117
 
118
    ldm0    (r0, r1, r2, r3, r4, r5, r6, r7)
119
    ldm1    (r8, r9, r10, r11, r12, r13, r14)
120
    ld      @r15+,  mdl
121
    ld      @r15+,  rp
122
    ld      @r15+,  ps
123
    ld      @r15+,  tbr
124
# TODO addsp to skip stack positions
125
    ld      @r15+,  mdl
126
    ld      @r15+,  mdl
127
    ld      @r15+,  mdl
128
    ld      @r15+,  mdh
129
    ld      @r15+,  mdl
130
    addsp   4
131
    ret
132
 
133
#------------------------------------------------------------------------------
134
# HAL longjmp, setjmp implementations
135
# hal_setjmp saves only to callee save registers r8, r9, r10, r11, r14, r15
136
# into buffer supplied in r4
137
# Note: These definitions are repeated in hal_arch.h. If changes are required
138
# remember to update both sets.
139
# setjmp/longjmp for FR30.  The jmpbuf looks like this:
140
#
141
# Register  jmpbuf offset
142
# r8        0x00
143
# r9        0x04
144
# r10       0x08
145
# r11       0x0c
146
# r14 (FP)  0x10
147
# r15 (SP)  0x14
148
# pc  (rp)  0x18
149
 
150
    .macro save reg
151
    st      \reg,   @r4
152
    addn    #4,     r4
153
    .endm
154
 
155
    .macro restore reg
156
    ld      @r4,    \reg
157
    addn    #4,     r4
158
    .endm
159
 
160
 
161
    .text
162
    .global hal_setjmp
163
    .type   hal_setjmp,@function
164
hal_setjmp:
165
    save    r8
166
    save    r9
167
    save    r10
168
    save    r11
169
    save    r14
170
    save    r15
171
    mov     rp,     r5
172
    st      r5,     @r4
173
 
174
# Return 0 to caller.
175
    ldi:8   #0,     r4
176
    ret
177
 
178
    .global hal_longjmp
179
hal_longjmp:
180
    restore r8
181
    restore r9
182
    restore r10
183
    restore r11
184
    restore r14
185
    restore r15
186
    ld      @r4,    r4
187
    mov     r4,     rp
188
 
189
# If caller attempted to return 0, return 1 instead.
190
 
191
    mov     r5,     r4
192
    or      r4,     r4
193
    bne     1f
194
    ldi:8   #1,     r4
195
1:
196
    ret
197
 
198
#-----------------------------------------------------------------------------
199
# End of context.S

powered by: WebSVN 2.1.0

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