blob: a726b59846dc2a16ed6997d5554d38cac50e841e [file] [log] [blame]
TsiChungLiew4a442d32007-08-16 19:23:50 -05001/*
2 * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de>
3 * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +020024#include <asm-offsets.h>
TsiChungLiew4a442d32007-08-16 19:23:50 -050025#include <config.h>
Peter Tyser561858e2008-11-03 09:30:59 -060026#include <timestamp.h>
TsiChungLiew4a442d32007-08-16 19:23:50 -050027#include "version.h"
TsiChung Liewdd9f0542010-03-11 22:12:53 -060028#include <asm/cache.h>
TsiChungLiew4a442d32007-08-16 19:23:50 -050029
30#ifndef CONFIG_IDENT_STRING
31#define CONFIG_IDENT_STRING ""
32#endif
33
34#define _START _start
35#define _FAULT _fault
36
37#define SAVE_ALL \
38 move.w #0x2700,%sr; /* disable intrs */ \
39 subl #60,%sp; /* space for 15 regs */ \
40 moveml %d0-%d7/%a0-%a6,%sp@;
41
42#define RESTORE_ALL \
43 moveml %sp@,%d0-%d7/%a0-%a6; \
44 addl #60,%sp; /* space for 15 regs */ \
45 rte;
46
47.text
48/*
49 * Vector table. This is used for initial platform startup.
50 * These vectors are to catch any un-intended traps.
51 */
52_vectors:
53
54INITSP: .long 0x00000000 /* Initial SP */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020055INITPC: .long _START /* Initial PC */
TsiChungLiew4a442d32007-08-16 19:23:50 -050056vector02: .long _FAULT /* Access Error */
57vector03: .long _FAULT /* Address Error */
58vector04: .long _FAULT /* Illegal Instruction */
59vector05: .long _FAULT /* Reserved */
60vector06: .long _FAULT /* Reserved */
61vector07: .long _FAULT /* Reserved */
62vector08: .long _FAULT /* Privilege Violation */
63vector09: .long _FAULT /* Trace */
64vector0A: .long _FAULT /* Unimplemented A-Line */
65vector0B: .long _FAULT /* Unimplemented F-Line */
66vector0C: .long _FAULT /* Debug Interrupt */
67vector0D: .long _FAULT /* Reserved */
68vector0E: .long _FAULT /* Format Error */
69vector0F: .long _FAULT /* Unitialized Int. */
70
71/* Reserved */
72vector10_17:
73.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
74
75vector18: .long _FAULT /* Spurious Interrupt */
76vector19: .long _FAULT /* Autovector Level 1 */
77vector1A: .long _FAULT /* Autovector Level 2 */
78vector1B: .long _FAULT /* Autovector Level 3 */
79vector1C: .long _FAULT /* Autovector Level 4 */
80vector1D: .long _FAULT /* Autovector Level 5 */
81vector1E: .long _FAULT /* Autovector Level 6 */
82vector1F: .long _FAULT /* Autovector Level 7 */
83
84/* TRAP #0 - #15 */
85vector20_2F:
86.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
87.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
88
89/* Reserved */
90vector30_3F:
91.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
92.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
93
94vector64_127:
95.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
96.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
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
104vector128_191:
105.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
106.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
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
114vector192_255:
115.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
116.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
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
124 .text
125
126 .globl _start
127_start:
128 nop
129 nop
130 move.w #0x2700,%sr /* Mask off Interrupt */
131
132 /* Set vector base register at the beginning of the Flash */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200133 move.l #CONFIG_SYS_FLASH_BASE, %d0
TsiChungLiew4a442d32007-08-16 19:23:50 -0500134 movec %d0, %VBR
135
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200136 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
TsiChungLiew4a442d32007-08-16 19:23:50 -0500137 movec %d0, %RAMBAR1
138
139 /* invalidate and disable cache */
TsiChung Liewdd9f0542010-03-11 22:12:53 -0600140 move.l #CF_CACR_CINV, %d0 /* Invalidate cache cmd */
TsiChungLiew4a442d32007-08-16 19:23:50 -0500141 movec %d0, %CACR /* Invalidate cache */
142 nop
143 move.l #0, %d0
144 movec %d0, %ACR0
145 movec %d0, %ACR1
146
147 /* initialize general use internal ram */
148 move.l #0, %d0
TsiChung Liewdd9f0542010-03-11 22:12:53 -0600149 move.l #(ICACHE_STATUS), %a1 /* icache */
150 move.l #(DCACHE_STATUS), %a2 /* icache */
TsiChungLiew4a442d32007-08-16 19:23:50 -0500151 move.l %d0, (%a1)
152 move.l %d0, (%a2)
153
154 /* set stackpointer to end of internal ram to get some stackspace for the
155 first c-code */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200156 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
TsiChungLiew4a442d32007-08-16 19:23:50 -0500157 clr.l %sp@-
158
159 move.l #__got_start, %a5 /* put relocation table address to a5 */
160
161 bsr cpu_init_f /* run low-level CPU init code (from flash) */
162 bsr board_init_f /* run low-level board init code (from flash) */
163
164 /* board_init_f() does not return */
165
166/*------------------------------------------------------------------------------*/
167
168/*
169 * void relocate_code (addr_sp, gd, addr_moni)
170 *
171 * This "function" does not return, instead it continues in RAM
172 * after relocating the monitor code.
173 *
174 * r3 = dest
175 * r4 = src
176 * r5 = length in bytes
177 * r6 = cachelinesize
178 */
179 .globl relocate_code
180relocate_code:
181 link.w %a6,#0
182 move.l 8(%a6), %sp /* set new stack pointer */
183
184 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
185 move.l 16(%a6), %a0 /* Save copy of Destination Address */
186
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200187 move.l #CONFIG_SYS_MONITOR_BASE, %a1
TsiChungLiew4a442d32007-08-16 19:23:50 -0500188 move.l #__init_end, %a2
189 move.l %a0, %a3
190
191 /* copy the code to RAM */
1921:
193 move.l (%a1)+, (%a3)+
194 cmp.l %a1,%a2
195 bgt.s 1b
196
197/*
198 * We are done. Do not return, instead branch to second part of board
199 * initialization, now running from RAM.
200 */
201 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200202 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
TsiChungLiew4a442d32007-08-16 19:23:50 -0500203 jmp (%a1)
204
205in_ram:
206
207clear_bss:
208 /*
209 * Now clear BSS segment
210 */
211 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200212 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
TsiChungLiew4a442d32007-08-16 19:23:50 -0500213 move.l %a0, %d1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200214 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
TsiChungLiew4a442d32007-08-16 19:23:50 -05002156:
216 clr.l (%a1)+
217 cmp.l %a1,%d1
218 bgt.s 6b
219
220 /*
221 * fix got table in RAM
222 */
223 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200224 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
TsiChungLiew4a442d32007-08-16 19:23:50 -0500225 move.l %a1,%a5 /* * fix got pointer register a5 */
226
227 move.l %a0, %a2
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200228 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
TsiChungLiew4a442d32007-08-16 19:23:50 -0500229
2307:
231 move.l (%a1),%d1
232 sub.l #_start,%d1
233 add.l %a0,%d1
234 move.l %d1,(%a1)+
235 cmp.l %a2, %a1
236 bne 7b
237
238 /* calculate relative jump to board_init_r in ram */
239 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200240 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
TsiChungLiew4a442d32007-08-16 19:23:50 -0500241
242 /* set parameters for board_init_r */
243 move.l %a0,-(%sp) /* dest_addr */
244 move.l %d0,-(%sp) /* gd */
245 jsr (%a1)
246
247/*------------------------------------------------------------------------------*/
248/* exception code */
249 .globl _fault
250_fault:
251 jmp _fault
252 .globl _exc_handler
253
254_exc_handler:
255 SAVE_ALL
256 movel %sp,%sp@-
257 bsr exc_handler
258 addql #4,%sp
259 RESTORE_ALL
260
261 .globl _int_handler
262_int_handler:
263 SAVE_ALL
264 movel %sp,%sp@-
265 bsr int_handler
266 addql #4,%sp
267 RESTORE_ALL
268
269/*------------------------------------------------------------------------------*/
TsiChungLiew4a442d32007-08-16 19:23:50 -0500270
271 .globl version_string
272version_string:
273 .ascii U_BOOT_VERSION
Peter Tyser561858e2008-11-03 09:30:59 -0600274 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
TsiChungLiew4a442d32007-08-16 19:23:50 -0500275 .ascii CONFIG_IDENT_STRING, "\0"
TsiChung Liew9b464322008-03-28 08:47:45 -0500276 .align 4