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