Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Startup Code for MIPS32 CPU-core |
| 4 | * |
| 5 | * Copyright (c) 2003 Wolfgang Denk <wd@denx.de> |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Wolfgang Denk | 25ddd1f | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 8 | #include <asm-offsets.h> |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 9 | #include <config.h> |
Paul Burton | a39b1cb | 2015-01-29 10:04:08 +0000 | [diff] [blame] | 10 | #include <asm/asm.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 | dd82128 | 2015-01-18 22:18:38 +0100 | [diff] [blame] | 14 | #ifndef CONFIG_SYS_INIT_SP_ADDR |
| 15 | #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + \ |
| 16 | CONFIG_SYS_INIT_SP_OFFSET) |
| 17 | #endif |
| 18 | |
Paul Burton | ab0d002 | 2015-01-29 10:04:09 +0000 | [diff] [blame] | 19 | #ifdef CONFIG_32BIT |
| 20 | # define MIPS_RELOC 3 |
Paul Burton | f1c64a0 | 2015-01-29 10:04:10 +0000 | [diff] [blame] | 21 | # define STATUS_SET 0 |
Paul Burton | ab0d002 | 2015-01-29 10:04:09 +0000 | [diff] [blame] | 22 | #endif |
| 23 | |
| 24 | #ifdef CONFIG_64BIT |
| 25 | # ifdef CONFIG_SYS_LITTLE_ENDIAN |
| 26 | # define MIPS64_R_INFO(ssym, r_type3, r_type2, r_type) \ |
| 27 | (((r_type) << 24) | ((r_type2) << 16) | ((r_type3) << 8) | (ssym)) |
| 28 | # else |
| 29 | # define MIPS64_R_INFO(ssym, r_type3, r_type2, r_type) \ |
| 30 | ((r_type) | ((r_type2) << 8) | ((r_type3) << 16) | (ssym) << 24) |
| 31 | # endif |
| 32 | # define MIPS_RELOC MIPS64_R_INFO(0x00, 0x00, 0x12, 0x03) |
Paul Burton | f1c64a0 | 2015-01-29 10:04:10 +0000 | [diff] [blame] | 33 | # define STATUS_SET ST0_KX |
Paul Burton | ab0d002 | 2015-01-29 10:04:09 +0000 | [diff] [blame] | 34 | #endif |
| 35 | |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 36 | .set noreorder |
| 37 | |
Daniel Schwierzeck | 65d297a | 2016-02-08 00:37:59 +0100 | [diff] [blame] | 38 | .macro init_wr sel |
| 39 | MTC0 zero, CP0_WATCHLO,\sel |
| 40 | mtc0 t1, CP0_WATCHHI,\sel |
| 41 | mfc0 t0, CP0_WATCHHI,\sel |
| 42 | bgez t0, wr_done |
| 43 | nop |
| 44 | .endm |
| 45 | |
Daniel Schwierzeck | 345490f | 2016-02-07 19:39:58 +0100 | [diff] [blame] | 46 | .macro uhi_mips_exception |
| 47 | move k0, t9 # preserve t9 in k0 |
| 48 | move k1, a0 # preserve a0 in k1 |
| 49 | li t9, 15 # UHI exception operation |
| 50 | li a0, 0 # Use hard register context |
| 51 | sdbbp 1 # Invoke UHI operation |
| 52 | .endm |
| 53 | |
Daniel Schwierzeck | c3e72ab | 2016-09-25 18:36:38 +0200 | [diff] [blame] | 54 | .macro setup_stack_gd |
| 55 | li t0, -16 |
| 56 | PTR_LI t1, CONFIG_SYS_INIT_SP_ADDR |
| 57 | and sp, t1, t0 # force 16 byte alignment |
| 58 | PTR_SUBU \ |
| 59 | sp, sp, GD_SIZE # reserve space for gd |
| 60 | and sp, sp, t0 # force 16 byte alignment |
| 61 | move k0, sp # save gd pointer |
Andy Yan | f5868a5 | 2017-07-24 17:45:27 +0800 | [diff] [blame] | 62 | #if CONFIG_VAL(SYS_MALLOC_F_LEN) |
| 63 | li t2, CONFIG_VAL(SYS_MALLOC_F_LEN) |
Daniel Schwierzeck | c3e72ab | 2016-09-25 18:36:38 +0200 | [diff] [blame] | 64 | PTR_SUBU \ |
| 65 | sp, sp, t2 # reserve space for early malloc |
| 66 | and sp, sp, t0 # force 16 byte alignment |
| 67 | #endif |
| 68 | move fp, sp |
| 69 | |
| 70 | /* Clear gd */ |
| 71 | move t0, k0 |
| 72 | 1: |
| 73 | PTR_S zero, 0(t0) |
| 74 | blt t0, t1, 1b |
| 75 | PTR_ADDIU t0, PTRSIZE |
| 76 | |
Andy Yan | f5868a5 | 2017-07-24 17:45:27 +0800 | [diff] [blame] | 77 | #if CONFIG_VAL(SYS_MALLOC_F_LEN) |
Daniel Schwierzeck | c3e72ab | 2016-09-25 18:36:38 +0200 | [diff] [blame] | 78 | PTR_S sp, GD_MALLOC_BASE(k0) # gd->malloc_base offset |
| 79 | #endif |
| 80 | .endm |
| 81 | |
Daniel Schwierzeck | 1134929 | 2015-12-19 20:20:45 +0100 | [diff] [blame] | 82 | ENTRY(_start) |
Bin Meng | a187559 | 2016-02-05 19:30:11 -0800 | [diff] [blame] | 83 | /* U-Boot entry point */ |
Daniel Schwierzeck | 8b1c734 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 84 | b reset |
Daniel Schwierzeck | 65d297a | 2016-02-08 00:37:59 +0100 | [diff] [blame] | 85 | mtc0 zero, CP0_COUNT # clear cp0 count for most accurate boot timing |
Daniel Schwierzeck | 8b1c734 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 86 | |
Daniel Schwierzeck | d1c3d8b | 2018-09-07 19:18:44 +0200 | [diff] [blame] | 87 | #if defined(CONFIG_MIPS_INSERT_BOOT_CONFIG) |
Daniel Schwierzeck | 7185adb | 2011-07-27 13:22:37 +0200 | [diff] [blame] | 88 | /* |
Daniel Schwierzeck | d1c3d8b | 2018-09-07 19:18:44 +0200 | [diff] [blame] | 89 | * Store some board-specific boot configuration. This is used by some |
| 90 | * MIPS systems like Malta. |
Daniel Schwierzeck | 7185adb | 2011-07-27 13:22:37 +0200 | [diff] [blame] | 91 | */ |
Daniel Schwierzeck | af3971f | 2016-02-14 18:52:57 +0100 | [diff] [blame] | 92 | .org 0x10 |
Daniel Schwierzeck | d1c3d8b | 2018-09-07 19:18:44 +0200 | [diff] [blame] | 93 | .word CONFIG_MIPS_BOOT_CONFIG_WORD0 |
| 94 | .word CONFIG_MIPS_BOOT_CONFIG_WORD1 |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 95 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 96 | |
Daniel Schwierzeck | af3971f | 2016-02-14 18:52:57 +0100 | [diff] [blame] | 97 | #if defined(CONFIG_ROM_EXCEPTION_VECTORS) |
Daniel Schwierzeck | 345490f | 2016-02-07 19:39:58 +0100 | [diff] [blame] | 98 | /* |
| 99 | * Exception vector entry points. When running from ROM, an exception |
| 100 | * cannot be handled. Halt execution and transfer control to debugger, |
| 101 | * if one is attached. |
| 102 | */ |
Daniel Schwierzeck | 8b1c734 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 103 | .org 0x200 |
| 104 | /* TLB refill, 32 bit task */ |
Daniel Schwierzeck | 345490f | 2016-02-07 19:39:58 +0100 | [diff] [blame] | 105 | uhi_mips_exception |
Daniel Schwierzeck | 8b1c734 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 106 | |
| 107 | .org 0x280 |
| 108 | /* XTLB refill, 64 bit task */ |
Daniel Schwierzeck | 345490f | 2016-02-07 19:39:58 +0100 | [diff] [blame] | 109 | uhi_mips_exception |
Daniel Schwierzeck | 8b1c734 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 110 | |
| 111 | .org 0x300 |
| 112 | /* Cache error exception */ |
Daniel Schwierzeck | 345490f | 2016-02-07 19:39:58 +0100 | [diff] [blame] | 113 | uhi_mips_exception |
Daniel Schwierzeck | 8b1c734 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 114 | |
| 115 | .org 0x380 |
| 116 | /* General exception */ |
Daniel Schwierzeck | 345490f | 2016-02-07 19:39:58 +0100 | [diff] [blame] | 117 | uhi_mips_exception |
Daniel Schwierzeck | 8b1c734 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 118 | |
| 119 | .org 0x400 |
| 120 | /* Catch interrupt exceptions */ |
Daniel Schwierzeck | 345490f | 2016-02-07 19:39:58 +0100 | [diff] [blame] | 121 | uhi_mips_exception |
Daniel Schwierzeck | 8b1c734 | 2013-02-12 22:22:12 +0100 | [diff] [blame] | 122 | |
| 123 | .org 0x480 |
| 124 | /* EJTAG debug exception */ |
| 125 | 1: b 1b |
| 126 | nop |
| 127 | |
Daniel Schwierzeck | af3971f | 2016-02-14 18:52:57 +0100 | [diff] [blame] | 128 | .org 0x500 |
| 129 | #endif |
| 130 | |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 131 | reset: |
Paul Burton | 31d36f7 | 2016-09-21 14:59:54 +0100 | [diff] [blame] | 132 | #if __mips_isa_rev >= 6 |
| 133 | mfc0 t0, CP0_CONFIG, 5 |
| 134 | and t0, t0, MIPS_CONF5_VP |
| 135 | beqz t0, 1f |
| 136 | nop |
| 137 | |
| 138 | b 2f |
| 139 | mfc0 t0, CP0_GLOBALNUMBER |
| 140 | #endif |
| 141 | |
Álvaro Fernández Rojas | ee42214 | 2017-04-25 00:39:20 +0200 | [diff] [blame] | 142 | #ifdef CONFIG_ARCH_BMIPS |
| 143 | 1: mfc0 t0, CP0_DIAGNOSTIC, 3 |
| 144 | and t0, t0, (1 << 31) |
| 145 | #else |
Paul Burton | 31d36f7 | 2016-09-21 14:59:54 +0100 | [diff] [blame] | 146 | 1: mfc0 t0, CP0_EBASE |
| 147 | and t0, t0, EBASE_CPUNUM |
Álvaro Fernández Rojas | ee42214 | 2017-04-25 00:39:20 +0200 | [diff] [blame] | 148 | #endif |
Paul Burton | 31d36f7 | 2016-09-21 14:59:54 +0100 | [diff] [blame] | 149 | |
| 150 | /* Hang if this isn't the first CPU in the system */ |
| 151 | 2: beqz t0, 4f |
| 152 | nop |
| 153 | 3: wait |
| 154 | b 3b |
| 155 | nop |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 156 | |
Daniel Schwierzeck | 65d297a | 2016-02-08 00:37:59 +0100 | [diff] [blame] | 157 | /* Init CP0 Status */ |
| 158 | 4: mfc0 t0, CP0_STATUS |
| 159 | and t0, ST0_IMPL |
| 160 | or t0, ST0_BEV | ST0_ERL | STATUS_SET |
| 161 | mtc0 t0, CP0_STATUS |
| 162 | |
| 163 | /* |
| 164 | * Check whether CP0 Config1 is implemented. If not continue |
| 165 | * with legacy Watch register initialization. |
| 166 | */ |
| 167 | mfc0 t0, CP0_CONFIG |
| 168 | bgez t0, wr_legacy |
| 169 | nop |
| 170 | |
| 171 | /* |
| 172 | * Check WR bit in CP0 Config1 to determine if Watch registers |
| 173 | * are implemented. |
| 174 | */ |
| 175 | mfc0 t0, CP0_CONFIG, 1 |
| 176 | andi t0, (1 << 3) |
| 177 | beqz t0, wr_done |
| 178 | nop |
| 179 | |
| 180 | /* Clear Watch Status bits and disable watch exceptions */ |
| 181 | li t1, 0x7 # Clear I, R and W conditions |
| 182 | init_wr 0 |
| 183 | init_wr 1 |
| 184 | init_wr 2 |
| 185 | init_wr 3 |
| 186 | init_wr 4 |
| 187 | init_wr 5 |
| 188 | init_wr 6 |
| 189 | init_wr 7 |
| 190 | b wr_done |
| 191 | nop |
| 192 | |
| 193 | wr_legacy: |
| 194 | MTC0 zero, CP0_WATCHLO |
Daniel Schwierzeck | e26e8dc | 2016-01-09 22:24:47 +0100 | [diff] [blame] | 195 | mtc0 zero, CP0_WATCHHI |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 196 | |
Daniel Schwierzeck | 65d297a | 2016-02-08 00:37:59 +0100 | [diff] [blame] | 197 | wr_done: |
| 198 | /* Clear WP, IV and SW interrupts */ |
Shinya Kuribayashi | d43d43e | 2008-03-25 21:30:07 +0900 | [diff] [blame] | 199 | mtc0 zero, CP0_CAUSE |
| 200 | |
Daniel Schwierzeck | 65d297a | 2016-02-08 00:37:59 +0100 | [diff] [blame] | 201 | /* Clear timer interrupt (CP0_COUNT cleared on branch to 'reset') */ |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 202 | mtc0 zero, CP0_COMPARE |
| 203 | |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 204 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
Paul Burton | 4f9226b | 2016-09-21 11:18:50 +0100 | [diff] [blame] | 205 | mfc0 t0, CP0_CONFIG |
| 206 | and t0, t0, MIPS_CONF_IMPL |
| 207 | or t0, t0, CONF_CM_UNCACHED |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 208 | mtc0 t0, CP0_CONFIG |
Paul Burton | c5b8412 | 2016-09-21 11:18:57 +0100 | [diff] [blame] | 209 | ehb |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 210 | #endif |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 211 | |
Paul Burton | b2b135d | 2016-09-21 11:18:53 +0100 | [diff] [blame] | 212 | #ifdef CONFIG_MIPS_CM |
| 213 | PTR_LA t9, mips_cm_map |
| 214 | jalr t9 |
| 215 | nop |
| 216 | #endif |
| 217 | |
Daniel Schwierzeck | 924ad86 | 2016-06-04 16:13:21 +0200 | [diff] [blame] | 218 | #ifdef CONFIG_MIPS_INIT_STACK_IN_SRAM |
| 219 | /* Set up initial stack and global data */ |
| 220 | setup_stack_gd |
Daniel Schwierzeck | 0d159d6 | 2017-04-24 19:03:34 +0200 | [diff] [blame] | 221 | |
| 222 | # ifdef CONFIG_DEBUG_UART |
| 223 | /* Earliest point to set up debug uart */ |
| 224 | PTR_LA t9, debug_uart_init |
| 225 | jalr t9 |
| 226 | nop |
| 227 | # endif |
Daniel Schwierzeck | 924ad86 | 2016-06-04 16:13:21 +0200 | [diff] [blame] | 228 | #endif |
| 229 | |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 230 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
Paul Burton | f898127 | 2016-09-21 11:18:51 +0100 | [diff] [blame] | 231 | # ifdef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 232 | /* Initialize any external memory */ |
Paul Burton | a39b1cb | 2015-01-29 10:04:08 +0000 | [diff] [blame] | 233 | PTR_LA t9, lowlevel_init |
Shinya Kuribayashi | 03c031d | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 234 | jalr t9 |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 235 | nop |
Paul Burton | f898127 | 2016-09-21 11:18:51 +0100 | [diff] [blame] | 236 | # endif |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 237 | |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 238 | /* Initialize caches... */ |
Paul Burton | a39b1cb | 2015-01-29 10:04:08 +0000 | [diff] [blame] | 239 | PTR_LA t9, mips_cache_reset |
Shinya Kuribayashi | 03c031d | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 240 | jalr t9 |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 241 | nop |
Paul Burton | f898127 | 2016-09-21 11:18:51 +0100 | [diff] [blame] | 242 | |
| 243 | # ifndef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD |
| 244 | /* Initialize any external memory */ |
| 245 | PTR_LA t9, lowlevel_init |
| 246 | jalr t9 |
| 247 | nop |
| 248 | # endif |
Shinya Kuribayashi | 7aa1f19 | 2011-05-07 00:18:13 +0900 | [diff] [blame] | 249 | #endif |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 250 | |
Daniel Schwierzeck | 924ad86 | 2016-06-04 16:13:21 +0200 | [diff] [blame] | 251 | #ifndef CONFIG_MIPS_INIT_STACK_IN_SRAM |
Daniel Schwierzeck | c3e72ab | 2016-09-25 18:36:38 +0200 | [diff] [blame] | 252 | /* Set up initial stack and global data */ |
| 253 | setup_stack_gd |
Daniel Schwierzeck | 0d159d6 | 2017-04-24 19:03:34 +0200 | [diff] [blame] | 254 | |
| 255 | # ifdef CONFIG_DEBUG_UART |
| 256 | /* Earliest point to set up debug uart */ |
| 257 | PTR_LA t9, debug_uart_init |
| 258 | jalr t9 |
| 259 | nop |
| 260 | # endif |
Daniel Schwierzeck | 924ad86 | 2016-06-04 16:13:21 +0200 | [diff] [blame] | 261 | #endif |
Daniel Schwierzeck | e26e8dc | 2016-01-09 22:24:47 +0100 | [diff] [blame] | 262 | |
Purna Chandra Mandal | a627909 | 2016-01-21 20:02:51 +0530 | [diff] [blame] | 263 | move a0, zero # a0 <-- boot_flags = 0 |
Paul Burton | a39b1cb | 2015-01-29 10:04:08 +0000 | [diff] [blame] | 264 | PTR_LA t9, board_init_f |
Daniel Schwierzeck | 345490f | 2016-02-07 19:39:58 +0100 | [diff] [blame] | 265 | |
Shinya Kuribayashi | 43c5092 | 2008-04-17 23:35:13 +0900 | [diff] [blame] | 266 | jr t9 |
Daniel Schwierzeck | 6d08e22 | 2014-11-20 23:55:32 +0100 | [diff] [blame] | 267 | move ra, zero |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 268 | |
Daniel Schwierzeck | 1134929 | 2015-12-19 20:20:45 +0100 | [diff] [blame] | 269 | END(_start) |