summaryrefslogtreecommitdiff
path: root/ecos/packages/hal/coldfire/arch/current/src/context.S
blob: 60e02b2a9412e52f81e8c790abdd90b233c5bf93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|=============================================================================
|
|      context.S
|
|      ColdFire architecture context switch code
|
|=============================================================================
| ####ECOSGPLCOPYRIGHTBEGIN####                                             
| -------------------------------------------                               
| This file is part of eCos, the Embedded Configurable Operating System.    
| Copyright (C) 1998, 1999, 2000, 2001, 2002, 2006 Free Software Foundation, Inc.
|
| eCos is free software; you can redistribute it and/or modify it under     
| the terms of the GNU General Public License as published by the Free      
| Software Foundation; either version 2 or (at your option) any later       
| version.                                                                  
|
| eCos is distributed in the hope that it will be useful, but WITHOUT       
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     
| FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License     
| for more details.                                                         
|
| You should have received a copy of the GNU General Public License         
| along with eCos; if not, write to the Free Software Foundation, Inc.,     
| 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             
|
| As a special exception, if other files instantiate templates or use       
| macros or inline functions from this file, or you compile this file       
| and link it with other works to produce a work based on this file,        
| this file does not by itself cause the resulting work to be covered by    
| the GNU General Public License. However the source code for this file     
| must still be made available in accordance with section (3) of the GNU    
| General Public License v2.                                                
|
| This exception does not invalidate any other reasons why a work based     
| on this file might be covered by the GNU General Public License.          
| -------------------------------------------                               
| ####ECOSGPLCOPYRIGHTEND####                                               
|=============================================================================
|#####DESCRIPTIONBEGIN####
|
| Author(s):     Enrico Piria
| Contributors:
| Date:          2005-25-06
| Purpose:       This file contains implementations of the thread context 
|                switch routines. It also contains the longjmp() and setjmp()
|                routines.
|
|####DESCRIPTIONEND####
|========================================================================


#include <pkgconf/hal.h>
#include <cyg/hal/cf_offsets.inc>
#include <cyg/hal/arch.inc>


| ----------------------------------------------------------------------------
| hal_thread_switch_context - Switch between two threads
|
| externC void hal_thread_switch_context(CYG_ADDRESS to, CYG_ADDRESS from)
|
| INPUT:
|   0(%sp) : return address
|   4(%sp) : to - address of sp of next thread to execute
|   8(%sp) : from - address of sp save location of current thread
|
| OUTPUT:
|   None
| 
| RETURN VALUE:
|   None
|
| d0, d1, a0, a1 are ours to abuse. Other registers are not touched.

FUNC_START(hal_thread_switch_context)

        ctx_save_registers

        | Read to and from parameters from the stack        
        move.l  CYGARC_CF_CONTEXT_SIZE+4(%sp),%a0  
        move.l  CYGARC_CF_CONTEXT_SIZE+8(%sp),%a1  

        | Store this thread's current stack pointer to *from
        move.l  %sp,(%a1)
                                            
        | Load the stack pointer for the next thread from *to
        move.l  (%a0),%sp
                                            
        ctx_restore_registers

        | Return to caller
        rts


| ----------------------------------------------------------------------------
| hal_thread_load_context - Load thread context
|
| externC void hal_thread_load_context(CYG_ADDRESS to)
| 
| INPUT:
|   4(%sp) : to - address of sp of next thread to execute
|
| OUTPUT:
|   None
| 
| RETURN VALUE:
|   None
|
| d0, d1, a0, a1 are ours to abuse.

FUNC_START(hal_thread_load_context)

        | Read the to parameter from the stack and switch to that stack
        | pointer
        move.l  4(%sp),%a0                  
        move.l  (%a0),%sp                   

        | Load all of the  preserved registers from the stack
        movem.l   CYGARC_CFREG_DREGS(%sp),%d0-%d7
        movem.l   CYGARC_CFREG_AREGS(%sp),%a0-%a6

        | Starting SR
        move.w CYGARC_CF_SR(%sp), %d0
        move.w %d0,%sr
        
        | Deallocate context frame
        lea CYGARC_CF_CONTEXT_SIZE(%sp),%sp

        | Return
        rts


| ----------------------------------------------------------------------------
| The following routines are based on the hal_jmp_buf structure layout, defined
| in hal_arch.h

| ----------------------------------------------------------------------------
| hal_setjmp - setjmp for the ColdFire architecture
| 
| externC int hal_setjmp(hal_jmp_buf env)
| 
| INPUT:
|   0(%sp) : return address
|   4(%sp) : env - address of a hal_jmp_buf structure
| 
| OUTPUT:
|   None 
| 
| RETURN VALUE:
|   This routine always returns zero in d0.l.
| 
| d0, d1, a0, a1 are ours to abuse.

FUNC_START(hal_setjmp)

        | Get a pointer to the register buffer
        move.l   4(%sp),%a0

        | Store all of the preserved registers
        movem.l %d2-%d7,CYGARC_JMPBUF_REG_D2(%a0)
        movem.l %a2-%a6,CYGARC_JMPBUF_REG_A2(%a0)

#ifdef CYGHWR_HAL_COLDFIRE_MAC
        | Store MAC registers

        | Store MACSR register
        move.l  %macsr,%d0
        move.l  %d0,CYGARC_JMPBUF_REG_MACSR(%a0)

        | Switch to integer mode. This allows to save the contents of ACC
        | without rounding
        and.l   #0x000000df,%d0
        move.l  %d0,%macsr

        | Store ACC register
        move.l  %acc,%d0
        move.l  %d0,CYGARC_JMPBUF_REG_MACC(%a0)

        | Store MASK register
        move.l  %mask,%d0
        move.l  %d0,CYGARC_JMPBUF_REG_MASK(%a0)
#endif

        | Store the stack pointer
        move.l  %sp,CYGARC_JMPBUF_REG_SP(%a0)

        | Store the return address into the structure
        move.l  (%sp),CYGARC_JMPBUF_REG_PC(%a0)

        | Load a zero return value
        clr.l %d0

        | Return
        rts


| ----------------------------------------------------------------------------
| hal_longjmp - longjmp for the ColdFire architecture
| 
| externC void hal_longjmp(hal_jmp_buf env, int val)
| 
| INPUT:
|   0(%sp): return address
|   4(%sp): env - address of a hal_jmp_buf structure
|   8(%sp): val - the non-zero value to return
| 
| OUTPUT:
|   None
| 
| RETURN VALUE:
|   This routine always returns the value from the val parameter in  d0.l
|   and to the location of the PC in the env structure.

FUNC_START(hal_longjmp)

        | Load the return value parameter
        move.l  8(%sp),%d0
                                            
        | Get a pointer to the buffer to read our state from
        move.l  4(%sp),%a0                  
                                            
        | Load all of the preserved registers
        movem.l CYGARC_JMPBUF_REG_D2(%a0),%d2-%d7
        movem.l CYGARC_JMPBUF_REG_A2(%a0),%a2-%a6

#ifdef CYGHWR_HAL_COLDFIRE_MAC
        | Load MAC registers

        | Load MACSR register
        move.l  CYGARC_JMPBUF_REG_MACSR(%a0),%d1
        move.l  %d1,%macsr

        | Load ACC register
        move.l  CYGARC_JMPBUF_REG_MACC(%a0),%d1
        move.l  %d1,%acc

        | Load MASK register
        move.l  CYGARC_JMPBUF_REG_MASK(%a0),%d1
        move.l  %d1,%mask        
#endif

        | Load the stack pointer
        move.l  CYGARC_JMPBUF_REG_SP(%a0),%sp                  

        | Load return address and store it on stack
        move.l  CYGARC_JMPBUF_REG_PC(%a0),(%sp)

        | Return to caller
        rts