xref: /OK3568_Linux_fs/u-boot/arch/mips/cpu/start.S (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun/*
2*4882a593Smuzhiyun *  Startup Code for MIPS32 CPU-core
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun *  Copyright (c) 2003	Wolfgang Denk <wd@denx.de>
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * SPDX-License-Identifier:	GPL-2.0+
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun#include <asm-offsets.h>
10*4882a593Smuzhiyun#include <config.h>
11*4882a593Smuzhiyun#include <asm/asm.h>
12*4882a593Smuzhiyun#include <asm/regdef.h>
13*4882a593Smuzhiyun#include <asm/mipsregs.h>
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun#ifndef CONFIG_SYS_INIT_SP_ADDR
16*4882a593Smuzhiyun#define CONFIG_SYS_INIT_SP_ADDR	(CONFIG_SYS_SDRAM_BASE + \
17*4882a593Smuzhiyun				CONFIG_SYS_INIT_SP_OFFSET)
18*4882a593Smuzhiyun#endif
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun#ifdef CONFIG_32BIT
21*4882a593Smuzhiyun# define MIPS_RELOC	3
22*4882a593Smuzhiyun# define STATUS_SET	0
23*4882a593Smuzhiyun#endif
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun#ifdef CONFIG_64BIT
26*4882a593Smuzhiyun# ifdef CONFIG_SYS_LITTLE_ENDIAN
27*4882a593Smuzhiyun#  define MIPS64_R_INFO(ssym, r_type3, r_type2, r_type) \
28*4882a593Smuzhiyun	(((r_type) << 24) | ((r_type2) << 16) | ((r_type3) << 8) | (ssym))
29*4882a593Smuzhiyun# else
30*4882a593Smuzhiyun#  define MIPS64_R_INFO(ssym, r_type3, r_type2, r_type) \
31*4882a593Smuzhiyun	((r_type) | ((r_type2) << 8) | ((r_type3) << 16) | (ssym) << 24)
32*4882a593Smuzhiyun# endif
33*4882a593Smuzhiyun# define MIPS_RELOC	MIPS64_R_INFO(0x00, 0x00, 0x12, 0x03)
34*4882a593Smuzhiyun# define STATUS_SET	ST0_KX
35*4882a593Smuzhiyun#endif
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun	.set noreorder
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun	.macro init_wr sel
40*4882a593Smuzhiyun	MTC0	zero, CP0_WATCHLO,\sel
41*4882a593Smuzhiyun	mtc0	t1, CP0_WATCHHI,\sel
42*4882a593Smuzhiyun	mfc0	t0, CP0_WATCHHI,\sel
43*4882a593Smuzhiyun	bgez	t0, wr_done
44*4882a593Smuzhiyun	 nop
45*4882a593Smuzhiyun	.endm
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun	.macro uhi_mips_exception
48*4882a593Smuzhiyun	move	k0, t9		# preserve t9 in k0
49*4882a593Smuzhiyun	move	k1, a0		# preserve a0 in k1
50*4882a593Smuzhiyun	li	t9, 15		# UHI exception operation
51*4882a593Smuzhiyun	li	a0, 0		# Use hard register context
52*4882a593Smuzhiyun	sdbbp	1		# Invoke UHI operation
53*4882a593Smuzhiyun	.endm
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun	.macro setup_stack_gd
56*4882a593Smuzhiyun	li	t0, -16
57*4882a593Smuzhiyun	PTR_LI	t1, CONFIG_SYS_INIT_SP_ADDR
58*4882a593Smuzhiyun	and	sp, t1, t0		# force 16 byte alignment
59*4882a593Smuzhiyun	PTR_SUBU \
60*4882a593Smuzhiyun		sp, sp, GD_SIZE		# reserve space for gd
61*4882a593Smuzhiyun	and	sp, sp, t0		# force 16 byte alignment
62*4882a593Smuzhiyun	move	k0, sp			# save gd pointer
63*4882a593Smuzhiyun#if CONFIG_VAL(SYS_MALLOC_F_LEN)
64*4882a593Smuzhiyun	li	t2, CONFIG_VAL(SYS_MALLOC_F_LEN)
65*4882a593Smuzhiyun	PTR_SUBU \
66*4882a593Smuzhiyun		sp, sp, t2		# reserve space for early malloc
67*4882a593Smuzhiyun	and	sp, sp, t0		# force 16 byte alignment
68*4882a593Smuzhiyun#endif
69*4882a593Smuzhiyun	move	fp, sp
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun	/* Clear gd */
72*4882a593Smuzhiyun	move	t0, k0
73*4882a593Smuzhiyun1:
74*4882a593Smuzhiyun	PTR_S	zero, 0(t0)
75*4882a593Smuzhiyun	blt	t0, t1, 1b
76*4882a593Smuzhiyun	 PTR_ADDIU t0, PTRSIZE
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun#if CONFIG_VAL(SYS_MALLOC_F_LEN)
79*4882a593Smuzhiyun	PTR_S	sp, GD_MALLOC_BASE(k0)	# gd->malloc_base offset
80*4882a593Smuzhiyun#endif
81*4882a593Smuzhiyun	.endm
82*4882a593Smuzhiyun
83*4882a593SmuzhiyunENTRY(_start)
84*4882a593Smuzhiyun	/* U-Boot entry point */
85*4882a593Smuzhiyun	b	reset
86*4882a593Smuzhiyun	 mtc0	zero, CP0_COUNT	# clear cp0 count for most accurate boot timing
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun#if defined(CONFIG_SYS_XWAY_EBU_BOOTCFG)
89*4882a593Smuzhiyun	/*
90*4882a593Smuzhiyun	 * Almost all Lantiq XWAY SoC devices have an external bus unit (EBU) to
91*4882a593Smuzhiyun	 * access external NOR flashes. If the board boots from NOR flash the
92*4882a593Smuzhiyun	 * internal BootROM does a blind read at address 0xB0000010 to read the
93*4882a593Smuzhiyun	 * initial configuration for that EBU in order to access the flash
94*4882a593Smuzhiyun	 * device with correct parameters. This config option is board-specific.
95*4882a593Smuzhiyun	 */
96*4882a593Smuzhiyun	.org 0x10
97*4882a593Smuzhiyun	.word CONFIG_SYS_XWAY_EBU_BOOTCFG
98*4882a593Smuzhiyun	.word 0x0
99*4882a593Smuzhiyun#endif
100*4882a593Smuzhiyun#if defined(CONFIG_MALTA)
101*4882a593Smuzhiyun	/*
102*4882a593Smuzhiyun	 * Linux expects the Board ID here.
103*4882a593Smuzhiyun	 */
104*4882a593Smuzhiyun	.org 0x10
105*4882a593Smuzhiyun	.word 0x00000420	# 0x420 (Malta Board with CoreLV)
106*4882a593Smuzhiyun	.word 0x00000000
107*4882a593Smuzhiyun#endif
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun#if defined(CONFIG_ROM_EXCEPTION_VECTORS)
110*4882a593Smuzhiyun	/*
111*4882a593Smuzhiyun	 * Exception vector entry points. When running from ROM, an exception
112*4882a593Smuzhiyun	 * cannot be handled. Halt execution and transfer control to debugger,
113*4882a593Smuzhiyun	 * if one is attached.
114*4882a593Smuzhiyun	 */
115*4882a593Smuzhiyun	.org 0x200
116*4882a593Smuzhiyun	/* TLB refill, 32 bit task */
117*4882a593Smuzhiyun	uhi_mips_exception
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun	.org 0x280
120*4882a593Smuzhiyun	/* XTLB refill, 64 bit task */
121*4882a593Smuzhiyun	uhi_mips_exception
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun	.org 0x300
124*4882a593Smuzhiyun	/* Cache error exception */
125*4882a593Smuzhiyun	uhi_mips_exception
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun	.org 0x380
128*4882a593Smuzhiyun	/* General exception */
129*4882a593Smuzhiyun	uhi_mips_exception
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun	.org 0x400
132*4882a593Smuzhiyun	/* Catch interrupt exceptions */
133*4882a593Smuzhiyun	uhi_mips_exception
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun	.org 0x480
136*4882a593Smuzhiyun	/* EJTAG debug exception */
137*4882a593Smuzhiyun1:	b	1b
138*4882a593Smuzhiyun	 nop
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun	.org 0x500
141*4882a593Smuzhiyun#endif
142*4882a593Smuzhiyun
143*4882a593Smuzhiyunreset:
144*4882a593Smuzhiyun#if __mips_isa_rev >= 6
145*4882a593Smuzhiyun	mfc0	t0, CP0_CONFIG, 5
146*4882a593Smuzhiyun	and	t0, t0, MIPS_CONF5_VP
147*4882a593Smuzhiyun	beqz	t0, 1f
148*4882a593Smuzhiyun	 nop
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun	b	2f
151*4882a593Smuzhiyun	 mfc0	t0, CP0_GLOBALNUMBER
152*4882a593Smuzhiyun#endif
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun#ifdef CONFIG_ARCH_BMIPS
155*4882a593Smuzhiyun1:	mfc0	t0, CP0_DIAGNOSTIC, 3
156*4882a593Smuzhiyun	and	t0, t0, (1 << 31)
157*4882a593Smuzhiyun#else
158*4882a593Smuzhiyun1:	mfc0	t0, CP0_EBASE
159*4882a593Smuzhiyun	and	t0, t0, EBASE_CPUNUM
160*4882a593Smuzhiyun#endif
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun	/* Hang if this isn't the first CPU in the system */
163*4882a593Smuzhiyun2:	beqz	t0, 4f
164*4882a593Smuzhiyun	 nop
165*4882a593Smuzhiyun3:	wait
166*4882a593Smuzhiyun	b	3b
167*4882a593Smuzhiyun	 nop
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun	/* Init CP0 Status */
170*4882a593Smuzhiyun4:	mfc0	t0, CP0_STATUS
171*4882a593Smuzhiyun	and	t0, ST0_IMPL
172*4882a593Smuzhiyun	or	t0, ST0_BEV | ST0_ERL | STATUS_SET
173*4882a593Smuzhiyun	mtc0	t0, CP0_STATUS
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun	/*
176*4882a593Smuzhiyun	 * Check whether CP0 Config1 is implemented. If not continue
177*4882a593Smuzhiyun	 * with legacy Watch register initialization.
178*4882a593Smuzhiyun	 */
179*4882a593Smuzhiyun	mfc0	t0, CP0_CONFIG
180*4882a593Smuzhiyun	bgez	t0, wr_legacy
181*4882a593Smuzhiyun	 nop
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun	/*
184*4882a593Smuzhiyun	 * Check WR bit in CP0 Config1 to determine if Watch registers
185*4882a593Smuzhiyun	 * are implemented.
186*4882a593Smuzhiyun	 */
187*4882a593Smuzhiyun	mfc0	t0, CP0_CONFIG, 1
188*4882a593Smuzhiyun	andi	t0, (1 << 3)
189*4882a593Smuzhiyun	beqz	t0, wr_done
190*4882a593Smuzhiyun	 nop
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun	/* Clear Watch Status bits and disable watch exceptions */
193*4882a593Smuzhiyun	li	t1, 0x7		# Clear I, R and W conditions
194*4882a593Smuzhiyun	init_wr	0
195*4882a593Smuzhiyun	init_wr	1
196*4882a593Smuzhiyun	init_wr	2
197*4882a593Smuzhiyun	init_wr	3
198*4882a593Smuzhiyun	init_wr	4
199*4882a593Smuzhiyun	init_wr	5
200*4882a593Smuzhiyun	init_wr	6
201*4882a593Smuzhiyun	init_wr	7
202*4882a593Smuzhiyun	b	wr_done
203*4882a593Smuzhiyun	 nop
204*4882a593Smuzhiyun
205*4882a593Smuzhiyunwr_legacy:
206*4882a593Smuzhiyun	MTC0	zero, CP0_WATCHLO
207*4882a593Smuzhiyun	mtc0	zero, CP0_WATCHHI
208*4882a593Smuzhiyun
209*4882a593Smuzhiyunwr_done:
210*4882a593Smuzhiyun	/* Clear WP, IV and SW interrupts */
211*4882a593Smuzhiyun	mtc0	zero, CP0_CAUSE
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun	/* Clear timer interrupt (CP0_COUNT cleared on branch to 'reset') */
214*4882a593Smuzhiyun	mtc0	zero, CP0_COMPARE
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun#ifndef CONFIG_SKIP_LOWLEVEL_INIT
217*4882a593Smuzhiyun	mfc0	t0, CP0_CONFIG
218*4882a593Smuzhiyun	and	t0, t0, MIPS_CONF_IMPL
219*4882a593Smuzhiyun	or	t0, t0, CONF_CM_UNCACHED
220*4882a593Smuzhiyun	mtc0	t0, CP0_CONFIG
221*4882a593Smuzhiyun	ehb
222*4882a593Smuzhiyun#endif
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun#ifdef CONFIG_MIPS_CM
225*4882a593Smuzhiyun	PTR_LA	t9, mips_cm_map
226*4882a593Smuzhiyun	jalr	t9
227*4882a593Smuzhiyun	 nop
228*4882a593Smuzhiyun#endif
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun#ifdef CONFIG_MIPS_INIT_STACK_IN_SRAM
231*4882a593Smuzhiyun	/* Set up initial stack and global data */
232*4882a593Smuzhiyun	setup_stack_gd
233*4882a593Smuzhiyun
234*4882a593Smuzhiyun# ifdef CONFIG_DEBUG_UART
235*4882a593Smuzhiyun	/* Earliest point to set up debug uart */
236*4882a593Smuzhiyun	PTR_LA	t9, debug_uart_init
237*4882a593Smuzhiyun	jalr	t9
238*4882a593Smuzhiyun	 nop
239*4882a593Smuzhiyun# endif
240*4882a593Smuzhiyun#endif
241*4882a593Smuzhiyun
242*4882a593Smuzhiyun#ifndef CONFIG_SKIP_LOWLEVEL_INIT
243*4882a593Smuzhiyun# ifdef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD
244*4882a593Smuzhiyun	/* Initialize any external memory */
245*4882a593Smuzhiyun	PTR_LA	t9, lowlevel_init
246*4882a593Smuzhiyun	jalr	t9
247*4882a593Smuzhiyun	 nop
248*4882a593Smuzhiyun# endif
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun	/* Initialize caches... */
251*4882a593Smuzhiyun	PTR_LA	t9, mips_cache_reset
252*4882a593Smuzhiyun	jalr	t9
253*4882a593Smuzhiyun	 nop
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun# ifndef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD
256*4882a593Smuzhiyun	/* Initialize any external memory */
257*4882a593Smuzhiyun	PTR_LA	t9, lowlevel_init
258*4882a593Smuzhiyun	jalr	t9
259*4882a593Smuzhiyun	 nop
260*4882a593Smuzhiyun# endif
261*4882a593Smuzhiyun#endif
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun#ifndef CONFIG_MIPS_INIT_STACK_IN_SRAM
264*4882a593Smuzhiyun	/* Set up initial stack and global data */
265*4882a593Smuzhiyun	setup_stack_gd
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun# ifdef CONFIG_DEBUG_UART
268*4882a593Smuzhiyun	/* Earliest point to set up debug uart */
269*4882a593Smuzhiyun	PTR_LA	t9, debug_uart_init
270*4882a593Smuzhiyun	jalr	t9
271*4882a593Smuzhiyun	 nop
272*4882a593Smuzhiyun# endif
273*4882a593Smuzhiyun#endif
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun	move	a0, zero		# a0 <-- boot_flags = 0
276*4882a593Smuzhiyun	PTR_LA	t9, board_init_f
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun	jr	t9
279*4882a593Smuzhiyun	 move	ra, zero
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun	END(_start)
282