1 |
27 |
unneback |
##==========================================================================
|
2 |
|
|
##
|
3 |
|
|
## hal_var_sp.inc
|
4 |
|
|
##
|
5 |
|
|
## SH support code for variants using stack at exception entry
|
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 |
|
|
##
|
13 |
|
|
## eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
## the terms of the GNU General Public License as published by the Free
|
15 |
|
|
## Software Foundation; either version 2 or (at your option) any later version.
|
16 |
|
|
##
|
17 |
|
|
## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
## WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
## for more details.
|
21 |
|
|
##
|
22 |
|
|
## You should have received a copy of the GNU General Public License along
|
23 |
|
|
## with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
##
|
26 |
|
|
## As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
## or inline functions from this file, or you compile this file and link it
|
28 |
|
|
## with other works to produce a work based on this file, this file does not
|
29 |
|
|
## by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
## License. However the source code for this file must still be made available
|
31 |
|
|
## in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
##
|
33 |
|
|
## This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
## this file might be covered by the GNU General Public License.
|
35 |
|
|
##
|
36 |
|
|
## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
## at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
## -------------------------------------------
|
39 |
|
|
#####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
##==========================================================================
|
41 |
|
|
#######DESCRIPTIONBEGIN####
|
42 |
|
|
##
|
43 |
|
|
## Author(s): jskov
|
44 |
|
|
## Contributors: jskov
|
45 |
|
|
## Date: 2002-01-11
|
46 |
|
|
## Purpose: SH support code for variants using stack at exception entry
|
47 |
|
|
##
|
48 |
|
|
######DESCRIPTIONEND####
|
49 |
|
|
##
|
50 |
|
|
##==========================================================================
|
51 |
|
|
|
52 |
|
|
#include
|
53 |
|
|
#include
|
54 |
|
|
|
55 |
|
|
## This is the address of the reset entry
|
56 |
|
|
|
57 |
|
|
#if defined(CYG_HAL_STARTUP_RAM) || defined(CYGARC_SH_MOD_CAC_NO_WINDOWS)
|
58 |
|
|
// No translation if RAM startup, or if the variant does not
|
59 |
|
|
// have cached/non-cached windows in the address space.
|
60 |
|
|
# define _RESET_ENTRY CYG_LABEL_DEFN(_reset_platform)
|
61 |
|
|
#elif defined(CYG_HAL_STARTUP_ROMRAM)
|
62 |
|
|
// Uncached "shadow" address but adjusted for VMA/LMA differences
|
63 |
|
|
# define _RESET_ENTRY __reset_platform+0x20000000-CYGMEM_REGION_ram+CYGMEM_REGION_rom
|
64 |
|
|
#else
|
65 |
|
|
// Uncached "shadow" address
|
66 |
|
|
# define _RESET_ENTRY CYG_LABEL_DEFN(_reset_platform)+0x20000000
|
67 |
|
|
#endif
|
68 |
|
|
|
69 |
|
|
#if !defined(CYG_HAL_STARTUP_RAM) || !defined(CYGSEM_HAL_USE_ROM_MONITOR)
|
70 |
|
|
|
71 |
|
|
## This is the table of HW_EXC_ENTRY pointers fetched from by the CPU
|
72 |
|
|
## on an exception. They point to pre-VSR handlers (below) which prep
|
73 |
|
|
## R0 with the vector number (which, AFAICT, there''s no other way
|
74 |
|
|
## to find) before calling the VSR.
|
75 |
|
|
## Note that this takes up a massive 4KiB so it should only be included
|
76 |
|
|
## when really needed (that is, when not relying on RedBoot to provide
|
77 |
|
|
## it).
|
78 |
|
|
|
79 |
|
|
.align 2
|
80 |
|
|
FUNC_START(_HW_EXC_ENTRY_TABLE)
|
81 |
|
|
# Power-on reset entry address and stack
|
82 |
|
|
.long _RESET_ENTRY
|
83 |
|
|
.long 0
|
84 |
|
|
# Manual reset entry address and stack
|
85 |
|
|
.long _RESET_ENTRY
|
86 |
|
|
.long 0
|
87 |
|
|
# All the other vectors
|
88 |
|
|
.set vecno, 0
|
89 |
|
|
.rept (256-4)
|
90 |
|
|
.long $vectors_code+(vecno)*16
|
91 |
|
|
.set vecno, vecno+1
|
92 |
|
|
.endr
|
93 |
|
|
|
94 |
|
|
## The piece of code pointed to by the HW_EXC table. Each vector
|
95 |
|
|
## has such a piece of code, which saves R0 on the stack, fetches
|
96 |
|
|
## the VSR pointer and loads the vector number into R0.
|
97 |
|
|
##
|
98 |
|
|
## Note the three variants:
|
99 |
|
|
## exception_vector: maps the HW_EXC vector to the same eCos HAL_VECTOR
|
100 |
|
|
## exception_vector_trap: maps the HW_EXC vector to the eCos HAL_VECTOR_TRAP
|
101 |
|
|
## exception_vector_int: maps the HW_EXC vector to the eCos HAL_VECTOR_INTERRUPT
|
102 |
|
|
##
|
103 |
|
|
## With these we translate the SH2 vector style exceptions to something more
|
104 |
|
|
## like the SH3/SH4 style:
|
105 |
|
|
##
|
106 |
|
|
## HW vectors eCos vectors
|
107 |
|
|
## 00-31 0-31 Various exceptions
|
108 |
|
|
## 32-63 32 TRAP
|
109 |
|
|
## 64-255 33 Interrupt
|
110 |
|
|
## 34-63 Free for application
|
111 |
|
|
##
|
112 |
|
|
## This allows the VSR table to be reduced to 1/4 of the size, and eases
|
113 |
|
|
## code sharing with the SH3/SH4 variants without any real loss of power.
|
114 |
|
|
##
|
115 |
|
|
.macro exception_vector vec
|
116 |
|
|
mov.l r0,@-r15
|
117 |
|
|
mov.l 1f,r0
|
118 |
|
|
mov.l @r0,r0
|
119 |
|
|
jmp @r0
|
120 |
|
|
mov #\vec,r0
|
121 |
|
|
.align 2
|
122 |
|
|
1: .long CYG_LABEL_DEFN(hal_vsr_table)+4*\vec
|
123 |
|
|
.endm
|
124 |
|
|
|
125 |
|
|
.macro exception_vector_trap vec
|
126 |
|
|
mov.l r0,@-r15
|
127 |
|
|
mov.l 1f,r0
|
128 |
|
|
mov.l @r0,r0
|
129 |
|
|
jmp @r0
|
130 |
|
|
mov #\vec,r0
|
131 |
|
|
.align 2
|
132 |
|
|
1: .long CYG_LABEL_DEFN(hal_vsr_table)+4*CYGNUM_HAL_VECTOR_TRAP
|
133 |
|
|
.endm
|
134 |
|
|
|
135 |
|
|
# The comment argument is not used for anything. It's just there
|
136 |
|
|
# to provide callers a slot for comments (which is not otherwise
|
137 |
|
|
# possible when doing multiple invocations on the same line).
|
138 |
|
|
.macro exception_vector_int vec,comment
|
139 |
|
|
mov.l r0,@-r15
|
140 |
|
|
mov.l 1f,r0
|
141 |
|
|
mov.l @r0,r0
|
142 |
|
|
jmp @r0
|
143 |
|
|
mov #\vec,r0
|
144 |
|
|
.align 2
|
145 |
|
|
1: .long CYG_LABEL_DEFN(hal_vsr_table)+4*CYGNUM_HAL_VECTOR_INTERRUPT
|
146 |
|
|
.endm
|
147 |
|
|
|
148 |
|
|
# And their entry points
|
149 |
|
|
$vectors_code:
|
150 |
|
|
exception_vector 4 // general illegal instr
|
151 |
|
|
exception_vector 5 // reserved
|
152 |
|
|
exception_vector 6 // slot illegal instr
|
153 |
|
|
exception_vector 7 // reserved
|
154 |
|
|
exception_vector 8 // reserved
|
155 |
|
|
exception_vector 9 // CPU address error
|
156 |
|
|
exception_vector 10 // DMA address error
|
157 |
|
|
exception_vector_int CYGNUM_HAL_INTERRUPT_NMI // NMI
|
158 |
|
|
exception_vector 12 // User Break
|
159 |
|
|
exception_vector 13 // H-UDI
|
160 |
|
|
.set vecno, 14
|
161 |
|
|
.rept (32-14)
|
162 |
|
|
exception_vector vecno // reserved
|
163 |
|
|
.set vecno, vecno+1
|
164 |
|
|
.endr
|
165 |
|
|
.set vecno, 32
|
166 |
|
|
.rept (64-32)
|
167 |
|
|
exception_vector_trap vecno // Trap
|
168 |
|
|
.set vecno, vecno+1
|
169 |
|
|
.endr
|
170 |
|
|
|
171 |
|
|
#ifdef CYGHWR_HAL_SH_SH2_CUSTOM_INTERRUPT_LAYOUT
|
172 |
|
|
# Some variants may have a very sparsely populated
|
173 |
|
|
# vector table (7044 is an example) which results
|
174 |
|
|
# in many unused entries in various interrupt tables.
|
175 |
|
|
# To reduce bloat, these may define a custom
|
176 |
|
|
# layout of these interrupt decoders - the code
|
177 |
|
|
# is to be found in var_intr.h since it's very
|
178 |
|
|
# tightly coupled with the interrupt vectors.
|
179 |
|
|
CYGHWR_HAL_SH_SH2_CUSTOM_INTERRUPT_LAYOUT
|
180 |
|
|
#else
|
181 |
|
|
# Note that there''s an entry for vector 0 (NMI) here again
|
182 |
|
|
# to avoid having to make hal_interrupt_set_vectors()
|
183 |
|
|
# adjust for this off-by-one discrepancy.
|
184 |
|
|
.set vecno, CYGNUM_HAL_INTERRUPT_NMI
|
185 |
|
|
.rept (256-64)
|
186 |
|
|
exception_vector_int vecno // interrupts
|
187 |
|
|
.set vecno, vecno+1
|
188 |
|
|
.endr
|
189 |
|
|
#endif // CYGHWR_HAL_SH_SH2_CUSTOM_INTERRUPT_LAYOUT
|
190 |
|
|
|
191 |
|
|
#endif // !defined(CYG_HAL_STARTUP_RAM) || !defined(CYGSEM_HAL_USE_ROM_MONITOR)
|
192 |
|
|
|
193 |
|
|
## For RAM startups, provide a convenient jump to the application start
|
194 |
|
|
## at the very start of the image.
|
195 |
|
|
FUNC_START(_reset)
|
196 |
|
|
mov.l 1f,r0
|
197 |
|
|
jmp @r0
|
198 |
|
|
nop
|
199 |
|
|
.align 2
|
200 |
|
|
1: .long _RESET_ENTRY
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
##-----------------------------------------------------------------------------
|
204 |
|
|
## Macros for saving/restoring register state on an exception. These
|
205 |
|
|
## are generic for all variants, so be careful to not make assumptions.
|
206 |
|
|
|
207 |
|
|
## r15 is location stored to/loaded from
|
208 |
|
|
## r0 is the available scratch register
|
209 |
|
|
|
210 |
|
|
## At exit:
|
211 |
|
|
## r7 is the vector #
|
212 |
|
|
## all other registers (except sp) are available
|
213 |
|
|
|
214 |
|
|
## Furthermore, stack content at this point is
|
215 |
|
|
#-- original SP address
|
216 |
|
|
# pre-exception SR
|
217 |
|
|
# pre-exception PC
|
218 |
|
|
# pre-exception r0
|
219 |
|
|
#-- present SP address
|
220 |
|
|
|
221 |
|
|
.macro hal_cpu_save_regs
|
222 |
|
|
mov.l r0,@-sp ! vector number
|
223 |
|
|
#ifdef CYGDBG_HAL_COMMON_INTERRUPTS_SAVE_MINIMUM_CONTEXT
|
224 |
|
|
add #-8,sp ! Space for gbr, and vbr
|
225 |
|
|
#else
|
226 |
|
|
stc gbr,r0 ! GBR
|
227 |
|
|
mov.l r0,@-sp
|
228 |
|
|
stc vbr,r0 ! VBR
|
229 |
|
|
mov.l r0,@-sp
|
230 |
|
|
#endif
|
231 |
|
|
|
232 |
|
|
add #-8,sp ! Space for entry PC and SR
|
233 |
|
|
|
234 |
|
|
#if 0 // FIXME
|
235 |
|
|
stc.l re,@-sp ! RE
|
236 |
|
|
stc.l rs,@-sp ! RS
|
237 |
|
|
stc.l mod,@-sp ! MOD
|
238 |
|
|
#endif
|
239 |
|
|
sts.l pr,@-sp ! PR
|
240 |
|
|
sts.l mach,@-sp ! mach
|
241 |
|
|
sts.l macl,@-sp ! macl
|
242 |
|
|
|
243 |
|
|
add #-4,sp ! Space for entry sp
|
244 |
|
|
mov.l r14,@-sp ! r14-r0
|
245 |
|
|
mov.l r13,@-sp
|
246 |
|
|
mov.l r12,@-sp
|
247 |
|
|
mov.l r11,@-sp
|
248 |
|
|
mov.l r10,@-sp
|
249 |
|
|
mov.l r9,@-sp
|
250 |
|
|
mov.l r8,@-sp
|
251 |
|
|
mov.l r7,@-sp
|
252 |
|
|
mov.l r6,@-sp
|
253 |
|
|
mov.l r5,@-sp
|
254 |
|
|
mov.l r4,@-sp
|
255 |
|
|
mov.l r3,@-sp
|
256 |
|
|
mov.l r2,@-sp
|
257 |
|
|
mov.l r1,@-sp
|
258 |
|
|
add #-4,sp ! space for r0
|
259 |
|
|
|
260 |
|
|
! Compute location of pre-exception r0 and move
|
261 |
|
|
! data from above structure into the structure
|
262 |
|
|
mov sp,r1
|
263 |
|
|
add #CYGARC_SH_EXCEPTION_SIZE,r1
|
264 |
|
|
mov.l @r1+,r0 ! pre-exception R0
|
265 |
|
|
mov.l r0,@(CYGARC_SHREG_REGS,sp)
|
266 |
|
|
mov.l @r1+,r2 ! pre-exception PC
|
267 |
|
|
mov #CYGARC_SHREG_PC,r0
|
268 |
|
|
mov.l r2,@(r0,sp)
|
269 |
|
|
mov.l @r1+,r2 ! pre-exception SR
|
270 |
|
|
mov #CYGARC_SHREG_SR,r0
|
271 |
|
|
mov.l r2,@(r0,sp)
|
272 |
|
|
mov #CYGARC_SHREG_SP,r0
|
273 |
|
|
mov.l r1,@(r0,sp) ! pre-exception SP
|
274 |
|
|
! Load up the vector number
|
275 |
|
|
mov #CYGARC_SHREG_EVENT,r0
|
276 |
|
|
mov.l @(r0,sp),r7
|
277 |
|
|
.endm
|
278 |
|
|
|
279 |
|
|
.macro hal_exception_entry_extras
|
280 |
|
|
# Disable interrupts before anything else
|
281 |
|
|
mov.l 1f,r0
|
282 |
|
|
ldc r0,sr
|
283 |
|
|
bra 2f
|
284 |
|
|
nop
|
285 |
|
|
.align 2
|
286 |
|
|
1: .long CYG_SR
|
287 |
|
|
2:
|
288 |
|
|
.endm
|
289 |
|
|
|
290 |
|
|
# No additional magic needed. hal_cpu_save_regs does it all.
|
291 |
|
|
.macro hal_interrupt_entry_extras
|
292 |
|
|
.endm
|
293 |
|
|
|
294 |
|
|
#---------------------------------------------------------------------------
|
295 |
|
|
## Restore registers after exception:
|
296 |
|
|
## At entry:
|
297 |
|
|
## r15 is location to be loaded from
|
298 |
|
|
## all other registers (except sp) are available
|
299 |
|
|
|
300 |
|
|
## At exit:
|
301 |
|
|
## Returns to interrupted code
|
302 |
|
|
|
303 |
|
|
.macro hal_cpu_restore_regs_return
|
304 |
|
|
! Disable interrupts during the restore operation
|
305 |
|
|
mov.l 1f,r1
|
306 |
|
|
ldc r1,sr
|
307 |
|
|
|
308 |
|
|
! Move R0/PC/SR values from register structure onto the stack where
|
309 |
|
|
! they''ll be popped from on return. Note that this is the SP as
|
310 |
|
|
! set in the register frame! (otherwise GDB would be unable to change
|
311 |
|
|
! SP).
|
312 |
|
|
mov.l @(CYGARC_SHREG_SP,sp),r0
|
313 |
|
|
mov r0,r1
|
314 |
|
|
add #-12,r1
|
315 |
|
|
mov.l @(CYGARC_SHREG_REGS,sp),r0
|
316 |
|
|
mov.l r0,@r1 ! pre-exception R0
|
317 |
|
|
mov #CYGARC_SHREG_PC,r0
|
318 |
|
|
mov.l @(r0,sp),r2
|
319 |
|
|
mov.l r2,@(4,r1) ! pre-exception PC
|
320 |
|
|
mov #CYGARC_SHREG_SR,r0
|
321 |
|
|
mov.l @(r0,sp),r2
|
322 |
|
|
mov.l r2,@(8,r1) ! pre-exception SR
|
323 |
|
|
|
324 |
|
|
! Load up registers
|
325 |
|
|
add #4,sp ! skip r0
|
326 |
|
|
mov.l @sp+,r1
|
327 |
|
|
mov.l @sp+,r2
|
328 |
|
|
mov.l @sp+,r3
|
329 |
|
|
mov.l @sp+,r4
|
330 |
|
|
mov.l @sp+,r5
|
331 |
|
|
mov.l @sp+,r6
|
332 |
|
|
mov.l @sp+,r7
|
333 |
|
|
mov.l @sp+,r8
|
334 |
|
|
mov.l @sp+,r9
|
335 |
|
|
mov.l @sp+,r10
|
336 |
|
|
mov.l @sp+,r11
|
337 |
|
|
mov.l @sp+,r12
|
338 |
|
|
mov.l @sp+,r13
|
339 |
|
|
mov.l @sp+,r14
|
340 |
|
|
add #4,sp ! skip SP
|
341 |
|
|
|
342 |
|
|
lds.l @sp+,macl ! macl
|
343 |
|
|
lds.l @sp+,mach ! mach
|
344 |
|
|
lds.l @sp+,pr ! PR
|
345 |
|
|
|
346 |
|
|
#if 0 // FIXME - also change SP adjustment below!
|
347 |
|
|
ldc.l @sp+,re ! RE
|
348 |
|
|
ldc.l @sp+,rs ! RS
|
349 |
|
|
ldc.l @sp+,mod ! MOD
|
350 |
|
|
#endif
|
351 |
|
|
add #8,sp ! skip sr and pc
|
352 |
|
|
|
353 |
|
|
#ifndef CYGDBG_HAL_COMMON_INTERRUPTS_SAVE_MINIMUM_CONTEXT
|
354 |
|
|
mov.l @sp+,r0
|
355 |
|
|
ldc r0,vbr ! return VBR
|
356 |
|
|
mov.l @sp+,r0
|
357 |
|
|
ldc r0,gbr ! return GBR
|
358 |
|
|
#else
|
359 |
|
|
add #8,sp ! skip VBR+GBR
|
360 |
|
|
#endif
|
361 |
|
|
|
362 |
|
|
add #-8*4,sp ! get to new SP
|
363 |
|
|
mov.l @sp,sp
|
364 |
|
|
add #-12,sp ! get to exception state + saved r0
|
365 |
|
|
|
366 |
|
|
mov.l @sp+,r0 ! pre-exception r0
|
367 |
|
|
rte
|
368 |
|
|
nop
|
369 |
|
|
.align 2
|
370 |
|
|
1: .long CYG_SR
|
371 |
|
|
.endm
|
372 |
|
|
|
373 |
|
|
#---------------------------------------------------------------------------
|
374 |
|
|
# Translate cause of exception to a vector number
|
375 |
|
|
.macro hal_exception_translate
|
376 |
|
|
.endm
|
377 |
|
|
|
378 |
|
|
#---------------------------------------------------------------------------
|
379 |
|
|
# end of hal_var_sp.inc
|