]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/fr30/arch/v2_0/src/context.S
Initial revision
[karo-tx-redboot.git] / packages / hal / fr30 / arch / v2_0 / src / context.S
1 ##=============================================================================
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 Red Hat, Inc.
12 ## Copyright (C) 2007 eCosCentric Ltd.
13 ##
14 ## eCos is free software; you can redistribute it and/or modify it under
15 ## the terms of the GNU General Public License as published by the Free
16 ## Software Foundation; either version 2 or (at your option) any later version.
17 ##
18 ## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 ## 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 along
24 ## with eCos; if not, write to the Free Software Foundation, Inc.,
25 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 ##
27 ## As a special exception, if other files instantiate templates or use macros
28 ## or inline functions from this file, or you compile this file and link it
29 ## with other works to produce a work based on this file, this file does not
30 ## by itself cause the resulting work to be covered by the GNU General Public
31 ## License. However the source code for this file must still be made available
32 ## in accordance with section (3) of the GNU General Public License.
33 ##
34 ## This exception does not invalidate any other reasons why a work based on
35 ## this file might be covered by the GNU General Public License.
36 ##
37 ## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38 ## at http://sources.redhat.com/ecos/ecos-license/
39 ## -------------------------------------------
40 #####ECOSGPLCOPYRIGHTEND####
41 ##=============================================================================
42 #######DESCRIPTIONBEGIN####
43 ##
44 ## Author(s):   larsi
45 ## Contributors:larsi
46 ## Date:        2006-06-03
47 ## Purpose:     fr30 context switch code
48 ## Description: This file contains implementations of the thread context 
49 ##              switch routines. It also contains the longjmp() and setjmp()
50 ##              routines.
51 ##
52 ######DESCRIPTIONEND####
53 ##
54 ##=============================================================================
55
56 #include <pkgconf/hal.h>
57
58 #include <cyg/hal/fr30.inc>
59
60 #include <cyg/hal/arch.inc>
61         
62 #------------------------------------------------------------------------------
63 # function declaration macro
64
65 #define FUNC_START(name)                        \
66         .globl name;                            \
67 name:
68
69 #------------------------------------------------------------------------------
70 # hal_thread_switch_context
71 # Switch thread contexts
72
73 # a timer interrupt should have caused this function to be called
74 # so interrupts are forbidden and we are in SSP mode (S flag=1)
75 #
76 # R4 and R5 contain our arguments.
77 # R5 is _fspptr_ (old USP), R4 is _tspptr_ (new USP).
78 # @(SSP) has the return address of the call to this function.
79 # In @(SSP,4) the PS and in @(SSP,8) the PC are saved by hardware.
80 # Before we RETI, we have to switch S flag in CCR to 0
81 # to use SSP for returning. Interrupts have to be
82 # reenabled before returning, but this is done by restoring PS.
83
84
85     .globl  hal_thread_switch_context
86 hal_thread_switch_context:
87
88 # at first switch to USP (set bit 5 in CCR in PS)
89     st      r0,     @-r15       ; push last_trap, cannot guarantee that it is
90                                 ; the right value, but that should not matter
91                                 ; as it is only for GDB
92     st      mdl,    @-r15
93     st      mdh,    @-r15
94
95     st      r0,     @-r15       ; store usp
96
97     st      r0,     @-r15       ; store ssp
98     st      rp,     @-r15
99     st      tbr,    @-r15
100     st      ps,     @-r15
101     st      rp,     @-r15       ; rp is our new pc when load_context executes
102
103     st      r15,    @-r15       ; store original r15 here
104
105     stm1    (r8, r9, r10, r11, r12, r13, r14)
106     stm0    (r0, r1, r2, r3 , r4 , r5 , r6 , r7)
107
108 # we should be finished saving context here
109
110     st      r15,    @r5         ; store pointer to saved context
111
112 #------------------------------------------------------------------------------
113 # hal_thread_load_context
114 # Load thread context
115 .globl  hal_thread_load_context
116 hal_thread_load_context:
117
118     ld      @r4,     r15
119
120     ldm0    (r0, r1, r2, r3, r4, r5, r6, r7)
121     ldm1    (r8, r9, r10, r11, r12, r13, r14)
122     ld      @r15+,  mdl
123     ld      @r15+,  rp
124     ld      @r15+,  ps
125     ld      @r15+,  tbr
126 # TODO addsp to skip stack positions
127     ld      @r15+,  mdl
128     ld      @r15+,  mdl
129     ld      @r15+,  mdl
130     ld      @r15+,  mdh
131     ld      @r15+,  mdl
132     addsp   4
133     ret
134
135 #------------------------------------------------------------------------------
136 # HAL longjmp, setjmp implementations
137 # hal_setjmp saves only to callee save registers r8, r9, r10, r11, r14, r15
138 # into buffer supplied in r4
139 # Note: These definitions are repeated in hal_arch.h. If changes are required
140 # remember to update both sets.
141 # setjmp/longjmp for FR30.  The jmpbuf looks like this:
142 #
143 # Register  jmpbuf offset
144 # r8        0x00
145 # r9        0x04
146 # r10       0x08
147 # r11       0x0c
148 # r14 (FP)  0x10
149 # r15 (SP)  0x14
150 # pc  (rp)  0x18
151
152     .macro save reg
153     st      \reg,   @r4
154     addn    #4,     r4
155     .endm
156
157     .macro restore reg
158     ld      @r4,    \reg
159     addn    #4,     r4
160     .endm
161
162
163     .text
164     .global hal_setjmp
165     .type   hal_setjmp,@function
166 hal_setjmp:
167     save    r8
168     save    r9
169     save    r10
170     save    r11
171     save    r14
172     save    r15
173     mov     rp,     r5
174     st      r5,     @r4
175
176 # Return 0 to caller.
177     ldi:8   #0,     r4
178     ret
179
180     .global hal_longjmp
181 hal_longjmp:
182     restore r8
183     restore r9
184     restore r10
185     restore r11
186     restore r14
187     restore r15
188     ld      @r4,    r4
189     mov     r4,     rp
190
191 # If caller attempted to return 0, return 1 instead.
192
193     mov     r5,     r4
194     or      r4,     r4
195     bne     1f
196     ldi:8   #1,     r4
197 1:
198     ret
199
200 #-----------------------------------------------------------------------------
201 # End of context.S