1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Startup Code for MIPS32 CPU-core
5 * Copyright (c) 2003 Wolfgang Denk <wd@denx.de>
8 #include <asm-offsets.h>
11 #include <asm/regdef.h>
12 #include <asm/mipsregs.h>
13 #include <system-constants.h>
20 # define STATUS_SET ST0_KX
26 MTC0 zero, CP0_WATCHLO,\sel
27 mtc0 t1, CP0_WATCHHI,\sel
28 mfc0 t0, CP0_WATCHHI,\sel
33 .macro uhi_mips_exception
34 move k0, t9 # preserve t9 in k0
35 move k1, a0 # preserve a0 in k1
36 li t9, 15 # UHI exception operation
37 li a0, 0 # Use hard register context
38 sdbbp 1 # Invoke UHI operation
43 PTR_LI t1, SYS_INIT_SP_ADDR
44 and sp, t1, t0 # force 16 byte alignment
46 sp, sp, GD_SIZE # reserve space for gd
47 and sp, sp, t0 # force 16 byte alignment
48 move k0, sp # save gd pointer
49 #if CONFIG_VAL(SYS_MALLOC_F_LEN) && \
50 !CONFIG_IS_ENABLED(INIT_STACK_WITHOUT_MALLOC_F)
51 li t2, CONFIG_VAL(SYS_MALLOC_F_LEN)
53 sp, sp, t2 # reserve space for early malloc
54 and sp, sp, t0 # force 16 byte alignment
66 #if CONFIG_VAL(SYS_MALLOC_F_LEN) && \
67 !CONFIG_IS_ENABLED(INIT_STACK_WITHOUT_MALLOC_F)
68 PTR_S sp, GD_MALLOC_BASE(k0) # gd->malloc_base offset
75 * Do not add instructions to the branch delay slot! Some SoC's
76 * like Octeon might patch the final U-Boot binary at this location
77 * with additional boot headers.
82 #if defined(CONFIG_MIPS_INSERT_BOOT_CONFIG)
84 * Store some board-specific boot configuration. This is used by some
85 * MIPS systems like Malta.
88 .word CONFIG_MIPS_BOOT_CONFIG_WORD0
89 .word CONFIG_MIPS_BOOT_CONFIG_WORD1
92 #if defined(CONFIG_ROM_EXCEPTION_VECTORS)
94 * Exception vector entry points. When running from ROM, an exception
95 * cannot be handled. Halt execution and transfer control to debugger,
99 /* TLB refill, 32 bit task */
103 /* XTLB refill, 64 bit task */
107 /* Cache error exception */
111 /* General exception */
115 /* Catch interrupt exceptions */
119 /* EJTAG debug exception */
127 mtc0 zero, CP0_COUNT # clear cp0 count for most accurate boot timing
128 #if __mips_isa_rev >= 6
129 mfc0 t0, CP0_CONFIG, 5
130 and t0, t0, MIPS_CONF5_VP
135 mfc0 t0, CP0_GLOBALNUMBER
138 #ifdef CONFIG_ARCH_BMIPS
139 1: mfc0 t0, CP0_DIAGNOSTIC, 3
140 and t0, t0, (1 << 31)
142 1: mfc0 t0, CP0_EBASE
143 and t0, t0, MIPS_EBASE_CPUNUM
146 /* Hang if this isn't the first CPU in the system */
153 /* Init CP0 Status */
154 4: mfc0 t0, CP0_STATUS
156 or t0, ST0_BEV | ST0_ERL | STATUS_SET
160 * Check whether CP0 Config1 is implemented. If not continue
161 * with legacy Watch register initialization.
168 * Check WR bit in CP0 Config1 to determine if Watch registers
171 mfc0 t0, CP0_CONFIG, 1
176 /* Clear Watch Status bits and disable watch exceptions */
177 li t1, 0x7 # Clear I, R and W conditions
190 MTC0 zero, CP0_WATCHLO
191 mtc0 zero, CP0_WATCHHI
194 /* Clear WP, IV and SW interrupts */
197 /* Clear timer interrupt (CP0_COUNT cleared on branch to 'reset') */
198 mtc0 zero, CP0_COMPARE
200 #ifdef CONFIG_MIPS_CACHE_DISABLE
202 PTR_LA t9, mips_cache_disable
207 #ifdef CONFIG_MIPS_CM
208 PTR_LA t9, mips_cm_map
213 #ifdef CONFIG_MIPS_INIT_STACK_IN_SRAM
214 #ifdef CONFIG_MIPS_SRAM_INIT
215 /* Initialize the SRAM first */
216 PTR_LA t9, mips_sram_init
221 /* Set up initial stack and global data */
224 # ifdef CONFIG_DEBUG_UART
225 /* Earliest point to set up debug uart */
226 PTR_LA t9, debug_uart_init
232 #if !CONFIG_IS_ENABLED(SKIP_LOWLEVEL_INIT)
233 # ifdef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD
234 /* Initialize any external memory */
235 PTR_LA t9, lowlevel_init
241 #ifdef CONFIG_MIPS_MACH_EARLY_INIT
242 bal mips_mach_early_init
246 #ifdef CONFIG_MIPS_CACHE_SETUP
247 /* Initialize caches... */
248 PTR_LA t9, mips_cache_reset
253 #if !CONFIG_IS_ENABLED(SKIP_LOWLEVEL_INIT)
254 # ifndef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD
255 /* Initialize any external memory */
256 PTR_LA t9, lowlevel_init
262 #ifndef CONFIG_MIPS_INIT_STACK_IN_SRAM
263 /* Set up initial stack and global data */
266 # ifdef CONFIG_DEBUG_UART
267 /* Earliest point to set up debug uart */
268 PTR_LA t9, debug_uart_init
274 move a0, zero # a0 <-- boot_flags = 0
275 PTR_LA t9, board_init_f