wdenk | c021880 | 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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Wolfgang Denk | 25ddd1f | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 9 | #include <asm-offsets.h> |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 10 | #include <config.h> |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 11 | #include <asm/regdef.h> |
| 12 | #include <asm/mipsregs.h> |
| 13 | |
Daniel Schwierzeck | ab2a98b | 2011-07-27 13:22:38 +0200 | [diff] [blame] | 14 | #ifndef CONFIG_SYS_MIPS_CACHE_MODE |
| 15 | #define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT |
| 16 | #endif |
| 17 | |
Shinya Kuribayashi | decaba6 | 2008-03-25 21:30:07 +0900 | [diff] [blame] | 18 | /* |
| 19 | * For the moment disable interrupts, mark the kernel mode and |
| 20 | * set ST0_KX so that the CPU does not spit fire when using |
| 21 | * 64-bit addresses. |
| 22 | */ |
| 23 | .macro setup_c0_status set clr |
| 24 | .set push |
| 25 | mfc0 t0, CP0_STATUS |
| 26 | or t0, ST0_CU0 | \set | 0x1f | \clr |
| 27 | xor t0, 0x1f | \clr |
| 28 | mtc0 t0, CP0_STATUS |
| 29 | .set noreorder |
| 30 | sll zero, 3 # ehb |
| 31 | .set pop |
| 32 | .endm |
| 33 | |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 34 | .set noreorder |
| 35 | |
| 36 | .globl _start |
| 37 | .text |
| 38 | _start: |
Daniel Schwierzeck | 8b1c734 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 39 | /* U-boot entry point */ |
| 40 | b reset |
| 41 | nop |
| 42 | |
| 43 | .org 0x10 |
Gabor Juhos | 843a76b | 2013-05-22 03:57:46 +0000 | [diff] [blame] | 44 | #if defined(CONFIG_SYS_XWAY_EBU_BOOTCFG) |
Daniel Schwierzeck | 7185adb | 2011-07-27 13:22:37 +0200 | [diff] [blame] | 45 | /* |
| 46 | * Almost all Lantiq XWAY SoC devices have an external bus unit (EBU) to |
| 47 | * access external NOR flashes. If the board boots from NOR flash the |
| 48 | * internal BootROM does a blind read at address 0xB0000010 to read the |
| 49 | * initial configuration for that EBU in order to access the flash |
| 50 | * device with correct parameters. This config option is board-specific. |
| 51 | */ |
| 52 | .word CONFIG_SYS_XWAY_EBU_BOOTCFG |
Daniel Schwierzeck | 8b1c734 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 53 | .word 0x0 |
Paul Burton | 7a9d109 | 2013-11-09 10:22:08 +0000 | [diff] [blame] | 54 | #elif defined(CONFIG_MALTA) |
Gabor Juhos | 843a76b | 2013-05-22 03:57:46 +0000 | [diff] [blame] | 55 | /* |
| 56 | * Linux expects the Board ID here. |
| 57 | */ |
| 58 | .word 0x00000420 # 0x420 (Malta Board with CoreLV) |
| 59 | .word 0x00000000 |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 60 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 61 | |
Daniel Schwierzeck | 8b1c734 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 62 | .org 0x200 |
| 63 | /* TLB refill, 32 bit task */ |
| 64 | 1: b 1b |
| 65 | nop |
| 66 | |
| 67 | .org 0x280 |
| 68 | /* XTLB refill, 64 bit task */ |
| 69 | 1: b 1b |
| 70 | nop |
| 71 | |
| 72 | .org 0x300 |
| 73 | /* Cache error exception */ |
| 74 | 1: b 1b |
| 75 | nop |
| 76 | |
| 77 | .org 0x380 |
| 78 | /* General exception */ |
| 79 | 1: b 1b |
| 80 | nop |
| 81 | |
| 82 | .org 0x400 |
| 83 | /* Catch interrupt exceptions */ |
| 84 | 1: b 1b |
| 85 | nop |
| 86 | |
| 87 | .org 0x480 |
| 88 | /* EJTAG debug exception */ |
| 89 | 1: b 1b |
| 90 | nop |
| 91 | |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 92 | .align 4 |
| 93 | reset: |
| 94 | |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 95 | /* Clear watch registers */ |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 96 | mtc0 zero, CP0_WATCHLO |
| 97 | mtc0 zero, CP0_WATCHHI |
| 98 | |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 99 | /* WP(Watch Pending), SW0/1 should be cleared */ |
Shinya Kuribayashi | d43d43e | 2008-03-25 21:30:07 +0900 | [diff] [blame] | 100 | mtc0 zero, CP0_CAUSE |
| 101 | |
Daniel Schwierzeck | 4dc7412 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 102 | setup_c0_status 0 0 |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 103 | |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 104 | /* Init Timer */ |
| 105 | mtc0 zero, CP0_COUNT |
| 106 | mtc0 zero, CP0_COMPARE |
| 107 | |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 108 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 109 | /* CONFIG0 register */ |
| 110 | li t0, CONF_CM_UNCACHED |
| 111 | mtc0 t0, CP0_CONFIG |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 112 | #endif |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 113 | |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 114 | /* Initialize $gp */ |
Shinya Kuribayashi | 03c031d | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 115 | bal 1f |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 116 | nop |
Shinya Kuribayashi | 2206921 | 2007-10-21 10:55:36 +0900 | [diff] [blame] | 117 | .word _gp |
Shinya Kuribayashi | 03c031d | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 118 | 1: |
Shinya Kuribayashi | 16664f7 | 2007-11-17 20:05:26 +0900 | [diff] [blame] | 119 | lw gp, 0(ra) |
Wolfgang Denk | c75eba3 | 2005-12-01 02:15:07 +0100 | [diff] [blame] | 120 | |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 121 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
| 122 | /* Initialize any external memory */ |
Shinya Kuribayashi | 03c031d | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 123 | la t9, lowlevel_init |
| 124 | jalr t9 |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 125 | nop |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 126 | |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 127 | /* Initialize caches... */ |
Shinya Kuribayashi | 03c031d | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 128 | la t9, mips_cache_reset |
| 129 | jalr t9 |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 130 | nop |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 131 | |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 132 | /* ... and enable them */ |
Daniel Schwierzeck | ab2a98b | 2011-07-27 13:22:38 +0200 | [diff] [blame] | 133 | li t0, CONFIG_SYS_MIPS_CACHE_MODE |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 134 | mtc0 t0, CP0_CONFIG |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 135 | #endif |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 136 | |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 137 | /* Set up temporary stack */ |
Gabor Juhos | f321b0f | 2013-01-24 06:27:52 +0000 | [diff] [blame] | 138 | li sp, CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET |
Daniel Schwierzeck | 6d08e22 | 2014-11-20 23:55:32 +0100 | [diff] [blame] | 139 | move fp, sp |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 140 | |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 141 | la t9, board_init_f |
Shinya Kuribayashi | 43c5092 | 2008-04-17 23:35:13 +0900 | [diff] [blame] | 142 | jr t9 |
Daniel Schwierzeck | 6d08e22 | 2014-11-20 23:55:32 +0100 | [diff] [blame] | 143 | move ra, zero |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 144 | |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 145 | /* |
| 146 | * void relocate_code (addr_sp, gd, addr_moni) |
| 147 | * |
| 148 | * This "function" does not return, instead it continues in RAM |
| 149 | * after relocating the monitor code. |
| 150 | * |
| 151 | * a0 = addr_sp |
| 152 | * a1 = gd |
| 153 | * a2 = destination address |
| 154 | */ |
| 155 | .globl relocate_code |
| 156 | .ent relocate_code |
| 157 | relocate_code: |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 158 | move sp, a0 # set new stack pointer |
Daniel Schwierzeck | 6d08e22 | 2014-11-20 23:55:32 +0100 | [diff] [blame] | 159 | move fp, sp |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 160 | |
Gabor Juhos | b2fe86f | 2013-01-24 06:27:53 +0000 | [diff] [blame] | 161 | move s0, a1 # save gd in s0 |
| 162 | move s2, a2 # save destination address in s2 |
| 163 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 164 | li t0, CONFIG_SYS_MONITOR_BASE |
Gabor Juhos | 248fe03 | 2013-01-24 06:27:54 +0000 | [diff] [blame] | 165 | sub s1, s2, t0 # s1 <-- relocation offset |
| 166 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 167 | la t3, in_ram |
Daniel Schwierzeck | 28875e2 | 2013-02-12 22:22:13 +0100 | [diff] [blame] | 168 | lw t2, -12(t3) # t2 <-- __image_copy_end |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 169 | move t1, a2 |
| 170 | |
Gabor Juhos | 248fe03 | 2013-01-24 06:27:54 +0000 | [diff] [blame] | 171 | add gp, s1 # adjust gp |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 172 | |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 173 | /* |
| 174 | * t0 = source address |
| 175 | * t1 = target address |
| 176 | * t2 = source end address |
| 177 | */ |
| 178 | 1: |
| 179 | lw t3, 0(t0) |
| 180 | sw t3, 0(t1) |
| 181 | addu t0, 4 |
Gabor Juhos | 5b7dd81 | 2013-01-24 06:27:51 +0000 | [diff] [blame] | 182 | blt t0, t2, 1b |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 183 | addu t1, 4 |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 184 | |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 185 | /* If caches were enabled, we would have to flush them here. */ |
Gabor Juhos | 67d80c9 | 2013-01-24 06:27:55 +0000 | [diff] [blame] | 186 | sub a1, t1, s2 # a1 <-- size |
Stefan Roese | 71fa071 | 2008-11-18 16:36:12 +0100 | [diff] [blame] | 187 | la t9, flush_cache |
| 188 | jalr t9 |
Gabor Juhos | 67d80c9 | 2013-01-24 06:27:55 +0000 | [diff] [blame] | 189 | move a0, s2 # a0 <-- destination address |
Stefan Roese | 71fa071 | 2008-11-18 16:36:12 +0100 | [diff] [blame] | 190 | |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 191 | /* Jump to where we've relocated ourselves */ |
Stefan Roese | 71fa071 | 2008-11-18 16:36:12 +0100 | [diff] [blame] | 192 | addi t0, s2, in_ram - _start |
Shinya Kuribayashi | 43c5092 | 2008-04-17 23:35:13 +0900 | [diff] [blame] | 193 | jr t0 |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 194 | nop |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 195 | |
Gabor Juhos | 04380c6 | 2013-02-12 22:22:13 +0100 | [diff] [blame] | 196 | .word __rel_dyn_end |
| 197 | .word __rel_dyn_start |
Daniel Schwierzeck | 28875e2 | 2013-02-12 22:22:13 +0100 | [diff] [blame] | 198 | .word __image_copy_end |
Vlad Lungu | 0f8c62a | 2008-05-05 14:04:00 +0300 | [diff] [blame] | 199 | .word _GLOBAL_OFFSET_TABLE_ |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 200 | .word num_got_entries |
| 201 | |
| 202 | in_ram: |
Shinya Kuribayashi | 2206921 | 2007-10-21 10:55:36 +0900 | [diff] [blame] | 203 | /* |
| 204 | * Now we want to update GOT. |
| 205 | * |
| 206 | * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object |
| 207 | * generated by GNU ld. Skip these reserved entries from relocation. |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 208 | */ |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 209 | lw t3, -4(t0) # t3 <-- num_got_entries |
Gabor Juhos | 680cb2d | 2013-06-13 12:59:27 +0200 | [diff] [blame] | 210 | lw t8, -8(t0) # t8 <-- _GLOBAL_OFFSET_TABLE_ |
| 211 | add t8, s1 # t8 now holds relocated _G_O_T_ |
| 212 | addi t8, t8, 8 # skipping first two entries |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 213 | li t2, 2 |
| 214 | 1: |
Gabor Juhos | 680cb2d | 2013-06-13 12:59:27 +0200 | [diff] [blame] | 215 | lw t1, 0(t8) |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 216 | beqz t1, 2f |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 217 | add t1, s1 |
Gabor Juhos | 680cb2d | 2013-06-13 12:59:27 +0200 | [diff] [blame] | 218 | sw t1, 0(t8) |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 219 | 2: |
| 220 | addi t2, 1 |
| 221 | blt t2, t3, 1b |
Gabor Juhos | 680cb2d | 2013-06-13 12:59:27 +0200 | [diff] [blame] | 222 | addi t8, 4 |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 223 | |
Gabor Juhos | 04380c6 | 2013-02-12 22:22:13 +0100 | [diff] [blame] | 224 | /* Update dynamic relocations */ |
| 225 | lw t1, -16(t0) # t1 <-- __rel_dyn_start |
| 226 | lw t2, -20(t0) # t2 <-- __rel_dyn_end |
| 227 | |
| 228 | b 2f # skip first reserved entry |
| 229 | addi t1, 8 |
| 230 | |
| 231 | 1: |
Gabor Juhos | 691995f | 2013-06-13 12:59:28 +0200 | [diff] [blame] | 232 | lw t8, -4(t1) # t8 <-- relocation info |
Gabor Juhos | 04380c6 | 2013-02-12 22:22:13 +0100 | [diff] [blame] | 233 | |
Gabor Juhos | 691995f | 2013-06-13 12:59:28 +0200 | [diff] [blame] | 234 | li t3, 3 |
| 235 | bne t8, t3, 2f # skip non R_MIPS_REL32 entries |
Gabor Juhos | 04380c6 | 2013-02-12 22:22:13 +0100 | [diff] [blame] | 236 | nop |
| 237 | |
| 238 | lw t3, -8(t1) # t3 <-- location to fix up in FLASH |
| 239 | |
Gabor Juhos | 680cb2d | 2013-06-13 12:59:27 +0200 | [diff] [blame] | 240 | lw t8, 0(t3) # t8 <-- original pointer |
| 241 | add t8, s1 # t8 <-- adjusted pointer |
Gabor Juhos | 04380c6 | 2013-02-12 22:22:13 +0100 | [diff] [blame] | 242 | |
| 243 | add t3, s1 # t3 <-- location to fix up in RAM |
Gabor Juhos | 680cb2d | 2013-06-13 12:59:27 +0200 | [diff] [blame] | 244 | sw t8, 0(t3) |
Gabor Juhos | 04380c6 | 2013-02-12 22:22:13 +0100 | [diff] [blame] | 245 | |
| 246 | 2: |
| 247 | blt t1, t2, 1b |
| 248 | addi t1, 8 # each rel.dyn entry is 8 bytes |
| 249 | |
Daniel Schwierzeck | 696a3b2 | 2013-02-12 22:22:13 +0100 | [diff] [blame] | 250 | /* |
| 251 | * Clear BSS |
| 252 | * |
| 253 | * GOT is now relocated. Thus __bss_start and __bss_end can be |
| 254 | * accessed directly via $gp. |
| 255 | */ |
| 256 | la t1, __bss_start # t1 <-- __bss_start |
| 257 | la t2, __bss_end # t2 <-- __bss_end |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 258 | |
Shinya Kuribayashi | 03c031d | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 259 | 1: |
Daniel Schwierzeck | 696a3b2 | 2013-02-12 22:22:13 +0100 | [diff] [blame] | 260 | sw zero, 0(t1) |
| 261 | blt t1, t2, 1b |
| 262 | addi t1, 4 |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 263 | |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 264 | move a0, s0 # a0 <-- gd |
Daniel Schwierzeck | 6d08e22 | 2014-11-20 23:55:32 +0100 | [diff] [blame] | 265 | move a1, s2 |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 266 | la t9, board_init_r |
Shinya Kuribayashi | 43c5092 | 2008-04-17 23:35:13 +0900 | [diff] [blame] | 267 | jr t9 |
Daniel Schwierzeck | 6d08e22 | 2014-11-20 23:55:32 +0100 | [diff] [blame] | 268 | move ra, zero |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 269 | |
| 270 | .end relocate_code |