Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 1998 Dan Malek <dmalek@jlc.net> |
| 4 | * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se> |
| 5 | * Copyright (C) 2000, 2001,2002 Wolfgang Denk <wd@denx.de> |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 6 | * Copyright Freescale Semiconductor, Inc. 2004, 2006, 2008. |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * U-Boot - Startup Code for MPC83xx PowerPC based Embedded Boards |
| 11 | */ |
| 12 | |
Wolfgang Denk | 0191e47 | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 13 | #include <asm-offsets.h> |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 14 | #include <config.h> |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 15 | #include <mpc83xx.h> |
Tom Rini | 4ddbade | 2022-05-25 12:16:03 -0400 | [diff] [blame] | 16 | #include <system-constants.h> |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 17 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 18 | #include <ppc_asm.tmpl> |
| 19 | #include <ppc_defs.h> |
| 20 | |
| 21 | #include <asm/cache.h> |
| 22 | #include <asm/mmu.h> |
Tom Rini | 7a21355 | 2023-11-01 12:28:11 -0400 | [diff] [blame] | 23 | #include <asm/fsl_lbc.h> |
Peter Tyser | 3a1362d | 2010-10-14 23:33:24 -0500 | [diff] [blame] | 24 | #include <asm/u-boot.h> |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 25 | |
Mario Six | 9486710 | 2019-01-21 09:17:54 +0100 | [diff] [blame] | 26 | #include "hrcw/hrcw.h" |
Mario Six | a861ea6 | 2019-01-21 09:17:57 +0100 | [diff] [blame] | 27 | #include "bats/bats.h" |
Mario Six | 8b2141c | 2019-01-21 09:18:09 +0100 | [diff] [blame] | 28 | #include "hid/hid.h" |
Mario Six | 9486710 | 2019-01-21 09:17:54 +0100 | [diff] [blame] | 29 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 30 | /* We don't want the MMU yet. |
| 31 | */ |
| 32 | #undef MSR_KERNEL |
| 33 | |
| 34 | /* |
| 35 | * Floating Point enable, Machine Check and Recoverable Interr. |
| 36 | */ |
| 37 | #ifdef DEBUG |
| 38 | #define MSR_KERNEL (MSR_FP|MSR_RI) |
| 39 | #else |
| 40 | #define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI) |
| 41 | #endif |
| 42 | |
Scott Wood | 2b36fbb | 2012-12-06 13:33:17 +0000 | [diff] [blame] | 43 | #if defined(CONFIG_NAND_SPL) || \ |
Tom Rini | 6b15c16 | 2022-05-13 12:26:35 -0400 | [diff] [blame] | 44 | (defined(CONFIG_SPL_BUILD) && CONFIG_IS_ENABLED(INIT_MINIMAL)) |
Scott Wood | 2b36fbb | 2012-12-06 13:33:17 +0000 | [diff] [blame] | 45 | #define MINIMAL_SPL |
| 46 | #endif |
| 47 | |
| 48 | #if !defined(CONFIG_SPL_BUILD) && !defined(CONFIG_NAND_SPL) && \ |
| 49 | !defined(CONFIG_SYS_RAMBOOT) |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 50 | #define CFG_SYS_FLASHBOOT |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 51 | #endif |
| 52 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 53 | /* |
| 54 | * Set up GOT: Global Offset Table |
| 55 | * |
Joakim Tjernlund | 3fbaa4d | 2010-01-19 14:41:56 +0100 | [diff] [blame] | 56 | * Use r12 to access the GOT |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 57 | */ |
| 58 | START_GOT |
| 59 | GOT_ENTRY(_GOT2_TABLE_) |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 60 | GOT_ENTRY(__bss_start) |
Simon Glass | ed70c8f | 2013-03-14 06:54:53 +0000 | [diff] [blame] | 61 | GOT_ENTRY(__bss_end) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 62 | |
Scott Wood | 2b36fbb | 2012-12-06 13:33:17 +0000 | [diff] [blame] | 63 | #ifndef MINIMAL_SPL |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 64 | GOT_ENTRY(_FIXUP_TABLE_) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 65 | GOT_ENTRY(_start) |
| 66 | GOT_ENTRY(_start_of_vectors) |
| 67 | GOT_ENTRY(_end_of_vectors) |
| 68 | GOT_ENTRY(transfer_to_handler) |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 69 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 70 | END_GOT |
| 71 | |
| 72 | /* |
Jerry Van Baren | 93eb931 | 2006-12-06 21:23:55 -0500 | [diff] [blame] | 73 | * The Hard Reset Configuration Word (HRCW) table is in the first 64 |
| 74 | * (0x40) bytes of flash. It has 8 bytes, but each byte is repeated 8 |
| 75 | * times so the processor can fetch it out of flash whether the flash |
| 76 | * is 8, 16, 32, or 64 bits wide (hardware trickery). |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 77 | */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 78 | .text |
| 79 | #define _HRCW_TABLE_ENTRY(w) \ |
| 80 | .fill 8,1,(((w)>>24)&0xff); \ |
| 81 | .fill 8,1,(((w)>>16)&0xff); \ |
| 82 | .fill 8,1,(((w)>> 8)&0xff); \ |
| 83 | .fill 8,1,(((w) )&0xff) |
| 84 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 85 | _HRCW_TABLE_ENTRY(CFG_SYS_HRCW_LOW) |
| 86 | _HRCW_TABLE_ENTRY(CFG_SYS_HRCW_HIGH) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 87 | |
Jerry Van Baren | 93eb931 | 2006-12-06 21:23:55 -0500 | [diff] [blame] | 88 | /* |
| 89 | * Magic number and version string - put it after the HRCW since it |
| 90 | * cannot be first in flash like it is in many other processors. |
| 91 | */ |
| 92 | .long 0x27051956 /* U-Boot Magic Number */ |
| 93 | |
Ron Madrid | 787b61d | 2008-12-12 13:12:45 -0800 | [diff] [blame] | 94 | .globl enable_addr_trans |
| 95 | enable_addr_trans: |
| 96 | /* enable address translation */ |
| 97 | mfmsr r5 |
| 98 | ori r5, r5, (MSR_IR | MSR_DR) |
| 99 | mtmsr r5 |
| 100 | isync |
| 101 | blr |
| 102 | |
| 103 | .globl disable_addr_trans |
| 104 | disable_addr_trans: |
| 105 | /* disable address translation */ |
| 106 | mflr r4 |
| 107 | mfmsr r3 |
| 108 | andi. r0, r3, (MSR_IR | MSR_DR) |
| 109 | beqlr |
| 110 | andc r3, r3, r0 |
| 111 | mtspr SRR0, r4 |
| 112 | mtspr SRR1, r3 |
| 113 | rfi |
| 114 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 115 | #ifndef CONFIG_DEFAULT_IMMR |
| 116 | #error CONFIG_DEFAULT_IMMR must be defined |
Heiko Schocher | 71cb3e9 | 2017-06-07 17:33:10 +0200 | [diff] [blame] | 117 | #endif /* CONFIG_DEFAULT_IMMR */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 118 | |
| 119 | /* |
| 120 | * After configuration, a system reset exception is executed using the |
| 121 | * vector at offset 0x100 relative to the base set by MSR[IP]. If |
| 122 | * MSR[IP] is 0, the base address is 0x00000000. If MSR[IP] is 1, the |
| 123 | * base address is 0xfff00000. In the case of a Power On Reset or Hard |
| 124 | * Reset, the value of MSR[IP] is determined by the CIP field in the |
| 125 | * HRCW. |
| 126 | * |
| 127 | * Other bits in the HRCW set up the Base Address and Port Size in BR0. |
| 128 | * This determines the location of the boot ROM (flash or EPROM) in the |
| 129 | * processor's address space at boot time. As long as the HRCW is set up |
| 130 | * so that we eventually end up executing the code below when the |
| 131 | * processor executes the reset exception, the actual values used should |
| 132 | * not matter. |
| 133 | * |
| 134 | * Once we have got here, the address mask in OR0 is cleared so that the |
| 135 | * bottom 32K of the boot ROM is effectively repeated all throughout the |
| 136 | * processor's address space, after which we can jump to the absolute |
| 137 | * address at which the boot ROM was linked at compile time, and proceed |
| 138 | * to initialise the memory controller without worrying if the rug will |
| 139 | * be pulled out from under us, so to speak (it will be fine as long as |
| 140 | * we configure BR0 with the same boot ROM link address). |
| 141 | */ |
| 142 | . = EXC_OFF_SYS_RESET |
| 143 | |
| 144 | .globl _start |
| 145 | _start: /* time t 0 */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 146 | lis r4, CONFIG_DEFAULT_IMMR@h |
| 147 | nop |
Peter Tyser | 0c44caf | 2010-09-14 19:13:53 -0500 | [diff] [blame] | 148 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 149 | mfmsr r5 /* save msr contents */ |
Scott Wood | 838450e | 2009-01-20 11:56:11 -0600 | [diff] [blame] | 150 | |
| 151 | /* 83xx manuals prescribe a specific sequence for updating IMMRBAR. */ |
| 152 | bl 1f |
| 153 | 1: mflr r7 |
| 154 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 155 | lis r3, CONFIG_SYS_IMMR@h |
| 156 | ori r3, r3, CONFIG_SYS_IMMR@l |
Scott Wood | 838450e | 2009-01-20 11:56:11 -0600 | [diff] [blame] | 157 | |
| 158 | lwz r6, IMMRBAR(r4) |
| 159 | isync |
| 160 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 161 | stw r3, IMMRBAR(r4) |
Scott Wood | 838450e | 2009-01-20 11:56:11 -0600 | [diff] [blame] | 162 | lwz r6, 0(r7) /* Arbitrary external load */ |
| 163 | isync |
| 164 | |
| 165 | lwz r6, IMMRBAR(r3) |
| 166 | isync |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 167 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 168 | /* Initialise the E300 processor core */ |
| 169 | /*------------------------------------------*/ |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 170 | |
Scott Wood | 2b36fbb | 2012-12-06 13:33:17 +0000 | [diff] [blame] | 171 | #if (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MPC83XX_WAIT_FOR_NAND)) || \ |
| 172 | defined(CONFIG_NAND_SPL) |
Lepcha Suchit | 7ed421f | 2008-10-16 13:38:00 -0500 | [diff] [blame] | 173 | /* The FCM begins execution after only the first page |
| 174 | * is loaded. Wait for the rest before branching |
| 175 | * to another flash page. |
| 176 | */ |
Scott Wood | 838450e | 2009-01-20 11:56:11 -0600 | [diff] [blame] | 177 | 1: lwz r6, 0x50b0(r3) |
Lepcha Suchit | 7ed421f | 2008-10-16 13:38:00 -0500 | [diff] [blame] | 178 | andi. r6, r6, 1 |
| 179 | beq 1b |
| 180 | #endif |
| 181 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 182 | bl init_e300_core |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 183 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 184 | #ifdef CFG_SYS_FLASHBOOT |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 185 | |
| 186 | /* Inflate flash location so it appears everywhere, calculate */ |
| 187 | /* the absolute address in final location of the FLASH, jump */ |
| 188 | /* there and deflate the flash size back to minimal size */ |
| 189 | /*------------------------------------------------------------*/ |
| 190 | bl map_flash_by_law1 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 191 | lis r4, (CONFIG_SYS_MONITOR_BASE)@h |
| 192 | ori r4, r4, (CONFIG_SYS_MONITOR_BASE)@l |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 193 | addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET |
| 194 | mtlr r5 |
| 195 | blr |
| 196 | in_flash: |
| 197 | #if 1 /* Remapping flash with LAW0. */ |
| 198 | bl remap_flash_by_law0 |
| 199 | #endif |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 200 | #endif /* CFG_SYS_FLASHBOOT */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 201 | |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 202 | /* setup the bats */ |
| 203 | bl setup_bats |
| 204 | sync |
| 205 | |
| 206 | /* |
| 207 | * Cache must be enabled here for stack-in-cache trick. |
| 208 | * This means we need to enable the BATS. |
| 209 | * This means: |
| 210 | * 1) for the EVB, original gt regs need to be mapped |
| 211 | * 2) need to have an IBAT for the 0xf region, |
| 212 | * we are running there! |
| 213 | * Cache should be turned on after BATs, since by default |
| 214 | * everything is write-through. |
| 215 | * The init-mem BAT can be reused after reloc. The old |
| 216 | * gt-regs BAT can be reused after board_init_f calls |
| 217 | * board_early_init_f (EVB only). |
| 218 | */ |
Christophe Leroy | cc46025 | 2023-01-18 20:52:38 +0100 | [diff] [blame] | 219 | #ifdef CONFIG_SYS_INIT_RAM_LOCK |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 220 | /* enable address translation */ |
| 221 | bl enable_addr_trans |
| 222 | sync |
| 223 | |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 224 | /* enable the data cache */ |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 225 | bl dcache_enable |
| 226 | sync |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 227 | bl lock_ram_in_cache |
| 228 | sync |
| 229 | #endif |
| 230 | |
| 231 | /* set up the stack pointer in our newly created |
mario.six@gdsys.cc | d4f4a54 | 2017-01-17 08:33:47 +0100 | [diff] [blame] | 232 | * cache-ram; use r3 to keep the new SP for now to |
| 233 | * avoid overiding the SP it uselessly */ |
Tom Rini | 4ddbade | 2022-05-25 12:16:03 -0400 | [diff] [blame] | 234 | lis r3, SYS_INIT_SP_ADDR@h |
| 235 | ori r3, r3, SYS_INIT_SP_ADDR@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 236 | |
mario.six@gdsys.cc | 85df7b4 | 2017-01-17 08:33:48 +0100 | [diff] [blame] | 237 | /* r4 = end of GD area */ |
| 238 | addi r4, r3, GENERATED_GBL_DATA_SIZE |
| 239 | |
| 240 | /* Zero GD area */ |
| 241 | li r0, 0 |
| 242 | 1: |
| 243 | subi r4, r4, 1 |
| 244 | stb r0, 0(r4) |
| 245 | cmplw r3, r4 |
| 246 | bne 1b |
| 247 | |
Simon Glass | adad2d0 | 2023-09-26 08:14:27 -0600 | [diff] [blame] | 248 | #if CONFIG_IS_ENABLED(SYS_MALLOC_F) |
mario.six@gdsys.cc | 85df7b4 | 2017-01-17 08:33:48 +0100 | [diff] [blame] | 249 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 250 | #if CONFIG_VAL(SYS_MALLOC_F_LEN) + GENERATED_GBL_DATA_SIZE > CFG_SYS_INIT_RAM_SIZE |
Andy Yan | ad0ac4b | 2017-07-24 17:47:27 +0800 | [diff] [blame] | 251 | #error "SYS_MALLOC_F_LEN too large to fit into initial RAM." |
mario.six@gdsys.cc | 85df7b4 | 2017-01-17 08:33:48 +0100 | [diff] [blame] | 252 | #endif |
| 253 | |
| 254 | /* r3 = new stack pointer / pre-reloc malloc area */ |
Andy Yan | ad0ac4b | 2017-07-24 17:47:27 +0800 | [diff] [blame] | 255 | subi r3, r3, CONFIG_VAL(SYS_MALLOC_F_LEN) |
mario.six@gdsys.cc | 85df7b4 | 2017-01-17 08:33:48 +0100 | [diff] [blame] | 256 | |
| 257 | /* Set pointer to pre-reloc malloc area in GD */ |
| 258 | stw r3, GD_MALLOC_BASE(r4) |
| 259 | #endif |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 260 | li r0, 0 /* Make room for stack frame header and */ |
mario.six@gdsys.cc | d4f4a54 | 2017-01-17 08:33:47 +0100 | [diff] [blame] | 261 | stwu r0, -4(r3) /* clear final stack frame so that */ |
| 262 | stwu r0, -4(r3) /* stack backtraces terminate cleanly */ |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 263 | |
mario.six@gdsys.cc | d4f4a54 | 2017-01-17 08:33:47 +0100 | [diff] [blame] | 264 | /* Finally, actually set SP */ |
| 265 | mr r1, r3 |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 266 | |
| 267 | /* let the C-code set up the rest */ |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 268 | /* */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 269 | /* Be careful to keep code relocatable & stack humble */ |
| 270 | /*------------------------------------------------------*/ |
| 271 | |
| 272 | GET_GOT /* initialize GOT access */ |
Joakim Tjernlund | f14554d | 2018-11-28 10:59:55 +0100 | [diff] [blame] | 273 | /* Needed for -msingle-pic-base */ |
| 274 | bl _GLOBAL_OFFSET_TABLE_@local-4 |
| 275 | mflr r30 |
Wolfgang Denk | b2d36ea | 2011-04-20 22:11:21 +0200 | [diff] [blame] | 276 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 277 | /* r3: IMMR */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 278 | lis r3, CONFIG_SYS_IMMR@h |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 279 | /* run low-level CPU init code (in Flash)*/ |
| 280 | bl cpu_init_f |
| 281 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 282 | /* run 1st part of board init code (in Flash)*/ |
Valentin Longchamp | e91e10a | 2014-10-03 11:45:23 +0200 | [diff] [blame] | 283 | li r3, 0 /* clear boot_flag for calling board_init_f */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 284 | bl board_init_f |
| 285 | |
Peter Tyser | 0c44caf | 2010-09-14 19:13:53 -0500 | [diff] [blame] | 286 | /* NOTREACHED - board_init_f() does not return */ |
| 287 | |
Scott Wood | 2b36fbb | 2012-12-06 13:33:17 +0000 | [diff] [blame] | 288 | #ifndef MINIMAL_SPL |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 289 | /* |
| 290 | * Vector Table |
| 291 | */ |
| 292 | |
| 293 | .globl _start_of_vectors |
| 294 | _start_of_vectors: |
| 295 | |
| 296 | /* Machine check */ |
| 297 | STD_EXCEPTION(0x200, MachineCheck, MachineCheckException) |
| 298 | |
| 299 | /* Data Storage exception. */ |
| 300 | STD_EXCEPTION(0x300, DataStorage, UnknownException) |
| 301 | |
| 302 | /* Instruction Storage exception. */ |
| 303 | STD_EXCEPTION(0x400, InstStorage, UnknownException) |
| 304 | |
| 305 | /* External Interrupt exception. */ |
| 306 | #ifndef FIXME |
| 307 | STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt) |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 308 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 309 | |
| 310 | /* Alignment exception. */ |
| 311 | . = 0x600 |
| 312 | Alignment: |
Rafal Jaworowski | 06244e4 | 2007-06-22 14:58:04 +0200 | [diff] [blame] | 313 | EXCEPTION_PROLOG(SRR0, SRR1) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 314 | mfspr r4,DAR |
| 315 | stw r4,_DAR(r21) |
| 316 | mfspr r5,DSISR |
| 317 | stw r5,_DSISR(r21) |
| 318 | addi r3,r1,STACK_FRAME_OVERHEAD |
Joakim Tjernlund | 4ff6bc0 | 2010-01-19 14:41:55 +0100 | [diff] [blame] | 319 | EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 320 | |
| 321 | /* Program check exception */ |
| 322 | . = 0x700 |
| 323 | ProgramCheck: |
Rafal Jaworowski | 06244e4 | 2007-06-22 14:58:04 +0200 | [diff] [blame] | 324 | EXCEPTION_PROLOG(SRR0, SRR1) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 325 | addi r3,r1,STACK_FRAME_OVERHEAD |
Joakim Tjernlund | 4ff6bc0 | 2010-01-19 14:41:55 +0100 | [diff] [blame] | 326 | EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException, |
| 327 | MSR_KERNEL, COPY_EE) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 328 | |
| 329 | STD_EXCEPTION(0x800, FPUnavailable, UnknownException) |
| 330 | |
| 331 | /* I guess we could implement decrementer, and may have |
| 332 | * to someday for timekeeping. |
| 333 | */ |
| 334 | STD_EXCEPTION(0x900, Decrementer, timer_interrupt) |
| 335 | |
| 336 | STD_EXCEPTION(0xa00, Trap_0a, UnknownException) |
| 337 | STD_EXCEPTION(0xb00, Trap_0b, UnknownException) |
| 338 | STD_EXCEPTION(0xc00, SystemCall, UnknownException) |
| 339 | STD_EXCEPTION(0xd00, SingleStep, UnknownException) |
| 340 | |
| 341 | STD_EXCEPTION(0xe00, Trap_0e, UnknownException) |
| 342 | STD_EXCEPTION(0xf00, Trap_0f, UnknownException) |
| 343 | |
| 344 | STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException) |
| 345 | STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException) |
| 346 | STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException) |
| 347 | #ifdef DEBUG |
| 348 | . = 0x1300 |
| 349 | /* |
| 350 | * This exception occurs when the program counter matches the |
| 351 | * Instruction Address Breakpoint Register (IABR). |
| 352 | * |
| 353 | * I want the cpu to halt if this occurs so I can hunt around |
| 354 | * with the debugger and look at things. |
| 355 | * |
| 356 | * When DEBUG is defined, both machine check enable (in the MSR) |
| 357 | * and checkstop reset enable (in the reset mode register) are |
| 358 | * turned off and so a checkstop condition will result in the cpu |
| 359 | * halting. |
| 360 | * |
| 361 | * I force the cpu into a checkstop condition by putting an illegal |
| 362 | * instruction here (at least this is the theory). |
| 363 | * |
| 364 | * well - that didnt work, so just do an infinite loop! |
| 365 | */ |
| 366 | 1: b 1b |
| 367 | #else |
| 368 | STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException) |
| 369 | #endif |
| 370 | STD_EXCEPTION(0x1400, SMI, UnknownException) |
| 371 | |
| 372 | STD_EXCEPTION(0x1500, Trap_15, UnknownException) |
| 373 | STD_EXCEPTION(0x1600, Trap_16, UnknownException) |
| 374 | STD_EXCEPTION(0x1700, Trap_17, UnknownException) |
| 375 | STD_EXCEPTION(0x1800, Trap_18, UnknownException) |
| 376 | STD_EXCEPTION(0x1900, Trap_19, UnknownException) |
| 377 | STD_EXCEPTION(0x1a00, Trap_1a, UnknownException) |
| 378 | STD_EXCEPTION(0x1b00, Trap_1b, UnknownException) |
| 379 | STD_EXCEPTION(0x1c00, Trap_1c, UnknownException) |
| 380 | STD_EXCEPTION(0x1d00, Trap_1d, UnknownException) |
| 381 | STD_EXCEPTION(0x1e00, Trap_1e, UnknownException) |
| 382 | STD_EXCEPTION(0x1f00, Trap_1f, UnknownException) |
| 383 | STD_EXCEPTION(0x2000, Trap_20, UnknownException) |
| 384 | STD_EXCEPTION(0x2100, Trap_21, UnknownException) |
| 385 | STD_EXCEPTION(0x2200, Trap_22, UnknownException) |
| 386 | STD_EXCEPTION(0x2300, Trap_23, UnknownException) |
| 387 | STD_EXCEPTION(0x2400, Trap_24, UnknownException) |
| 388 | STD_EXCEPTION(0x2500, Trap_25, UnknownException) |
| 389 | STD_EXCEPTION(0x2600, Trap_26, UnknownException) |
| 390 | STD_EXCEPTION(0x2700, Trap_27, UnknownException) |
| 391 | STD_EXCEPTION(0x2800, Trap_28, UnknownException) |
| 392 | STD_EXCEPTION(0x2900, Trap_29, UnknownException) |
| 393 | STD_EXCEPTION(0x2a00, Trap_2a, UnknownException) |
| 394 | STD_EXCEPTION(0x2b00, Trap_2b, UnknownException) |
| 395 | STD_EXCEPTION(0x2c00, Trap_2c, UnknownException) |
| 396 | STD_EXCEPTION(0x2d00, Trap_2d, UnknownException) |
| 397 | STD_EXCEPTION(0x2e00, Trap_2e, UnknownException) |
| 398 | STD_EXCEPTION(0x2f00, Trap_2f, UnknownException) |
| 399 | |
| 400 | |
| 401 | .globl _end_of_vectors |
| 402 | _end_of_vectors: |
| 403 | |
| 404 | . = 0x3000 |
| 405 | |
| 406 | /* |
| 407 | * This code finishes saving the registers to the exception frame |
| 408 | * and jumps to the appropriate handler for the exception. |
| 409 | * Register r21 is pointer into trap frame, r1 has new stack pointer. |
| 410 | */ |
| 411 | .globl transfer_to_handler |
| 412 | transfer_to_handler: |
| 413 | stw r22,_NIP(r21) |
| 414 | lis r22,MSR_POW@h |
| 415 | andc r23,r23,r22 |
| 416 | stw r23,_MSR(r21) |
| 417 | SAVE_GPR(7, r21) |
| 418 | SAVE_4GPRS(8, r21) |
| 419 | SAVE_8GPRS(12, r21) |
| 420 | SAVE_8GPRS(24, r21) |
| 421 | mflr r23 |
| 422 | andi. r24,r23,0x3f00 /* get vector offset */ |
| 423 | stw r24,TRAP(r21) |
| 424 | li r22,0 |
| 425 | stw r22,RESULT(r21) |
| 426 | lwz r24,0(r23) /* virtual address of handler */ |
| 427 | lwz r23,4(r23) /* where to go when done */ |
| 428 | mtspr SRR0,r24 |
| 429 | mtspr SRR1,r20 |
| 430 | mtlr r23 |
| 431 | SYNC |
| 432 | rfi /* jump to handler, enable MMU */ |
| 433 | |
| 434 | int_return: |
| 435 | mfmsr r28 /* Disable interrupts */ |
| 436 | li r4,0 |
| 437 | ori r4,r4,MSR_EE |
| 438 | andc r28,r28,r4 |
| 439 | SYNC /* Some chip revs need this... */ |
| 440 | mtmsr r28 |
| 441 | SYNC |
| 442 | lwz r2,_CTR(r1) |
| 443 | lwz r0,_LINK(r1) |
| 444 | mtctr r2 |
| 445 | mtlr r0 |
| 446 | lwz r2,_XER(r1) |
| 447 | lwz r0,_CCR(r1) |
| 448 | mtspr XER,r2 |
| 449 | mtcrf 0xFF,r0 |
| 450 | REST_10GPRS(3, r1) |
| 451 | REST_10GPRS(13, r1) |
| 452 | REST_8GPRS(23, r1) |
| 453 | REST_GPR(31, r1) |
| 454 | lwz r2,_NIP(r1) /* Restore environment */ |
| 455 | lwz r0,_MSR(r1) |
| 456 | mtspr SRR0,r2 |
| 457 | mtspr SRR1,r0 |
| 458 | lwz r0,GPR0(r1) |
| 459 | lwz r2,GPR2(r1) |
| 460 | lwz r1,GPR1(r1) |
| 461 | SYNC |
| 462 | rfi |
Scott Wood | 2b36fbb | 2012-12-06 13:33:17 +0000 | [diff] [blame] | 463 | #endif /* !MINIMAL_SPL */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 464 | |
| 465 | /* |
| 466 | * This code initialises the E300 processor core |
| 467 | * (conforms to PowerPC 603e spec) |
| 468 | * Note: expects original MSR contents to be in r5. |
| 469 | */ |
| 470 | .globl init_e300_core |
| 471 | init_e300_core: /* time t 10 */ |
| 472 | /* Initialize machine status; enable machine check interrupt */ |
| 473 | /*-----------------------------------------------------------*/ |
| 474 | |
| 475 | li r3, MSR_KERNEL /* Set ME and RI flags */ |
| 476 | rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */ |
| 477 | #ifdef DEBUG |
| 478 | rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */ |
| 479 | #endif |
| 480 | SYNC /* Some chip revs need this... */ |
| 481 | mtmsr r3 |
| 482 | SYNC |
| 483 | mtspr SRR1, r3 /* Make SRR1 match MSR */ |
| 484 | |
| 485 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 486 | lis r3, CONFIG_SYS_IMMR@h |
Christophe Leroy | 39d3795 | 2023-04-03 10:39:59 +0200 | [diff] [blame] | 487 | #ifndef CONFIG_WDT_MPC8xxx |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 488 | #if defined(CONFIG_WATCHDOG) |
Horst Kronstorfer | 4565e04 | 2010-05-18 10:37:05 +0200 | [diff] [blame] | 489 | /* Initialise the Watchdog values and reset it (if req) */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 490 | /*------------------------------------------------------*/ |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 491 | lis r4, CFG_SYS_WATCHDOG_VALUE |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 492 | ori r4, r4, (SWCRR_SWEN | SWCRR_SWRI | SWCRR_SWPR) |
| 493 | stw r4, SWCRR(r3) |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 494 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 495 | /* and reset it */ |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 496 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 497 | li r4, 0x556C |
| 498 | sth r4, SWSRR@l(r3) |
Heiko Schocher | 6dfb2e5 | 2008-01-11 15:15:17 +0100 | [diff] [blame] | 499 | li r4, -0x55C7 |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 500 | sth r4, SWSRR@l(r3) |
| 501 | #else |
Horst Kronstorfer | 4565e04 | 2010-05-18 10:37:05 +0200 | [diff] [blame] | 502 | /* Disable Watchdog */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 503 | /*-------------------*/ |
Kumar Gala | b42751c | 2006-01-11 11:23:01 -0600 | [diff] [blame] | 504 | lwz r4, SWCRR(r3) |
| 505 | /* Check to see if its enabled for disabling |
| 506 | once disabled by SW you can't re-enable */ |
| 507 | andi. r4, r4, 0x4 |
| 508 | beq 1f |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 509 | xor r4, r4, r4 |
| 510 | stw r4, SWCRR(r3) |
Kumar Gala | b42751c | 2006-01-11 11:23:01 -0600 | [diff] [blame] | 511 | 1: |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 512 | #endif /* CONFIG_WATCHDOG */ |
Christophe Leroy | 39d3795 | 2023-04-03 10:39:59 +0200 | [diff] [blame] | 513 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 514 | |
Nick Spence | 56fd3c2 | 2008-08-28 14:09:19 -0700 | [diff] [blame] | 515 | #if defined(CONFIG_MASK_AER_AO) |
| 516 | /* Write the Arbiter Event Enable to mask Address Only traps. */ |
| 517 | /* This prevents the dcbz instruction from being trapped when */ |
| 518 | /* HID0_ABE Address Broadcast Enable is set and the MEMORY */ |
| 519 | /* COHERENCY bit is set in the WIMG bits, which is often */ |
| 520 | /* needed for PCI operation. */ |
| 521 | lwz r4, 0x0808(r3) |
| 522 | rlwinm r0, r4, 0, ~AER_AO |
| 523 | stw r0, 0x0808(r3) |
| 524 | #endif /* CONFIG_MASK_AER_AO */ |
| 525 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 526 | /* Initialize the Hardware Implementation-dependent Registers */ |
| 527 | /* HID0 also contains cache control */ |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 528 | /* - force invalidation of data and instruction caches */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 529 | /*------------------------------------------------------*/ |
| 530 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 531 | lis r3, CFG_SYS_HID0_INIT@h |
| 532 | ori r3, r3, (CFG_SYS_HID0_INIT | HID0_ICFI | HID0_DCFI)@l |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 533 | SYNC |
| 534 | mtspr HID0, r3 |
| 535 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 536 | lis r3, CFG_SYS_HID0_FINAL@h |
| 537 | ori r3, r3, (CFG_SYS_HID0_FINAL & ~(HID0_ICFI | HID0_DCFI))@l |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 538 | SYNC |
| 539 | mtspr HID0, r3 |
| 540 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 541 | lis r3, CFG_SYS_HID2@h |
| 542 | ori r3, r3, CFG_SYS_HID2@l |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 543 | SYNC |
| 544 | mtspr HID2, r3 |
| 545 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 546 | /* Done! */ |
| 547 | /*------------------------------*/ |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 548 | blr |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 549 | |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 550 | /* setup_bats - set them up to some initial state */ |
| 551 | .globl setup_bats |
| 552 | setup_bats: |
| 553 | addis r0, r0, 0x0000 |
| 554 | |
| 555 | /* IBAT 0 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 556 | addis r4, r0, CFG_SYS_IBAT0L@h |
| 557 | ori r4, r4, CFG_SYS_IBAT0L@l |
| 558 | addis r3, r0, CFG_SYS_IBAT0U@h |
| 559 | ori r3, r3, CFG_SYS_IBAT0U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 560 | mtspr IBAT0L, r4 |
| 561 | mtspr IBAT0U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 562 | |
| 563 | /* DBAT 0 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 564 | addis r4, r0, CFG_SYS_DBAT0L@h |
| 565 | ori r4, r4, CFG_SYS_DBAT0L@l |
| 566 | addis r3, r0, CFG_SYS_DBAT0U@h |
| 567 | ori r3, r3, CFG_SYS_DBAT0U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 568 | mtspr DBAT0L, r4 |
| 569 | mtspr DBAT0U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 570 | |
| 571 | /* IBAT 1 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 572 | addis r4, r0, CFG_SYS_IBAT1L@h |
| 573 | ori r4, r4, CFG_SYS_IBAT1L@l |
| 574 | addis r3, r0, CFG_SYS_IBAT1U@h |
| 575 | ori r3, r3, CFG_SYS_IBAT1U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 576 | mtspr IBAT1L, r4 |
| 577 | mtspr IBAT1U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 578 | |
| 579 | /* DBAT 1 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 580 | addis r4, r0, CFG_SYS_DBAT1L@h |
| 581 | ori r4, r4, CFG_SYS_DBAT1L@l |
| 582 | addis r3, r0, CFG_SYS_DBAT1U@h |
| 583 | ori r3, r3, CFG_SYS_DBAT1U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 584 | mtspr DBAT1L, r4 |
| 585 | mtspr DBAT1U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 586 | |
| 587 | /* IBAT 2 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 588 | addis r4, r0, CFG_SYS_IBAT2L@h |
| 589 | ori r4, r4, CFG_SYS_IBAT2L@l |
| 590 | addis r3, r0, CFG_SYS_IBAT2U@h |
| 591 | ori r3, r3, CFG_SYS_IBAT2U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 592 | mtspr IBAT2L, r4 |
| 593 | mtspr IBAT2U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 594 | |
| 595 | /* DBAT 2 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 596 | addis r4, r0, CFG_SYS_DBAT2L@h |
| 597 | ori r4, r4, CFG_SYS_DBAT2L@l |
| 598 | addis r3, r0, CFG_SYS_DBAT2U@h |
| 599 | ori r3, r3, CFG_SYS_DBAT2U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 600 | mtspr DBAT2L, r4 |
| 601 | mtspr DBAT2U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 602 | |
| 603 | /* IBAT 3 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 604 | addis r4, r0, CFG_SYS_IBAT3L@h |
| 605 | ori r4, r4, CFG_SYS_IBAT3L@l |
| 606 | addis r3, r0, CFG_SYS_IBAT3U@h |
| 607 | ori r3, r3, CFG_SYS_IBAT3U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 608 | mtspr IBAT3L, r4 |
| 609 | mtspr IBAT3U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 610 | |
| 611 | /* DBAT 3 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 612 | addis r4, r0, CFG_SYS_DBAT3L@h |
| 613 | ori r4, r4, CFG_SYS_DBAT3L@l |
| 614 | addis r3, r0, CFG_SYS_DBAT3U@h |
| 615 | ori r3, r3, CFG_SYS_DBAT3U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 616 | mtspr DBAT3L, r4 |
| 617 | mtspr DBAT3U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 618 | |
Becky Bruce | 03ea1be | 2008-05-08 19:02:12 -0500 | [diff] [blame] | 619 | #ifdef CONFIG_HIGH_BATS |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 620 | /* IBAT 4 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 621 | addis r4, r0, CFG_SYS_IBAT4L@h |
| 622 | ori r4, r4, CFG_SYS_IBAT4L@l |
| 623 | addis r3, r0, CFG_SYS_IBAT4U@h |
| 624 | ori r3, r3, CFG_SYS_IBAT4U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 625 | mtspr IBAT4L, r4 |
| 626 | mtspr IBAT4U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 627 | |
| 628 | /* DBAT 4 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 629 | addis r4, r0, CFG_SYS_DBAT4L@h |
| 630 | ori r4, r4, CFG_SYS_DBAT4L@l |
| 631 | addis r3, r0, CFG_SYS_DBAT4U@h |
| 632 | ori r3, r3, CFG_SYS_DBAT4U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 633 | mtspr DBAT4L, r4 |
| 634 | mtspr DBAT4U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 635 | |
| 636 | /* IBAT 5 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 637 | addis r4, r0, CFG_SYS_IBAT5L@h |
| 638 | ori r4, r4, CFG_SYS_IBAT5L@l |
| 639 | addis r3, r0, CFG_SYS_IBAT5U@h |
| 640 | ori r3, r3, CFG_SYS_IBAT5U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 641 | mtspr IBAT5L, r4 |
| 642 | mtspr IBAT5U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 643 | |
| 644 | /* DBAT 5 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 645 | addis r4, r0, CFG_SYS_DBAT5L@h |
| 646 | ori r4, r4, CFG_SYS_DBAT5L@l |
| 647 | addis r3, r0, CFG_SYS_DBAT5U@h |
| 648 | ori r3, r3, CFG_SYS_DBAT5U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 649 | mtspr DBAT5L, r4 |
| 650 | mtspr DBAT5U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 651 | |
| 652 | /* IBAT 6 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 653 | addis r4, r0, CFG_SYS_IBAT6L@h |
| 654 | ori r4, r4, CFG_SYS_IBAT6L@l |
| 655 | addis r3, r0, CFG_SYS_IBAT6U@h |
| 656 | ori r3, r3, CFG_SYS_IBAT6U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 657 | mtspr IBAT6L, r4 |
| 658 | mtspr IBAT6U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 659 | |
| 660 | /* DBAT 6 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 661 | addis r4, r0, CFG_SYS_DBAT6L@h |
| 662 | ori r4, r4, CFG_SYS_DBAT6L@l |
| 663 | addis r3, r0, CFG_SYS_DBAT6U@h |
| 664 | ori r3, r3, CFG_SYS_DBAT6U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 665 | mtspr DBAT6L, r4 |
| 666 | mtspr DBAT6U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 667 | |
| 668 | /* IBAT 7 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 669 | addis r4, r0, CFG_SYS_IBAT7L@h |
| 670 | ori r4, r4, CFG_SYS_IBAT7L@l |
| 671 | addis r3, r0, CFG_SYS_IBAT7U@h |
| 672 | ori r3, r3, CFG_SYS_IBAT7U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 673 | mtspr IBAT7L, r4 |
| 674 | mtspr IBAT7U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 675 | |
| 676 | /* DBAT 7 */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 677 | addis r4, r0, CFG_SYS_DBAT7L@h |
| 678 | ori r4, r4, CFG_SYS_DBAT7L@l |
| 679 | addis r3, r0, CFG_SYS_DBAT7U@h |
| 680 | ori r3, r3, CFG_SYS_DBAT7U@l |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 681 | mtspr DBAT7L, r4 |
| 682 | mtspr DBAT7U, r3 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 683 | #endif |
| 684 | |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 685 | isync |
| 686 | |
| 687 | /* invalidate all tlb's |
| 688 | * |
| 689 | * From the 603e User Manual: "The 603e provides the ability to |
| 690 | * invalidate a TLB entry. The TLB Invalidate Entry (tlbie) |
| 691 | * instruction invalidates the TLB entry indexed by the EA, and |
| 692 | * operates on both the instruction and data TLBs simultaneously |
| 693 | * invalidating four TLB entries (both sets in each TLB). The |
| 694 | * index corresponds to bits 15-19 of the EA. To invalidate all |
| 695 | * entries within both TLBs, 32 tlbie instructions should be |
| 696 | * issued, incrementing this field by one each time." |
| 697 | * |
| 698 | * "Note that the tlbia instruction is not implemented on the |
| 699 | * 603e." |
| 700 | * |
| 701 | * bits 15-19 correspond to addresses 0x00000000 to 0x0001F000 |
| 702 | * incrementing by 0x1000 each time. The code below is sort of |
Stefan Roese | 88fbf93 | 2010-04-15 16:07:28 +0200 | [diff] [blame] | 703 | * based on code in "flush_tlbs" from arch/powerpc/kernel/head.S |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 704 | * |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 705 | */ |
| 706 | lis r3, 0 |
| 707 | lis r5, 2 |
| 708 | |
| 709 | 1: |
| 710 | tlbie r3 |
| 711 | addi r3, r3, 0x1000 |
| 712 | cmp 0, 0, r3, r5 |
| 713 | blt 1b |
| 714 | |
| 715 | blr |
| 716 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 717 | /* Cache functions. |
| 718 | * |
| 719 | * Note: requires that all cache bits in |
| 720 | * HID0 are in the low half word. |
| 721 | */ |
Scott Wood | 2b36fbb | 2012-12-06 13:33:17 +0000 | [diff] [blame] | 722 | #ifndef MINIMAL_SPL |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 723 | .globl icache_enable |
| 724 | icache_enable: |
| 725 | mfspr r3, HID0 |
| 726 | ori r3, r3, HID0_ICE |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 727 | li r4, HID0_ICFI|HID0_ILOCK |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 728 | andc r3, r3, r4 |
| 729 | ori r4, r3, HID0_ICFI |
| 730 | isync |
| 731 | mtspr HID0, r4 /* sets enable and invalidate, clears lock */ |
| 732 | isync |
| 733 | mtspr HID0, r3 /* clears invalidate */ |
| 734 | blr |
| 735 | |
| 736 | .globl icache_disable |
| 737 | icache_disable: |
| 738 | mfspr r3, HID0 |
| 739 | lis r4, 0 |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 740 | ori r4, r4, HID0_ICE|HID0_ICFI|HID0_ILOCK |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 741 | andc r3, r3, r4 |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 742 | isync |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 743 | mtspr HID0, r3 /* clears invalidate, enable and lock */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 744 | blr |
| 745 | |
| 746 | .globl icache_status |
| 747 | icache_status: |
| 748 | mfspr r3, HID0 |
Marian Balakowicz | 758e5d3 | 2006-03-14 16:01:25 +0100 | [diff] [blame] | 749 | rlwinm r3, r3, (31 - HID0_ICE_SHIFT + 1), 31, 31 |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 750 | blr |
Scott Wood | 2b36fbb | 2012-12-06 13:33:17 +0000 | [diff] [blame] | 751 | #endif /* !MINIMAL_SPL */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 752 | |
| 753 | .globl dcache_enable |
| 754 | dcache_enable: |
| 755 | mfspr r3, HID0 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 756 | li r5, HID0_DCFI|HID0_DLOCK |
| 757 | andc r3, r3, r5 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 758 | ori r3, r3, HID0_DCE |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 759 | sync |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 760 | mtspr HID0, r3 /* enable, no invalidate */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 761 | blr |
| 762 | |
| 763 | .globl dcache_disable |
| 764 | dcache_disable: |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 765 | mflr r4 |
| 766 | bl flush_dcache /* uses r3 and r5 */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 767 | mfspr r3, HID0 |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 768 | li r5, HID0_DCE|HID0_DLOCK |
| 769 | andc r3, r3, r5 |
| 770 | ori r5, r3, HID0_DCFI |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 771 | sync |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 772 | mtspr HID0, r5 /* sets invalidate, clears enable and lock */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 773 | sync |
| 774 | mtspr HID0, r3 /* clears invalidate */ |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 775 | mtlr r4 |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 776 | blr |
| 777 | |
| 778 | .globl dcache_status |
| 779 | dcache_status: |
| 780 | mfspr r3, HID0 |
Marian Balakowicz | 758e5d3 | 2006-03-14 16:01:25 +0100 | [diff] [blame] | 781 | rlwinm r3, r3, (31 - HID0_DCE_SHIFT + 1), 31, 31 |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 782 | blr |
| 783 | |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 784 | .globl flush_dcache |
| 785 | flush_dcache: |
| 786 | lis r3, 0 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 787 | lis r5, CONFIG_SYS_CACHELINE_SIZE |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 788 | 1: cmp 0, 1, r3, r5 |
| 789 | bge 2f |
| 790 | lwz r5, 0(r3) |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 791 | lis r5, CONFIG_SYS_CACHELINE_SIZE |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 792 | addi r3, r3, 0x4 |
| 793 | b 1b |
| 794 | 2: blr |
| 795 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 796 | /*-------------------------------------------------------------------*/ |
| 797 | |
| 798 | /* |
Simon Glass | 284f71b | 2019-12-28 10:44:45 -0700 | [diff] [blame] | 799 | * void relocate_code(addr_sp, gd, addr_moni) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 800 | * |
| 801 | * This "function" does not return, instead it continues in RAM |
| 802 | * after relocating the monitor code. |
| 803 | * |
| 804 | * r3 = dest |
| 805 | * r4 = src |
| 806 | * r5 = length in bytes |
| 807 | * r6 = cachelinesize |
| 808 | */ |
| 809 | .globl relocate_code |
| 810 | relocate_code: |
| 811 | mr r1, r3 /* Set new stack pointer */ |
| 812 | mr r9, r4 /* Save copy of Global Data pointer */ |
| 813 | mr r10, r5 /* Save copy of Destination Address */ |
| 814 | |
Joakim Tjernlund | 3fbaa4d | 2010-01-19 14:41:56 +0100 | [diff] [blame] | 815 | GET_GOT |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 816 | mr r3, r5 /* Destination Address */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 817 | lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */ |
| 818 | ori r4, r4, CONFIG_SYS_MONITOR_BASE@l |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 819 | lwz r5, GOT(__bss_start) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 820 | sub r5, r5, r4 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 821 | li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 822 | |
| 823 | /* |
| 824 | * Fix GOT pointer: |
| 825 | * |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 826 | * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 827 | * + Destination Address |
| 828 | * |
| 829 | * Offset: |
| 830 | */ |
| 831 | sub r15, r10, r4 |
| 832 | |
| 833 | /* First our own GOT */ |
Joakim Tjernlund | 3fbaa4d | 2010-01-19 14:41:56 +0100 | [diff] [blame] | 834 | add r12, r12, r15 |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 835 | /* then the one used by the C code */ |
| 836 | add r30, r30, r15 |
| 837 | |
| 838 | /* |
| 839 | * Now relocate code |
| 840 | */ |
| 841 | |
| 842 | cmplw cr1,r3,r4 |
| 843 | addi r0,r5,3 |
| 844 | srwi. r0,r0,2 |
| 845 | beq cr1,4f /* In place copy is not necessary */ |
| 846 | beq 7f /* Protect against 0 count */ |
| 847 | mtctr r0 |
| 848 | bge cr1,2f |
| 849 | la r8,-4(r4) |
| 850 | la r7,-4(r3) |
| 851 | |
| 852 | /* copy */ |
| 853 | 1: lwzu r0,4(r8) |
| 854 | stwu r0,4(r7) |
| 855 | bdnz 1b |
| 856 | |
| 857 | addi r0,r5,3 |
| 858 | srwi. r0,r0,2 |
| 859 | mtctr r0 |
| 860 | la r8,-4(r4) |
| 861 | la r7,-4(r3) |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 862 | |
| 863 | /* and compare */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 864 | 20: lwzu r20,4(r8) |
| 865 | lwzu r21,4(r7) |
| 866 | xor. r22, r20, r21 |
| 867 | bne 30f |
| 868 | bdnz 20b |
| 869 | b 4f |
| 870 | |
| 871 | /* compare failed */ |
| 872 | 30: li r3, 0 |
| 873 | blr |
| 874 | |
| 875 | 2: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */ |
| 876 | add r8,r4,r0 |
| 877 | add r7,r3,r0 |
| 878 | 3: lwzu r0,-4(r8) |
| 879 | stwu r0,-4(r7) |
| 880 | bdnz 3b |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 881 | |
| 882 | /* |
| 883 | * Now flush the cache: note that we must start from a cache aligned |
| 884 | * address. Otherwise we might miss one cache line. |
| 885 | */ |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 886 | 4: cmpwi r6,0 |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 887 | add r5,r3,r5 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 888 | beq 7f /* Always flush prefetch queue in any case */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 889 | subi r0,r6,1 |
| 890 | andc r3,r3,r0 |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 891 | mr r4,r3 |
| 892 | 5: dcbst 0,r4 |
| 893 | add r4,r4,r6 |
| 894 | cmplw r4,r5 |
| 895 | blt 5b |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 896 | sync /* Wait for all dcbst to complete on bus */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 897 | mr r4,r3 |
| 898 | 6: icbi 0,r4 |
| 899 | add r4,r4,r6 |
| 900 | cmplw r4,r5 |
| 901 | blt 6b |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 902 | 7: sync /* Wait for all icbi to complete on bus */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 903 | isync |
| 904 | |
| 905 | /* |
| 906 | * We are done. Do not return, instead branch to second part of board |
| 907 | * initialization, now running from RAM. |
| 908 | */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 909 | addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET |
| 910 | mtlr r0 |
| 911 | blr |
| 912 | |
| 913 | in_ram: |
| 914 | |
| 915 | /* |
Joakim Tjernlund | 3fbaa4d | 2010-01-19 14:41:56 +0100 | [diff] [blame] | 916 | * Relocation Function, r12 point to got2+0x8000 |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 917 | * |
| 918 | * Adjust got2 pointers, no need to check for 0, this code |
| 919 | * already puts a few entries in the table. |
| 920 | */ |
| 921 | li r0,__got2_entries@sectoff@l |
| 922 | la r3,GOT(_GOT2_TABLE_) |
| 923 | lwz r11,GOT(_GOT2_TABLE_) |
| 924 | mtctr r0 |
| 925 | sub r11,r3,r11 |
| 926 | addi r3,r3,-4 |
| 927 | 1: lwzu r0,4(r3) |
Joakim Tjernlund | 4f2fdac | 2009-10-08 02:03:51 +0200 | [diff] [blame] | 928 | cmpwi r0,0 |
| 929 | beq- 2f |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 930 | add r0,r0,r11 |
| 931 | stw r0,0(r3) |
Joakim Tjernlund | 4f2fdac | 2009-10-08 02:03:51 +0200 | [diff] [blame] | 932 | 2: bdnz 1b |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 933 | |
Scott Wood | 2b36fbb | 2012-12-06 13:33:17 +0000 | [diff] [blame] | 934 | #ifndef MINIMAL_SPL |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 935 | /* |
| 936 | * Now adjust the fixups and the pointers to the fixups |
| 937 | * in case we need to move ourselves again. |
| 938 | */ |
Joakim Tjernlund | 4f2fdac | 2009-10-08 02:03:51 +0200 | [diff] [blame] | 939 | li r0,__fixup_entries@sectoff@l |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 940 | lwz r3,GOT(_FIXUP_TABLE_) |
| 941 | cmpwi r0,0 |
| 942 | mtctr r0 |
| 943 | addi r3,r3,-4 |
| 944 | beq 4f |
| 945 | 3: lwzu r4,4(r3) |
| 946 | lwzux r0,r4,r11 |
Joakim Tjernlund | c61b25a | 2010-10-14 11:51:44 +0200 | [diff] [blame] | 947 | cmpwi r0,0 |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 948 | add r0,r0,r11 |
Joakim Tjernlund | 401b592 | 2010-11-04 19:02:00 +0100 | [diff] [blame] | 949 | stw r4,0(r3) |
Joakim Tjernlund | c61b25a | 2010-10-14 11:51:44 +0200 | [diff] [blame] | 950 | beq- 5f |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 951 | stw r0,0(r4) |
Joakim Tjernlund | c61b25a | 2010-10-14 11:51:44 +0200 | [diff] [blame] | 952 | 5: bdnz 3b |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 953 | 4: |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 954 | #endif |
| 955 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 956 | clear_bss: |
| 957 | /* |
| 958 | * Now clear BSS segment |
| 959 | */ |
| 960 | lwz r3,GOT(__bss_start) |
Simon Glass | ed70c8f | 2013-03-14 06:54:53 +0000 | [diff] [blame] | 961 | lwz r4,GOT(__bss_end) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 962 | |
| 963 | cmplw 0, r3, r4 |
| 964 | beq 6f |
| 965 | |
| 966 | li r0, 0 |
| 967 | 5: |
| 968 | stw r0, 0(r3) |
| 969 | addi r3, r3, 4 |
| 970 | cmplw 0, r3, r4 |
| 971 | bne 5b |
| 972 | 6: |
| 973 | |
| 974 | mr r3, r9 /* Global Data pointer */ |
| 975 | mr r4, r10 /* Destination Address */ |
| 976 | bl board_init_r |
| 977 | |
Scott Wood | 2b36fbb | 2012-12-06 13:33:17 +0000 | [diff] [blame] | 978 | #ifndef MINIMAL_SPL |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 979 | /* |
| 980 | * Copy exception vector code to low memory |
| 981 | * |
| 982 | * r3: dest_addr |
| 983 | * r7: source address, r8: end address, r9: target address |
| 984 | */ |
| 985 | .globl trap_init |
| 986 | trap_init: |
Joakim Tjernlund | 3fbaa4d | 2010-01-19 14:41:56 +0100 | [diff] [blame] | 987 | mflr r4 /* save link register */ |
| 988 | GET_GOT |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 989 | lwz r7, GOT(_start) |
| 990 | lwz r8, GOT(_end_of_vectors) |
| 991 | |
| 992 | li r9, 0x100 /* reset vector always at 0x100 */ |
| 993 | |
| 994 | cmplw 0, r7, r8 |
| 995 | bgelr /* return if r7>=r8 - just in case */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 996 | 1: |
| 997 | lwz r0, 0(r7) |
| 998 | stw r0, 0(r9) |
| 999 | addi r7, r7, 4 |
| 1000 | addi r9, r9, 4 |
| 1001 | cmplw 0, r7, r8 |
| 1002 | bne 1b |
| 1003 | |
| 1004 | /* |
| 1005 | * relocate `hdlr' and `int_return' entries |
| 1006 | */ |
| 1007 | li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET |
| 1008 | li r8, Alignment - _start + EXC_OFF_SYS_RESET |
| 1009 | 2: |
| 1010 | bl trap_reloc |
| 1011 | addi r7, r7, 0x100 /* next exception vector */ |
| 1012 | cmplw 0, r7, r8 |
| 1013 | blt 2b |
| 1014 | |
| 1015 | li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET |
| 1016 | bl trap_reloc |
| 1017 | |
| 1018 | li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET |
| 1019 | bl trap_reloc |
| 1020 | |
| 1021 | li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET |
| 1022 | li r8, SystemCall - _start + EXC_OFF_SYS_RESET |
| 1023 | 3: |
| 1024 | bl trap_reloc |
| 1025 | addi r7, r7, 0x100 /* next exception vector */ |
| 1026 | cmplw 0, r7, r8 |
| 1027 | blt 3b |
| 1028 | |
| 1029 | li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET |
| 1030 | li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET |
| 1031 | 4: |
| 1032 | bl trap_reloc |
| 1033 | addi r7, r7, 0x100 /* next exception vector */ |
| 1034 | cmplw 0, r7, r8 |
| 1035 | blt 4b |
| 1036 | |
| 1037 | mfmsr r3 /* now that the vectors have */ |
| 1038 | lis r7, MSR_IP@h /* relocated into low memory */ |
| 1039 | ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */ |
| 1040 | andc r3, r3, r7 /* (if it was on) */ |
| 1041 | SYNC /* Some chip revs need this... */ |
| 1042 | mtmsr r3 |
| 1043 | SYNC |
| 1044 | |
| 1045 | mtlr r4 /* restore link register */ |
| 1046 | blr |
| 1047 | |
Scott Wood | 2b36fbb | 2012-12-06 13:33:17 +0000 | [diff] [blame] | 1048 | #endif /* !MINIMAL_SPL */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1049 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1050 | #ifdef CONFIG_SYS_INIT_RAM_LOCK |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 1051 | lock_ram_in_cache: |
| 1052 | /* Allocate Initial RAM in data cache. |
| 1053 | */ |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1054 | lis r3, (CFG_SYS_INIT_RAM_ADDR & ~31)@h |
| 1055 | ori r3, r3, (CFG_SYS_INIT_RAM_ADDR & ~31)@l |
| 1056 | li r4, ((CFG_SYS_INIT_RAM_SIZE & ~31) + \ |
| 1057 | (CFG_SYS_INIT_RAM_ADDR & 31) + 31) / 32 |
Nick Spence | b89d6fb | 2008-08-28 14:09:11 -0700 | [diff] [blame] | 1058 | mtctr r4 |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 1059 | 1: |
| 1060 | dcbz r0, r3 |
| 1061 | addi r3, r3, 32 |
| 1062 | bdnz 1b |
| 1063 | |
| 1064 | /* Lock the data cache */ |
| 1065 | mfspr r0, HID0 |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 1066 | ori r0, r0, HID0_DLOCK |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 1067 | sync |
| 1068 | mtspr HID0, r0 |
| 1069 | sync |
| 1070 | blr |
| 1071 | |
Scott Wood | 2b36fbb | 2012-12-06 13:33:17 +0000 | [diff] [blame] | 1072 | #ifndef MINIMAL_SPL |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1073 | .globl unlock_ram_in_cache |
| 1074 | unlock_ram_in_cache: |
| 1075 | /* invalidate the INIT_RAM section */ |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1076 | lis r3, (CFG_SYS_INIT_RAM_ADDR & ~31)@h |
| 1077 | ori r3, r3, (CFG_SYS_INIT_RAM_ADDR & ~31)@l |
| 1078 | li r4, ((CFG_SYS_INIT_RAM_SIZE & ~31) + \ |
| 1079 | (CFG_SYS_INIT_RAM_ADDR & 31) + 31) / 32 |
Nick Spence | b89d6fb | 2008-08-28 14:09:11 -0700 | [diff] [blame] | 1080 | mtctr r4 |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1081 | 1: icbi r0, r3 |
| 1082 | dcbi r0, r3 |
| 1083 | addi r3, r3, 32 |
| 1084 | bdnz 1b |
| 1085 | sync /* Wait for all icbi to complete on bus */ |
| 1086 | isync |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 1087 | |
| 1088 | /* Unlock the data cache and invalidate it */ |
| 1089 | mfspr r3, HID0 |
| 1090 | li r5, HID0_DLOCK|HID0_DCFI |
| 1091 | andc r3, r3, r5 /* no invalidate, unlock */ |
| 1092 | ori r5, r3, HID0_DCFI /* invalidate, unlock */ |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 1093 | sync |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 1094 | mtspr HID0, r5 /* invalidate, unlock */ |
Kumar Gala | d5d94d6 | 2006-02-10 15:40:06 -0600 | [diff] [blame] | 1095 | sync |
Nick Spence | 7c20aef | 2008-08-28 14:09:25 -0700 | [diff] [blame] | 1096 | mtspr HID0, r3 /* no invalidate, unlock */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1097 | blr |
Scott Wood | 2b36fbb | 2012-12-06 13:33:17 +0000 | [diff] [blame] | 1098 | #endif /* !MINIMAL_SPL */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1099 | #endif /* CONFIG_SYS_INIT_RAM_LOCK */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1100 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 1101 | #ifdef CFG_SYS_FLASHBOOT |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1102 | map_flash_by_law1: |
| 1103 | /* When booting from ROM (Flash or EPROM), clear the */ |
| 1104 | /* Address Mask in OR0 so ROM appears everywhere */ |
| 1105 | /*----------------------------------------------------*/ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1106 | lis r3, (CONFIG_SYS_IMMR)@h /* r3 <= CONFIG_SYS_IMMR */ |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 1107 | lwz r4, OR0@l(r3) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1108 | li r5, 0x7fff /* r5 <= 0x00007FFFF */ |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 1109 | and r4, r4, r5 |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1110 | stw r4, OR0@l(r3) /* OR0 <= OR0 & 0x00007FFFF */ |
| 1111 | |
| 1112 | /* As MPC8349E User's Manual presented, when RCW[BMS] is set to 0, |
| 1113 | * system will boot from 0x0000_0100, and the LBLAWBAR0[BASE_ADDR] |
| 1114 | * reset value is 0x00000; when RCW[BMS] is set to 1, system will boot |
| 1115 | * from 0xFFF0_0100, and the LBLAWBAR0[BASE_ADDR] reset value is |
| 1116 | * 0xFF800. From the hard resetting to here, the processor fetched and |
| 1117 | * executed the instructions one by one. There is not absolutely |
| 1118 | * jumping happened. Laterly, the u-boot code has to do an absolutely |
| 1119 | * jumping to tell the CPU instruction fetching component what the |
| 1120 | * u-boot TEXT base address is. Because the TEXT base resides in the |
| 1121 | * boot ROM memory space, to garantee the code can run smoothly after |
| 1122 | * that jumping, we must map in the entire boot ROM by Local Access |
| 1123 | * Window. Sometimes, we desire an non-0x00000 or non-0xFF800 starting |
| 1124 | * address for boot ROM, such as 0xFE000000. In this case, the default |
| 1125 | * LBIU Local Access Widow 0 will not cover this memory space. So, we |
| 1126 | * need another window to map in it. |
| 1127 | */ |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1128 | lis r4, (CFG_SYS_FLASH_BASE)@h |
| 1129 | ori r4, r4, (CFG_SYS_FLASH_BASE)@l |
| 1130 | stw r4, LBLAWBAR1(r3) /* LBLAWBAR1 <= CFG_SYS_FLASH_BASE */ |
Timur Tabi | 53b4617 | 2006-08-22 17:07:00 -0500 | [diff] [blame] | 1131 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1132 | /* Store 0x80000012 + log2(CFG_SYS_FLASH_SIZE) into LBLAWAR1 */ |
Timur Tabi | 53b4617 | 2006-08-22 17:07:00 -0500 | [diff] [blame] | 1133 | lis r4, (0x80000012)@h |
| 1134 | ori r4, r4, (0x80000012)@l |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1135 | li r5, CFG_SYS_FLASH_SIZE |
Timur Tabi | 53b4617 | 2006-08-22 17:07:00 -0500 | [diff] [blame] | 1136 | 1: srawi. r5, r5, 1 /* r5 = r5 >> 1 */ |
| 1137 | addi r4, r4, 1 |
| 1138 | bne 1b |
| 1139 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1140 | stw r4, LBLAWAR1(r3) /* LBLAWAR1 <= 8MB Flash Size */ |
Joakim Tjernlund | b168d63 | 2010-11-19 14:15:33 +0100 | [diff] [blame] | 1141 | /* Wait for HW to catch up */ |
| 1142 | lwz r4, LBLAWAR1(r3) |
| 1143 | twi 0,r4,0 |
| 1144 | isync |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1145 | blr |
| 1146 | |
| 1147 | /* Though all the LBIU Local Access Windows and LBC Banks will be |
| 1148 | * initialized in the C code, we'd better configure boot ROM's |
| 1149 | * window 0 and bank 0 correctly at here. |
| 1150 | */ |
| 1151 | remap_flash_by_law0: |
| 1152 | /* Initialize the BR0 with the boot ROM starting address. */ |
| 1153 | lwz r4, BR0(r3) |
| 1154 | li r5, 0x7FFF |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 1155 | and r4, r4, r5 |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1156 | lis r5, (CFG_SYS_FLASH_BASE & 0xFFFF8000)@h |
| 1157 | ori r5, r5, (CFG_SYS_FLASH_BASE & 0xFFFF8000)@l |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1158 | or r5, r5, r4 |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1159 | stw r5, BR0(r3) /* r5 <= (CFG_SYS_FLASH_BASE & 0xFFFF8000) | (BR0 & 0x00007FFF) */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1160 | |
| 1161 | lwz r4, OR0(r3) |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1162 | lis r5, ~((CFG_SYS_FLASH_SIZE << 4) - 1) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1163 | or r4, r4, r5 |
Timur Tabi | 53b4617 | 2006-08-22 17:07:00 -0500 | [diff] [blame] | 1164 | stw r4, OR0(r3) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1165 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1166 | lis r4, (CFG_SYS_FLASH_BASE)@h |
| 1167 | ori r4, r4, (CFG_SYS_FLASH_BASE)@l |
| 1168 | stw r4, LBLAWBAR0(r3) /* LBLAWBAR0 <= CFG_SYS_FLASH_BASE */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1169 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1170 | /* Store 0x80000012 + log2(CFG_SYS_FLASH_SIZE) into LBLAWAR0 */ |
Timur Tabi | 53b4617 | 2006-08-22 17:07:00 -0500 | [diff] [blame] | 1171 | lis r4, (0x80000012)@h |
| 1172 | ori r4, r4, (0x80000012)@l |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1173 | li r5, CFG_SYS_FLASH_SIZE |
Timur Tabi | 53b4617 | 2006-08-22 17:07:00 -0500 | [diff] [blame] | 1174 | 1: srawi. r5, r5, 1 /* r5 = r5 >> 1 */ |
| 1175 | addi r4, r4, 1 |
| 1176 | bne 1b |
| 1177 | stw r4, LBLAWAR0(r3) /* LBLAWAR0 <= Flash Size */ |
| 1178 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1179 | |
| 1180 | xor r4, r4, r4 |
| 1181 | stw r4, LBLAWBAR1(r3) |
| 1182 | stw r4, LBLAWAR1(r3) /* Off LBIU LAW1 */ |
Joakim Tjernlund | b168d63 | 2010-11-19 14:15:33 +0100 | [diff] [blame] | 1183 | /* Wait for HW to catch up */ |
| 1184 | lwz r4, LBLAWAR1(r3) |
| 1185 | twi 0,r4,0 |
| 1186 | isync |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1187 | blr |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 1188 | #endif /* CFG_SYS_FLASHBOOT */ |