]> git.ipfire.org Git - people/ms/u-boot.git/blob - cpu/mcf532x/start.S
allow MCF532x to use CONFIG_MONITOR_IS_IN_RAM
[people/ms/u-boot.git] / cpu / mcf532x / start.S
1 /*
2 * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de>
3 * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
4 *
5 * (C) Copyright 2004-2008 Freescale Semiconductor, Inc.
6 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27 #include <config.h>
28 #include <timestamp.h>
29 #include "version.h"
30
31 #ifndef CONFIG_IDENT_STRING
32 #define CONFIG_IDENT_STRING ""
33 #endif
34
35 #define _START _start
36 #define _FAULT _fault
37
38 #define SAVE_ALL \
39 move.w #0x2700,%sr; /* disable intrs */ \
40 subl #60,%sp; /* space for 15 regs */ \
41 moveml %d0-%d7/%a0-%a6,%sp@;
42
43 #define RESTORE_ALL \
44 moveml %sp@,%d0-%d7/%a0-%a6; \
45 addl #60,%sp; /* space for 15 regs */ \
46 rte;
47
48 #if !defined(CONFIG_MONITOR_IS_IN_RAM)
49 .text
50 /*
51 * Vector table. This is used for initial platform startup.
52 * These vectors are to catch any un-intended traps.
53 */
54 _vectors:
55
56 INITSP: .long 0x00000000 /* Initial SP */
57 INITPC: .long _START /* Initial PC */
58 vector02: .long _FAULT /* Access Error */
59 vector03: .long _FAULT /* Address Error */
60 vector04: .long _FAULT /* Illegal Instruction */
61 vector05: .long _FAULT /* Reserved */
62 vector06: .long _FAULT /* Reserved */
63 vector07: .long _FAULT /* Reserved */
64 vector08: .long _FAULT /* Privilege Violation */
65 vector09: .long _FAULT /* Trace */
66 vector0A: .long _FAULT /* Unimplemented A-Line */
67 vector0B: .long _FAULT /* Unimplemented F-Line */
68 vector0C: .long _FAULT /* Debug Interrupt */
69 vector0D: .long _FAULT /* Reserved */
70 vector0E: .long _FAULT /* Format Error */
71 vector0F: .long _FAULT /* Unitialized Int. */
72
73 /* Reserved */
74 vector10_17:
75 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
76
77 vector18: .long _FAULT /* Spurious Interrupt */
78 vector19: .long _FAULT /* Autovector Level 1 */
79 vector1A: .long _FAULT /* Autovector Level 2 */
80 vector1B: .long _FAULT /* Autovector Level 3 */
81 vector1C: .long _FAULT /* Autovector Level 4 */
82 vector1D: .long _FAULT /* Autovector Level 5 */
83 vector1E: .long _FAULT /* Autovector Level 6 */
84 vector1F: .long _FAULT /* Autovector Level 7 */
85
86 /* TRAP #0 - #15 */
87 vector20_2F:
88 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
89 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
90
91 /* Reserved */
92 vector30_3F:
93 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
94 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
95
96 vector64_127:
97 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
98 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
99 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
100 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
101 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
102 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
103 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
104 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
105
106 vector128_191:
107 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
108 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
109 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
110 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
111 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
112 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
113 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
114 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
115
116 vector192_255:
117 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
118 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
119 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
120 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
121 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
122 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
123 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
124 .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
125 #endif /* !defined(CONFIG_MONITOR_IS_IN_RAM) */
126
127 .text
128
129 .globl _start
130 _start:
131 nop
132 nop
133 move.w #0x2700,%sr /* Mask off Interrupt */
134
135 #if !defined(CONFIG_MONITOR_IS_IN_RAM)
136 /* Set vector base register at the beginning of the Flash */
137 move.l #CONFIG_SYS_FLASH_BASE, %d0
138 movec %d0, %VBR
139 #endif
140
141 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
142 movec %d0, %RAMBAR1
143
144 /* invalidate and disable cache */
145 move.l #0x01000000, %d0 /* Invalidate cache cmd */
146 movec %d0, %CACR /* Invalidate cache */
147 move.l #0, %d0
148 movec %d0, %ACR0
149 movec %d0, %ACR1
150
151 #ifdef CONFIG_MCF5301x
152 move.l #(0xFC0a0010), %a0
153 move.w (%a0), %d0
154 and.l %d0, 0xEFFF
155
156 move.w %d0, (%a0)
157 #endif
158
159 /* initialize general use internal ram */
160 move.l #0, %d0
161 move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-8), %a1
162 move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-4), %a2
163 move.l %d0, (%a1)
164 move.l %d0, (%a2)
165
166 /* set stackpointer to end of internal ram to get some stackspace for the
167 first c-code */
168 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
169 clr.l %sp@-
170
171 move.l #__got_start, %a5 /* put relocation table address to a5 */
172
173 bsr cpu_init_f /* run low-level CPU init code (from flash) */
174 bsr board_init_f /* run low-level board init code (from flash) */
175
176 /* board_init_f() does not return */
177
178 /*------------------------------------------------------------------------------*/
179
180 /*
181 * void relocate_code (addr_sp, gd, addr_moni)
182 *
183 * This "function" does not return, instead it continues in RAM
184 * after relocating the monitor code.
185 *
186 * r3 = dest
187 * r4 = src
188 * r5 = length in bytes
189 * r6 = cachelinesize
190 */
191 .globl relocate_code
192 relocate_code:
193 link.w %a6,#0
194 move.l 8(%a6), %sp /* set new stack pointer */
195
196 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
197 move.l 16(%a6), %a0 /* Save copy of Destination Address */
198
199 move.l #CONFIG_SYS_MONITOR_BASE, %a1
200 move.l #__init_end, %a2
201 move.l %a0, %a3
202
203 /* copy the code to RAM */
204 1:
205 move.l (%a1)+, (%a3)+
206 cmp.l %a1,%a2
207 bgt.s 1b
208
209 /*
210 * We are done. Do not return, instead branch to second part of board
211 * initialization, now running from RAM.
212 */
213 move.l %a0, %a1
214 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
215 jmp (%a1)
216
217 in_ram:
218
219 clear_bss:
220 /*
221 * Now clear BSS segment
222 */
223 move.l %a0, %a1
224 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
225 move.l %a0, %d1
226 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
227 6:
228 clr.l (%a1)+
229 cmp.l %a1,%d1
230 bgt.s 6b
231
232 /*
233 * fix got table in RAM
234 */
235 move.l %a0, %a1
236 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
237 move.l %a1,%a5 /* * fix got pointer register a5 */
238
239 move.l %a0, %a2
240 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
241
242 7:
243 move.l (%a1),%d1
244 sub.l #_start,%d1
245 add.l %a0,%d1
246 move.l %d1,(%a1)+
247 cmp.l %a2, %a1
248 bne 7b
249
250 /* calculate relative jump to board_init_r in ram */
251 move.l %a0, %a1
252 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
253
254 /* set parameters for board_init_r */
255 move.l %a0,-(%sp) /* dest_addr */
256 move.l %d0,-(%sp) /* gd */
257 jsr (%a1)
258
259 /*------------------------------------------------------------------------------*/
260 /* exception code */
261 .globl _fault
262 _fault:
263 jmp _fault
264 .globl _exc_handler
265
266 _exc_handler:
267 SAVE_ALL
268 movel %sp,%sp@-
269 bsr exc_handler
270 addql #4,%sp
271 RESTORE_ALL
272
273 .globl _int_handler
274 _int_handler:
275 SAVE_ALL
276 movel %sp,%sp@-
277 bsr int_handler
278 addql #4,%sp
279 RESTORE_ALL
280
281 /*------------------------------------------------------------------------------*/
282 /* cache functions */
283 .globl icache_enable
284 icache_enable:
285 move.l #0x01000000, %d0 /* Invalidate cache cmd */
286 movec %d0, %CACR /* Invalidate cache */
287 move.l #(CONFIG_SYS_SDRAM_BASE + 0xc000 + ((CONFIG_SYS_SDRAM_SIZE & 0x1fe0) << 11)), %d0
288 movec %d0, %ACR0 /* Enable cache */
289
290 move.l #0x80000200, %d0 /* Setup cache mask */
291 movec %d0, %CACR /* Enable cache */
292 nop
293
294 move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-8), %a1
295 moveq #1, %d0
296 move.l %d0, (%a1)
297 rts
298
299 .globl icache_disable
300 icache_disable:
301 move.l #0x01000000, %d0 /* Setup cache mask */
302 movec %d0, %CACR /* Disable cache */
303 clr.l %d0 /* Setup cache mask */
304 movec %d0, %ACR0
305 movec %d0, %ACR1
306
307 move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-8), %a1
308 moveq #0, %d0
309 move.l %d0, (%a1)
310 rts
311
312 .globl icache_status
313 icache_status:
314 move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-8), %a1
315 move.l (%a1), %d0
316 rts
317
318 .globl icache_invalid
319 icache_invalid:
320 move.l #0x81000200, %d0 /* Setup cache mask */
321 movec %d0, %CACR /* Enable cache */
322 rts
323
324 .globl dcache_enable
325 dcache_enable:
326 move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-4), %a1
327 moveq #1, %d0
328 move.l %d0, (%a1)
329 rts
330
331 /* No dcache, just a dummy function */
332 .globl dcache_disable
333 dcache_disable:
334 move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-4), %a1
335 moveq #0, %d0
336 move.l %d0, (%a1)
337 rts
338
339 .globl dcache_status
340 dcache_status:
341 move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-4), %a1
342 move.l (%a1), %d0
343 rts
344
345 /*------------------------------------------------------------------------------*/
346
347 .globl version_string
348 version_string:
349 .ascii U_BOOT_VERSION
350 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
351 .ascii CONFIG_IDENT_STRING, "\0"
352 .align 4