xref: /openbmc/u-boot/arch/m68k/cpu/mcf532x/start.S (revision ae485b54)
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 * (C) Copyright 2004-2008 Freescale Semiconductor, Inc.
7 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
8 */
9
10#include <asm-offsets.h>
11#include <config.h>
12#include "version.h"
13#include <asm/cache.h>
14
15#define _START	_start
16#define _FAULT	_fault
17
18#define SAVE_ALL						\
19	move.w	#0x2700,%sr;		/* disable intrs */	\
20	subl	#60,%sp;		/* space for 15 regs */ \
21	moveml	%d0-%d7/%a0-%a6,%sp@;
22
23#define RESTORE_ALL						\
24	moveml	%sp@,%d0-%d7/%a0-%a6;				\
25	addl	#60,%sp;		/* space for 15 regs */ \
26	rte;
27
28#if !defined(CONFIG_MONITOR_IS_IN_RAM)
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#endif /* !defined(CONFIG_MONITOR_IS_IN_RAM) */
91
92.text
93
94.globl _start
95_start:
96	nop
97	nop
98	move.w	#0x2700,%sr	/* Mask off Interrupt */
99
100#if !defined(CONFIG_MONITOR_IS_IN_RAM)
101	/* Set vector base register at the beginning of the Flash */
102	move.l	#CONFIG_SYS_FLASH_BASE, %d0
103	movec	%d0, %VBR
104#endif
105
106	move.l	#(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
107	movec	%d0, %RAMBAR1
108
109	/* invalidate and disable cache */
110	move.l	#CF_CACR_CINVA, %d0		/* Invalidate cache cmd */
111	movec	%d0, %CACR			/* Invalidate cache */
112	move.l	#0, %d0
113	movec	%d0, %ACR0
114	movec	%d0, %ACR1
115
116#ifdef CONFIG_MCF5301x
117	move.l	#(0xFC0a0010), %a0
118	move.w	(%a0), %d0
119	and.l	%d0, 0xEFFF
120
121	move.w	%d0, (%a0)
122#endif
123
124	/* initialize general use internal ram */
125	move.l	#0, %d0
126	move.l	#(ICACHE_STATUS), %a1	/* icache */
127	move.l	#(DCACHE_STATUS), %a2	/* icache */
128	move.l	%d0, (%a1)
129	move.l	%d0, (%a2)
130
131	/* put relocation table address to a5 */
132	move.l	#__got_start, %a5
133
134	/* setup stack initially on top of internal static ram  */
135	move.l  #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
136
137	/*
138	 * if configured, malloc_f arena will be reserved first,
139	 * then (and always) gd struct space will be reserved
140	 */
141	move.l	%sp, -(%sp)
142	move.l	#board_init_f_alloc_reserve, %a1
143	jsr	(%a1)
144
145	/* update stack and frame-pointers */
146	move.l  %d0, %sp
147	move.l  %sp, %fp
148
149	/* initialize reserved area */
150	move.l	%d0, -(%sp)
151	move.l	#board_init_f_init_reserve, %a1
152	jsr	(%a1)
153
154	/* run low-level CPU init code (from flash) */
155	move.l	#cpu_init_f, %a1
156	jsr	(%a1)
157
158	/* run low-level board init code (from flash) */
159	clr.l   %sp@-
160	move.l #board_init_f, %a1
161	jsr (%a1)
162
163	/* board_init_f() does not return */
164
165/******************************************************************************/
166
167/*
168 * void relocate_code (addr_sp, gd, addr_moni)
169 *
170 * This "function" does not return, instead it continues in RAM
171 * after relocating the monitor code.
172 *
173 * r3 = dest
174 * r4 = src
175 * r5 = length in bytes
176 * r6 = cachelinesize
177 */
178.globl relocate_code
179relocate_code:
180	link.w	%a6,#0
181	move.l	8(%a6), %sp		/* set new stack pointer */
182
183	move.l	12(%a6), %d0		/* Save copy of Global Data pointer */
184	move.l	16(%a6), %a0		/* Save copy of Destination Address */
185
186	move.l	#CONFIG_SYS_MONITOR_BASE, %a1
187	move.l	#__init_end, %a2
188	move.l	%a0, %a3
189
190	/* copy the code to RAM */
1911:
192	move.l	(%a1)+, (%a3)+
193	cmp.l	%a1,%a2
194	bgt.s	1b
195
196/*
197 * We are done. Do not return, instead branch to second part of board
198 * initialization, now running from RAM.
199 */
200	move.l	%a0, %a1
201	add.l	#(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
202	jmp	(%a1)
203
204in_ram:
205
206clear_bss:
207	/*
208	 * Now clear BSS segment
209	 */
210	move.l	%a0, %a1
211	add.l	#(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
212	move.l	%a0, %d1
213	add.l	#(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
2146:
215	clr.l	(%a1)+
216	cmp.l	%a1,%d1
217	bgt.s	6b
218
219	/*
220	 * fix got table in RAM
221	 */
222	move.l	%a0, %a1
223	add.l	#(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
224	move.l	%a1,%a5			/* fix got pointer register a5 */
225
226	move.l	%a0, %a2
227	add.l	#(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
228
2297:
230	move.l	(%a1),%d1
231	sub.l	#_start,%d1
232	add.l	%a0,%d1
233	move.l	%d1,(%a1)+
234	cmp.l	%a2, %a1
235	bne	7b
236
237	/* calculate relative jump to board_init_r in ram */
238	move.l	%a0, %a1
239	add.l	#(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
240
241	/* set parameters for board_init_r */
242	move.l	%a0,-(%sp)		/* dest_addr */
243	move.l	%d0,-(%sp)		/* gd */
244	jsr	(%a1)
245
246/******************************************************************************/
247
248/* exception code */
249.globl _fault
250_fault:
251	bra _fault
252
253.globl _exc_handler
254_exc_handler:
255	SAVE_ALL
256	movel	%sp,%sp@-
257	bsr	exc_handler
258	addql	#4,%sp
259	RESTORE_ALL
260
261.globl _int_handler
262_int_handler:
263	SAVE_ALL
264	movel	%sp,%sp@-
265	bsr	int_handler
266	addql	#4,%sp
267	RESTORE_ALL
268
269/******************************************************************************/
270
271.globl version_string
272version_string:
273.ascii U_BOOT_VERSION_STRING, "\0"
274.align 4
275