xref: /openbmc/u-boot/arch/m68k/cpu/mcf523x/start.S (revision ad3098f7)
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 *	Vector table. This is used for initial platform startup.
33 *	These vectors are to catch any un-intended traps.
34 */
35_vectors:
36
37INITSP:		.long	0x00000000	/* Initial SP	*/
38INITPC:		.long	_START	/* Initial PC		*/
39vector02:	.long	_FAULT	/* Access Error		*/
40vector03:	.long	_FAULT	/* Address Error	*/
41vector04:	.long	_FAULT	/* Illegal Instruction	*/
42vector05:	.long	_FAULT	/* Reserved		*/
43vector06:	.long	_FAULT	/* Reserved		*/
44vector07:	.long	_FAULT	/* Reserved		*/
45vector08:	.long	_FAULT	/* Privilege Violation	*/
46vector09:	.long	_FAULT	/* Trace		*/
47vector0A:	.long	_FAULT	/* Unimplemented A-Line	*/
48vector0B:	.long	_FAULT	/* Unimplemented F-Line	*/
49vector0C:	.long	_FAULT	/* Debug Interrupt	*/
50vector0D:	.long	_FAULT	/* Reserved		*/
51vector0E:	.long	_FAULT	/* Format Error		*/
52vector0F:	.long	_FAULT	/* Unitialized Int.	*/
53
54/* Reserved */
55vector10_17:
56.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
57
58vector18:	.long	_FAULT	/* Spurious Interrupt	*/
59vector19:	.long	_FAULT	/* Autovector Level 1	*/
60vector1A:	.long	_FAULT	/* Autovector Level 2	*/
61vector1B:	.long	_FAULT	/* Autovector Level 3	*/
62vector1C:	.long	_FAULT	/* Autovector Level 4	*/
63vector1D:	.long	_FAULT	/* Autovector Level 5	*/
64vector1E:	.long	_FAULT	/* Autovector Level 6	*/
65vector1F:	.long	_FAULT	/* Autovector Level 7	*/
66
67/* TRAP #0 - #15 */
68vector20_2F:
69.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
70.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
71
72/* Reserved	*/
73vector30_3F:
74.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
75.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
76
77vector64_127:
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.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
86
87vector128_191:
88.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
89.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
90.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
91.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
92.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
93.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
94.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
95.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
96
97vector192_255:
98.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
99.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
100.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
101.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
102.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
103.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
104.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
105.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
106
107	.text
108
109	.globl	_start
110_start:
111	nop
112	nop
113	move.w #0x2700,%sr	/* Mask off Interrupt */
114
115	/* Set vector base register at the beginning of the Flash */
116	move.l	#CONFIG_SYS_FLASH_BASE, %d0
117	movec	%d0, %VBR
118
119	move.l	#(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
120	movec	%d0, %RAMBAR1
121
122	/* invalidate and disable cache */
123	move.l	#CF_CACR_CINV, %d0		/* Invalidate cache cmd */
124	movec	%d0, %CACR			/* Invalidate cache */
125	nop
126	move.l	#0, %d0
127	movec	%d0, %ACR0
128	movec	%d0, %ACR1
129
130	/* initialize general use internal ram */
131	move.l #0, %d0
132	move.l #(ICACHE_STATUS), %a1	/* icache */
133	move.l #(DCACHE_STATUS), %a2	/* icache */
134	move.l %d0, (%a1)
135	move.l %d0, (%a2)
136
137	/* put relocation table address to a5 */
138	move.l #__got_start, %a5
139
140	/* setup stack initially on top of internal static ram  */
141	move.l  #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
142
143	/*
144	 * if configured, malloc_f arena will be reserved first,
145	 * then (and always) gd struct space will be reserved
146	 */
147	move.l	%sp, -(%sp)
148	move.l	#board_init_f_alloc_reserve, %a1
149	jsr	(%a1)
150
151	/* update stack and frame-pointers */
152	move.l  %d0, %sp
153	move.l  %sp, %fp
154
155	/* initialize reserved area */
156	move.l  %d0, -(%sp)
157	move.l	#board_init_f_init_reserve, %a1
158	jsr	(%a1)
159
160	/* run low-level CPU init code (from flash) */
161	move.l #cpu_init_f, %a1
162	jsr (%a1)
163	/* run low-level board init code (from flash) */
164	clr.l   %sp@-
165	move.l #board_init_f, %a1
166	jsr (%a1)
167
168	/* board_init_f() does not return */
169
170/*------------------------------------------------------------------------------*/
171
172/*
173 * void relocate_code (addr_sp, gd, addr_moni)
174 *
175 * This "function" does not return, instead it continues in RAM
176 * after relocating the monitor code.
177 *
178 * r3 = dest
179 * r4 = src
180 * r5 = length in bytes
181 * r6 = cachelinesize
182 */
183	.globl	relocate_code
184relocate_code:
185	link.w %a6,#0
186	move.l 8(%a6), %sp		/* set new stack pointer */
187
188	move.l 12(%a6), %d0		/* Save copy of Global Data pointer */
189	move.l 16(%a6), %a0		/* Save copy of Destination Address */
190
191	move.l #CONFIG_SYS_MONITOR_BASE, %a1
192	move.l #__init_end, %a2
193	move.l %a0, %a3
194
195	/* copy the code to RAM */
1961:
197	move.l (%a1)+, (%a3)+
198	cmp.l  %a1,%a2
199	bgt.s	 1b
200
201/*
202 * We are done. Do not return, instead branch to second part of board
203 * initialization, now running from RAM.
204 */
205	move.l	%a0, %a1
206	add.l	#(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
207	jmp	(%a1)
208
209in_ram:
210
211clear_bss:
212	/*
213	 * Now clear BSS segment
214	 */
215	move.l	%a0, %a1
216	add.l	#(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
217	move.l	%a0, %d1
218	add.l	#(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
2196:
220	clr.l	(%a1)+
221	cmp.l	%a1,%d1
222	bgt.s	6b
223
224	/*
225	 * fix got table in RAM
226	 */
227	move.l	%a0, %a1
228	add.l	#(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
229	move.l	%a1,%a5		/* * fix got pointer register a5 */
230
231	move.l	%a0, %a2
232	add.l	#(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
233
2347:
235	move.l	(%a1),%d1
236	sub.l	#_start,%d1
237	add.l	%a0,%d1
238	move.l	%d1,(%a1)+
239	cmp.l	%a2, %a1
240	bne	7b
241
242	/* calculate relative jump to board_init_r in ram */
243	move.l %a0, %a1
244	add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
245
246	/* set parameters for board_init_r */
247	move.l %a0,-(%sp)		/* dest_addr */
248	move.l %d0,-(%sp)		/* gd */
249	jsr	(%a1)
250
251/*------------------------------------------------------------------------------*/
252/* exception code */
253	.globl _fault
254_fault:
255	bra _fault
256	.globl	_exc_handler
257
258_exc_handler:
259	SAVE_ALL
260	movel	%sp,%sp@-
261	bsr exc_handler
262	addql	#4,%sp
263	RESTORE_ALL
264
265	.globl	_int_handler
266_int_handler:
267	SAVE_ALL
268	movel	%sp,%sp@-
269	bsr int_handler
270	addql	#4,%sp
271	RESTORE_ALL
272
273/*------------------------------------------------------------------------------*/
274
275	.globl	version_string
276version_string:
277	.ascii U_BOOT_VERSION_STRING, "\0"
278	.align 4
279