1 |
786 |
skrzyp |
// #========================================================================
|
2 |
|
|
// #
|
3 |
|
|
// # vectors.S
|
4 |
|
|
// #
|
5 |
|
|
// # M68K startup and exception handling.
|
6 |
|
|
// #
|
7 |
|
|
// #========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 2003, 2004, 2005, 2006, 2008 Free Software Foundation, 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
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY 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
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//========================================================================
|
40 |
|
|
//###DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): bartv
|
43 |
|
|
// Date: 2003-06-04
|
44 |
|
|
//
|
45 |
|
|
//###DESCRIPTIONEND####
|
46 |
|
|
//========================================================================
|
47 |
|
|
|
48 |
|
|
#include
|
49 |
|
|
#include
|
50 |
|
|
#include
|
51 |
|
|
#include CYGBLD_HAL_TARGET_H
|
52 |
|
|
#include
|
53 |
|
|
#include
|
54 |
|
|
|
55 |
|
|
// ----------------------------------------------------------------------------
|
56 |
|
|
// These are for compatibility with older HALs
|
57 |
|
|
#ifdef HAL_M68K_EXCEPTION_VECTORS
|
58 |
|
|
# define _HAL_M68K_START_ HAL_M68K_EXCEPTION_VECTORS
|
59 |
|
|
# undef HAL_M68K_EXCEPTION_VECTORS
|
60 |
|
|
#endif
|
61 |
|
|
#ifdef HAL_M68K_COPY_ROM_DATA_TO_RAM
|
62 |
|
|
# define _HAL_M68K_COPY_ROM_DATA_TO_RAM_ 1
|
63 |
|
|
# undef HAL_M68K_COPY_ROM_DATA_TO_RAM
|
64 |
|
|
#endif
|
65 |
|
|
|
66 |
|
|
// ----------------------------------------------------------------------------
|
67 |
|
|
// Exception vectors. Typically there are two exception vectors. There is
|
68 |
|
|
// one in flash which contains the h/w entry point. This is the section
|
69 |
|
|
// .m68k_start. Then there is the run-time set of exception vectors, typically
|
70 |
|
|
// held in RAM, which is the section .ram_vectors. In addition to the pointers
|
71 |
|
|
// to the exception and interrupt VSRs that section contains the virtual vector
|
72 |
|
|
// table and any data that needs to be shared between RedBoot and the application,
|
73 |
|
|
// for example shadow copies of read-only registers.
|
74 |
|
|
//
|
75 |
|
|
// Typical scenarios include the following:
|
76 |
|
|
//
|
77 |
|
|
// 1) _HAL_M68K_START_ code relocates the flash from its boot location of 0x0
|
78 |
|
|
// to somewhere else. _HAL_M68K_PLATFORM_SETUP1_ initializes SDRAM and
|
79 |
|
|
// places it at 0x0. _HAL_M68K_START_ only contains the two initial exception
|
80 |
|
|
// vector slots for the start address and stack, the RAM vectors are fully
|
81 |
|
|
// populated at run-time by the architectural HAL. This is the typical
|
82 |
|
|
// scenario for "large" systems.
|
83 |
|
|
//
|
84 |
|
|
// 2) for "small" systems where usually there is no RedBoot and the application
|
85 |
|
|
// runs directly from flash, all the exception vectors also reside in flash
|
86 |
|
|
// and are statically initialized. _HAL_M68K_START_ contains the full set
|
87 |
|
|
// of vectors.
|
88 |
|
|
//
|
89 |
|
|
// 3) as a variant of (2) the run-time exception vectors may live in RAM,
|
90 |
|
|
// typically relocated via the VBR register. The vectors will usually be
|
91 |
|
|
// dynamically initialized, but if the application is loaded via gdb then
|
92 |
|
|
// some code may be saved by static initialization.
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
.section ".m68k_start", "ax"
|
96 |
|
|
// This will typically be defined by the platform HAL to get the world
|
97 |
|
|
// in a sane state. It should do one-off initializations like getting
|
98 |
|
|
// the system into a state matching the memory map. If booting from
|
99 |
|
|
// flash it should also contain the initial PC and stack exception
|
100 |
|
|
// vectors.
|
101 |
|
|
#ifdef _HAL_M68K_START_
|
102 |
|
|
_HAL_M68K_START_
|
103 |
|
|
#endif
|
104 |
|
|
|
105 |
|
|
.section ".m68k_start.hal_m68k_exception_reset", "ax"
|
106 |
|
|
// The actual entry point, as defined in the linker script. The exact
|
107 |
|
|
// state of the system at this point depends on the configuration and
|
108 |
|
|
// the processor.
|
109 |
|
|
.global hal_m68k_exception_reset
|
110 |
|
|
.type hal_m68k_exception_reset, function
|
111 |
|
|
hal_m68k_exception_reset:
|
112 |
|
|
|
113 |
|
|
// Make absolutely sure that the status register is in a
|
114 |
|
|
// sensible state with interrupts disabled, irrespective of
|
115 |
|
|
// the platform.
|
116 |
|
|
mov.w #0x2700,%sr
|
117 |
|
|
|
118 |
|
|
// Platform-specific initialization. This will do things like starting
|
119 |
|
|
// up the SDRAM controller. It may also run variant and processor
|
120 |
|
|
// initialization code, but the platform HAL gets to decide the order.
|
121 |
|
|
#ifdef _HAL_M68K_PLATFORM_SETUP1_
|
122 |
|
|
_HAL_M68K_PLATFORM_SETUP1_
|
123 |
|
|
#endif
|
124 |
|
|
|
125 |
|
|
// All memory should now be running so we can get the C environment
|
126 |
|
|
// set up. Clear BSS before switching to C mode
|
127 |
|
|
.extern _hal_bss_start
|
128 |
|
|
.extern _hal_bss_end
|
129 |
|
|
move.l # _hal_bss_start,%a0
|
130 |
|
|
move.l # _hal_bss_end,%a1
|
131 |
|
|
1:
|
132 |
|
|
cmp.l %a0,%a1
|
133 |
|
|
ble 2f
|
134 |
|
|
clr.l (%a0)+
|
135 |
|
|
jra 1b
|
136 |
|
|
2:
|
137 |
|
|
|
138 |
|
|
// If booting from ROM, move .data from ROM to RAM
|
139 |
|
|
#ifdef _HAL_M68K_COPY_ROM_DATA_TO_RAM_
|
140 |
|
|
.extern _hal_data_section_start_lma
|
141 |
|
|
.extern _hal_data_section_end_lma
|
142 |
|
|
.extern _hal_data_section_start_vma
|
143 |
|
|
move.l # _hal_data_section_start_lma, %a0
|
144 |
|
|
move.l # _hal_data_section_end_lma, %a1
|
145 |
|
|
move.l # _hal_data_section_start_vma, %a2
|
146 |
|
|
1:
|
147 |
|
|
cmp.l %a0,%a1
|
148 |
|
|
ble 2f
|
149 |
|
|
mov.l (%a0)+,(%a2)+
|
150 |
|
|
jra 1b
|
151 |
|
|
2:
|
152 |
|
|
#endif
|
153 |
|
|
|
154 |
|
|
// If there is an FPU, set the default mode
|
155 |
|
|
#ifdef CYGINT_HAL_M68K_VARIANT_FPU
|
156 |
|
|
mov.w # CYGNUM_HAL_M68K_FPU_CR_DEFAULT, %fpcr
|
157 |
|
|
#endif
|
158 |
|
|
|
159 |
|
|
// If there is on-chip RAM, copy code and data there and clear
|
160 |
|
|
// its BSS.
|
161 |
|
|
#ifdef _HAL_M68K_INITIALIZE_IRAM_
|
162 |
|
|
.extern _hal_iram_text_section_start_lma
|
163 |
|
|
.extern _hal_iram_data_section_end_lma
|
164 |
|
|
.extern _hal_iram_text_section_start_vma
|
165 |
|
|
.extern _hal_iram_bss_section_start
|
166 |
|
|
.extern _hal_iram_bss_section_end
|
167 |
|
|
|
168 |
|
|
move.l # _hal_iram_text_section_start_lma, %a0
|
169 |
|
|
move.l # _hal_iram_data_section_end_lma, %a1
|
170 |
|
|
move.l # _hal_iram_text_section_start_vma, %a2
|
171 |
|
|
1:
|
172 |
|
|
cmp.l %a0, %a1
|
173 |
|
|
ble 2f
|
174 |
|
|
mov.l (%a0)+, (%a2)+
|
175 |
|
|
jra 1b
|
176 |
|
|
2:
|
177 |
|
|
move.l # _hal_iram_bss_section_start, %a0
|
178 |
|
|
move.l # _hal_iram_bss_section_end, %a1
|
179 |
|
|
3:
|
180 |
|
|
cmp.l %a0, %a1
|
181 |
|
|
ble 4f
|
182 |
|
|
clr.l (%a0)+
|
183 |
|
|
jra 3b
|
184 |
|
|
4:
|
185 |
|
|
#endif
|
186 |
|
|
|
187 |
|
|
// Now we just need a valid stack and we can switch to C
|
188 |
|
|
// for the remaining initialization. Clearing the frame
|
189 |
|
|
// pointer may make life easier for gdb.
|
190 |
|
|
mov.l _HAL_M68K_STARTUP_STACK_,%sp
|
191 |
|
|
suba.l %a6, %a6
|
192 |
|
|
|
193 |
|
|
.extern hal_m68k_c_startup
|
194 |
|
|
jmp hal_m68k_c_startup
|
195 |
|
|
|
196 |
|
|
// The exception vector table. Usually this will be held in RAM
|
197 |
|
|
// at location 0x0, although it may get moved around via e.g.
|
198 |
|
|
// the %vbr register. In addition to the exception vectors the
|
199 |
|
|
// virtual vector table is held here, as is any data that needs
|
200 |
|
|
// to be shared between RedBoot and eCos.
|
201 |
|
|
//
|
202 |
|
|
// Some targets in some configurations may define their own version
|
203 |
|
|
// of this, if for example the exception vector is held in ROM.
|
204 |
|
|
#if defined(_HAL_M68K_RAM_VECTORS_)
|
205 |
|
|
|
206 |
|
|
_HAL_M68K_RAM_VECTORS_
|
207 |
|
|
|
208 |
|
|
#elif !defined(_HAL_M68K_RAM_VECTORS_DEFINED_)
|
209 |
|
|
.section ".ram_vectors", "aw", @nobits
|
210 |
|
|
|
211 |
|
|
# ifndef _HAL_M68K_SUPPRESS_RAM_VECTORS_VSR_TABLE_
|
212 |
|
|
// Start with the interrupt/exception vectors.
|
213 |
|
|
.global hal_m68k_vsr_table
|
214 |
|
|
hal_m68k_vsr_table:
|
215 |
|
|
.rept HAL_M68K_VSR_COUNT
|
216 |
|
|
.long 0
|
217 |
|
|
.endr
|
218 |
|
|
# endif
|
219 |
|
|
|
220 |
|
|
// Next the virtual vector table. Space for this is usually allocated,
|
221 |
|
|
// even if virtual vectors are not supported. That avoids confusion
|
222 |
|
|
// if RedBoot and the application are configured differently. If a
|
223 |
|
|
// platform will never support RedBoot, e.g. because of lack of memory,
|
224 |
|
|
// then it can suppress the virtual vectors.
|
225 |
|
|
//
|
226 |
|
|
// The size of the table comes from ,
|
227 |
|
|
// CYGNUM_CALL_IF_TABLE_SIZE, but that header cannot easily be included
|
228 |
|
|
// in assembler.
|
229 |
|
|
# ifndef _HAL_M68K_SUPPRESS_VIRTUAL_VECTOR_
|
230 |
|
|
.global hal_virtual_vector_table
|
231 |
|
|
hal_virtual_vector_table:
|
232 |
|
|
.rept 64
|
233 |
|
|
.long 0
|
234 |
|
|
.endr
|
235 |
|
|
# endif
|
236 |
|
|
|
237 |
|
|
// Allow the variant, processor and platform HALs to store additional
|
238 |
|
|
// information in the global vectors section. Typically this is used for
|
239 |
|
|
// data which needs to be shared between RedBoot and the application,
|
240 |
|
|
// e.g. shadow copies of write-only hardware registers.
|
241 |
|
|
# ifdef _HAL_M68K_VARIANT_RAM_VECTORS_
|
242 |
|
|
_HAL_M68K_VARIANT_RAM_VECTORS_
|
243 |
|
|
# endif
|
244 |
|
|
# ifdef _HAL_M68K_PROCESSOR_RAM_VECTORS_
|
245 |
|
|
_HAL_M68K_PROCESSOR_RAM_VECTORS_
|
246 |
|
|
# endif
|
247 |
|
|
# ifdef _HAL_M68K_PLATFORM_RAM_VECTORS_
|
248 |
|
|
_HAL_M68K_PLATFORM_RAM_VECTORS_
|
249 |
|
|
# endif
|
250 |
|
|
#endif // _HAL_M68K_RAM_VECTORS_DEFINED_
|
251 |
|
|
|
252 |
|
|
|
253 |
|
|
// ----------------------------------------------------------------------------
|
254 |
|
|
// end of vectors.S
|