xref: /openbmc/u-boot/arch/m68k/cpu/mcf523x/start.S (revision e11ef3d2)
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, %RAMBAR1
100
101	/* invalidate and disable cache */
102	move.l	#CF_CACR_CINV, %d0	/* Invalidate cache cmd */
103	movec	%d0, %CACR		/* Invalidate cache */
104	nop
105	move.l	#0, %d0
106	movec	%d0, %ACR0
107	movec	%d0, %ACR1
108
109	/* initialize general use internal ram */
110	move.l	#0, %d0
111	move.l	#(ICACHE_STATUS), %a1	/* icache */
112	move.l	#(DCACHE_STATUS), %a2	/* icache */
113	move.l	%d0, (%a1)
114	move.l	%d0, (%a2)
115
116	/* put relocation table address to a5 */
117	move.l	#__got_start, %a5
118
119	/* setup stack initially on top of internal static ram  */
120	move.l  #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
121
122	/*
123	 * if configured, malloc_f arena will be reserved first,
124	 * then (and always) gd struct space will be reserved
125	 */
126	move.l	%sp, -(%sp)
127	move.l	#board_init_f_alloc_reserve, %a1
128	jsr	(%a1)
129
130	/* update stack and frame-pointers */
131	move.l	%d0, %sp
132	move.l	%sp, %fp
133
134	/* initialize reserved area */
135	move.l	%d0, -(%sp)
136	move.l	#board_init_f_init_reserve, %a1
137	jsr	(%a1)
138
139	/* run low-level CPU init code (from flash) */
140	move.l	#cpu_init_f, %a1
141	jsr	(%a1)
142
143	/* run low-level board init code (from flash) */
144	clr.l	%sp@-
145	move.l	#board_init_f, %a1
146	jsr	(%a1)
147
148	/* board_init_f() does not return */
149
150/******************************************************************************/
151
152/*
153 * void relocate_code (addr_sp, gd, addr_moni)
154 *
155 * This "function" does not return, instead it continues in RAM
156 * after relocating the monitor code.
157 *
158 * r3 = dest
159 * r4 = src
160 * r5 = length in bytes
161 * r6 = cachelinesize
162 */
163.globl relocate_code
164relocate_code:
165	link.w	%a6,#0
166	move.l	8(%a6), %sp		/* set new stack pointer */
167
168	move.l	12(%a6), %d0		/* Save copy of Global Data pointer */
169	move.l	16(%a6), %a0		/* Save copy of Destination Address */
170
171	move.l	#CONFIG_SYS_MONITOR_BASE, %a1
172	move.l	#__init_end, %a2
173	move.l	%a0, %a3
174
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
209	move.l	%a1,%a5		/* * fix got pointer register a5 */
210
211	move.l	%a0, %a2
212	add.l	#(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
213
2147:
215	move.l	(%a1),%d1
216	sub.l	#_start,%d1
217	add.l	%a0,%d1
218	move.l	%d1,(%a1)+
219	cmp.l	%a2, %a1
220	bne	7b
221
222	/* calculate relative jump to board_init_r in ram */
223	move.l	%a0, %a1
224	add.l	#(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
225
226	/* set parameters for board_init_r */
227	move.l	%a0,-(%sp)		/* dest_addr */
228	move.l	%d0,-(%sp)		/* gd */
229	jsr	(%a1)
230
231/******************************************************************************/
232
233/* exception code */
234.globl _fault
235_fault:
236	bra	_fault
237
238.globl _exc_handler
239_exc_handler:
240	SAVE_ALL
241	movel	%sp,%sp@-
242	bsr	exc_handler
243	addql	#4,%sp
244	RESTORE_ALL
245
246.globl _int_handler
247_int_handler:
248	SAVE_ALL
249	movel	%sp,%sp@-
250	bsr	int_handler
251	addql	#4,%sp
252	RESTORE_ALL
253
254/******************************************************************************/
255
256.globl version_string
257version_string:
258.ascii U_BOOT_VERSION_STRING, "\0"
259.align 4
260