xref: /openbmc/u-boot/arch/m68k/cpu/mcf547x_8x/start.S (revision 78a88f79)
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright (C) 2003	Josef Baumgartner <josef.baumgartner@telex.de>
4 * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
5 */
6
7#include <asm-offsets.h>
8#include <config.h>
9#include "version.h"
10#include <asm/cache.h>
11
12#define _START	_start
13#define _FAULT	_fault
14
15#define SAVE_ALL						\
16	move.w	#0x2700,%sr;		/* disable intrs */	\
17	subl	#60,%sp;		/* space for 15 regs */ \
18	moveml	%d0-%d7/%a0-%a6,%sp@;
19
20#define RESTORE_ALL						\
21	moveml	%sp@,%d0-%d7/%a0-%a6;				\
22	addl	#60,%sp;		/* space for 15 regs */ \
23	rte;
24
25.text
26
27/*
28 * Vector table. This is used for initial platform startup.
29 * These vectors are to catch any un-intended traps.
30 */
31_vectors:
32INITSP:	.long	0x00000000		/* Initial SP	*/
33INITPC:	.long	_START			/* Initial PC	*/
34
35vector02_0F:
36.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
37.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
38
39/* Reserved */
40vector10_17:
41.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
42
43vector18_1F:
44.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
45
46/* TRAP #0 - #15 */
47vector20_2F:
48.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
49.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
50
51/* Reserved	*/
52vector30_3F:
53.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
54.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
55
56vector64_127:
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, _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
66vector128_191:
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.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
76vector192_255:
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.text
87
88.globl _start
89_start:
90	nop
91	nop
92	move.w	#0x2700,%sr		/* Mask off Interrupt */
93
94	/* Set vector base register at the beginning of the Flash */
95	move.l	#CONFIG_SYS_FLASH_BASE, %d0
96	movec	%d0, %VBR
97
98	move.l	#(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
99	movec	%d0, %RAMBAR0
100
101	move.l	#(CONFIG_SYS_INIT_RAM1_ADDR + CONFIG_SYS_INIT_RAM1_CTRL), %d0
102	movec	%d0, %RAMBAR1
103
104	move.l	#CONFIG_SYS_MBAR, %d0	/* set MBAR address */
105	move.c	%d0, %MBAR
106
107	/* invalidate and disable cache */
108	move.l	#0x01040100, %d0	/* Invalidate cache cmd */
109	movec	%d0, %CACR		/* Invalidate cache */
110	move.l	#0, %d0
111	movec	%d0, %ACR0
112	movec	%d0, %ACR1
113	movec	%d0, %ACR2
114	movec	%d0, %ACR3
115
116	/* initialize general use internal ram */
117	move.l	#0, %d0
118	move.l	#(ICACHE_STATUS), %a1	/* icache */
119	move.l	#(DCACHE_STATUS), %a2	/* icache */
120	move.l	%d0, (%a1)
121	move.l	%d0, (%a2)
122
123	/* put relocation table address to a5 */
124	move.l	#__got_start, %a5
125
126	/* setup stack initially on top of internal static ram  */
127	move.l	#(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
128
129	/*
130	 * if configured, malloc_f arena will be reserved first,
131	 * then (and always) gd struct space will be reserved
132	 */
133	move.l	%sp, -(%sp)
134	bsr	board_init_f_alloc_reserve
135
136	/* update stack and frame-pointers */
137	move.l  %d0, %sp
138	move.l  %sp, %fp
139
140	/* initialize reserved area */
141	move.l	%d0, -(%sp)
142	bsr	board_init_f_init_reserve
143
144	/* run low-level CPU init code (from flash) */
145	jbsr	cpu_init_f
146
147	/* run low-level board init code (from flash) */
148	clr.l	%sp@-
149	jbsr	board_init_f
150
151	/* board_init_f() does not return */
152
153/******************************************************************************/
154
155/*
156 * void relocate_code (addr_sp, gd, addr_moni)
157 *
158 * This "function" does not return, instead it continues in RAM
159 * after relocating the monitor code.
160 *
161 * r3 = dest
162 * r4 = src
163 * r5 = length in bytes
164 * r6 = cachelinesize
165 */
166.globl relocate_code
167relocate_code:
168	link.w	%a6,#0
169	move.l	8(%a6), %sp		/* set new stack pointer */
170
171	move.l	12(%a6), %d0		/* Save copy of Global Data pointer */
172	move.l	16(%a6), %a0		/* Save copy of Destination Address */
173
174	move.l	#CONFIG_SYS_MONITOR_BASE, %a1
175	move.l	#__init_end, %a2
176	move.l	%a0, %a3
177
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	move.l	%a1,%a5			/* fix got pointer register a5 */
213
214	move.l	%a0, %a2
215	add.l	#(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
216
2177:
218	move.l	(%a1),%d1
219	sub.l	#_start,%d1
220	add.l	%a0,%d1
221	move.l	%d1,(%a1)+
222	cmp.l	%a2, %a1
223	bne	7b
224
225	/* calculate relative jump to board_init_r in ram */
226	move.l	%a0, %a1
227	add.l	#(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
228
229	/* set parameters for board_init_r */
230	move.l	%a0,-(%sp)		/* dest_addr */
231	move.l	%d0,-(%sp)		/* gd */
232	jsr	(%a1)
233
234/******************************************************************************/
235
236/* exception code */
237.globl _fault
238_fault:
239	bra	_fault
240
241.globl _exc_handler
242_exc_handler:
243	SAVE_ALL
244	movel	%sp,%sp@-
245	bsr	exc_handler
246	addql	#4,%sp
247	RESTORE_ALL
248
249.globl _int_handler
250_int_handler:
251	SAVE_ALL
252	movel	%sp,%sp@-
253	bsr	int_handler
254	addql	#4,%sp
255	RESTORE_ALL
256
257/******************************************************************************/
258
259.globl version_string
260version_string:
261.ascii U_BOOT_VERSION_STRING, "\0"
262.align 4
263