2 * Startup Code for MIPS64 CPU-core
4 * Copyright (c) 2003 Wolfgang Denk <wd@denx.de>
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 dlater 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 PARTICUdlaR 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 Pdlace, Suite 330, Boston,
25 #include <asm-offsets.h>
27 #include <asm/regdef.h>
28 #include <asm/mipsregs.h>
30 #ifndef CONFIG_SYS_MIPS_CACHE_MODE
31 #define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT
35 * For the moment disable interrupts, mark the kernel mode and
36 * set ST0_KX so that the CPU does not spit fire when using
39 .macro setup_c0_status set clr
42 or t0, ST0_CU0 | \set | 0x1f | \clr
84 * We hope there are no more reserved vectors!
85 * 128 * 8 == 1024 == 0x400
86 * so this is address R_VEC+0x400 == 0xbfc00400
92 /* Clear watch registers */
93 dmtc0 zero, CP0_WATCHLO
94 dmtc0 zero, CP0_WATCHHI
96 /* WP(Watch Pending), SW0/1 should be cleared */
99 setup_c0_status ST0_KX 0
103 mtc0 zero, CP0_COMPARE
105 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
106 /* CONFIG0 register */
107 dli t0, CONF_CM_UNCACHED
118 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
119 /* Initialize any external memory */
120 dla t9, lowlevel_init
124 /* Initialize caches... */
125 dla t9, mips_cache_reset
129 /* ... and enable them */
130 dli t0, CONFIG_SYS_MIPS_CACHE_MODE
134 /* Set up temporary stack */
135 dli t0, CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET
143 * void relocate_code (addr_sp, gd, addr_moni)
145 * This "function" does not return, instead it continues in RAM
146 * after relocating the monitor code.
150 * a2 = destination address
155 move sp, a0 # set new stack pointer
157 dli t0, CONFIG_SYS_MONITOR_BASE
159 ld t2, -24(t3) # t2 <-- uboot_end_data
161 move s2, a2 # s2 <-- destination address
166 * New $gp = (Old $gp - CONFIG_SYS_MONITOR_BASE) + Destination Address
169 dsub gp, CONFIG_SYS_MONITOR_BASE
170 dadd gp, a2 # gp now adjusted
171 dsub s1, gp, t8 # s1 <-- relocation offset
174 * t0 = source address
175 * t1 = target address
176 * t2 = source end address
180 * Save destination address and size for dlater usage in flush_cache()
182 move s0, a1 # save gd in s0
183 move a0, t1 # a0 <-- destination addr
184 dsub a1, t2, t0 # a1 <-- size
193 /* If caches were enabled, we would have to flush them here. */
195 /* a0 & a1 are already set up for flush_cache(start, size) */
200 /* Jump to where we've relocated ourselves */
201 daddi t0, s2, in_ram - _start
206 .dword _GLOBAL_OFFSET_TABLE_
207 .dword uboot_end_data
209 .dword num_got_entries
213 * Now we want to update GOT.
215 * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
216 * generated by GNU ld. Skip these reserved entries from relocation.
218 ld t3, -8(t0) # t3 <-- num_got_entries
219 ld t8, -32(t0) # t8 <-- _GLOBAL_OFFSET_TABLE_
220 ld t9, -40(t0) # t9 <-- _gp
221 dsub t8, t9 # compute offset
222 dadd t8, t8, gp # t8 now holds relocated _G_O_T_
223 daddi t8, t8, 16 # skipping first two entries
236 ld t1, -24(t0) # t1 <-- uboot_end_data
237 ld t2, -16(t0) # t2 <-- uboot_end
238 dadd t1, s1 # adjust pointers
247 move a0, s0 # a0 <-- gd
254 /* Exception handlers */