blob: 53ac471a416905352622ed16581eb174d004a516 [file] [log] [blame]
TsiChung Liew8e585f02007-06-18 13:50:13 -05001/*
2 * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de>
3 * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
4 *
TsiChung Liew536e7da2008-10-22 11:38:21 +00005 * (C) Copyright 2004-2008 Freescale Semiconductor, Inc.
6 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
7 *
TsiChung Liew8e585f02007-06-18 13:50:13 -05008 * 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
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +020027#include <asm-offsets.h>
TsiChung Liew8e585f02007-06-18 13:50:13 -050028#include <config.h>
Peter Tyser561858e2008-11-03 09:30:59 -060029#include <timestamp.h>
TsiChung Liew8e585f02007-06-18 13:50:13 -050030#include "version.h"
TsiChung Liewdd9f0542010-03-11 22:12:53 -060031#include <asm/cache.h>
TsiChung Liew8e585f02007-06-18 13:50:13 -050032
33#ifndef CONFIG_IDENT_STRING
34#define CONFIG_IDENT_STRING ""
35#endif
36
37#define _START _start
38#define _FAULT _fault
39
TsiChung Liew8e585f02007-06-18 13:50:13 -050040#define SAVE_ALL \
41 move.w #0x2700,%sr; /* disable intrs */ \
42 subl #60,%sp; /* space for 15 regs */ \
43 moveml %d0-%d7/%a0-%a6,%sp@;
44
45#define RESTORE_ALL \
46 moveml %sp@,%d0-%d7/%a0-%a6; \
47 addl #60,%sp; /* space for 15 regs */ \
48 rte;
49
Wolfgang Wegnerc7de8102010-03-02 10:59:20 +010050#if !defined(CONFIG_MONITOR_IS_IN_RAM)
TsiChung Liew8e585f02007-06-18 13:50:13 -050051.text
52/*
53 * Vector table. This is used for initial platform startup.
54 * These vectors are to catch any un-intended traps.
55 */
56_vectors:
57
TsiChungLiewddd104f2007-07-05 23:06:55 -050058INITSP: .long 0x00000000 /* Initial SP */
Wolfgang Denk53677ef2008-05-20 16:00:29 +020059INITPC: .long _START /* Initial PC */
TsiChungLiewddd104f2007-07-05 23:06:55 -050060vector02: .long _FAULT /* Access Error */
61vector03: .long _FAULT /* Address Error */
62vector04: .long _FAULT /* Illegal Instruction */
63vector05: .long _FAULT /* Reserved */
64vector06: .long _FAULT /* Reserved */
65vector07: .long _FAULT /* Reserved */
66vector08: .long _FAULT /* Privilege Violation */
67vector09: .long _FAULT /* Trace */
68vector0A: .long _FAULT /* Unimplemented A-Line */
69vector0B: .long _FAULT /* Unimplemented F-Line */
70vector0C: .long _FAULT /* Debug Interrupt */
71vector0D: .long _FAULT /* Reserved */
72vector0E: .long _FAULT /* Format Error */
73vector0F: .long _FAULT /* Unitialized Int. */
TsiChung Liew8e585f02007-06-18 13:50:13 -050074
TsiChungLiewddd104f2007-07-05 23:06:55 -050075/* Reserved */
TsiChung Liew8e585f02007-06-18 13:50:13 -050076vector10_17:
77.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
78
TsiChungLiewddd104f2007-07-05 23:06:55 -050079vector18: .long _FAULT /* Spurious Interrupt */
80vector19: .long _FAULT /* Autovector Level 1 */
81vector1A: .long _FAULT /* Autovector Level 2 */
82vector1B: .long _FAULT /* Autovector Level 3 */
83vector1C: .long _FAULT /* Autovector Level 4 */
84vector1D: .long _FAULT /* Autovector Level 5 */
85vector1E: .long _FAULT /* Autovector Level 6 */
86vector1F: .long _FAULT /* Autovector Level 7 */
TsiChung Liew8e585f02007-06-18 13:50:13 -050087
88/* TRAP #0 - #15 */
89vector20_2F:
90.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
91.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
92
93/* Reserved */
94vector30_3F:
95.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
96.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
97
98vector64_127:
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.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
106.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
107
108vector128_191:
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.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
116.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
117
118vector192_255:
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.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
126.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
Wolfgang Wegnerc7de8102010-03-02 10:59:20 +0100127#endif /* !defined(CONFIG_MONITOR_IS_IN_RAM) */
TsiChung Liew8e585f02007-06-18 13:50:13 -0500128
129 .text
130
131 .globl _start
132_start:
133 nop
134 nop
TsiChungLiewddd104f2007-07-05 23:06:55 -0500135 move.w #0x2700,%sr /* Mask off Interrupt */
TsiChung Liew8e585f02007-06-18 13:50:13 -0500136
Wolfgang Wegnerc7de8102010-03-02 10:59:20 +0100137#if !defined(CONFIG_MONITOR_IS_IN_RAM)
TsiChungLiewddd104f2007-07-05 23:06:55 -0500138 /* Set vector base register at the beginning of the Flash */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200139 move.l #CONFIG_SYS_FLASH_BASE, %d0
TsiChung Liew8e585f02007-06-18 13:50:13 -0500140 movec %d0, %VBR
Wolfgang Wegnerc7de8102010-03-02 10:59:20 +0100141#endif
TsiChung Liew8e585f02007-06-18 13:50:13 -0500142
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200143 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
TsiChungLiewc67e12e2007-10-25 17:12:36 -0500144 movec %d0, %RAMBAR1
TsiChung Liew8e585f02007-06-18 13:50:13 -0500145
146 /* invalidate and disable cache */
TsiChung Liewdd9f0542010-03-11 22:12:53 -0600147 move.l #CF_CACR_CINVA, %d0 /* Invalidate cache cmd */
TsiChung Liew8e585f02007-06-18 13:50:13 -0500148 movec %d0, %CACR /* Invalidate cache */
149 move.l #0, %d0
150 movec %d0, %ACR0
151 movec %d0, %ACR1
152
TsiChung Liew536e7da2008-10-22 11:38:21 +0000153#ifdef CONFIG_MCF5301x
154 move.l #(0xFC0a0010), %a0
155 move.w (%a0), %d0
156 and.l %d0, 0xEFFF
157
158 move.w %d0, (%a0)
159#endif
160
TsiChung Liew8e585f02007-06-18 13:50:13 -0500161 /* initialize general use internal ram */
162 move.l #0, %d0
TsiChung Liewdd9f0542010-03-11 22:12:53 -0600163 move.l #(ICACHE_STATUS), %a1 /* icache */
164 move.l #(DCACHE_STATUS), %a2 /* icache */
TsiChung Liew8e585f02007-06-18 13:50:13 -0500165 move.l %d0, (%a1)
166 move.l %d0, (%a2)
167
TsiChungLiewddd104f2007-07-05 23:06:55 -0500168 /* set stackpointer to end of internal ram to get some stackspace for the
169 first c-code */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200170 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
TsiChung Liew8e585f02007-06-18 13:50:13 -0500171 clr.l %sp@-
172
TsiChungLiewddd104f2007-07-05 23:06:55 -0500173 move.l #__got_start, %a5 /* put relocation table address to a5 */
TsiChung Liew8e585f02007-06-18 13:50:13 -0500174
TsiChungLiewddd104f2007-07-05 23:06:55 -0500175 bsr cpu_init_f /* run low-level CPU init code (from flash) */
176 bsr board_init_f /* run low-level board init code (from flash) */
TsiChung Liew8e585f02007-06-18 13:50:13 -0500177
178 /* board_init_f() does not return */
179
180/*------------------------------------------------------------------------------*/
181
182/*
183 * void relocate_code (addr_sp, gd, addr_moni)
184 *
185 * This "function" does not return, instead it continues in RAM
186 * after relocating the monitor code.
187 *
188 * r3 = dest
189 * r4 = src
190 * r5 = length in bytes
191 * r6 = cachelinesize
192 */
193 .globl relocate_code
194relocate_code:
195 link.w %a6,#0
196 move.l 8(%a6), %sp /* set new stack pointer */
197
198 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
199 move.l 16(%a6), %a0 /* Save copy of Destination Address */
200
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200201 move.l #CONFIG_SYS_MONITOR_BASE, %a1
TsiChung Liew8e585f02007-06-18 13:50:13 -0500202 move.l #__init_end, %a2
203 move.l %a0, %a3
204
205 /* copy the code to RAM */
2061:
207 move.l (%a1)+, (%a3)+
208 cmp.l %a1,%a2
209 bgt.s 1b
210
211/*
212 * We are done. Do not return, instead branch to second part of board
213 * initialization, now running from RAM.
214 */
215 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200216 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
TsiChung Liew8e585f02007-06-18 13:50:13 -0500217 jmp (%a1)
218
219in_ram:
220
221clear_bss:
222 /*
223 * Now clear BSS segment
224 */
225 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200226 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
TsiChung Liew8e585f02007-06-18 13:50:13 -0500227 move.l %a0, %d1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200228 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
TsiChung Liew8e585f02007-06-18 13:50:13 -05002296:
230 clr.l (%a1)+
231 cmp.l %a1,%d1
232 bgt.s 6b
233
234 /*
235 * fix got table in RAM
236 */
237 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200238 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
TsiChung Liew8e585f02007-06-18 13:50:13 -0500239 move.l %a1,%a5 /* * fix got pointer register a5 */
240
241 move.l %a0, %a2
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200242 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
TsiChung Liew8e585f02007-06-18 13:50:13 -0500243
2447:
245 move.l (%a1),%d1
246 sub.l #_start,%d1
247 add.l %a0,%d1
248 move.l %d1,(%a1)+
249 cmp.l %a2, %a1
250 bne 7b
251
252 /* calculate relative jump to board_init_r in ram */
253 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200254 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
TsiChung Liew8e585f02007-06-18 13:50:13 -0500255
256 /* set parameters for board_init_r */
257 move.l %a0,-(%sp) /* dest_addr */
258 move.l %d0,-(%sp) /* gd */
259 jsr (%a1)
260
261/*------------------------------------------------------------------------------*/
262/* exception code */
263 .globl _fault
264_fault:
265 jmp _fault
266 .globl _exc_handler
267
268_exc_handler:
269 SAVE_ALL
270 movel %sp,%sp@-
271 bsr exc_handler
272 addql #4,%sp
273 RESTORE_ALL
274
275 .globl _int_handler
276_int_handler:
277 SAVE_ALL
278 movel %sp,%sp@-
279 bsr int_handler
280 addql #4,%sp
281 RESTORE_ALL
282
283/*------------------------------------------------------------------------------*/
TsiChung Liew8e585f02007-06-18 13:50:13 -0500284 .globl version_string
285version_string:
286 .ascii U_BOOT_VERSION
Peter Tyser561858e2008-11-03 09:30:59 -0600287 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
TsiChung Liew8e585f02007-06-18 13:50:13 -0500288 .ascii CONFIG_IDENT_STRING, "\0"
TsiChung Liew9b464322008-03-28 08:47:45 -0500289 .align 4