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