2 * Startup Code for MIPS32 CPU-core
4 * Copyright (c) 2003 Wolfgang Denk <wd@denx.de>
6 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm-offsets.h>
11 #include <asm/regdef.h>
12 #include <asm/mipsregs.h>
14 #ifndef CONFIG_SYS_MIPS_CACHE_MODE
15 #define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT
18 #ifndef CONFIG_SYS_INIT_SP_ADDR
19 #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + \
20 CONFIG_SYS_INIT_SP_OFFSET)
24 * For the moment disable interrupts, mark the kernel mode and
25 * set ST0_KX so that the CPU does not spit fire when using
28 .macro setup_c0_status set clr
31 or t0, ST0_CU0 | \set | 0x1f | \clr
44 /* U-boot entry point */
49 #if defined(CONFIG_SYS_XWAY_EBU_BOOTCFG)
51 * Almost all Lantiq XWAY SoC devices have an external bus unit (EBU) to
52 * access external NOR flashes. If the board boots from NOR flash the
53 * internal BootROM does a blind read at address 0xB0000010 to read the
54 * initial configuration for that EBU in order to access the flash
55 * device with correct parameters. This config option is board-specific.
57 .word CONFIG_SYS_XWAY_EBU_BOOTCFG
59 #elif defined(CONFIG_MALTA)
61 * Linux expects the Board ID here.
63 .word 0x00000420 # 0x420 (Malta Board with CoreLV)
68 /* TLB refill, 32 bit task */
73 /* XTLB refill, 64 bit task */
78 /* Cache error exception */
83 /* General exception */
88 /* Catch interrupt exceptions */
93 /* EJTAG debug exception */
100 /* Clear watch registers */
101 mtc0 zero, CP0_WATCHLO
102 mtc0 zero, CP0_WATCHHI
104 /* WP(Watch Pending), SW0/1 should be cleared */
111 mtc0 zero, CP0_COMPARE
113 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
114 /* CONFIG0 register */
115 li t0, CONF_CM_UNCACHED
126 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
127 /* Initialize any external memory */
132 /* Initialize caches... */
133 la t9, mips_cache_reset
137 /* ... and enable them */
138 li t0, CONFIG_SYS_MIPS_CACHE_MODE
142 /* Set up temporary stack */
144 li t1, CONFIG_SYS_INIT_SP_ADDR
145 and sp, t1, t0 # force 16 byte alignment
146 sub sp, sp, GD_SIZE # reserve space for gd
147 and sp, sp, t0 # force 16 byte alignment
148 move k0, sp # save gd pointer
149 #ifdef CONFIG_SYS_MALLOC_F_LEN
150 li t2, CONFIG_SYS_MALLOC_F_LEN
151 sub sp, sp, t2 # reserve space for early malloc
152 and sp, sp, t0 # force 16 byte alignment
163 #ifdef CONFIG_SYS_MALLOC_F_LEN
164 addu t0, k0, GD_MALLOC_BASE # gd->malloc_base offset
173 * void relocate_code (addr_sp, gd, addr_moni)
175 * This "function" does not return, instead it continues in RAM
176 * after relocating the monitor code.
180 * a2 = destination address
185 move sp, a0 # set new stack pointer
188 move s0, a1 # save gd in s0
189 move s2, a2 # save destination address in s2
191 li t0, CONFIG_SYS_MONITOR_BASE
192 sub s1, s2, t0 # s1 <-- relocation offset
195 lw t2, -12(t3) # t2 <-- __image_copy_end
198 add gp, s1 # adjust gp
201 * t0 = source address
202 * t1 = target address
203 * t2 = source end address
212 /* If caches were enabled, we would have to flush them here. */
213 sub a1, t1, s2 # a1 <-- size
216 move a0, s2 # a0 <-- destination address
218 /* Jump to where we've relocated ourselves */
219 addi t0, s2, in_ram - _start
224 .word __rel_dyn_start
225 .word __image_copy_end
226 .word _GLOBAL_OFFSET_TABLE_
227 .word num_got_entries
231 * Now we want to update GOT.
233 * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
234 * generated by GNU ld. Skip these reserved entries from relocation.
236 lw t3, -4(t0) # t3 <-- num_got_entries
237 lw t8, -8(t0) # t8 <-- _GLOBAL_OFFSET_TABLE_
238 add t8, s1 # t8 now holds relocated _G_O_T_
239 addi t8, t8, 8 # skipping first two entries
251 /* Update dynamic relocations */
252 lw t1, -16(t0) # t1 <-- __rel_dyn_start
253 lw t2, -20(t0) # t2 <-- __rel_dyn_end
255 b 2f # skip first reserved entry
259 lw t8, -4(t1) # t8 <-- relocation info
262 bne t8, t3, 2f # skip non R_MIPS_REL32 entries
265 lw t3, -8(t1) # t3 <-- location to fix up in FLASH
267 lw t8, 0(t3) # t8 <-- original pointer
268 add t8, s1 # t8 <-- adjusted pointer
270 add t3, s1 # t3 <-- location to fix up in RAM
275 addi t1, 8 # each rel.dyn entry is 8 bytes
280 * GOT is now relocated. Thus __bss_start and __bss_end can be
281 * accessed directly via $gp.
283 la t1, __bss_start # t1 <-- __bss_start
284 la t2, __bss_end # t2 <-- __bss_end
291 move a0, s0 # a0 <-- gd