blob: cd8b914da317248a6bd9f4bf1d9d5e37a3f5eed1 [file] [log] [blame]
wdenkbb1b8262003-03-27 12:09:35 +00001/*
2 * Startup Code for MIPS32 CPU-core
3 *
4 * Copyright (c) 2003 Wolfgang Denk <wd@denx.de>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
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.
13 *
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.
18 *
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,
22 * MA 02111-1307 USA
23 */
24
Wolfgang Denk0191e472010-10-26 14:34:52 +020025#include <asm-offsets.h>
wdenkbb1b8262003-03-27 12:09:35 +000026#include <config.h>
wdenkbb1b8262003-03-27 12:09:35 +000027#include <asm/regdef.h>
28#include <asm/mipsregs.h>
29
Daniel Schwierzeck7dc16be2011-07-27 13:22:38 +020030#ifndef CONFIG_SYS_MIPS_CACHE_MODE
31#define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT
32#endif
33
Shinya Kuribayashi2300af12008-03-25 21:30:07 +090034 /*
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
37 * 64-bit addresses.
38 */
39 .macro setup_c0_status set clr
40 .set push
41 mfc0 t0, CP0_STATUS
42 or t0, ST0_CU0 | \set | 0x1f | \clr
43 xor t0, 0x1f | \clr
44 mtc0 t0, CP0_STATUS
45 .set noreorder
46 sll zero, 3 # ehb
47 .set pop
48 .endm
49
wdenkbb1b8262003-03-27 12:09:35 +000050 .set noreorder
51
52 .globl _start
53 .text
54_start:
Daniel Schwierzeckec443162013-02-12 22:22:12 +010055 /* U-boot entry point */
56 b reset
57 nop
58
59 .org 0x10
Daniel Schwierzeck6ff8ae02011-07-27 13:22:37 +020060#ifdef CONFIG_SYS_XWAY_EBU_BOOTCFG
61 /*
62 * Almost all Lantiq XWAY SoC devices have an external bus unit (EBU) to
63 * access external NOR flashes. If the board boots from NOR flash the
64 * internal BootROM does a blind read at address 0xB0000010 to read the
65 * initial configuration for that EBU in order to access the flash
66 * device with correct parameters. This config option is board-specific.
67 */
68 .word CONFIG_SYS_XWAY_EBU_BOOTCFG
Daniel Schwierzeckec443162013-02-12 22:22:12 +010069 .word 0x0
wdenkbb1b8262003-03-27 12:09:35 +000070#endif
wdenk57b2d802003-06-27 21:31:46 +000071
Daniel Schwierzeckec443162013-02-12 22:22:12 +010072 .org 0x200
73 /* TLB refill, 32 bit task */
741: b 1b
75 nop
76
77 .org 0x280
78 /* XTLB refill, 64 bit task */
791: b 1b
80 nop
81
82 .org 0x300
83 /* Cache error exception */
841: b 1b
85 nop
86
87 .org 0x380
88 /* General exception */
891: b 1b
90 nop
91
92 .org 0x400
93 /* Catch interrupt exceptions */
941: b 1b
95 nop
96
97 .org 0x480
98 /* EJTAG debug exception */
991: b 1b
100 nop
101
wdenkbb1b8262003-03-27 12:09:35 +0000102 .align 4
103reset:
104
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900105 /* Clear watch registers */
wdenkbb1b8262003-03-27 12:09:35 +0000106 mtc0 zero, CP0_WATCHLO
107 mtc0 zero, CP0_WATCHHI
108
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900109 /* WP(Watch Pending), SW0/1 should be cleared */
Shinya Kuribayashi79727f82008-03-25 21:30:07 +0900110 mtc0 zero, CP0_CAUSE
111
Daniel Schwierzeck7e446142013-02-12 22:22:12 +0100112 setup_c0_status 0 0
wdenkbb1b8262003-03-27 12:09:35 +0000113
wdenkbb1b8262003-03-27 12:09:35 +0000114 /* Init Timer */
115 mtc0 zero, CP0_COUNT
116 mtc0 zero, CP0_COMPARE
117
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900118#ifndef CONFIG_SKIP_LOWLEVEL_INIT
wdenkbb1b8262003-03-27 12:09:35 +0000119 /* CONFIG0 register */
120 li t0, CONF_CM_UNCACHED
121 mtc0 t0, CP0_CONFIG
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900122#endif
wdenkbb1b8262003-03-27 12:09:35 +0000123
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900124 /* Initialize $gp */
Shinya Kuribayashic7faac52007-10-27 15:27:06 +0900125 bal 1f
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900126 nop
Shinya Kuribayashi7cb56762007-10-21 10:55:36 +0900127 .word _gp
Shinya Kuribayashic7faac52007-10-27 15:27:06 +09001281:
Shinya Kuribayashiec655bd2007-11-17 20:05:26 +0900129 lw gp, 0(ra)
Wolfgang Denk117b0b12005-12-01 02:15:07 +0100130
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900131#ifndef CONFIG_SKIP_LOWLEVEL_INIT
132 /* Initialize any external memory */
Shinya Kuribayashic7faac52007-10-27 15:27:06 +0900133 la t9, lowlevel_init
134 jalr t9
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900135 nop
wdenkbb1b8262003-03-27 12:09:35 +0000136
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900137 /* Initialize caches... */
Shinya Kuribayashic7faac52007-10-27 15:27:06 +0900138 la t9, mips_cache_reset
139 jalr t9
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900140 nop
wdenkbb1b8262003-03-27 12:09:35 +0000141
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900142 /* ... and enable them */
Daniel Schwierzeck7dc16be2011-07-27 13:22:38 +0200143 li t0, CONFIG_SYS_MIPS_CACHE_MODE
wdenkbb1b8262003-03-27 12:09:35 +0000144 mtc0 t0, CP0_CONFIG
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900145#endif
wdenkbb1b8262003-03-27 12:09:35 +0000146
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900147 /* Set up temporary stack */
Gabor Juhosd9bcb6c2013-01-24 06:27:52 +0000148 li sp, CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET
wdenkbb1b8262003-03-27 12:09:35 +0000149
wdenkbb1b8262003-03-27 12:09:35 +0000150 la t9, board_init_f
Shinya Kuribayashi9dabea12008-04-17 23:35:13 +0900151 jr t9
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900152 nop
wdenkbb1b8262003-03-27 12:09:35 +0000153
wdenkbb1b8262003-03-27 12:09:35 +0000154/*
155 * void relocate_code (addr_sp, gd, addr_moni)
156 *
157 * This "function" does not return, instead it continues in RAM
158 * after relocating the monitor code.
159 *
160 * a0 = addr_sp
161 * a1 = gd
162 * a2 = destination address
163 */
164 .globl relocate_code
165 .ent relocate_code
166relocate_code:
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900167 move sp, a0 # set new stack pointer
wdenkbb1b8262003-03-27 12:09:35 +0000168
Gabor Juhosf902d462013-01-24 06:27:53 +0000169 move s0, a1 # save gd in s0
170 move s2, a2 # save destination address in s2
171
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200172 li t0, CONFIG_SYS_MONITOR_BASE
Gabor Juhosfac2f652013-01-24 06:27:54 +0000173 sub s1, s2, t0 # s1 <-- relocation offset
174
wdenk874ac262003-07-24 23:38:38 +0000175 la t3, in_ram
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900176 lw t2, -12(t3) # t2 <-- uboot_end_data
wdenk874ac262003-07-24 23:38:38 +0000177 move t1, a2
178
Gabor Juhosfac2f652013-01-24 06:27:54 +0000179 add gp, s1 # adjust gp
wdenk57b2d802003-06-27 21:31:46 +0000180
wdenkbb1b8262003-03-27 12:09:35 +0000181 /*
182 * t0 = source address
183 * t1 = target address
184 * t2 = source end address
185 */
1861:
187 lw t3, 0(t0)
188 sw t3, 0(t1)
189 addu t0, 4
Gabor Juhos9a081ab2013-01-24 06:27:51 +0000190 blt t0, t2, 1b
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900191 addu t1, 4
wdenkbb1b8262003-03-27 12:09:35 +0000192
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900193 /* If caches were enabled, we would have to flush them here. */
Gabor Juhoseb590242013-01-24 06:27:55 +0000194 sub a1, t1, s2 # a1 <-- size
Stefan Roeseaed3f502008-11-18 16:36:12 +0100195 la t9, flush_cache
196 jalr t9
Gabor Juhoseb590242013-01-24 06:27:55 +0000197 move a0, s2 # a0 <-- destination address
Stefan Roeseaed3f502008-11-18 16:36:12 +0100198
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900199 /* Jump to where we've relocated ourselves */
Stefan Roeseaed3f502008-11-18 16:36:12 +0100200 addi t0, s2, in_ram - _start
Shinya Kuribayashi9dabea12008-04-17 23:35:13 +0900201 jr t0
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900202 nop
wdenkbb1b8262003-03-27 12:09:35 +0000203
Vlad Lungu82809fa2008-05-05 14:04:00 +0300204 .word _GLOBAL_OFFSET_TABLE_
wdenkbb1b8262003-03-27 12:09:35 +0000205 .word uboot_end_data
206 .word uboot_end
207 .word num_got_entries
208
209in_ram:
Shinya Kuribayashi7cb56762007-10-21 10:55:36 +0900210 /*
211 * Now we want to update GOT.
212 *
213 * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
214 * generated by GNU ld. Skip these reserved entries from relocation.
wdenkbb1b8262003-03-27 12:09:35 +0000215 */
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900216 lw t3, -4(t0) # t3 <-- num_got_entries
217 lw t4, -16(t0) # t4 <-- _GLOBAL_OFFSET_TABLE_
Gabor Juhosbc18d0b2013-01-30 04:56:37 +0000218 add t4, s1 # t4 now holds relocated _G_O_T_
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900219 addi t4, t4, 8 # skipping first two entries
wdenkbb1b8262003-03-27 12:09:35 +0000220 li t2, 2
2211:
222 lw t1, 0(t4)
223 beqz t1, 2f
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900224 add t1, s1
wdenkbb1b8262003-03-27 12:09:35 +0000225 sw t1, 0(t4)
2262:
227 addi t2, 1
228 blt t2, t3, 1b
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900229 addi t4, 4
wdenkbb1b8262003-03-27 12:09:35 +0000230
Daniel Schwierzeck0de9cc52013-02-12 22:22:13 +0100231 /*
232 * Clear BSS
233 *
234 * GOT is now relocated. Thus __bss_start and __bss_end can be
235 * accessed directly via $gp.
236 */
237 la t1, __bss_start # t1 <-- __bss_start
238 la t2, __bss_end # t2 <-- __bss_end
wdenkbb1b8262003-03-27 12:09:35 +0000239
Shinya Kuribayashic7faac52007-10-27 15:27:06 +09002401:
Daniel Schwierzeck0de9cc52013-02-12 22:22:13 +0100241 sw zero, 0(t1)
242 blt t1, t2, 1b
243 addi t1, 4
wdenk57b2d802003-06-27 21:31:46 +0000244
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900245 move a0, s0 # a0 <-- gd
wdenkbb1b8262003-03-27 12:09:35 +0000246 la t9, board_init_r
Shinya Kuribayashi9dabea12008-04-17 23:35:13 +0900247 jr t9
Shinya Kuribayashi6911d0a2011-05-07 00:18:13 +0900248 move a1, s2
wdenkbb1b8262003-03-27 12:09:35 +0000249
250 .end relocate_code