1 ##=============================================================================
5 ## FR30 context switch and longjmp setjmp code
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.
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.
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
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.
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.
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.
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####
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()
52 ######DESCRIPTIONEND####
54 ##=============================================================================
56 #include <pkgconf/hal.h>
58 #include <cyg/hal/fr30.inc>
60 #include <cyg/hal/arch.inc>
62 #------------------------------------------------------------------------------
63 # function declaration macro
65 #define FUNC_START(name) \
69 #------------------------------------------------------------------------------
70 # hal_thread_switch_context
71 # Switch thread contexts
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)
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.
85 .globl hal_thread_switch_context
86 hal_thread_switch_context:
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
95 st r0, @-r15 ; store usp
97 st r0, @-r15 ; store ssp
101 st rp, @-r15 ; rp is our new pc when load_context executes
103 st r15, @-r15 ; store original r15 here
105 stm1 (r8, r9, r10, r11, r12, r13, r14)
106 stm0 (r0, r1, r2, r3 , r4 , r5 , r6 , r7)
108 # we should be finished saving context here
110 st r15, @r5 ; store pointer to saved context
112 #------------------------------------------------------------------------------
113 # hal_thread_load_context
114 # Load thread context
115 .globl hal_thread_load_context
116 hal_thread_load_context:
120 ldm0 (r0, r1, r2, r3, r4, r5, r6, r7)
121 ldm1 (r8, r9, r10, r11, r12, r13, r14)
126 # TODO addsp to skip stack positions
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:
143 # Register jmpbuf offset
165 .type hal_setjmp,@function
176 # Return 0 to caller.
191 # If caller attempted to return 0, return 1 instead.
200 #-----------------------------------------------------------------------------