wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 1 | /* |
| 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 Denk | 0191e47 | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 25 | #include <asm-offsets.h> |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 26 | #include <config.h> |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 27 | #include <asm/regdef.h> |
| 28 | #include <asm/mipsregs.h> |
| 29 | |
Daniel Schwierzeck | 7dc16be | 2011-07-27 13:22:38 +0200 | [diff] [blame] | 30 | #ifndef CONFIG_SYS_MIPS_CACHE_MODE |
| 31 | #define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT |
| 32 | #endif |
| 33 | |
Shinya Kuribayashi | 2300af1 | 2008-03-25 21:30:07 +0900 | [diff] [blame] | 34 | /* |
| 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 | |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 50 | .set noreorder |
| 51 | |
| 52 | .globl _start |
| 53 | .text |
| 54 | _start: |
Daniel Schwierzeck | ec44316 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 55 | /* U-boot entry point */ |
| 56 | b reset |
| 57 | nop |
| 58 | |
| 59 | .org 0x10 |
Daniel Schwierzeck | 6ff8ae0 | 2011-07-27 13:22:37 +0200 | [diff] [blame] | 60 | #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 Schwierzeck | ec44316 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 69 | .word 0x0 |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 70 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 71 | |
Daniel Schwierzeck | ec44316 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 72 | .org 0x200 |
| 73 | /* TLB refill, 32 bit task */ |
| 74 | 1: b 1b |
| 75 | nop |
| 76 | |
| 77 | .org 0x280 |
| 78 | /* XTLB refill, 64 bit task */ |
| 79 | 1: b 1b |
| 80 | nop |
| 81 | |
| 82 | .org 0x300 |
| 83 | /* Cache error exception */ |
| 84 | 1: b 1b |
| 85 | nop |
| 86 | |
| 87 | .org 0x380 |
| 88 | /* General exception */ |
| 89 | 1: b 1b |
| 90 | nop |
| 91 | |
| 92 | .org 0x400 |
| 93 | /* Catch interrupt exceptions */ |
| 94 | 1: b 1b |
| 95 | nop |
| 96 | |
| 97 | .org 0x480 |
| 98 | /* EJTAG debug exception */ |
| 99 | 1: b 1b |
| 100 | nop |
| 101 | |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 102 | .align 4 |
| 103 | reset: |
| 104 | |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 105 | /* Clear watch registers */ |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 106 | mtc0 zero, CP0_WATCHLO |
| 107 | mtc0 zero, CP0_WATCHHI |
| 108 | |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 109 | /* WP(Watch Pending), SW0/1 should be cleared */ |
Shinya Kuribayashi | 79727f8 | 2008-03-25 21:30:07 +0900 | [diff] [blame] | 110 | mtc0 zero, CP0_CAUSE |
| 111 | |
Daniel Schwierzeck | 7e44614 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 112 | setup_c0_status 0 0 |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 113 | |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 114 | /* Init Timer */ |
| 115 | mtc0 zero, CP0_COUNT |
| 116 | mtc0 zero, CP0_COMPARE |
| 117 | |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 118 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 119 | /* CONFIG0 register */ |
| 120 | li t0, CONF_CM_UNCACHED |
| 121 | mtc0 t0, CP0_CONFIG |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 122 | #endif |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 123 | |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 124 | /* Initialize $gp */ |
Shinya Kuribayashi | c7faac5 | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 125 | bal 1f |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 126 | nop |
Shinya Kuribayashi | 7cb5676 | 2007-10-21 10:55:36 +0900 | [diff] [blame] | 127 | .word _gp |
Shinya Kuribayashi | c7faac5 | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 128 | 1: |
Shinya Kuribayashi | ec655bd | 2007-11-17 20:05:26 +0900 | [diff] [blame] | 129 | lw gp, 0(ra) |
Wolfgang Denk | 117b0b1 | 2005-12-01 02:15:07 +0100 | [diff] [blame] | 130 | |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 131 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
| 132 | /* Initialize any external memory */ |
Shinya Kuribayashi | c7faac5 | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 133 | la t9, lowlevel_init |
| 134 | jalr t9 |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 135 | nop |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 136 | |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 137 | /* Initialize caches... */ |
Shinya Kuribayashi | c7faac5 | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 138 | la t9, mips_cache_reset |
| 139 | jalr t9 |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 140 | nop |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 141 | |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 142 | /* ... and enable them */ |
Daniel Schwierzeck | 7dc16be | 2011-07-27 13:22:38 +0200 | [diff] [blame] | 143 | li t0, CONFIG_SYS_MIPS_CACHE_MODE |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 144 | mtc0 t0, CP0_CONFIG |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 145 | #endif |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 146 | |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 147 | /* Set up temporary stack */ |
Gabor Juhos | d9bcb6c | 2013-01-24 06:27:52 +0000 | [diff] [blame] | 148 | li sp, CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 149 | |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 150 | la t9, board_init_f |
Shinya Kuribayashi | 9dabea1 | 2008-04-17 23:35:13 +0900 | [diff] [blame] | 151 | jr t9 |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 152 | nop |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 153 | |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 154 | /* |
| 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 |
| 166 | relocate_code: |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 167 | move sp, a0 # set new stack pointer |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 168 | |
Gabor Juhos | f902d46 | 2013-01-24 06:27:53 +0000 | [diff] [blame] | 169 | move s0, a1 # save gd in s0 |
| 170 | move s2, a2 # save destination address in s2 |
| 171 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 172 | li t0, CONFIG_SYS_MONITOR_BASE |
Gabor Juhos | fac2f65 | 2013-01-24 06:27:54 +0000 | [diff] [blame] | 173 | sub s1, s2, t0 # s1 <-- relocation offset |
| 174 | |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 175 | la t3, in_ram |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 176 | lw t2, -12(t3) # t2 <-- uboot_end_data |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 177 | move t1, a2 |
| 178 | |
Gabor Juhos | fac2f65 | 2013-01-24 06:27:54 +0000 | [diff] [blame] | 179 | add gp, s1 # adjust gp |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 180 | |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 181 | /* |
| 182 | * t0 = source address |
| 183 | * t1 = target address |
| 184 | * t2 = source end address |
| 185 | */ |
| 186 | 1: |
| 187 | lw t3, 0(t0) |
| 188 | sw t3, 0(t1) |
| 189 | addu t0, 4 |
Gabor Juhos | 9a081ab | 2013-01-24 06:27:51 +0000 | [diff] [blame] | 190 | blt t0, t2, 1b |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 191 | addu t1, 4 |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 192 | |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 193 | /* If caches were enabled, we would have to flush them here. */ |
Gabor Juhos | eb59024 | 2013-01-24 06:27:55 +0000 | [diff] [blame] | 194 | sub a1, t1, s2 # a1 <-- size |
Stefan Roese | aed3f50 | 2008-11-18 16:36:12 +0100 | [diff] [blame] | 195 | la t9, flush_cache |
| 196 | jalr t9 |
Gabor Juhos | eb59024 | 2013-01-24 06:27:55 +0000 | [diff] [blame] | 197 | move a0, s2 # a0 <-- destination address |
Stefan Roese | aed3f50 | 2008-11-18 16:36:12 +0100 | [diff] [blame] | 198 | |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 199 | /* Jump to where we've relocated ourselves */ |
Stefan Roese | aed3f50 | 2008-11-18 16:36:12 +0100 | [diff] [blame] | 200 | addi t0, s2, in_ram - _start |
Shinya Kuribayashi | 9dabea1 | 2008-04-17 23:35:13 +0900 | [diff] [blame] | 201 | jr t0 |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 202 | nop |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 203 | |
Vlad Lungu | 82809fa | 2008-05-05 14:04:00 +0300 | [diff] [blame] | 204 | .word _GLOBAL_OFFSET_TABLE_ |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 205 | .word uboot_end_data |
| 206 | .word uboot_end |
| 207 | .word num_got_entries |
| 208 | |
| 209 | in_ram: |
Shinya Kuribayashi | 7cb5676 | 2007-10-21 10:55:36 +0900 | [diff] [blame] | 210 | /* |
| 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. |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 215 | */ |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 216 | lw t3, -4(t0) # t3 <-- num_got_entries |
| 217 | lw t4, -16(t0) # t4 <-- _GLOBAL_OFFSET_TABLE_ |
Gabor Juhos | bc18d0b | 2013-01-30 04:56:37 +0000 | [diff] [blame] | 218 | add t4, s1 # t4 now holds relocated _G_O_T_ |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 219 | addi t4, t4, 8 # skipping first two entries |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 220 | li t2, 2 |
| 221 | 1: |
| 222 | lw t1, 0(t4) |
| 223 | beqz t1, 2f |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 224 | add t1, s1 |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 225 | sw t1, 0(t4) |
| 226 | 2: |
| 227 | addi t2, 1 |
| 228 | blt t2, t3, 1b |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 229 | addi t4, 4 |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 230 | |
Daniel Schwierzeck | 0de9cc5 | 2013-02-12 22:22:13 +0100 | [diff] [blame^] | 231 | /* |
| 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 |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 239 | |
Shinya Kuribayashi | c7faac5 | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 240 | 1: |
Daniel Schwierzeck | 0de9cc5 | 2013-02-12 22:22:13 +0100 | [diff] [blame^] | 241 | sw zero, 0(t1) |
| 242 | blt t1, t2, 1b |
| 243 | addi t1, 4 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 244 | |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 245 | move a0, s0 # a0 <-- gd |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 246 | la t9, board_init_r |
Shinya Kuribayashi | 9dabea1 | 2008-04-17 23:35:13 +0900 | [diff] [blame] | 247 | jr t9 |
Shinya Kuribayashi | 6911d0a | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 248 | move a1, s2 |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 249 | |
| 250 | .end relocate_code |