2 * Startup Code for MIPS32 XBURST CPU-core
4 * Copyright (c) 2010 Xiangfu Liu <xiangfu@sharism.cc>
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <asm/regdef.h>
28 #include <asm/mipsregs.h>
29 #include <asm/addrspace.h>
30 #include <asm/cacheops.h>
44 /* Set up temporary stack */
45 li sp, CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET
52 * void relocate_code (addr_sp, gd, addr_moni)
54 * This "function" does not return, instead it continues in RAM
55 * after relocating the monitor code.
59 * a2 = destination address
64 move sp, a0 # set new stack pointer
66 li t0, CONFIG_SYS_MONITOR_BASE
68 lw t2, -12(t3) # t2 <-- uboot_end_data
74 * New $gp = (Old $gp - CONFIG_SYS_MONITOR_BASE) + Destination Address
77 sub gp, CONFIG_SYS_MONITOR_BASE
78 add gp, a2 # gp now adjusted
79 sub t6, gp, t6 # t6 <-- relocation offset
84 * t2 = source end address
93 /* If caches were enabled, we would have to flush them here. */
97 addi t1, t0, CONFIG_SYS_DCACHE_SIZE
99 cache Index_Writeback_Inv_D, 0(t0)
101 addi t0, CONFIG_SYS_CACHELINE_SIZE
107 addi t1, t0, CONFIG_SYS_ICACHE_SIZE
109 cache Index_Invalidate_I, 0(t0)
111 addi t0, CONFIG_SYS_CACHELINE_SIZE
114 mfc0 t0, CP0_CONFIG, 7
117 mtc0 t0, CP0_CONFIG, 7
120 /* Jump to where we've relocated ourselves */
121 addi t0, a2, in_ram - _start
126 .word _GLOBAL_OFFSET_TABLE_
129 .word num_got_entries
133 * Now we want to update GOT.
135 * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
136 * generated by GNU ld. Skip these reserved entries from relocation.
138 lw t3, -4(t0) # t3 <-- num_got_entries
139 lw t4, -16(t0) # t4 <-- _GLOBAL_OFFSET_TABLE_
140 lw t5, -20(t0) # t5 <-- _gp
141 sub t4, t5 # compute offset
142 add t4, t4, gp # t4 now holds relocated _G_O_T_
143 addi t4, t4, 8 # skipping first two entries
156 lw t1, -12(t0) # t1 <-- uboot_end_data
157 lw t2, -8(t0) # t2 <-- uboot_end
158 add t1, t6 # adjust pointers
166 move a0, a1 # a0 <-- gd