summaryrefslogtreecommitdiff
path: root/ecos/packages/hal/coldfire/arch/current/include/arch.inc
blob: 64d7fcd8b30c6ad81916ad136b17f9dbf7128de9 (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
251
252
253
254
255
256
257
258
#ifndef CYGONCE_HAL_ARCH_INC
#define CYGONCE_HAL_ARCH_INC
|=============================================================================
|
|  arch.inc
|
|  ColdFire architecture assembler header file
|
|=============================================================================
| ####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:      MCF5272 variant definitions.
| Description:  This file contains macro definitions used in the
|               architecture HAL assembler file.
|
|####DESCRIPTIONEND####
|==========================================================================


#define FUNC_START(name)    \
    .text;                  \
    .balign 4;              \
    .type name,@function;   \
    .globl name;            \
name:


| ----------------------------------------------------------------------------
| Macros to deal with the interrupt priority level in the status register.

        .macro hal_cpu_int_disable
        move.w  #0x2700,%sr
        .endm

        
        .macro hal_cpu_int_enable work
        move.w  %sr,\work
        and.l   #0xf8ff,\work
        move.w  \work,%sr
        .endm

        
        .macro hal_cpu_int_merge from work
        move.w  %sr,\work
        and.l   #0xf8ff,\work
        and.l   #0x0700,\from
        or.l    \from,\work
        move.w \work,%sr
        .endm

| ----------------------------------------------------------------------------
| Macro to find the value the SP register had before an exception.
        
        .macro find_original_sp out
        move.b  CYGARC_CF_FMTVECWORD(%sp),\out
        lsr.l   #4,\out
        and.l   #0x00000003,\out
        add.l   #CYGARC_CF_EXCEPTION_SIZE,\out
        add.l   %sp,\out
        .endm


| ----------------------------------------------------------------------------
| Macros used to save and restore MAC registers during interrupts/exceptions.

#ifdef CYGHWR_HAL_COLDFIRE_MAC
        .macro  save_mac_registers work
        | Store MACSR register
        move.l  %macsr,\work
        move.l  \work,CYGARC_CFREG_MACSR(%sp)

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

        | Store ACC register
        move.l  %acc,\work
        move.l  \work,CYGARC_CFREG_MACC(%sp)

        | Store MASK register
        move.l  %mask,\work
        move.l  \work,CYGARC_CFREG_MASK(%sp)
        .endm


        .macro  restore_mac_registers work
        | Load MACSR register
        move.l  CYGARC_CFREG_MACSR(%sp),\work
        move.l  \work,%macsr

        | Load ACC register
        move.l  CYGARC_CFREG_MACC(%sp),\work
        move.l  \work,%acc

        | Load MASK register
        move.l  CYGARC_CFREG_MASK(%sp),\work
        move.l  \work,%mask
        .endm
#endif


| ----------------------------------------------------------------------------
| Macros used to save registers in interrupt handlers. During an interrupt,
| we save registers %d0-%d1 and %a0-%a1 because of the GNU C calling
| conventions. During the handler we also need register %d2.

#ifdef CYGDBG_HAL_COMMON_INTERRUPTS_SAVE_MINIMUM_CONTEXT
        .macro int_pres_regs
        lea.l     -CYGARC_CF_EXCEPTION_DECREMENT(%sp),%sp
        movem.l   %d0-%d2,CYGARC_CFREG_DREGS(%sp)
        movem.l   %a0-%a1,CYGARC_CFREG_AREGS(%sp)
        .endm

        
        .macro int_rest_regs
        movem.l   CYGARC_CFREG_AREGS(%sp),%a0-%a1
        movem.l   CYGARC_CFREG_DREGS(%sp),%d0-%d2
        lea.l     CYGARC_CF_EXCEPTION_DECREMENT(%sp),%sp
        .endm

#else /* CYGDBG_HAL_COMMON_INTERRUPTS_SAVE_MINIMUM_CONTEXT */

        .macro int_pres_regs
        lea.l     -CYGARC_CF_EXCEPTION_DECREMENT(%sp),%sp
        movem.l   %d0-%d7,CYGARC_CFREG_DREGS(%sp)
        movem.l   %a0-%a6,CYGARC_CFREG_AREGS(%sp)

#ifdef CYGHWR_HAL_COLDFIRE_MAC
        save_mac_registers %d0
#endif

        | Save old SP (before interrupt)
        find_original_sp %d0
        move.l    %d0,CYGARC_CFREG_SP(%sp)
        .endm

        
        .macro int_rest_regs

#ifdef CYGHWR_HAL_COLDFIRE_MAC
        restore_mac_registers %d0
#endif
        
        movem.l   CYGARC_CFREG_AREGS(%sp),%a0-%a6
        movem.l   CYGARC_CFREG_DREGS(%sp),%d0-%d7
        lea.l     CYGARC_CF_EXCEPTION_DECREMENT(%sp),%sp
        .endm

#endif /* CYGDBG_HAL_COMMON_INTERRUPTS_SAVE_MINIMUM_CONTEXT */


| ----------------------------------------------------------------------------
| Macros used to save/restore registers during context switches.
| We don't save registers %d0-%d1 and %a0-%a1 because of the GNU C calling
| conventions: these macros are used in a routine called by C code.

#ifdef CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM

        .macro ctx_save_registers
        lea     -CYGARC_CF_CONTEXT_SIZE(%sp),%sp
        movem.l %d2-%d7,CYGARC_CFREG_D2(%sp)
        movem.l %a2-%a6,CYGARC_CFREG_A2(%sp)
#ifdef CYGHWR_HAL_COLDFIRE_MAC
        save_mac_registers %d0
#endif
        | Save SR and interrupt level
        move.w %sr,%d0
        move.w %d0,CYGARC_CF_SR(%sp)        
        .endm
                                                    

        .macro ctx_restore_registers
        | Restore SR and interrupt level
        move.w CYGARC_CF_SR(%sp),%d0
        move.w %d0,%sr
        
#ifdef CYGHWR_HAL_COLDFIRE_MAC
        restore_mac_registers %d0
#endif
        movem.l CYGARC_CFREG_D2(%sp),%d2-%d7
        movem.l CYGARC_CFREG_A2(%sp), %a2-%a6
        lea     CYGARC_CF_CONTEXT_SIZE(%sp),%sp
        .endm

#else /* CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM */

        .macro ctx_save_registers
        | Save all of the registers
        lea     -CYGARC_CF_CONTEXT_SIZE(%sp),%sp
        movem.l %d0-%d7,CYGARC_CFREG_DREGS(%sp)
        movem.l %a0-%a7,CYGARC_CFREG_AREGS(%sp)        
#ifdef CYGHWR_HAL_COLDFIRE_MAC
        save_mac_registers %d0
#endif

        | Save pc (useful during debugging with GDB)
        lea (%pc),%a0
        move.l %a0,CYGARC_CFREG_PC(%sp)

        | Save SR and interrupt level
        move.w %sr,%d0
        move.w %d0,CYGARC_CF_SR(%sp)        
        .endm
        

        .macro ctx_restore_registers
        | Restore SR and interrupt level
        move.w CYGARC_CF_SR(%sp),%d0
        move.w %d0,%sr
        
#ifdef CYGHWR_HAL_COLDFIRE_MAC
        restore_mac_registers %d0
#endif
        movem.l CYGARC_CFREG_DREGS(%sp),%d0-%d7
        movem.l CYGARC_CFREG_AREGS(%sp),%a0-%a6                       
        lea     CYGARC_CF_CONTEXT_SIZE(%sp),%sp     
        .endm
#endif /* CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM */

| ----------------------------------------------------------------------------
| End of arch.inc
#endif /* ifndef CYGONCE_HAL_ARCH_INC */