blob: f25bc541be7cf6f1110b55d3c5d15669395ce15d [file] [log] [blame]
TsiChung Liewf6afe722007-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 Liewe7e4fc82008-10-22 11:38:21 +00005 * (C) Copyright 2004-2008 Freescale Semiconductor, Inc.
6 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
7 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +02008 * SPDX-License-Identifier: GPL-2.0+
TsiChung Liewf6afe722007-06-18 13:50:13 -05009 */
10
Wolfgang Denk0191e472010-10-26 14:34:52 +020011#include <asm-offsets.h>
TsiChung Liewf6afe722007-06-18 13:50:13 -050012#include <config.h>
13#include "version.h"
TsiChung Liew0ee47d42010-03-11 22:12:53 -060014#include <asm/cache.h>
TsiChung Liewf6afe722007-06-18 13:50:13 -050015
16#ifndef CONFIG_IDENT_STRING
17#define CONFIG_IDENT_STRING ""
18#endif
19
20#define _START _start
21#define _FAULT _fault
22
TsiChung Liewf6afe722007-06-18 13:50:13 -050023#define SAVE_ALL \
24 move.w #0x2700,%sr; /* disable intrs */ \
25 subl #60,%sp; /* space for 15 regs */ \
26 moveml %d0-%d7/%a0-%a6,%sp@;
27
28#define RESTORE_ALL \
29 moveml %sp@,%d0-%d7/%a0-%a6; \
30 addl #60,%sp; /* space for 15 regs */ \
31 rte;
32
Wolfgang Wegnerea32ab22010-03-02 10:59:20 +010033#if !defined(CONFIG_MONITOR_IS_IN_RAM)
TsiChung Liewf6afe722007-06-18 13:50:13 -050034.text
35/*
36 * Vector table. This is used for initial platform startup.
37 * These vectors are to catch any un-intended traps.
38 */
39_vectors:
40
TsiChungLiew8592cda2007-07-05 23:06:55 -050041INITSP: .long 0x00000000 /* Initial SP */
Wolfgang Denka1be4762008-05-20 16:00:29 +020042INITPC: .long _START /* Initial PC */
TsiChungLiew8592cda2007-07-05 23:06:55 -050043vector02: .long _FAULT /* Access Error */
44vector03: .long _FAULT /* Address Error */
45vector04: .long _FAULT /* Illegal Instruction */
46vector05: .long _FAULT /* Reserved */
47vector06: .long _FAULT /* Reserved */
48vector07: .long _FAULT /* Reserved */
49vector08: .long _FAULT /* Privilege Violation */
50vector09: .long _FAULT /* Trace */
51vector0A: .long _FAULT /* Unimplemented A-Line */
52vector0B: .long _FAULT /* Unimplemented F-Line */
53vector0C: .long _FAULT /* Debug Interrupt */
54vector0D: .long _FAULT /* Reserved */
55vector0E: .long _FAULT /* Format Error */
56vector0F: .long _FAULT /* Unitialized Int. */
TsiChung Liewf6afe722007-06-18 13:50:13 -050057
TsiChungLiew8592cda2007-07-05 23:06:55 -050058/* Reserved */
TsiChung Liewf6afe722007-06-18 13:50:13 -050059vector10_17:
60.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
61
TsiChungLiew8592cda2007-07-05 23:06:55 -050062vector18: .long _FAULT /* Spurious Interrupt */
63vector19: .long _FAULT /* Autovector Level 1 */
64vector1A: .long _FAULT /* Autovector Level 2 */
65vector1B: .long _FAULT /* Autovector Level 3 */
66vector1C: .long _FAULT /* Autovector Level 4 */
67vector1D: .long _FAULT /* Autovector Level 5 */
68vector1E: .long _FAULT /* Autovector Level 6 */
69vector1F: .long _FAULT /* Autovector Level 7 */
TsiChung Liewf6afe722007-06-18 13:50:13 -050070
71/* TRAP #0 - #15 */
72vector20_2F:
73.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
74.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
75
76/* Reserved */
77vector30_3F:
78.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
79.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
80
81vector64_127:
82.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
83.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
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
91vector128_191:
92.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
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
101vector192_255:
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.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
Wolfgang Wegnerea32ab22010-03-02 10:59:20 +0100110#endif /* !defined(CONFIG_MONITOR_IS_IN_RAM) */
TsiChung Liewf6afe722007-06-18 13:50:13 -0500111
112 .text
113
114 .globl _start
115_start:
116 nop
117 nop
TsiChungLiew8592cda2007-07-05 23:06:55 -0500118 move.w #0x2700,%sr /* Mask off Interrupt */
TsiChung Liewf6afe722007-06-18 13:50:13 -0500119
Wolfgang Wegnerea32ab22010-03-02 10:59:20 +0100120#if !defined(CONFIG_MONITOR_IS_IN_RAM)
TsiChungLiew8592cda2007-07-05 23:06:55 -0500121 /* Set vector base register at the beginning of the Flash */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200122 move.l #CONFIG_SYS_FLASH_BASE, %d0
TsiChung Liewf6afe722007-06-18 13:50:13 -0500123 movec %d0, %VBR
Wolfgang Wegnerea32ab22010-03-02 10:59:20 +0100124#endif
TsiChung Liewf6afe722007-06-18 13:50:13 -0500125
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200126 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
TsiChungLiew942383d2007-10-25 17:12:36 -0500127 movec %d0, %RAMBAR1
TsiChung Liewf6afe722007-06-18 13:50:13 -0500128
129 /* invalidate and disable cache */
TsiChung Liew0ee47d42010-03-11 22:12:53 -0600130 move.l #CF_CACR_CINVA, %d0 /* Invalidate cache cmd */
TsiChung Liewf6afe722007-06-18 13:50:13 -0500131 movec %d0, %CACR /* Invalidate cache */
132 move.l #0, %d0
133 movec %d0, %ACR0
134 movec %d0, %ACR1
135
TsiChung Liewe7e4fc82008-10-22 11:38:21 +0000136#ifdef CONFIG_MCF5301x
137 move.l #(0xFC0a0010), %a0
138 move.w (%a0), %d0
139 and.l %d0, 0xEFFF
140
141 move.w %d0, (%a0)
142#endif
143
TsiChung Liewf6afe722007-06-18 13:50:13 -0500144 /* initialize general use internal ram */
145 move.l #0, %d0
TsiChung Liew0ee47d42010-03-11 22:12:53 -0600146 move.l #(ICACHE_STATUS), %a1 /* icache */
147 move.l #(DCACHE_STATUS), %a2 /* icache */
TsiChung Liewf6afe722007-06-18 13:50:13 -0500148 move.l %d0, (%a1)
149 move.l %d0, (%a2)
150
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200151 /* put relocation table address to a5 */
152 move.l #__got_start, %a5
TsiChung Liewf6afe722007-06-18 13:50:13 -0500153
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200154 /* setup stack initially on top of internal static ram */
155 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
156
157 /*
158 * if configured, malloc_f arena will be reserved first,
159 * then (and always) gd struct space will be reserved
160 */
161 move.l %sp, -(%sp)
162 move.l #board_init_f_alloc_reserve, %a1
163 jsr (%a1)
164
165 /* update stack and frame-pointers */
166 move.l %d0, %sp
167 move.l %sp, %fp
168
169 /* initialize reserved area */
170 move.l %d0, -(%sp)
171 move.l #board_init_f_init_reserve, %a1
172 jsr (%a1)
TsiChung Liewf6afe722007-06-18 13:50:13 -0500173
angelo@sysam.itb8cd1322016-04-12 00:30:59 +0200174 /* run low-level CPU init code (from flash) */
175 move.l #cpu_init_f, %a1
176 jsr (%a1)
177 /* run low-level board init code (from flash) */
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200178 clr.l %sp@-
angelo@sysam.itb8cd1322016-04-12 00:30:59 +0200179 move.l #board_init_f, %a1
180 jsr (%a1)
TsiChung Liewf6afe722007-06-18 13:50:13 -0500181
182 /* board_init_f() does not return */
183
184/*------------------------------------------------------------------------------*/
185
186/*
187 * void relocate_code (addr_sp, gd, addr_moni)
188 *
189 * This "function" does not return, instead it continues in RAM
190 * after relocating the monitor code.
191 *
192 * r3 = dest
193 * r4 = src
194 * r5 = length in bytes
195 * r6 = cachelinesize
196 */
197 .globl relocate_code
198relocate_code:
199 link.w %a6,#0
200 move.l 8(%a6), %sp /* set new stack pointer */
201
202 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
203 move.l 16(%a6), %a0 /* Save copy of Destination Address */
204
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200205 move.l #CONFIG_SYS_MONITOR_BASE, %a1
TsiChung Liewf6afe722007-06-18 13:50:13 -0500206 move.l #__init_end, %a2
207 move.l %a0, %a3
208
209 /* copy the code to RAM */
2101:
211 move.l (%a1)+, (%a3)+
212 cmp.l %a1,%a2
213 bgt.s 1b
214
215/*
216 * We are done. Do not return, instead branch to second part of board
217 * initialization, now running from RAM.
218 */
219 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200220 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
TsiChung Liewf6afe722007-06-18 13:50:13 -0500221 jmp (%a1)
222
223in_ram:
224
225clear_bss:
226 /*
227 * Now clear BSS segment
228 */
229 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200230 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
TsiChung Liewf6afe722007-06-18 13:50:13 -0500231 move.l %a0, %d1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200232 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
TsiChung Liewf6afe722007-06-18 13:50:13 -05002336:
234 clr.l (%a1)+
235 cmp.l %a1,%d1
236 bgt.s 6b
237
238 /*
239 * fix got table in RAM
240 */
241 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200242 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
TsiChung Liewf6afe722007-06-18 13:50:13 -0500243 move.l %a1,%a5 /* * fix got pointer register a5 */
244
245 move.l %a0, %a2
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200246 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
TsiChung Liewf6afe722007-06-18 13:50:13 -0500247
2487:
249 move.l (%a1),%d1
250 sub.l #_start,%d1
251 add.l %a0,%d1
252 move.l %d1,(%a1)+
253 cmp.l %a2, %a1
254 bne 7b
255
256 /* calculate relative jump to board_init_r in ram */
257 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200258 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
TsiChung Liewf6afe722007-06-18 13:50:13 -0500259
260 /* set parameters for board_init_r */
261 move.l %a0,-(%sp) /* dest_addr */
262 move.l %d0,-(%sp) /* gd */
263 jsr (%a1)
264
265/*------------------------------------------------------------------------------*/
266/* exception code */
267 .globl _fault
268_fault:
Marek Vasut876813b2012-10-03 13:28:43 +0000269 bra _fault
TsiChung Liewf6afe722007-06-18 13:50:13 -0500270 .globl _exc_handler
271
272_exc_handler:
273 SAVE_ALL
274 movel %sp,%sp@-
275 bsr exc_handler
276 addql #4,%sp
277 RESTORE_ALL
278
279 .globl _int_handler
280_int_handler:
281 SAVE_ALL
282 movel %sp,%sp@-
283 bsr int_handler
284 addql #4,%sp
285 RESTORE_ALL
286
287/*------------------------------------------------------------------------------*/
TsiChung Liewf6afe722007-06-18 13:50:13 -0500288 .globl version_string
289version_string:
Andreas Bießmann61d01952011-07-18 20:24:04 +0200290 .ascii U_BOOT_VERSION_STRING, "\0"
TsiChung Liew9d636e92008-03-28 08:47:45 -0500291 .align 4