blob: ca8bb320630187713e6d991673ff5a387f795ab1 [file] [log] [blame]
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +01001/*
2 * (C) Copyright 2015 Angelo Dureghello <angelo@sysam.it>
3 * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <asm-offsets.h>
9#include <config.h>
10#include "version.h"
11#include <asm/cache.h>
12
13#ifndef CONFIG_IDENT_STRING
14#define CONFIG_IDENT_STRING ""
15#endif
16
17#define _START _start
18#define _FAULT _fault
19
20
21.macro SAVE_ALL
22 move.w #0x2700,%sr; /* disable intrs */
23 subl #60,%sp; /* space for 15 regs */
24 moveml %d0-%d7/%a0-%a6,%sp@
25.endm
26
27.macro RESTORE_ALL
28 moveml %sp@,%d0-%d7/%a0-%a6;
29 addl #60,%sp; /* space for 15 regs */
30 rte
31.endm
32
33/* If we come from a pre-loader we don't need an initial exception
34 * table.
35 */
36#if !defined(CONFIG_MONITOR_IS_IN_RAM)
37
38.text
39/*
40 * Vector table. This is used for initial platform startup.
41 * These vectors are to catch any un-intended traps.
42 */
43_vectors:
44
45/* Flash offset is 0 until we setup CS0 */
46.long 0x00000000
47#if defined(CONFIG_M5307) && \
48 (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
49.long _start - CONFIG_SYS_TEXT_BASE
50#else
51.long _START
52#endif
53
54.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
55.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
56.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
57.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
58.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
59.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
60.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
61.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
62
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.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
71
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
81.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
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
90#endif
91
92 .text
93 .globl _start
94_start:
95 nop
96 nop
97 move.w #0x2700,%sr
98
99 /* set MBAR address + valid flag */
100 move.l #(CONFIG_SYS_MBAR + 1), %d0
101 move.c %d0, %MBAR
102
103 move.l #(CONFIG_SYS_INIT_RAM_ADDR + 1), %d0
104 move.c %d0, %RAMBAR
105
106 /* DS 4.8.2 (Cache Organization) invalidate and disable cache */
107 move.l #CF_CACR_CINVA, %d0
108 movec %d0, %CACR
109 move.l #0, %d0
110 movec %d0, %ACR0
111 movec %d0, %ACR1
112
113 /*
114 * if we come from a pre-loader we have no exception table and
115 * therefore no VBR to set
116 */
117#if !defined(CONFIG_MONITOR_IS_IN_RAM)
118 move.l #CONFIG_SYS_FLASH_BASE, %d0
119 movec %d0, %VBR
120#endif
121
122 /* initialize general use internal ram */
123 move.l #0, %d0
124 move.l #(ICACHE_STATUS), %a1 /* icache */
125 move.l #(DCACHE_STATUS), %a2 /* dcache */
126 move.l %d0, (%a1)
127 move.l %d0, (%a2)
128
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200129 /* put relocation table address to a5 */
130 move.l #__got_start, %a5
131
132 /* setup stack initially on top of internal static ram */
133 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
134
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100135 /*
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200136 * if configured, malloc_f arena will be reserved first,
137 * then (and always) gd struct space will be reserved
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100138 */
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200139 move.l %sp, -(%sp)
140 bsr board_init_f_alloc_reserve
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100141
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200142 /* update stack and frame-pointers */
143 move.l %d0, %sp
144 move.l %sp, %fp
145
146 /* initialize reserved area */
147 move.l %d0, -(%sp)
148 bsr board_init_f_init_reserve
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100149
150 /* run low-level CPU init code (from flash) */
151 bsr cpu_init_f
152
153 /* run low-level board init code (from flash) */
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200154 clr.l %sp@-
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100155 bsr board_init_f
156
157 /* board_init_f() does not return */
158
159/*--------------------------------------------------------------------------*/
160
161/*
162 * void relocate_code (addr_sp, gd, addr_moni)
163 *
164 * This "function" does not return, instead it continues in RAM
165 * after relocating the monitor code.
166 *
167 */
168 .globl relocate_code
169relocate_code:
170 link.w %a6,#0
171 move.l 8(%a6), %sp /* set new stack pointer */
172 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
173 move.l 16(%a6), %a0 /* Save copy of Destination Address */
174
175 move.l #CONFIG_SYS_MONITOR_BASE, %a1
176 move.l #__init_end, %a2
177 move.l %a0, %a3
178 /* copy the code to RAM */
1791:
180 move.l (%a1)+, (%a3)+
181 cmp.l %a1,%a2
182 bgt.s 1b
183
184/*
185 * We are done. Do not return, instead branch to second part of board
186 * initialization, now running from RAM.
187 */
188 move.l %a0, %a1
189 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
190 jmp (%a1)
191
192in_ram:
193
194clear_bss:
195 /*
196 * Now clear BSS segment
197 */
198 move.l %a0, %a1
199 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE), %a1
200 move.l %a0, %d1
201 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE), %d1
2026:
203 clr.l (%a1)+
204 cmp.l %a1,%d1
205 bgt.s 6b
206
207 /*
208 * fix got table in RAM
209 */
210 move.l %a0, %a1
211 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE), %a1
212 /* * fix got pointer register a5 */
213 move.l %a1,%a5
214
215 move.l %a0, %a2
216 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE), %a2
217
2187:
219 move.l (%a1),%d1
220 sub.l #_start, %d1
221 add.l %a0,%d1
222 move.l %d1,(%a1)+
223 cmp.l %a2, %a1
224 bne 7b
225
226 /* calculate relative jump to board_init_r in ram */
227 move.l %a0, %a1
228 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
229
230 /* set parameters for board_init_r */
231 move.l %a0,-(%sp) /* dest_addr */
232 move.l %d0,-(%sp) /* gd */
233#if defined(DEBUG) && (CONFIG_SYS_TEXT_BASE!=CONFIG_SYS_INT_FLASH_BASE) && \
234 defined(CONFIG_SYS_HALT_BEFOR_RAM_JUMP)
235 halt
236#endif
237 jsr (%a1)
238
239/*--------------------------------------------------------------------------*/
240/* exception code */
241 .globl _fault
242_fault:
243 bra _fault
244
245 .globl _exc_handler
246_exc_handler:
247 SAVE_ALL
248 movel %sp,%sp@-
249 bsr exc_handler
250 addql #4,%sp
251 RESTORE_ALL
252
253 .globl _int_handler
254_int_handler:
255 SAVE_ALL
256 movel %sp,%sp@-
257 bsr int_handler
258 addql #4,%sp
259 RESTORE_ALL
260
261/*--------------------------------------------------------------------------*/
262
263 .globl version_string
264version_string:
265 .ascii U_BOOT_VERSION
266 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
267 .ascii CONFIG_IDENT_STRING, "\0"
268 .align 4