blob: 536daa441e2bcdd24a65f0d8dcc14683000e7318 [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
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +010013#define _START _start
14#define _FAULT _fault
15
16
17.macro SAVE_ALL
18 move.w #0x2700,%sr; /* disable intrs */
19 subl #60,%sp; /* space for 15 regs */
20 moveml %d0-%d7/%a0-%a6,%sp@
21.endm
22
23.macro RESTORE_ALL
24 moveml %sp@,%d0-%d7/%a0-%a6;
25 addl #60,%sp; /* space for 15 regs */
26 rte
27.endm
28
29/* If we come from a pre-loader we don't need an initial exception
30 * table.
31 */
32#if !defined(CONFIG_MONITOR_IS_IN_RAM)
33
34.text
Angelo Dureghello65d59912016-05-22 00:14:29 +020035
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +010036/*
Angelo Dureghello65d59912016-05-22 00:14:29 +020037 * Vector table. This is used for initial platform startup.
38 * These vectors are to catch any un-intended traps.
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +010039 */
40_vectors:
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +010041/* Flash offset is 0 until we setup CS0 */
42.long 0x00000000
43#if defined(CONFIG_M5307) && \
44 (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
45.long _start - CONFIG_SYS_TEXT_BASE
46#else
47.long _START
48#endif
49
50.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
51.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
52.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
53.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
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
58
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, _FAULT, _FAULT
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
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, _FAULT, _FAULT
74.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
75.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
76
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.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
84.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
85
86#endif
87
Angelo Dureghello65d59912016-05-22 00:14:29 +020088.text
89
90.globl _start
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +010091_start:
92 nop
93 nop
Angelo Dureghello65d59912016-05-22 00:14:29 +020094 move.w #0x2700,%sr
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +010095
96 /* set MBAR address + valid flag */
97 move.l #(CONFIG_SYS_MBAR + 1), %d0
98 move.c %d0, %MBAR
99
100 move.l #(CONFIG_SYS_INIT_RAM_ADDR + 1), %d0
101 move.c %d0, %RAMBAR
102
103 /* DS 4.8.2 (Cache Organization) invalidate and disable cache */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200104 move.l #CF_CACR_CINVA, %d0
105 movec %d0, %CACR
106 move.l #0, %d0
107 movec %d0, %ACR0
108 movec %d0, %ACR1
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100109
110 /*
111 * if we come from a pre-loader we have no exception table and
112 * therefore no VBR to set
113 */
114#if !defined(CONFIG_MONITOR_IS_IN_RAM)
115 move.l #CONFIG_SYS_FLASH_BASE, %d0
116 movec %d0, %VBR
117#endif
118
119 /* initialize general use internal ram */
120 move.l #0, %d0
121 move.l #(ICACHE_STATUS), %a1 /* icache */
122 move.l #(DCACHE_STATUS), %a2 /* dcache */
123 move.l %d0, (%a1)
124 move.l %d0, (%a2)
125
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200126 /* put relocation table address to a5 */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200127 move.l #__got_start, %a5
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200128
129 /* setup stack initially on top of internal static ram */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200130 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200131
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100132 /*
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200133 * if configured, malloc_f arena will be reserved first,
134 * then (and always) gd struct space will be reserved
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100135 */
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200136 move.l %sp, -(%sp)
137 bsr board_init_f_alloc_reserve
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100138
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200139 /* update stack and frame-pointers */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200140 move.l %d0, %sp
141 move.l %sp, %fp
angelo@sysam.itef9707c2016-04-27 21:50:44 +0200142
143 /* initialize reserved area */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200144 move.l %d0, -(%sp)
145 bsr board_init_f_init_reserve
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100146
147 /* run low-level CPU init code (from flash) */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200148 bsr cpu_init_f
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100149
150 /* run low-level board init code (from flash) */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200151 clr.l %sp@-
152 bsr board_init_f
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100153
154 /* board_init_f() does not return */
155
Angelo Dureghello65d59912016-05-22 00:14:29 +0200156/******************************************************************************/
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100157
158/*
159 * void relocate_code (addr_sp, gd, addr_moni)
160 *
161 * This "function" does not return, instead it continues in RAM
162 * after relocating the monitor code.
163 *
164 */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200165.globl relocate_code
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100166relocate_code:
167 link.w %a6,#0
168 move.l 8(%a6), %sp /* set new stack pointer */
169 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
170 move.l 16(%a6), %a0 /* Save copy of Destination Address */
171
172 move.l #CONFIG_SYS_MONITOR_BASE, %a1
173 move.l #__init_end, %a2
174 move.l %a0, %a3
175 /* copy the code to RAM */
1761:
177 move.l (%a1)+, (%a3)+
178 cmp.l %a1,%a2
179 bgt.s 1b
180
181/*
182 * We are done. Do not return, instead branch to second part of board
183 * initialization, now running from RAM.
184 */
185 move.l %a0, %a1
186 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
187 jmp (%a1)
188
189in_ram:
190
191clear_bss:
192 /*
193 * Now clear BSS segment
194 */
195 move.l %a0, %a1
196 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE), %a1
197 move.l %a0, %d1
198 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE), %d1
1996:
200 clr.l (%a1)+
201 cmp.l %a1,%d1
202 bgt.s 6b
203
204 /*
205 * fix got table in RAM
206 */
207 move.l %a0, %a1
208 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE), %a1
Angelo Dureghello65d59912016-05-22 00:14:29 +0200209
210 /* fix got pointer register a5 */
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100211 move.l %a1,%a5
212
213 move.l %a0, %a2
214 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE), %a2
215
2167:
217 move.l (%a1),%d1
218 sub.l #_start, %d1
219 add.l %a0,%d1
220 move.l %d1,(%a1)+
221 cmp.l %a2, %a1
222 bne 7b
223
224 /* calculate relative jump to board_init_r in ram */
225 move.l %a0, %a1
226 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
227
228 /* set parameters for board_init_r */
229 move.l %a0,-(%sp) /* dest_addr */
230 move.l %d0,-(%sp) /* gd */
231#if defined(DEBUG) && (CONFIG_SYS_TEXT_BASE!=CONFIG_SYS_INT_FLASH_BASE) && \
232 defined(CONFIG_SYS_HALT_BEFOR_RAM_JUMP)
233 halt
234#endif
235 jsr (%a1)
236
Angelo Dureghello65d59912016-05-22 00:14:29 +0200237/******************************************************************************/
238
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100239/* exception code */
Angelo Dureghello65d59912016-05-22 00:14:29 +0200240.globl _fault
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100241_fault:
242 bra _fault
243
Angelo Dureghello65d59912016-05-22 00:14:29 +0200244.globl _exc_handler
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100245_exc_handler:
246 SAVE_ALL
247 movel %sp,%sp@-
Angelo Dureghello65d59912016-05-22 00:14:29 +0200248 bsr exc_handler
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100249 addql #4,%sp
250 RESTORE_ALL
251
Angelo Dureghello65d59912016-05-22 00:14:29 +0200252.globl _int_handler
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100253_int_handler:
254 SAVE_ALL
255 movel %sp,%sp@-
Angelo Dureghello65d59912016-05-22 00:14:29 +0200256 bsr int_handler
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100257 addql #4,%sp
258 RESTORE_ALL
259
Angelo Dureghello65d59912016-05-22 00:14:29 +0200260/******************************************************************************/
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100261
Angelo Dureghello65d59912016-05-22 00:14:29 +0200262.globl version_string
angelo@sysam.itbb4ba2c2015-02-12 01:40:00 +0100263version_string:
Angelo Dureghello65d59912016-05-22 00:14:29 +0200264.ascii U_BOOT_VERSION
265.ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
266.ascii CONFIG_IDENT_STRING, "\0"
267.align 4