blob: fecf253d4bba4cf767c60038d915682ed28c1ed7 [file] [log] [blame]
TsiChungLiew8999e6b2008-01-15 13:37:34 -06001/*
2 * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de>
3 * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
4 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +02005 * SPDX-License-Identifier: GPL-2.0+
TsiChungLiew8999e6b2008-01-15 13:37:34 -06006 */
7
Wolfgang Denk0191e472010-10-26 14:34:52 +02008#include <asm-offsets.h>
TsiChungLiew8999e6b2008-01-15 13:37:34 -06009#include <config.h>
10#include "version.h"
TsiChung Liew0ee47d42010-03-11 22:12:53 -060011#include <asm/cache.h>
TsiChungLiew8999e6b2008-01-15 13:37:34 -060012
13#ifndef CONFIG_IDENT_STRING
14#define CONFIG_IDENT_STRING ""
15#endif
16
TsiChungLiew8999e6b2008-01-15 13:37:34 -060017#define _START _start
18#define _FAULT _fault
19
20#define SAVE_ALL \
21 move.w #0x2700,%sr; /* disable intrs */ \
22 subl #60,%sp; /* space for 15 regs */ \
23 moveml %d0-%d7/%a0-%a6,%sp@;
24
25#define RESTORE_ALL \
26 moveml %sp@,%d0-%d7/%a0-%a6; \
27 addl #60,%sp; /* space for 15 regs */ \
28 rte;
29
30.text
Angelo Dureghello65d59912016-05-22 00:14:29 +020031
TsiChungLiew8999e6b2008-01-15 13:37:34 -060032/*
Angelo Dureghello65d59912016-05-22 00:14:29 +020033 * Vector table. This is used for initial platform startup.
34 * These vectors are to catch any un-intended traps.
TsiChungLiew8999e6b2008-01-15 13:37:34 -060035 */
36_vectors:
Angelo Dureghello65d59912016-05-22 00:14:29 +020037INITSP: .long 0x00000000 /* Initial SP */
38INITPC: .long _START /* Initial PC */
TsiChungLiew8999e6b2008-01-15 13:37:34 -060039
Angelo Dureghello65d59912016-05-22 00:14:29 +020040vector02_0F:
41.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
42.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
TsiChungLiew8999e6b2008-01-15 13:37:34 -060043
44/* Reserved */
45vector10_17:
46.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
47
Angelo Dureghello65d59912016-05-22 00:14:29 +020048vector18_1F:
49.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
TsiChungLiew8999e6b2008-01-15 13:37:34 -060050
51/* TRAP #0 - #15 */
52vector20_2F:
53.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
54.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
55
56/* Reserved */
57vector30_3F:
58.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
59.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
60
61vector64_127:
62.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
63.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
64.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
65.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
66.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
71vector128_191:
72.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
73.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
74.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
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
81vector192_255:
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
Angelo Dureghello65d59912016-05-22 00:14:29 +020091.text
TsiChungLiew8999e6b2008-01-15 13:37:34 -060092
Angelo Dureghello65d59912016-05-22 00:14:29 +020093.globl _start
TsiChungLiew8999e6b2008-01-15 13:37:34 -060094_start:
95 nop
96 nop
Angelo Dureghello65d59912016-05-22 00:14:29 +020097 move.w #0x2700,%sr /* Mask off Interrupt */
TsiChungLiew8999e6b2008-01-15 13:37:34 -060098
99 /* Set vector base register at the beginning of the Flash */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200100 move.l #CONFIG_SYS_FLASH_BASE, %d0
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600101 movec %d0, %VBR
102
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200103 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600104 movec %d0, %RAMBAR0
105
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200106 move.l #(CONFIG_SYS_INIT_RAM1_ADDR + CONFIG_SYS_INIT_RAM1_CTRL), %d0
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600107 movec %d0, %RAMBAR1
108
Angelo Dureghello65d59912016-05-22 00:14:29 +0200109 move.l #CONFIG_SYS_MBAR, %d0 /* set MBAR address */
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600110 move.c %d0, %MBAR
111
112 /* invalidate and disable cache */
113 move.l #0x01040100, %d0 /* Invalidate cache cmd */
114 movec %d0, %CACR /* Invalidate cache */
115 move.l #0, %d0
116 movec %d0, %ACR0
117 movec %d0, %ACR1
118 movec %d0, %ACR2
119 movec %d0, %ACR3
120
121 /* initialize general use internal ram */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200122 move.l #0, %d0
123 move.l #(ICACHE_STATUS), %a1 /* icache */
124 move.l #(DCACHE_STATUS), %a2 /* icache */
125 move.l %d0, (%a1)
126 move.l %d0, (%a2)
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600127
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200128 /* put relocation table address to a5 */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200129 move.l #__got_start, %a5
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600130
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200131 /* setup stack initially on top of internal static ram */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200132 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200133
134 /*
135 * if configured, malloc_f arena will be reserved first,
136 * then (and always) gd struct space will be reserved
137 */
138 move.l %sp, -(%sp)
139 bsr board_init_f_alloc_reserve
140
141 /* update stack and frame-pointers */
142 move.l %d0, %sp
143 move.l %sp, %fp
144
145 /* initialize reserved area */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200146 move.l %d0, -(%sp)
147 bsr board_init_f_init_reserve
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600148
Angelo Dureghello65d59912016-05-22 00:14:29 +0200149 /* run low-level CPU init code (from flash) */
150 jbsr cpu_init_f
151
152 /* run low-level board init code (from flash) */
153 clr.l %sp@-
154 jbsr board_init_f
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600155
156 /* board_init_f() does not return */
157
Angelo Dureghello65d59912016-05-22 00:14:29 +0200158/******************************************************************************/
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600159
160/*
161 * void relocate_code (addr_sp, gd, addr_moni)
162 *
163 * This "function" does not return, instead it continues in RAM
164 * after relocating the monitor code.
165 *
166 * r3 = dest
167 * r4 = src
168 * r5 = length in bytes
169 * r6 = cachelinesize
170 */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200171.globl relocate_code
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600172relocate_code:
Angelo Dureghello65d59912016-05-22 00:14:29 +0200173 link.w %a6,#0
174 move.l 8(%a6), %sp /* set new stack pointer */
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600175
Angelo Dureghello65d59912016-05-22 00:14:29 +0200176 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
177 move.l 16(%a6), %a0 /* Save copy of Destination Address */
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600178
Angelo Dureghello65d59912016-05-22 00:14:29 +0200179 move.l #CONFIG_SYS_MONITOR_BASE, %a1
180 move.l #__init_end, %a2
181 move.l %a0, %a3
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600182
183 /* copy the code to RAM */
1841:
Angelo Dureghello65d59912016-05-22 00:14:29 +0200185 move.l (%a1)+, (%a3)+
186 cmp.l %a1,%a2
187 bgt.s 1b
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600188
189/*
190 * We are done. Do not return, instead branch to second part of board
191 * initialization, now running from RAM.
192 */
193 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200194 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600195 jmp (%a1)
196
197in_ram:
198
199clear_bss:
200 /*
201 * Now clear BSS segment
202 */
203 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200204 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600205 move.l %a0, %d1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200206 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
TsiChungLiew8999e6b2008-01-15 13:37:34 -06002076:
208 clr.l (%a1)+
209 cmp.l %a1,%d1
210 bgt.s 6b
211
212 /*
213 * fix got table in RAM
214 */
215 move.l %a0, %a1
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200216 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
Angelo Dureghello65d59912016-05-22 00:14:29 +0200217 move.l %a1,%a5 /* fix got pointer register a5 */
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600218
219 move.l %a0, %a2
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200220 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600221
2227:
223 move.l (%a1),%d1
224 sub.l #_start,%d1
225 add.l %a0,%d1
226 move.l %d1,(%a1)+
227 cmp.l %a2, %a1
228 bne 7b
229
230 /* calculate relative jump to board_init_r in ram */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200231 move.l %a0, %a1
232 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600233
234 /* set parameters for board_init_r */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200235 move.l %a0,-(%sp) /* dest_addr */
236 move.l %d0,-(%sp) /* gd */
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600237 jsr (%a1)
238
Angelo Dureghello65d59912016-05-22 00:14:29 +0200239/******************************************************************************/
240
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600241/* exception code */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200242.globl _fault
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600243_fault:
Angelo Dureghello65d59912016-05-22 00:14:29 +0200244 bra _fault
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600245
Angelo Dureghello65d59912016-05-22 00:14:29 +0200246.globl _exc_handler
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600247_exc_handler:
248 SAVE_ALL
249 movel %sp,%sp@-
Angelo Dureghello65d59912016-05-22 00:14:29 +0200250 bsr exc_handler
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600251 addql #4,%sp
252 RESTORE_ALL
253
Angelo Dureghello65d59912016-05-22 00:14:29 +0200254.globl _int_handler
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600255_int_handler:
256 SAVE_ALL
257 movel %sp,%sp@-
Angelo Dureghello65d59912016-05-22 00:14:29 +0200258 bsr int_handler
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600259 addql #4,%sp
260 RESTORE_ALL
261
Angelo Dureghello65d59912016-05-22 00:14:29 +0200262/******************************************************************************/
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600263
Angelo Dureghello65d59912016-05-22 00:14:29 +0200264.globl version_string
TsiChungLiew8999e6b2008-01-15 13:37:34 -0600265version_string:
Angelo Dureghello65d59912016-05-22 00:14:29 +0200266.ascii U_BOOT_VERSION_STRING, "\0"
267.align 4