1 |=============================================================================
5 | ColdFire architecture context switch 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) 2006 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.
36 | -------------------------------------------
37 |###ECOSGPLCOPYRIGHTEND####
38 |=============================================================================
39 |#####DESCRIPTIONBEGIN####
41 | Author(s): Enrico Piria
44 | Purpose: This file contains implementations of the thread context
45 | switch routines. It also contains the longjmp() and setjmp()
48 |####DESCRIPTIONEND####
49 |========================================================================
52 #include <pkgconf/hal.h>
53 #include <cyg/hal/cf_offsets.inc>
54 #include <cyg/hal/arch.inc>
57 | ----------------------------------------------------------------------------
58 | hal_thread_switch_context - Switch between two threads
60 | externC void hal_thread_switch_context(CYG_ADDRESS to, CYG_ADDRESS from)
63 | 0(%sp) : return address
64 | 4(%sp) : to - address of sp of next thread to execute
65 | 8(%sp) : from - address of sp save location of current thread
73 | d0, d1, a0, a1 are ours to abuse. Other registers are not touched.
75 FUNC_START(hal_thread_switch_context)
79 | Read to and from parameters from the stack
80 move.l CYGARC_CF_CONTEXT_SIZE+4(%sp),%a0
81 move.l CYGARC_CF_CONTEXT_SIZE+8(%sp),%a1
83 | Store this thread's current stack pointer to *from
86 | Load the stack pointer for the next thread from *to
95 | ----------------------------------------------------------------------------
96 | hal_thread_load_context - Load thread context
98 | externC void hal_thread_load_context(CYG_ADDRESS to)
101 | 4(%sp) : to - address of sp of next thread to execute
109 | d0, d1, a0, a1 are ours to abuse.
111 FUNC_START(hal_thread_load_context)
113 | Read the to parameter from the stack and switch to that stack
118 | Load all of the preserved registers from the stack
119 movem.l CYGARC_CFREG_DREGS(%sp),%d0-%d7
120 movem.l CYGARC_CFREG_AREGS(%sp),%a0-%a6
123 move.w CYGARC_CF_SR(%sp), %d0
126 | Deallocate context frame
127 lea CYGARC_CF_CONTEXT_SIZE(%sp),%sp
133 | ----------------------------------------------------------------------------
134 | The following routines are based on the hal_jmp_buf structure layout, defined
137 | ----------------------------------------------------------------------------
138 | hal_setjmp - setjmp for the ColdFire architecture
140 | externC int hal_setjmp(hal_jmp_buf env)
143 | 0(%sp) : return address
144 | 4(%sp) : env - address of a hal_jmp_buf structure
150 | This routine always returns zero in d0.l.
152 | d0, d1, a0, a1 are ours to abuse.
154 FUNC_START(hal_setjmp)
156 | Get a pointer to the register buffer
159 | Store all of the preserved registers
160 movem.l %d2-%d7,CYGARC_JMPBUF_REG_D2(%a0)
161 movem.l %a2-%a6,CYGARC_JMPBUF_REG_A2(%a0)
163 #ifdef CYGHWR_HAL_COLDFIRE_MAC
164 | Store MAC registers
166 | Store MACSR register
168 move.l %d0,CYGARC_JMPBUF_REG_MACSR(%a0)
170 | Switch to integer mode. This allows to save the contents of ACC
172 and.l #0x000000df,%d0
177 move.l %d0,CYGARC_JMPBUF_REG_MACC(%a0)
179 | Store MASK register
181 move.l %d0,CYGARC_JMPBUF_REG_MASK(%a0)
184 | Store the stack pointer
185 move.l %sp,CYGARC_JMPBUF_REG_SP(%a0)
187 | Store the return address into the structure
188 move.l (%sp),CYGARC_JMPBUF_REG_PC(%a0)
190 | Load a zero return value
197 | ----------------------------------------------------------------------------
198 | hal_longjmp - longjmp for the ColdFire architecture
200 | externC void hal_longjmp(hal_jmp_buf env, int val)
203 | 0(%sp): return address
204 | 4(%sp): env - address of a hal_jmp_buf structure
205 | 8(%sp): val - the non-zero value to return
211 | This routine always returns the value from the val parameter in d0.l
212 | and to the location of the PC in the env structure.
214 FUNC_START(hal_longjmp)
216 | Load the return value parameter
219 | Get a pointer to the buffer to read our state from
222 | Load all of the preserved registers
223 movem.l CYGARC_JMPBUF_REG_D2(%a0),%d2-%d7
224 movem.l CYGARC_JMPBUF_REG_A2(%a0),%a2-%a6
226 #ifdef CYGHWR_HAL_COLDFIRE_MAC
229 | Load MACSR register
230 move.l CYGARC_JMPBUF_REG_MACSR(%a0),%d1
234 move.l CYGARC_JMPBUF_REG_MACC(%a0),%d1
238 move.l CYGARC_JMPBUF_REG_MASK(%a0),%d1
242 | Load the stack pointer
243 move.l CYGARC_JMPBUF_REG_SP(%a0),%sp
245 | Load return address and store it on stack
246 move.l CYGARC_JMPBUF_REG_PC(%a0),(%sp)