2 * Startup Code for MIPS32 XBURST CPU-core
4 * Copyright (c) 2010 Xiangfu Liu <xiangfu@sharism.cc>
6 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/regdef.h>
12 #include <asm/mipsregs.h>
13 #include <asm/addrspace.h>
14 #include <asm/cacheops.h>
28 /* Set up temporary stack */
29 li sp, CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET
36 * void relocate_code (addr_sp, gd, addr_moni)
38 * This "function" does not return, instead it continues in RAM
39 * after relocating the monitor code.
43 * a2 = destination address
48 move sp, a0 # set new stack pointer
50 move s0, a1 # save gd in s0
51 move s2, a2 # save destination address in s2
53 li t0, CONFIG_SYS_MONITOR_BASE
54 sub s1, s2, t0 # s1 <-- relocation offset
57 lw t2, -12(t3) # t2 <-- __image_copy_end
60 add gp, s1 # adjust gp
65 * t2 = source end address
74 /* If caches were enabled, we would have to flush them here. */
78 addi t1, t0, CONFIG_SYS_DCACHE_SIZE
80 cache INDEX_WRITEBACK_INV_D, 0(t0)
82 addi t0, CONFIG_SYS_CACHELINE_SIZE
88 addi t1, t0, CONFIG_SYS_ICACHE_SIZE
90 cache INDEX_INVALIDATE_I, 0(t0)
92 addi t0, CONFIG_SYS_CACHELINE_SIZE
95 mfc0 t0, CP0_CONFIG, 7
98 mtc0 t0, CP0_CONFIG, 7
101 /* Jump to where we've relocated ourselves */
102 addi t0, s2, in_ram - _start
107 .word __rel_dyn_start
108 .word __image_copy_end
109 .word _GLOBAL_OFFSET_TABLE_
110 .word num_got_entries
114 * Now we want to update GOT.
116 * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
117 * generated by GNU ld. Skip these reserved entries from relocation.
119 lw t3, -4(t0) # t3 <-- num_got_entries
120 lw t8, -8(t0) # t8 <-- _GLOBAL_OFFSET_TABLE_
121 add t8, s1 # t8 now holds relocated _G_O_T_
122 addi t8, t8, 8 # skipping first two entries
134 /* Update dynamic relocations */
135 lw t1, -16(t0) # t1 <-- __rel_dyn_start
136 lw t2, -20(t0) # t2 <-- __rel_dyn_end
138 b 2f # skip first reserved entry
142 lw t3, -4(t1) # t3 <-- relocation info
145 bnez t3, 2f # skip non R_MIPS_REL32 entries
148 lw t3, -8(t1) # t3 <-- location to fix up in FLASH
150 lw t8, 0(t3) # t8 <-- original pointer
151 add t8, s1 # t8 <-- adjusted pointer
153 add t3, s1 # t3 <-- location to fix up in RAM
158 addi t1, 8 # each rel.dyn entry is 8 bytes
163 * GOT is now relocated. Thus __bss_start and __bss_end can be
164 * accessed directly via $gp.
166 la t1, __bss_start # t1 <-- __bss_start
167 la t2, __bss_end # t2 <-- __bss_end
174 move a0, s0 # a0 <-- gd