blob: f5e55dd9657c9209ca72dd3346165a02ee38a12f [file] [log] [blame]
wdenkbf9e3b32004-02-12 00:47:09 +00001/*
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>
wdenkbf9e3b32004-02-12 00:47:09 +000025#include <config.h>
26#include "version.h"
TsiChung Liewdd9f0542010-03-11 22:12:53 -060027#include <asm/cache.h>
wdenkbf9e3b32004-02-12 00:47:09 +000028
29#ifndef CONFIG_IDENT_STRING
30#define CONFIG_IDENT_STRING ""
31#endif
32
wdenkbf9e3b32004-02-12 00:47:09 +000033#define _START _start
34#define _FAULT _fault
35
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/* If we come from a pre-loader we don't need an initial exception
48 * table.
49 */
50#if !defined(CONFIG_MONITOR_IS_IN_RAM)
51
52.text
53/*
54 * Vector table. This is used for initial platform startup.
55 * These vectors are to catch any un-intended traps.
56 */
57_vectors:
58
Wolfgang Denk4176c792006-06-10 19:27:47 +020059.long 0x00000000 /* Flash offset is 0 until we setup CS0 */
Wolfgang Denk14d0a022010-10-07 21:51:12 +020060#if defined(CONFIG_M5282) && (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
61.long _start - CONFIG_SYS_TEXT_BASE
Zachary P. Landaueacbd312006-01-26 17:35:56 -050062#else
Wolfgang Denk4176c792006-06-10 19:27:47 +020063.long _START
Zachary P. Landaueacbd312006-01-26 17:35:56 -050064#endif
Wolfgang Denk4176c792006-06-10 19:27:47 +020065
wdenkbf9e3b32004-02-12 00:47:09 +000066.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
67.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
68.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
69.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
70.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
71.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
72.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
73.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
74
75.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
76.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
77.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
78.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
79.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
80.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
81.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
82.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
83
84.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
85.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
86.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
87.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
88.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
89.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
90.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
91.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
92
93.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
94.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
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
102#endif
103
104 .text
105
Heiko Schocher9acb6262006-04-20 08:42:42 +0200106
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200107#if defined(CONFIG_SYS_INT_FLASH_BASE) && \
Heiko Schocher9acb6262006-04-20 08:42:42 +0200108 (defined(CONFIG_M5282) || defined(CONFIG_M5281))
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200109 #if (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
Heiko Schocher9acb6262006-04-20 08:42:42 +0200110 .long 0x55AA55AA,0xAA55AA55 /* CFM Backdoorkey */
111 .long 0xFFFFFFFF /* all sectors protected */
112 .long 0x00000000 /* supervisor/User restriction */
113 .long 0x00000000 /* programm/data space restriction */
114 .long 0x00000000 /* Flash security */
115 #endif
116#endif
wdenkbf9e3b32004-02-12 00:47:09 +0000117 .globl _start
118_start:
119 nop
120 nop
121 move.w #0x2700,%sr
122
TsiChung Liewbf9a5212009-06-12 11:29:00 +0000123#if defined(CONFIG_M5208)
124 /* Initialize RAMBAR: locate SRAM and validate it */
125 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
126 movec %d0, %RAMBAR1
127#endif
128
TsiChungLiewa1436a82007-08-16 13:20:50 -0500129#if defined(CONFIG_M5272) || defined(CONFIG_M5249) || defined(CONFIG_M5253)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200130 move.l #(CONFIG_SYS_MBAR + 1), %d0 /* set MBAR address + valid flag */
wdenkbf9e3b32004-02-12 00:47:09 +0000131 move.c %d0, %MBAR
132
stroese8c725b92004-12-16 18:09:49 +0000133 /*** The 5249 has MBAR2 as well ***/
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200134#ifdef CONFIG_SYS_MBAR2
135 move.l #(CONFIG_SYS_MBAR2 + 1), %d0 /* Get MBAR2 address */
stroese8c725b92004-12-16 18:09:49 +0000136 movec %d0, #0xc0e /* Set MBAR2 */
137#endif
138
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200139 move.l #(CONFIG_SYS_INIT_RAM_ADDR + 1), %d0
wdenkbf9e3b32004-02-12 00:47:09 +0000140 movec %d0, %RAMBAR0
TsiChungLiewa1436a82007-08-16 13:20:50 -0500141#endif /* CONFIG_M5272 || CONFIG_M5249 || CONFIG_M5253 */
wdenkbf9e3b32004-02-12 00:47:09 +0000142
Wolfgang Denk4176c792006-06-10 19:27:47 +0200143#if defined(CONFIG_M5282) || defined(CONFIG_M5271)
wdenkbf9e3b32004-02-12 00:47:09 +0000144 /* Initialize IPSBAR */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200145 move.l #(CONFIG_SYS_MBAR + 1), %d0 /* set IPSBAR address + valid flag */
wdenkbf9e3b32004-02-12 00:47:09 +0000146 move.l %d0, 0x40000000
147
wdenkbf9e3b32004-02-12 00:47:09 +0000148 /* Initialize RAMBAR1: locate SRAM and validate it */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200149 move.l #(CONFIG_SYS_INIT_RAM_ADDR + 0x21), %d0
wdenkbf9e3b32004-02-12 00:47:09 +0000150 movec %d0, %RAMBAR1
Heiko Schocher9acb6262006-04-20 08:42:42 +0200151
Bartlomiej Siekadaa6e412006-12-20 00:27:32 +0100152#if defined(CONFIG_M5282)
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200153#if (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
Heiko Schocher9acb6262006-04-20 08:42:42 +0200154 /* Setup code in SRAM to initialize FLASHBAR, if start from internal Flash */
155
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200156 move.l #(_flashbar_setup-CONFIG_SYS_INT_FLASH_BASE), %a0
157 move.l #(_flashbar_setup_end-CONFIG_SYS_INT_FLASH_BASE), %a1
158 move.l #(CONFIG_SYS_INIT_RAM_ADDR), %a2
Heiko Schocher9acb6262006-04-20 08:42:42 +0200159_copy_flash:
160 move.l (%a0)+, (%a2)+
161 cmp.l %a0, %a1
162 bgt.s _copy_flash
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200163 jmp CONFIG_SYS_INIT_RAM_ADDR
Heiko Schocher9acb6262006-04-20 08:42:42 +0200164
165_flashbar_setup:
166 /* Initialize FLASHBAR: locate internal Flash and validate it */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200167 move.l #(CONFIG_SYS_INT_FLASH_BASE + CONFIG_SYS_INT_FLASH_ENABLE), %d0
TsiChung Liew43d60642008-03-13 14:26:32 -0500168 movec %d0, %FLASHBAR
Heiko Schocher9acb6262006-04-20 08:42:42 +0200169 jmp _after_flashbar_copy.L /* Force jump to absolute address */
170_flashbar_setup_end:
171 nop
172_after_flashbar_copy:
173#else
174 /* Setup code to initialize FLASHBAR, if start from external Memory */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200175 move.l #(CONFIG_SYS_INT_FLASH_BASE + CONFIG_SYS_INT_FLASH_ENABLE), %d0
TsiChung Liew4cb4e652008-08-11 15:54:25 +0000176 movec %d0, %FLASHBAR
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200177#endif /* (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE) */
Heiko Schocher9acb6262006-04-20 08:42:42 +0200178
179#endif
Wolfgang Denk6741ae92006-09-04 01:03:57 +0200180#endif
Heiko Schocher9acb6262006-04-20 08:42:42 +0200181 /* if we come from a pre-loader we have no exception table and
182 * therefore no VBR to set
183 */
184#if !defined(CONFIG_MONITOR_IS_IN_RAM)
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200185#if defined(CONFIG_M5282) && (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200186 move.l #CONFIG_SYS_INT_FLASH_BASE, %d0
TsiChungLiew2acefa72007-10-25 17:09:17 -0500187#else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200188 move.l #CONFIG_SYS_FLASH_BASE, %d0
TsiChungLiew2acefa72007-10-25 17:09:17 -0500189#endif
Heiko Schocher9acb6262006-04-20 08:42:42 +0200190 movec %d0, %VBR
Marian Balakowicz6f5155a2006-05-09 11:51:51 +0200191#endif
192
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600193#ifdef CONFIG_M5275
194 /* Initialize IPSBAR */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200195 move.l #(CONFIG_SYS_MBAR + 1), %d0 /* set IPSBAR address + valid flag */
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600196 move.l %d0, 0x40000000
197/* movec %d0, %MBAR */
198
199 /* Initialize RAMBAR: locate SRAM and validate it */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200200 move.l #(CONFIG_SYS_INIT_RAM_ADDR + 0x21), %d0
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600201 movec %d0, %RAMBAR1
202#endif
203
TsiChung Liewdd9f0542010-03-11 22:12:53 -0600204 /* initialize general use internal ram */
205 move.l #0, %d0
206 move.l #(ICACHE_STATUS), %a1 /* icache */
207 move.l #(DCACHE_STATUS), %a2 /* icache */
208 move.l %d0, (%a1)
209 move.l %d0, (%a2)
210
wdenkbf9e3b32004-02-12 00:47:09 +0000211 /* set stackpointer to end of internal ram to get some stackspace for the first c-code */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200212 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
wdenkbf9e3b32004-02-12 00:47:09 +0000213 clr.l %sp@-
214
215 move.l #__got_start, %a5 /* put relocation table address to a5 */
216
217 bsr cpu_init_f /* run low-level CPU init code (from flash) */
218 bsr board_init_f /* run low-level board init code (from flash) */
219
Marian Balakowicz6f5155a2006-05-09 11:51:51 +0200220 /* board_init_f() does not return */
wdenkbf9e3b32004-02-12 00:47:09 +0000221
222/*------------------------------------------------------------------------------*/
223
224/*
225 * void relocate_code (addr_sp, gd, addr_moni)
226 *
227 * This "function" does not return, instead it continues in RAM
228 * after relocating the monitor code.
229 *
230 * r3 = dest
231 * r4 = src
232 * r5 = length in bytes
233 * r6 = cachelinesize
234 */
235 .globl relocate_code
236relocate_code:
237 link.w %a6,#0
238 move.l 8(%a6), %sp /* set new stack pointer */
239
240 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
241 move.l 16(%a6), %a0 /* Save copy of Destination Address */
242
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200243 move.l #CONFIG_SYS_MONITOR_BASE, %a1
wdenkbf9e3b32004-02-12 00:47:09 +0000244 move.l #__init_end, %a2
245 move.l %a0, %a3
wdenkbf9e3b32004-02-12 00:47:09 +0000246 /* copy the code to RAM */
2471:
248 move.l (%a1)+, (%a3)+
249 cmp.l %a1,%a2
250 bgt.s 1b
251
252/*
253 * We are done. Do not return, instead branch to second part of board
254 * initialization, now running from RAM.
255 */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200256 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200257 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
wdenkbf9e3b32004-02-12 00:47:09 +0000258 jmp (%a1)
259
260in_ram:
261
262clear_bss:
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200263 /*
wdenkbf9e3b32004-02-12 00:47:09 +0000264 * Now clear BSS segment
265 */
266 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200267 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
wdenkbf9e3b32004-02-12 00:47:09 +0000268 move.l %a0, %d1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200269 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
wdenkbf9e3b32004-02-12 00:47:09 +00002706:
271 clr.l (%a1)+
272 cmp.l %a1,%d1
273 bgt.s 6b
274
275 /*
276 * fix got table in RAM
277 */
278 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200279 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
wdenkbf9e3b32004-02-12 00:47:09 +0000280 move.l %a1,%a5 /* * fix got pointer register a5 */
281
282 move.l %a0, %a2
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200283 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
wdenkbf9e3b32004-02-12 00:47:09 +0000284
2857:
286 move.l (%a1),%d1
287 sub.l #_start,%d1
288 add.l %a0,%d1
289 move.l %d1,(%a1)+
290 cmp.l %a2, %a1
291 bne 7b
292
293 /* calculate relative jump to board_init_r in ram */
294 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200295 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
wdenkbf9e3b32004-02-12 00:47:09 +0000296
297 /* set parameters for board_init_r */
298 move.l %a0,-(%sp) /* dest_addr */
299 move.l %d0,-(%sp) /* gd */
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200300#if defined(DEBUG) && (CONFIG_SYS_TEXT_BASE != CONFIG_SYS_INT_FLASH_BASE) && \
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200301 defined(CONFIG_SYS_HALT_BEFOR_RAM_JUMP)
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500302 halt
303#endif
wdenkbf9e3b32004-02-12 00:47:09 +0000304 jsr (%a1)
305
306/*------------------------------------------------------------------------------*/
307/* exception code */
308 .globl _fault
309_fault:
Marek Vasut37d6cc32012-10-03 13:28:43 +0000310 bra _fault
wdenkbf9e3b32004-02-12 00:47:09 +0000311
312 .globl _exc_handler
313_exc_handler:
314 SAVE_ALL
315 movel %sp,%sp@-
316 bsr exc_handler
317 addql #4,%sp
318 RESTORE_ALL
319
320 .globl _int_handler
321_int_handler:
322 SAVE_ALL
323 movel %sp,%sp@-
324 bsr int_handler
325 addql #4,%sp
326 RESTORE_ALL
327
328/*------------------------------------------------------------------------------*/
wdenkbf9e3b32004-02-12 00:47:09 +0000329
330 .globl version_string
331version_string:
Andreas Bießmann09c2e902011-07-18 20:24:04 +0200332 .ascii U_BOOT_VERSION_STRING, "\0"
TsiChung Liew9b464322008-03-28 08:47:45 -0500333 .align 4