xref: /openbmc/u-boot/arch/m68k/cpu/mcf547x_8x/start.S (revision 45d85f08)
1/*
2 * Copyright (C) 2003	Josef Baumgartner <josef.baumgartner@telex.de>
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#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
31
32/*
33 * Vector table. This is used for initial platform startup.
34 * These vectors are to catch any un-intended traps.
35 */
36_vectors:
37INITSP:	.long	0x00000000		/* Initial SP	*/
38INITPC:	.long	_START			/* Initial PC	*/
39
40vector02_0F:
41.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
42.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
43
44/* Reserved */
45vector10_17:
46.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
47
48vector18_1F:
49.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
50
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
91.text
92
93.globl _start
94_start:
95	nop
96	nop
97	move.w	#0x2700,%sr		/* Mask off Interrupt */
98
99	/* Set vector base register at the beginning of the Flash */
100	move.l	#CONFIG_SYS_FLASH_BASE, %d0
101	movec	%d0, %VBR
102
103	move.l	#(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
104	movec	%d0, %RAMBAR0
105
106	move.l	#(CONFIG_SYS_INIT_RAM1_ADDR + CONFIG_SYS_INIT_RAM1_CTRL), %d0
107	movec	%d0, %RAMBAR1
108
109	move.l	#CONFIG_SYS_MBAR, %d0	/* set MBAR address */
110	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 */
122	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)
127
128	/* put relocation table address to a5 */
129	move.l	#__got_start, %a5
130
131	/* setup stack initially on top of internal static ram  */
132	move.l	#(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
133
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 */
146	move.l	%d0, -(%sp)
147	bsr	board_init_f_init_reserve
148
149	/* 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
155
156	/* board_init_f() does not return */
157
158/******************************************************************************/
159
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 */
171.globl relocate_code
172relocate_code:
173	link.w	%a6,#0
174	move.l	8(%a6), %sp		/* set new stack pointer */
175
176	move.l	12(%a6), %d0		/* Save copy of Global Data pointer */
177	move.l	16(%a6), %a0		/* Save copy of Destination Address */
178
179	move.l	#CONFIG_SYS_MONITOR_BASE, %a1
180	move.l	#__init_end, %a2
181	move.l	%a0, %a3
182
183	/* copy the code to RAM */
1841:
185	move.l	(%a1)+, (%a3)+
186	cmp.l	%a1,%a2
187	bgt.s	1b
188
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
194	add.l	#(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
195	jmp	(%a1)
196
197in_ram:
198
199clear_bss:
200	/*
201	 * Now clear BSS segment
202	 */
203	move.l	%a0, %a1
204	add.l	#(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
205	move.l	%a0, %d1
206	add.l	#(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
2076:
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
216	add.l	#(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
217	move.l	%a1,%a5			/* fix got pointer register a5 */
218
219	move.l	%a0, %a2
220	add.l	#(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
221
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 */
231	move.l	%a0, %a1
232	add.l	#(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
233
234	/* set parameters for board_init_r */
235	move.l	%a0,-(%sp)		/* dest_addr */
236	move.l	%d0,-(%sp)		/* gd */
237	jsr	(%a1)
238
239/******************************************************************************/
240
241/* exception code */
242.globl _fault
243_fault:
244	bra	_fault
245
246.globl _exc_handler
247_exc_handler:
248	SAVE_ALL
249	movel	%sp,%sp@-
250	bsr	exc_handler
251	addql	#4,%sp
252	RESTORE_ALL
253
254.globl _int_handler
255_int_handler:
256	SAVE_ALL
257	movel	%sp,%sp@-
258	bsr	int_handler
259	addql	#4,%sp
260	RESTORE_ALL
261
262/******************************************************************************/
263
264.globl version_string
265version_string:
266.ascii U_BOOT_VERSION_STRING, "\0"
267.align 4
268