xref: /openbmc/u-boot/arch/m68k/cpu/mcf52x2/start.S (revision baefb63a)
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#define _START	_start
14#define _FAULT	_fault
15
16
17#define SAVE_ALL						\
18	move.w	#0x2700,%sr;		/* disable intrs */	\
19	subl	#60,%sp;		/* space for 15 regs */ \
20	moveml	%d0-%d7/%a0-%a6,%sp@;				\
21
22#define RESTORE_ALL						\
23	moveml	%sp@,%d0-%d7/%a0-%a6;				\
24	addl	#60,%sp;		/* space for 15 regs */ \
25	rte
26
27/* If we come from a pre-loader we don't need an initial exception
28 * table.
29 */
30#if !defined(CONFIG_MONITOR_IS_IN_RAM)
31
32.text
33
34/*
35 * Vector table. This is used for initial platform startup.
36 * These vectors are to catch any un-intended traps.
37 */
38_vectors:
39.long	0x00000000		/* Flash offset is 0 until we setup CS0 */
40#if defined(CONFIG_M5282) && (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
41.long	_start - CONFIG_SYS_TEXT_BASE
42#else
43.long	_START
44#endif
45
46.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
47.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
48.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
49.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
50.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
51.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
52.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
53.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
54
55.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
56.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
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
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.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
71.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
72
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.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
81
82#endif
83
84.text
85
86#if defined(CONFIG_SYS_INT_FLASH_BASE) && \
87    (defined(CONFIG_M5282) || defined(CONFIG_M5281))
88#if (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
89.long	0x55AA55AA,0xAA55AA55		/* CFM Backdoorkey */
90.long	0xFFFFFFFF			/* all sectors protected */
91.long	0x00000000			/* supervisor/User restriction */
92.long	0x00000000			/* programm/data space restriction */
93.long	0x00000000			/* Flash security */
94#endif
95#endif
96
97.globl _start
98_start:
99	nop
100	nop
101	move.w	#0x2700,%sr
102
103#if defined(CONFIG_M5208)
104	/* Initialize RAMBAR: locate SRAM and validate it */
105	move.l	#(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
106	movec	%d0, %RAMBAR1
107#endif
108
109#if defined(CONFIG_M5272) || defined(CONFIG_M5249) || defined(CONFIG_M5253)
110	/* set MBAR address + valid flag */
111	move.l	#(CONFIG_SYS_MBAR + 1), %d0
112	move.c	%d0, %MBAR
113
114	/*** The 5249 has MBAR2 as well ***/
115#ifdef CONFIG_SYS_MBAR2
116	/* Get MBAR2 address */
117	move.l	#(CONFIG_SYS_MBAR2 + 1), %d0
118	 /* Set MBAR2 */
119	movec	%d0, #0xc0e
120#endif
121	move.l	#(CONFIG_SYS_INIT_RAM_ADDR + 1), %d0
122	movec	%d0, %RAMBAR0
123#endif /* CONFIG_M5272 || CONFIG_M5249 || CONFIG_M5253 */
124
125#if defined(CONFIG_M5282) || defined(CONFIG_M5271)
126	/* set MBAR address + valid flag */
127	move.l	#(CONFIG_SYS_MBAR + 1), %d0
128	move.l	%d0, 0x40000000
129
130	/* Initialize RAMBAR1: locate SRAM and validate it */
131	move.l	#(CONFIG_SYS_INIT_RAM_ADDR + 0x21), %d0
132	movec	%d0, %RAMBAR1
133
134#if defined(CONFIG_M5282)
135#if (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
136	/*
137	 * Setup code in SRAM to initialize FLASHBAR,
138	 * if start from internal Flash
139	 */
140	move.l	#(_flashbar_setup-CONFIG_SYS_INT_FLASH_BASE), %a0
141	move.l	#(_flashbar_setup_end-CONFIG_SYS_INT_FLASH_BASE), %a1
142	move.l	#(CONFIG_SYS_INIT_RAM_ADDR), %a2
143_copy_flash:
144	move.l	(%a0)+, (%a2)+
145	cmp.l	%a0, %a1
146	bgt.s	_copy_flash
147	jmp	CONFIG_SYS_INIT_RAM_ADDR
148
149_flashbar_setup:
150	/* Initialize FLASHBAR: locate internal Flash and validate it */
151	move.l	#(CONFIG_SYS_INT_FLASH_BASE + CONFIG_SYS_INT_FLASH_ENABLE), %d0
152	movec	%d0, %FLASHBAR
153	jmp	_after_flashbar_copy.L	/* Force jump to absolute address */
154_flashbar_setup_end:
155	nop
156_after_flashbar_copy:
157#else
158	/* Setup code to initialize FLASHBAR, if start from external Memory */
159	move.l	#(CONFIG_SYS_INT_FLASH_BASE + CONFIG_SYS_INT_FLASH_ENABLE), %d0
160	movec	%d0, %FLASHBAR
161#endif /* (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE) */
162
163#endif
164#endif
165	/*
166	 * if we come from a pre-loader we have no exception table and
167	 * therefore no VBR to set
168	 */
169#if !defined(CONFIG_MONITOR_IS_IN_RAM)
170#if defined(CONFIG_M5282) && (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE)
171	move.l	#CONFIG_SYS_INT_FLASH_BASE, %d0
172#else
173	move.l	#CONFIG_SYS_FLASH_BASE, %d0
174#endif
175	movec	%d0, %VBR
176#endif
177
178#ifdef CONFIG_M5275
179	/* set MBAR address + valid flag */
180	move.l	#(CONFIG_SYS_MBAR + 1), %d0
181	move.l	%d0, 0x40000000
182/*	movec	%d0, %MBAR */
183
184	/* Initialize RAMBAR: locate SRAM and validate it */
185	move.l	#(CONFIG_SYS_INIT_RAM_ADDR + 0x21), %d0
186	movec	%d0, %RAMBAR1
187#endif
188
189	/* initialize general use internal ram */
190	move.l	#0, %d0
191	move.l	#(ICACHE_STATUS), %a1	/* icache */
192	move.l	#(DCACHE_STATUS), %a2	/* icache */
193	move.l	%d0, (%a1)
194	move.l	%d0, (%a2)
195
196	/* put relocation table address to a5 */
197	move.l	#__got_start, %a5
198
199	/* setup stack initially on top of internal static ram  */
200	move.l	#(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
201
202	/*
203	 * if configured, malloc_f arena will be reserved first,
204	 * then (and always) gd struct space will be reserved
205	 */
206	move.l	%sp, -(%sp)
207	move.l	#board_init_f_alloc_reserve, %a1
208	jsr	(%a1)
209
210	/* update stack and frame-pointers */
211	move.l	%d0, %sp
212	move.l	%sp, %fp
213
214	/* initialize reserved area */
215	move.l	%d0, -(%sp)
216	move.l	#board_init_f_init_reserve, %a1
217	jsr	(%a1)
218
219	/* run low-level CPU init code (from flash) */
220	move.l	#cpu_init_f, %a1
221	jsr	(%a1)
222
223	/* run low-level board init code (from flash) */
224	clr.l	%sp@-
225	move.l	#board_init_f, %a1
226	jsr	(%a1)
227
228	/* board_init_f() does not return */
229
230/******************************************************************************/
231
232/*
233 * void relocate_code (addr_sp, gd, addr_moni)
234 *
235 * This "function" does not return, instead it continues in RAM
236 * after relocating the monitor code.
237 *
238 * r3 = dest
239 * r4 = src
240 * r5 = length in bytes
241 * r6 = cachelinesize
242 */
243.globl relocate_code
244relocate_code:
245	link.w	%a6,#0
246	move.l	8(%a6), %sp		/* set new stack pointer */
247
248	move.l	12(%a6), %d0		/* Save copy of Global Data pointer */
249	move.l	16(%a6), %a0		/* Save copy of Destination Address */
250
251	move.l	#CONFIG_SYS_MONITOR_BASE, %a1
252	move.l	#__init_end, %a2
253	move.l	%a0, %a3
254	/* copy the code to RAM */
2551:
256	move.l	(%a1)+, (%a3)+
257	cmp.l	%a1,%a2
258	bgt.s	1b
259
260/*
261 * We are done. Do not return, instead branch to second part of board
262 * initialization, now running from RAM.
263 */
264	move.l	%a0, %a1
265	add.l	#(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
266	jmp	(%a1)
267
268in_ram:
269
270clear_bss:
271	/*
272	 * Now clear BSS segment
273	 */
274	move.l	%a0, %a1
275	add.l	#(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
276	move.l	%a0, %d1
277	add.l	#(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
2786:
279	clr.l	(%a1)+
280	cmp.l	%a1,%d1
281	bgt.s	6b
282
283	/*
284	 * fix got table in RAM
285	 */
286	move.l	%a0, %a1
287	add.l	#(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
288	move.l	%a1,%a5			/* fix got pointer register a5 */
289
290	move.l	%a0, %a2
291	add.l	#(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
292
2937:
294	move.l	(%a1),%d1
295	sub.l	#_start,%d1
296	add.l	%a0,%d1
297	move.l	%d1,(%a1)+
298	cmp.l	%a2, %a1
299	bne	7b
300
301	/* calculate relative jump to board_init_r in ram */
302	move.l	%a0, %a1
303	add.l	#(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
304
305	/* set parameters for board_init_r */
306	move.l	%a0,-(%sp)		/* dest_addr */
307	move.l	%d0,-(%sp)		/* gd */
308#if defined(DEBUG) && (CONFIG_SYS_TEXT_BASE != CONFIG_SYS_INT_FLASH_BASE) && \
309    defined(CONFIG_SYS_HALT_BEFOR_RAM_JUMP)
310	halt
311#endif
312	jsr	(%a1)
313
314/******************************************************************************/
315
316/* exception code */
317.globl _fault
318_fault:
319	bra	_fault
320
321.globl _exc_handler
322_exc_handler:
323	SAVE_ALL
324	movel	%sp,%sp@-
325	bsr	exc_handler
326	addql	#4,%sp
327	RESTORE_ALL
328
329.globl _int_handler
330_int_handler:
331	SAVE_ALL
332	movel	%sp,%sp@-
333	bsr	int_handler
334	addql	#4,%sp
335	RESTORE_ALL
336
337/******************************************************************************/
338
339.globl version_string
340version_string:
341.ascii U_BOOT_VERSION_STRING, "\0"
342.align 4
343