]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/coldfire/arch/v2_0/include/arch.inc
Initial revision
[karo-tx-redboot.git] / packages / hal / coldfire / arch / v2_0 / include / arch.inc
1 #ifndef CYGONCE_HAL_ARCH_INC
2 #define CYGONCE_HAL_ARCH_INC
3 |=============================================================================
4 |
5 |  arch.inc
6 |
7 |  ColdFire architecture assembler header file
8 |
9 |=============================================================================
10 |###ECOSGPLCOPYRIGHTBEGIN####
11 | -------------------------------------------
12 | This file is part of eCos, the Embedded Configurable Operating System.
13 | Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14 | Copyright (C) 2006 eCosCentric Ltd.
15 |
16 | eCos is free software; you can redistribute it and/or modify it under
17 | the terms of the GNU General Public License as published by the Free
18 | Software Foundation; either version 2 or (at your option) any later version.
19 |
20 | eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 | FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23 | for more details.
24 |
25 | You should have received a copy of the GNU General Public License along
26 | with eCos; if not, write to the Free Software Foundation, Inc.,
27 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 |
29 | As a special exception, if other files instantiate templates or use macros
30 | or inline functions from this file, or you compile this file and link it
31 | with other works to produce a work based on this file, this file does not
32 | by itself cause the resulting work to be covered by the GNU General Public
33 | License. However the source code for this file must still be made available
34 | in accordance with section (3) of the GNU General Public License.
35 |
36 | This exception does not invalidate any other reasons why a work based on
37 | this file might be covered by the GNU General Public License.
38 | -------------------------------------------
39 |###ECOSGPLCOPYRIGHTEND####
40 |=============================================================================
41 |#####DESCRIPTIONBEGIN####
42 |
43 | Author(s):    Enrico Piria
44 | Contributors:
45 | Date:         2005-25-06
46 | Purpose:      MCF5272 variant definitions.
47 | Description:  This file contains macro definitions used in the
48 |               architecture HAL assembler file.
49 |
50 |####DESCRIPTIONEND####
51 |==========================================================================
52
53
54 #define FUNC_START(name)    \
55     .text;                  \
56     .balign 4;              \
57     .type name,@function;   \
58     .globl name;            \
59 name:
60
61
62 | ----------------------------------------------------------------------------
63 | Macros to deal with the interrupt priority level in the status register.
64
65         .macro hal_cpu_int_disable
66         move.w  #0x2700,%sr
67         .endm
68
69         
70         .macro hal_cpu_int_enable work
71         move.w  %sr,\work
72         and.l   #0xf8ff,\work
73         move.w  \work,%sr
74         .endm
75
76         
77         .macro hal_cpu_int_merge from work
78         move.w  %sr,\work
79         and.l   #0xf8ff,\work
80         and.l   #0x0700,\from
81         or.l    \from,\work
82         move.w \work,%sr
83         .endm
84
85 | ----------------------------------------------------------------------------
86 | Macro to find the value the SP register had before an exception.
87         
88         .macro find_original_sp out
89         move.b  CYGARC_CF_FMTVECWORD(%sp),\out
90         lsr.l   #4,\out
91         and.l   #0x00000003,\out
92         add.l   #CYGARC_CF_EXCEPTION_SIZE,\out
93         add.l   %sp,\out
94         .endm
95
96
97 | ----------------------------------------------------------------------------
98 | Macros used to save and restore MAC registers during interrupts/exceptions.
99
100 #ifdef CYGHWR_HAL_COLDFIRE_MAC
101         .macro  save_mac_registers work
102         | Store MACSR register
103         move.l  %macsr,\work
104         move.l  \work,CYGARC_CFREG_MACSR(%sp)
105
106         | Switch to integer mode. This allows to save the contents of ACC
107         | without rounding
108         and.l   #0x000000df,\work
109         move.l  \work,%macsr
110
111         | Store ACC register
112         move.l  %acc,\work
113         move.l  \work,CYGARC_CFREG_MACC(%sp)
114
115         | Store MASK register
116         move.l  %mask,\work
117         move.l  \work,CYGARC_CFREG_MASK(%sp)
118         .endm
119
120
121         .macro  restore_mac_registers work
122         | Load MACSR register
123         move.l  CYGARC_CFREG_MACSR(%sp),\work
124         move.l  \work,%macsr
125
126         | Load ACC register
127         move.l  CYGARC_CFREG_MACC(%sp),\work
128         move.l  \work,%acc
129
130         | Load MASK register
131         move.l  CYGARC_CFREG_MASK(%sp),\work
132         move.l  \work,%mask
133         .endm
134 #endif
135
136
137 | ----------------------------------------------------------------------------
138 | Macros used to save registers in interrupt handlers. During an interrupt,
139 | we save registers %d0-%d1 and %a0-%a1 because of the GNU C calling
140 | conventions. During the handler we also need register %d2.
141
142 #ifdef CYGDBG_HAL_COMMON_INTERRUPTS_SAVE_MINIMUM_CONTEXT
143         .macro int_pres_regs
144         lea.l     -CYGARC_CF_EXCEPTION_DECREMENT(%sp),%sp
145         movem.l   %d0-%d2,CYGARC_CFREG_DREGS(%sp)
146         movem.l   %a0-%a1,CYGARC_CFREG_AREGS(%sp)
147         .endm
148
149         
150         .macro int_rest_regs
151         movem.l   CYGARC_CFREG_AREGS(%sp),%a0-%a1
152         movem.l   CYGARC_CFREG_DREGS(%sp),%d0-%d2
153         lea.l     CYGARC_CF_EXCEPTION_DECREMENT(%sp),%sp
154         .endm
155
156 #else /* CYGDBG_HAL_COMMON_INTERRUPTS_SAVE_MINIMUM_CONTEXT */
157
158         .macro int_pres_regs
159         lea.l     -CYGARC_CF_EXCEPTION_DECREMENT(%sp),%sp
160         movem.l   %d0-%d7,CYGARC_CFREG_DREGS(%sp)
161         movem.l   %a0-%a6,CYGARC_CFREG_AREGS(%sp)
162
163 #ifdef CYGHWR_HAL_COLDFIRE_MAC
164         save_mac_registers %d0
165 #endif
166
167         | Save old SP (before interrupt)
168         find_original_sp %d0
169         move.l    %d0,CYGARC_CFREG_SP(%sp)
170         .endm
171
172         
173         .macro int_rest_regs
174
175 #ifdef CYGHWR_HAL_COLDFIRE_MAC
176         restore_mac_registers %d0
177 #endif
178         
179         movem.l   CYGARC_CFREG_AREGS(%sp),%a0-%a6
180         movem.l   CYGARC_CFREG_DREGS(%sp),%d0-%d7
181         lea.l     CYGARC_CF_EXCEPTION_DECREMENT(%sp),%sp
182         .endm
183
184 #endif /* CYGDBG_HAL_COMMON_INTERRUPTS_SAVE_MINIMUM_CONTEXT */
185
186
187 | ----------------------------------------------------------------------------
188 | Macros used to save/restore registers during context switches.
189 | We don't save registers %d0-%d1 and %a0-%a1 because of the GNU C calling
190 | conventions: these macros are used in a routine called by C code.
191
192 #ifdef CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM
193
194         .macro ctx_save_registers
195         lea     -CYGARC_CF_CONTEXT_SIZE(%sp),%sp
196         movem.l %d2-%d7,CYGARC_CFREG_D2(%sp)
197         movem.l %a2-%a6,CYGARC_CFREG_A2(%sp)
198 #ifdef CYGHWR_HAL_COLDFIRE_MAC
199         save_mac_registers %d0
200 #endif
201         | Save SR and interrupt level
202         move.w %sr,%d0
203         move.w %d0,CYGARC_CF_SR(%sp)        
204         .endm
205                                                     
206
207         .macro ctx_restore_registers
208         | Restore SR and interrupt level
209         move.w CYGARC_CF_SR(%sp),%d0
210         move.w %d0,%sr
211         
212 #ifdef CYGHWR_HAL_COLDFIRE_MAC
213         restore_mac_registers %d0
214 #endif
215         movem.l CYGARC_CFREG_D2(%sp),%d2-%d7
216         movem.l CYGARC_CFREG_A2(%sp), %a2-%a6
217         lea     CYGARC_CF_CONTEXT_SIZE(%sp),%sp
218         .endm
219
220 #else /* CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM */
221
222         .macro ctx_save_registers
223         | Save all of the registers
224         lea     -CYGARC_CF_CONTEXT_SIZE(%sp),%sp
225         movem.l %d0-%d7,CYGARC_CFREG_DREGS(%sp)
226         movem.l %a0-%a7,CYGARC_CFREG_AREGS(%sp)        
227 #ifdef CYGHWR_HAL_COLDFIRE_MAC
228         save_mac_registers %d0
229 #endif
230
231         | Save pc (useful during debugging with GDB)
232         lea (%pc),%a0
233         move.l %a0,CYGARC_CFREG_PC(%sp)
234
235         | Save SR and interrupt level
236         move.w %sr,%d0
237         move.w %d0,CYGARC_CF_SR(%sp)        
238         .endm
239         
240
241         .macro ctx_restore_registers
242         | Restore SR and interrupt level
243         move.w CYGARC_CF_SR(%sp),%d0
244         move.w %d0,%sr
245         
246 #ifdef CYGHWR_HAL_COLDFIRE_MAC
247         restore_mac_registers %d0
248 #endif
249         movem.l CYGARC_CFREG_DREGS(%sp),%d0-%d7
250         movem.l CYGARC_CFREG_AREGS(%sp),%a0-%a6                       
251         lea     CYGARC_CF_CONTEXT_SIZE(%sp),%sp     
252         .endm
253 #endif /* CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM */
254
255 | ----------------------------------------------------------------------------
256 | End of arch.inc
257 #endif /* ifndef CYGONCE_HAL_ARCH_INC */