xref: /OK3568_Linux_fs/u-boot/arch/m68k/cpu/mcf523x/start.S (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun/*
2*4882a593Smuzhiyun * Copyright (C) 2003	Josef Baumgartner <josef.baumgartner@telex.de>
3*4882a593Smuzhiyun * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * SPDX-License-Identifier:	GPL-2.0+
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun#include <asm-offsets.h>
9*4882a593Smuzhiyun#include <config.h>
10*4882a593Smuzhiyun#include "version.h"
11*4882a593Smuzhiyun#include <asm/cache.h>
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun#define _START	_start
14*4882a593Smuzhiyun#define _FAULT	_fault
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun#define SAVE_ALL						\
17*4882a593Smuzhiyun	move.w	#0x2700,%sr;		/* disable intrs */	\
18*4882a593Smuzhiyun	subl	#60,%sp;		/* space for 15 regs */ \
19*4882a593Smuzhiyun	moveml	%d0-%d7/%a0-%a6,%sp@;
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun#define RESTORE_ALL						\
22*4882a593Smuzhiyun	moveml	%sp@,%d0-%d7/%a0-%a6;				\
23*4882a593Smuzhiyun	addl	#60,%sp;		/* space for 15 regs */ \
24*4882a593Smuzhiyun	rte;
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun.text
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun/*
29*4882a593Smuzhiyun * Vector table. This is used for initial platform startup.
30*4882a593Smuzhiyun * These vectors are to catch any un-intended traps.
31*4882a593Smuzhiyun */
32*4882a593Smuzhiyun_vectors:
33*4882a593SmuzhiyunINITSP:	.long	0x00000000		/* Initial SP	*/
34*4882a593SmuzhiyunINITPC:	.long	_START			/* Initial PC	*/
35*4882a593Smuzhiyun
36*4882a593Smuzhiyunvector02_0F:
37*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
38*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun/* Reserved */
41*4882a593Smuzhiyunvector10_17:
42*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
43*4882a593Smuzhiyun
44*4882a593Smuzhiyunvector18_1F:
45*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun/* TRAP #0 - #15 */
48*4882a593Smuzhiyunvector20_2F:
49*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
50*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun/* Reserved	*/
53*4882a593Smuzhiyunvector30_3F:
54*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
55*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
56*4882a593Smuzhiyun
57*4882a593Smuzhiyunvector64_127:
58*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
59*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
60*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
61*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
62*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
63*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
64*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
65*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
66*4882a593Smuzhiyun
67*4882a593Smuzhiyunvector128_191:
68*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
69*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
70*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
71*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
72*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
73*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
74*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
75*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
76*4882a593Smuzhiyun
77*4882a593Smuzhiyunvector192_255:
78*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
79*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
80*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
81*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
82*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
83*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
84*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
85*4882a593Smuzhiyun.long	_FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun.text
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun.globl _start
90*4882a593Smuzhiyun_start:
91*4882a593Smuzhiyun	nop
92*4882a593Smuzhiyun	nop
93*4882a593Smuzhiyun	move.w	#0x2700,%sr		/* Mask off Interrupt */
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun	/* Set vector base register at the beginning of the Flash */
96*4882a593Smuzhiyun	move.l	#CONFIG_SYS_FLASH_BASE, %d0
97*4882a593Smuzhiyun	movec	%d0, %VBR
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun	move.l	#(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
100*4882a593Smuzhiyun	movec	%d0, %RAMBAR1
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun	/* invalidate and disable cache */
103*4882a593Smuzhiyun	move.l	#CF_CACR_CINV, %d0	/* Invalidate cache cmd */
104*4882a593Smuzhiyun	movec	%d0, %CACR		/* Invalidate cache */
105*4882a593Smuzhiyun	nop
106*4882a593Smuzhiyun	move.l	#0, %d0
107*4882a593Smuzhiyun	movec	%d0, %ACR0
108*4882a593Smuzhiyun	movec	%d0, %ACR1
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun	/* initialize general use internal ram */
111*4882a593Smuzhiyun	move.l	#0, %d0
112*4882a593Smuzhiyun	move.l	#(ICACHE_STATUS), %a1	/* icache */
113*4882a593Smuzhiyun	move.l	#(DCACHE_STATUS), %a2	/* icache */
114*4882a593Smuzhiyun	move.l	%d0, (%a1)
115*4882a593Smuzhiyun	move.l	%d0, (%a2)
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun	/* put relocation table address to a5 */
118*4882a593Smuzhiyun	move.l	#__got_start, %a5
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun	/* setup stack initially on top of internal static ram  */
121*4882a593Smuzhiyun	move.l  #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun	/*
124*4882a593Smuzhiyun	 * if configured, malloc_f arena will be reserved first,
125*4882a593Smuzhiyun	 * then (and always) gd struct space will be reserved
126*4882a593Smuzhiyun	 */
127*4882a593Smuzhiyun	move.l	%sp, -(%sp)
128*4882a593Smuzhiyun	move.l	#board_init_f_alloc_reserve, %a1
129*4882a593Smuzhiyun	jsr	(%a1)
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun	/* update stack and frame-pointers */
132*4882a593Smuzhiyun	move.l	%d0, %sp
133*4882a593Smuzhiyun	move.l	%sp, %fp
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun	/* initialize reserved area */
136*4882a593Smuzhiyun	move.l	%d0, -(%sp)
137*4882a593Smuzhiyun	move.l	#board_init_f_init_reserve, %a1
138*4882a593Smuzhiyun	jsr	(%a1)
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun	/* run low-level CPU init code (from flash) */
141*4882a593Smuzhiyun	move.l	#cpu_init_f, %a1
142*4882a593Smuzhiyun	jsr	(%a1)
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun	/* run low-level board init code (from flash) */
145*4882a593Smuzhiyun	clr.l	%sp@-
146*4882a593Smuzhiyun	move.l	#board_init_f, %a1
147*4882a593Smuzhiyun	jsr	(%a1)
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun	/* board_init_f() does not return */
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun/******************************************************************************/
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun/*
154*4882a593Smuzhiyun * void relocate_code (addr_sp, gd, addr_moni)
155*4882a593Smuzhiyun *
156*4882a593Smuzhiyun * This "function" does not return, instead it continues in RAM
157*4882a593Smuzhiyun * after relocating the monitor code.
158*4882a593Smuzhiyun *
159*4882a593Smuzhiyun * r3 = dest
160*4882a593Smuzhiyun * r4 = src
161*4882a593Smuzhiyun * r5 = length in bytes
162*4882a593Smuzhiyun * r6 = cachelinesize
163*4882a593Smuzhiyun */
164*4882a593Smuzhiyun.globl relocate_code
165*4882a593Smuzhiyunrelocate_code:
166*4882a593Smuzhiyun	link.w	%a6,#0
167*4882a593Smuzhiyun	move.l	8(%a6), %sp		/* set new stack pointer */
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun	move.l	12(%a6), %d0		/* Save copy of Global Data pointer */
170*4882a593Smuzhiyun	move.l	16(%a6), %a0		/* Save copy of Destination Address */
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun	move.l	#CONFIG_SYS_MONITOR_BASE, %a1
173*4882a593Smuzhiyun	move.l	#__init_end, %a2
174*4882a593Smuzhiyun	move.l	%a0, %a3
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun	/* copy the code to RAM */
177*4882a593Smuzhiyun1:
178*4882a593Smuzhiyun	move.l	(%a1)+, (%a3)+
179*4882a593Smuzhiyun	cmp.l	%a1,%a2
180*4882a593Smuzhiyun	bgt.s	1b
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun/*
183*4882a593Smuzhiyun * We are done. Do not return, instead branch to second part of board
184*4882a593Smuzhiyun * initialization, now running from RAM.
185*4882a593Smuzhiyun */
186*4882a593Smuzhiyun	move.l	%a0, %a1
187*4882a593Smuzhiyun	add.l	#(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
188*4882a593Smuzhiyun	jmp	(%a1)
189*4882a593Smuzhiyun
190*4882a593Smuzhiyunin_ram:
191*4882a593Smuzhiyun
192*4882a593Smuzhiyunclear_bss:
193*4882a593Smuzhiyun	/*
194*4882a593Smuzhiyun	 * Now clear BSS segment
195*4882a593Smuzhiyun	 */
196*4882a593Smuzhiyun	move.l	%a0, %a1
197*4882a593Smuzhiyun	add.l	#(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
198*4882a593Smuzhiyun	move.l	%a0, %d1
199*4882a593Smuzhiyun	add.l	#(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
200*4882a593Smuzhiyun6:
201*4882a593Smuzhiyun	clr.l	(%a1)+
202*4882a593Smuzhiyun	cmp.l	%a1,%d1
203*4882a593Smuzhiyun	bgt.s	6b
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun	/*
206*4882a593Smuzhiyun	 * fix got table in RAM
207*4882a593Smuzhiyun	 */
208*4882a593Smuzhiyun	move.l	%a0, %a1
209*4882a593Smuzhiyun	add.l	#(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
210*4882a593Smuzhiyun	move.l	%a1,%a5		/* * fix got pointer register a5 */
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun	move.l	%a0, %a2
213*4882a593Smuzhiyun	add.l	#(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun7:
216*4882a593Smuzhiyun	move.l	(%a1),%d1
217*4882a593Smuzhiyun	sub.l	#_start,%d1
218*4882a593Smuzhiyun	add.l	%a0,%d1
219*4882a593Smuzhiyun	move.l	%d1,(%a1)+
220*4882a593Smuzhiyun	cmp.l	%a2, %a1
221*4882a593Smuzhiyun	bne	7b
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun	/* calculate relative jump to board_init_r in ram */
224*4882a593Smuzhiyun	move.l	%a0, %a1
225*4882a593Smuzhiyun	add.l	#(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun	/* set parameters for board_init_r */
228*4882a593Smuzhiyun	move.l	%a0,-(%sp)		/* dest_addr */
229*4882a593Smuzhiyun	move.l	%d0,-(%sp)		/* gd */
230*4882a593Smuzhiyun	jsr	(%a1)
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun/******************************************************************************/
233*4882a593Smuzhiyun
234*4882a593Smuzhiyun/* exception code */
235*4882a593Smuzhiyun.globl _fault
236*4882a593Smuzhiyun_fault:
237*4882a593Smuzhiyun	bra	_fault
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun.globl _exc_handler
240*4882a593Smuzhiyun_exc_handler:
241*4882a593Smuzhiyun	SAVE_ALL
242*4882a593Smuzhiyun	movel	%sp,%sp@-
243*4882a593Smuzhiyun	bsr	exc_handler
244*4882a593Smuzhiyun	addql	#4,%sp
245*4882a593Smuzhiyun	RESTORE_ALL
246*4882a593Smuzhiyun
247*4882a593Smuzhiyun.globl _int_handler
248*4882a593Smuzhiyun_int_handler:
249*4882a593Smuzhiyun	SAVE_ALL
250*4882a593Smuzhiyun	movel	%sp,%sp@-
251*4882a593Smuzhiyun	bsr	int_handler
252*4882a593Smuzhiyun	addql	#4,%sp
253*4882a593Smuzhiyun	RESTORE_ALL
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun/******************************************************************************/
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun.globl version_string
258*4882a593Smuzhiyunversion_string:
259*4882a593Smuzhiyun.ascii U_BOOT_VERSION_STRING, "\0"
260*4882a593Smuzhiyun.align 4
261