]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/coldfire/arch/v2_0/src/context.S
Initial revision
[karo-tx-redboot.git] / packages / hal / coldfire / arch / v2_0 / src / context.S
1 |=============================================================================
2 |
3 |      context.S
4 |
5 |      ColdFire architecture 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 Red Hat, Inc.
12 | Copyright (C) 2006 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 |###ECOSGPLCOPYRIGHTEND####
38 |=============================================================================
39 |#####DESCRIPTIONBEGIN####
40 |
41 | Author(s):     Enrico Piria
42 | Contributors:
43 | Date:          2005-25-06
44 | Purpose:       This file contains implementations of the thread context 
45 |                switch routines. It also contains the longjmp() and setjmp()
46 |                routines.
47 |
48 |####DESCRIPTIONEND####
49 |========================================================================
50
51
52 #include <pkgconf/hal.h>
53 #include <cyg/hal/cf_offsets.inc>
54 #include <cyg/hal/arch.inc>
55
56
57 | ----------------------------------------------------------------------------
58 | hal_thread_switch_context - Switch between two threads
59 |
60 | externC void hal_thread_switch_context(CYG_ADDRESS to, CYG_ADDRESS from)
61 |
62 | INPUT:
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
66 |
67 | OUTPUT:
68 |   None
69
70 | RETURN VALUE:
71 |   None
72 |
73 | d0, d1, a0, a1 are ours to abuse. Other registers are not touched.
74
75 FUNC_START(hal_thread_switch_context)
76
77         ctx_save_registers
78
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  
82
83         | Store this thread's current stack pointer to *from
84         move.l  %sp,(%a1)
85                                             
86         | Load the stack pointer for the next thread from *to
87         move.l  (%a0),%sp
88                                             
89         ctx_restore_registers
90
91         | Return to caller
92         rts
93
94
95 | ----------------------------------------------------------------------------
96 | hal_thread_load_context - Load thread context
97 |
98 | externC void hal_thread_load_context(CYG_ADDRESS to)
99
100 | INPUT:
101 |   4(%sp) : to - address of sp of next thread to execute
102 |
103 | OUTPUT:
104 |   None
105
106 | RETURN VALUE:
107 |   None
108 |
109 | d0, d1, a0, a1 are ours to abuse.
110
111 FUNC_START(hal_thread_load_context)
112
113         | Read the to parameter from the stack and switch to that stack
114         | pointer
115         move.l  4(%sp),%a0                  
116         move.l  (%a0),%sp                   
117
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
121
122         | Starting SR
123         move.w CYGARC_CF_SR(%sp), %d0
124         move.w %d0,%sr
125         
126         | Deallocate context frame
127         lea CYGARC_CF_CONTEXT_SIZE(%sp),%sp
128
129         | Return
130         rts
131
132
133 | ----------------------------------------------------------------------------
134 | The following routines are based on the hal_jmp_buf structure layout, defined
135 | in hal_arch.h
136
137 | ----------------------------------------------------------------------------
138 | hal_setjmp - setjmp for the ColdFire architecture
139
140 | externC int hal_setjmp(hal_jmp_buf env)
141
142 | INPUT:
143 |   0(%sp) : return address
144 |   4(%sp) : env - address of a hal_jmp_buf structure
145
146 | OUTPUT:
147 |   None 
148
149 | RETURN VALUE:
150 |   This routine always returns zero in d0.l.
151
152 | d0, d1, a0, a1 are ours to abuse.
153
154 FUNC_START(hal_setjmp)
155
156         | Get a pointer to the register buffer
157         move.l   4(%sp),%a0
158
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)
162
163 #ifdef CYGHWR_HAL_COLDFIRE_MAC
164         | Store MAC registers
165
166         | Store MACSR register
167         move.l  %macsr,%d0
168         move.l  %d0,CYGARC_JMPBUF_REG_MACSR(%a0)
169
170         | Switch to integer mode. This allows to save the contents of ACC
171         | without rounding
172         and.l   #0x000000df,%d0
173         move.l  %d0,%macsr
174
175         | Store ACC register
176         move.l  %acc,%d0
177         move.l  %d0,CYGARC_JMPBUF_REG_MACC(%a0)
178
179         | Store MASK register
180         move.l  %mask,%d0
181         move.l  %d0,CYGARC_JMPBUF_REG_MASK(%a0)
182 #endif
183
184         | Store the stack pointer
185         move.l  %sp,CYGARC_JMPBUF_REG_SP(%a0)
186
187         | Store the return address into the structure
188         move.l  (%sp),CYGARC_JMPBUF_REG_PC(%a0)
189
190         | Load a zero return value
191         clr.l %d0
192
193         | Return
194         rts
195
196
197 | ----------------------------------------------------------------------------
198 | hal_longjmp - longjmp for the ColdFire architecture
199
200 | externC void hal_longjmp(hal_jmp_buf env, int val)
201
202 | INPUT:
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
206
207 | OUTPUT:
208 |   None
209
210 | RETURN VALUE:
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.
213
214 FUNC_START(hal_longjmp)
215
216         | Load the return value parameter
217         move.l  8(%sp),%d0
218                                             
219         | Get a pointer to the buffer to read our state from
220         move.l  4(%sp),%a0                  
221                                             
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
225
226 #ifdef CYGHWR_HAL_COLDFIRE_MAC
227         | Load MAC registers
228
229         | Load MACSR register
230         move.l  CYGARC_JMPBUF_REG_MACSR(%a0),%d1
231         move.l  %d1,%macsr
232
233         | Load ACC register
234         move.l  CYGARC_JMPBUF_REG_MACC(%a0),%d1
235         move.l  %d1,%acc
236
237         | Load MASK register
238         move.l  CYGARC_JMPBUF_REG_MASK(%a0),%d1
239         move.l  %d1,%mask        
240 #endif
241
242         | Load the stack pointer
243         move.l  CYGARC_JMPBUF_REG_SP(%a0),%sp                  
244
245         | Load return address and store it on stack
246         move.l  CYGARC_JMPBUF_REG_PC(%a0),(%sp)
247
248         | Return to caller
249         rts