xref: /openbmc/u-boot/arch/m68k/cpu/mcf523x/start.S (revision f55137fd)
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, %RAMBAR1
105
106	/* invalidate and disable cache */
107	move.l	#CF_CACR_CINV, %d0	/* Invalidate cache cmd */
108	movec	%d0, %CACR		/* Invalidate cache */
109	nop
110	move.l	#0, %d0
111	movec	%d0, %ACR0
112	movec	%d0, %ACR1
113
114	/* initialize general use internal ram */
115	move.l	#0, %d0
116	move.l	#(ICACHE_STATUS), %a1	/* icache */
117	move.l	#(DCACHE_STATUS), %a2	/* icache */
118	move.l	%d0, (%a1)
119	move.l	%d0, (%a2)
120
121	/* put relocation table address to a5 */
122	move.l	#__got_start, %a5
123
124	/* setup stack initially on top of internal static ram  */
125	move.l  #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
126
127	/*
128	 * if configured, malloc_f arena will be reserved first,
129	 * then (and always) gd struct space will be reserved
130	 */
131	move.l	%sp, -(%sp)
132	move.l	#board_init_f_alloc_reserve, %a1
133	jsr	(%a1)
134
135	/* update stack and frame-pointers */
136	move.l	%d0, %sp
137	move.l	%sp, %fp
138
139	/* initialize reserved area */
140	move.l	%d0, -(%sp)
141	move.l	#board_init_f_init_reserve, %a1
142	jsr	(%a1)
143
144	/* run low-level CPU init code (from flash) */
145	move.l	#cpu_init_f, %a1
146	jsr	(%a1)
147
148	/* run low-level board init code (from flash) */
149	clr.l	%sp@-
150	move.l	#board_init_f, %a1
151	jsr	(%a1)
152
153	/* board_init_f() does not return */
154
155/******************************************************************************/
156
157/*
158 * void relocate_code (addr_sp, gd, addr_moni)
159 *
160 * This "function" does not return, instead it continues in RAM
161 * after relocating the monitor code.
162 *
163 * r3 = dest
164 * r4 = src
165 * r5 = length in bytes
166 * r6 = cachelinesize
167 */
168.globl relocate_code
169relocate_code:
170	link.w	%a6,#0
171	move.l	8(%a6), %sp		/* set new stack pointer */
172
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
180	/* copy the code to RAM */
1811:
182	move.l	(%a1)+, (%a3)+
183	cmp.l	%a1,%a2
184	bgt.s	1b
185
186/*
187 * We are done. Do not return, instead branch to second part of board
188 * initialization, now running from RAM.
189 */
190	move.l	%a0, %a1
191	add.l	#(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
192	jmp	(%a1)
193
194in_ram:
195
196clear_bss:
197	/*
198	 * Now clear BSS segment
199	 */
200	move.l	%a0, %a1
201	add.l	#(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
202	move.l	%a0, %d1
203	add.l	#(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
2046:
205	clr.l	(%a1)+
206	cmp.l	%a1,%d1
207	bgt.s	6b
208
209	/*
210	 * fix got table in RAM
211	 */
212	move.l	%a0, %a1
213	add.l	#(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
214	move.l	%a1,%a5		/* * fix got pointer register a5 */
215
216	move.l	%a0, %a2
217	add.l	#(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
218
2197:
220	move.l	(%a1),%d1
221	sub.l	#_start,%d1
222	add.l	%a0,%d1
223	move.l	%d1,(%a1)+
224	cmp.l	%a2, %a1
225	bne	7b
226
227	/* calculate relative jump to board_init_r in ram */
228	move.l	%a0, %a1
229	add.l	#(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
230
231	/* set parameters for board_init_r */
232	move.l	%a0,-(%sp)		/* dest_addr */
233	move.l	%d0,-(%sp)		/* gd */
234	jsr	(%a1)
235
236/******************************************************************************/
237
238/* exception code */
239.globl _fault
240_fault:
241	bra	_fault
242
243.globl _exc_handler
244_exc_handler:
245	SAVE_ALL
246	movel	%sp,%sp@-
247	bsr	exc_handler
248	addql	#4,%sp
249	RESTORE_ALL
250
251.globl _int_handler
252_int_handler:
253	SAVE_ALL
254	movel	%sp,%sp@-
255	bsr	int_handler
256	addql	#4,%sp
257	RESTORE_ALL
258
259/******************************************************************************/
260
261.globl version_string
262version_string:
263.ascii U_BOOT_VERSION_STRING, "\0"
264.align 4
265