blob: da41c9af34bd75acc8b35c7691a30a11455b0e94 [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
Angelo Dureghello65d59912016-05-22 00:14:29 +020039
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +010040/*
Angelo Dureghello65d59912016-05-22 00:14:29 +020041 * Vector table. This is used for initial platform startup.
42 * These vectors are to catch any un-intended traps.
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +010043 */
44_vectors:
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +010045/* 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
Angelo Dureghello65d59912016-05-22 00:14:29 +020092.text
93
94.globl _start
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +010095_start:
96 nop
97 nop
Angelo Dureghello65d59912016-05-22 00:14:29 +020098 move.w #0x2700,%sr
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +010099
100 /* set MBAR address + valid flag */
101 move.l #(CONFIG_SYS_MBAR + 1), %d0
102 move.c %d0, %MBAR
103
104 move.l #(CONFIG_SYS_INIT_RAM_ADDR + 1), %d0
105 move.c %d0, %RAMBAR
106
107 /* DS 4.8.2 (Cache Organization) invalidate and disable cache */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200108 move.l #CF_CACR_CINVA, %d0
109 movec %d0, %CACR
110 move.l #0, %d0
111 movec %d0, %ACR0
112 movec %d0, %ACR1
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100113
114 /*
115 * if we come from a pre-loader we have no exception table and
116 * therefore no VBR to set
117 */
118#if !defined(CONFIG_MONITOR_IS_IN_RAM)
119 move.l #CONFIG_SYS_FLASH_BASE, %d0
120 movec %d0, %VBR
121#endif
122
123 /* initialize general use internal ram */
124 move.l #0, %d0
125 move.l #(ICACHE_STATUS), %a1 /* icache */
126 move.l #(DCACHE_STATUS), %a2 /* dcache */
127 move.l %d0, (%a1)
128 move.l %d0, (%a2)
129
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200130 /* put relocation table address to a5 */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200131 move.l #__got_start, %a5
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200132
133 /* setup stack initially on top of internal static ram */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200134 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200135
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100136 /*
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200137 * if configured, malloc_f arena will be reserved first,
138 * then (and always) gd struct space will be reserved
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100139 */
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200140 move.l %sp, -(%sp)
141 bsr board_init_f_alloc_reserve
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100142
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200143 /* update stack and frame-pointers */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200144 move.l %d0, %sp
145 move.l %sp, %fp
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200146
147 /* initialize reserved area */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200148 move.l %d0, -(%sp)
149 bsr board_init_f_init_reserve
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100150
151 /* run low-level CPU init code (from flash) */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200152 bsr cpu_init_f
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100153
154 /* run low-level board init code (from flash) */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200155 clr.l %sp@-
156 bsr board_init_f
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100157
158 /* board_init_f() does not return */
159
Angelo Dureghello65d59912016-05-22 00:14:29 +0200160/******************************************************************************/
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100161
162/*
163 * void relocate_code (addr_sp, gd, addr_moni)
164 *
165 * This "function" does not return, instead it continues in RAM
166 * after relocating the monitor code.
167 *
168 */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200169.globl relocate_code
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100170relocate_code:
171 link.w %a6,#0
172 move.l 8(%a6), %sp /* set new stack pointer */
173 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
174 move.l 16(%a6), %a0 /* Save copy of Destination Address */
175
176 move.l #CONFIG_SYS_MONITOR_BASE, %a1
177 move.l #__init_end, %a2
178 move.l %a0, %a3
179 /* copy the code to RAM */
1801:
181 move.l (%a1)+, (%a3)+
182 cmp.l %a1,%a2
183 bgt.s 1b
184
185/*
186 * We are done. Do not return, instead branch to second part of board
187 * initialization, now running from RAM.
188 */
189 move.l %a0, %a1
190 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
191 jmp (%a1)
192
193in_ram:
194
195clear_bss:
196 /*
197 * Now clear BSS segment
198 */
199 move.l %a0, %a1
200 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE), %a1
201 move.l %a0, %d1
202 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE), %d1
2036:
204 clr.l (%a1)+
205 cmp.l %a1,%d1
206 bgt.s 6b
207
208 /*
209 * fix got table in RAM
210 */
211 move.l %a0, %a1
212 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE), %a1
Angelo Dureghello65d59912016-05-22 00:14:29 +0200213
214 /* fix got pointer register a5 */
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100215 move.l %a1,%a5
216
217 move.l %a0, %a2
218 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE), %a2
219
2207:
221 move.l (%a1),%d1
222 sub.l #_start, %d1
223 add.l %a0,%d1
224 move.l %d1,(%a1)+
225 cmp.l %a2, %a1
226 bne 7b
227
228 /* calculate relative jump to board_init_r in ram */
229 move.l %a0, %a1
230 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
231
232 /* set parameters for board_init_r */
233 move.l %a0,-(%sp) /* dest_addr */
234 move.l %d0,-(%sp) /* gd */
235#if defined(DEBUG) && (CONFIG_SYS_TEXT_BASE!=CONFIG_SYS_INT_FLASH_BASE) && \
236 defined(CONFIG_SYS_HALT_BEFOR_RAM_JUMP)
237 halt
238#endif
239 jsr (%a1)
240
Angelo Dureghello65d59912016-05-22 00:14:29 +0200241/******************************************************************************/
242
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100243/* exception code */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200244.globl _fault
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100245_fault:
246 bra _fault
247
Angelo Dureghello65d59912016-05-22 00:14:29 +0200248.globl _exc_handler
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100249_exc_handler:
250 SAVE_ALL
251 movel %sp,%sp@-
Angelo Dureghello65d59912016-05-22 00:14:29 +0200252 bsr exc_handler
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100253 addql #4,%sp
254 RESTORE_ALL
255
Angelo Dureghello65d59912016-05-22 00:14:29 +0200256.globl _int_handler
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100257_int_handler:
258 SAVE_ALL
259 movel %sp,%sp@-
Angelo Dureghello65d59912016-05-22 00:14:29 +0200260 bsr int_handler
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100261 addql #4,%sp
262 RESTORE_ALL
263
Angelo Dureghello65d59912016-05-22 00:14:29 +0200264/******************************************************************************/
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100265
Angelo Dureghello65d59912016-05-22 00:14:29 +0200266.globl version_string
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100267version_string:
Angelo Dureghello65d59912016-05-22 00:14:29 +0200268.ascii U_BOOT_VERSION
269.ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
270.ascii CONFIG_IDENT_STRING, "\0"
271.align 4