Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1998 Dan Malek <dmalek@jlc.net> |
| 3 | * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se> |
| 4 | * Copyright (C) 2000, 2001, 2002, 2007 Wolfgang Denk <wd@denx.de> |
| 5 | * Copyright Freescale Semiconductor, Inc. 2004, 2006. All rights reserved. |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | * |
| 25 | * Based on the MPC83xx code. |
| 26 | */ |
| 27 | |
| 28 | /* |
| 29 | * U-Boot - Startup Code for MPC512x based Embedded Boards |
| 30 | */ |
| 31 | |
| 32 | #include <config.h> |
| 33 | #include <mpc512x.h> |
Peter Tyser | 561858e | 2008-11-03 09:30:59 -0600 | [diff] [blame] | 34 | #include <timestamp.h> |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 35 | #include <version.h> |
| 36 | |
| 37 | #define CONFIG_521X 1 /* needed for Linux kernel header files*/ |
| 38 | |
| 39 | #include <ppc_asm.tmpl> |
| 40 | #include <ppc_defs.h> |
| 41 | |
| 42 | #include <asm/cache.h> |
| 43 | #include <asm/mmu.h> |
| 44 | |
| 45 | #ifndef CONFIG_IDENT_STRING |
| 46 | #define CONFIG_IDENT_STRING "MPC512X" |
| 47 | #endif |
| 48 | |
| 49 | /* |
| 50 | * Floating Point enable, Machine Check and Recoverable Interr. |
| 51 | */ |
| 52 | #undef MSR_KERNEL |
| 53 | #ifdef DEBUG |
| 54 | #define MSR_KERNEL (MSR_FP|MSR_RI) |
| 55 | #else |
| 56 | #define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI) |
| 57 | #endif |
| 58 | |
| 59 | /* Macros for manipulating CSx_START/STOP */ |
| 60 | #define START_REG(start) ((start) >> 16) |
| 61 | #define STOP_REG(start, size) (((start) + (size) - 1) >> 16) |
| 62 | |
| 63 | /* |
| 64 | * Set up GOT: Global Offset Table |
| 65 | * |
| 66 | * Use r14 to access the GOT |
| 67 | */ |
| 68 | START_GOT |
| 69 | GOT_ENTRY(_GOT2_TABLE_) |
| 70 | GOT_ENTRY(_FIXUP_TABLE_) |
| 71 | |
| 72 | GOT_ENTRY(_start) |
| 73 | GOT_ENTRY(_start_of_vectors) |
| 74 | GOT_ENTRY(_end_of_vectors) |
| 75 | GOT_ENTRY(transfer_to_handler) |
| 76 | |
| 77 | GOT_ENTRY(__init_end) |
| 78 | GOT_ENTRY(_end) |
| 79 | GOT_ENTRY(__bss_start) |
| 80 | END_GOT |
| 81 | |
| 82 | /* |
| 83 | * Magic number and version string |
| 84 | */ |
| 85 | .long 0x27051956 /* U-Boot Magic Number */ |
| 86 | .globl version_string |
| 87 | version_string: |
| 88 | .ascii U_BOOT_VERSION |
Peter Tyser | 561858e | 2008-11-03 09:30:59 -0600 | [diff] [blame] | 89 | .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")" |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 90 | .ascii " ", CONFIG_IDENT_STRING, "\0" |
| 91 | |
| 92 | /* |
| 93 | * Vector Table |
| 94 | */ |
| 95 | .text |
| 96 | . = EXC_OFF_SYS_RESET |
| 97 | |
| 98 | .globl _start |
| 99 | /* Start from here after reset/power on */ |
| 100 | _start: |
| 101 | li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */ |
| 102 | b boot_cold |
| 103 | |
| 104 | .globl _start_of_vectors |
| 105 | _start_of_vectors: |
| 106 | |
| 107 | /* Machine check */ |
| 108 | STD_EXCEPTION(0x200, MachineCheck, MachineCheckException) |
| 109 | |
| 110 | /* Data Storage exception. */ |
| 111 | STD_EXCEPTION(0x300, DataStorage, UnknownException) |
| 112 | |
| 113 | /* Instruction Storage exception. */ |
| 114 | STD_EXCEPTION(0x400, InstStorage, UnknownException) |
| 115 | |
| 116 | /* External Interrupt exception. */ |
| 117 | STD_EXCEPTION(0x500, ExtInterrupt, UnknownException) |
| 118 | |
| 119 | /* Alignment exception. */ |
| 120 | . = 0x600 |
| 121 | Alignment: |
| 122 | EXCEPTION_PROLOG(SRR0, SRR1) |
| 123 | mfspr r4,DAR |
| 124 | stw r4,_DAR(r21) |
| 125 | mfspr r5,DSISR |
| 126 | stw r5,_DSISR(r21) |
| 127 | addi r3,r1,STACK_FRAME_OVERHEAD |
| 128 | li r20,MSR_KERNEL |
| 129 | rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */ |
| 130 | rlwimi r20,r23,0,25,25 /* copy IP bit from saved MSR */ |
| 131 | lwz r6,GOT(transfer_to_handler) |
| 132 | mtlr r6 |
| 133 | blrl |
| 134 | .L_Alignment: |
| 135 | .long AlignmentException - _start + EXC_OFF_SYS_RESET |
| 136 | .long int_return - _start + EXC_OFF_SYS_RESET |
| 137 | |
| 138 | /* Program check exception */ |
| 139 | . = 0x700 |
| 140 | ProgramCheck: |
| 141 | EXCEPTION_PROLOG(SRR0, SRR1) |
| 142 | addi r3,r1,STACK_FRAME_OVERHEAD |
| 143 | li r20,MSR_KERNEL |
| 144 | rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */ |
| 145 | rlwimi r20,r23,0,25,25 /* copy IP bit from saved MSR */ |
| 146 | lwz r6,GOT(transfer_to_handler) |
| 147 | mtlr r6 |
| 148 | blrl |
| 149 | .L_ProgramCheck: |
| 150 | .long ProgramCheckException - _start + EXC_OFF_SYS_RESET |
| 151 | .long int_return - _start + EXC_OFF_SYS_RESET |
| 152 | |
| 153 | /* Floating Point Unit unavailable exception */ |
| 154 | STD_EXCEPTION(0x800, FPUnavailable, UnknownException) |
| 155 | |
| 156 | /* Decrementer */ |
| 157 | STD_EXCEPTION(0x900, Decrementer, timer_interrupt) |
| 158 | |
| 159 | /* Critical interrupt */ |
| 160 | STD_EXCEPTION(0xa00, Critical, UnknownException) |
| 161 | |
| 162 | /* System Call */ |
| 163 | STD_EXCEPTION(0xc00, SystemCall, UnknownException) |
| 164 | |
| 165 | /* Trace interrupt */ |
| 166 | STD_EXCEPTION(0xd00, Trace, UnknownException) |
| 167 | |
| 168 | /* Performance Monitor interrupt */ |
| 169 | STD_EXCEPTION(0xf00, PerfMon, UnknownException) |
| 170 | |
| 171 | /* Intruction Translation Miss */ |
| 172 | STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException) |
| 173 | |
| 174 | /* Data Load Translation Miss */ |
| 175 | STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException) |
| 176 | |
| 177 | /* Data Store Translation Miss */ |
| 178 | STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException) |
| 179 | |
| 180 | /* Instruction Address Breakpoint */ |
| 181 | STD_EXCEPTION(0x1300, InstructionAddrBreakpoint, DebugException) |
| 182 | |
| 183 | /* System Management interrupt */ |
| 184 | STD_EXCEPTION(0x1400, SystemMgmtInterrupt, UnknownException) |
| 185 | |
| 186 | .globl _end_of_vectors |
| 187 | _end_of_vectors: |
| 188 | |
| 189 | . = 0x3000 |
| 190 | boot_cold: |
| 191 | /* Save msr contents */ |
| 192 | mfmsr r5 |
| 193 | |
| 194 | /* Set IMMR area to our preferred location */ |
| 195 | lis r4, CONFIG_DEFAULT_IMMR@h |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 196 | lis r3, CONFIG_SYS_IMMR@h |
| 197 | ori r3, r3, CONFIG_SYS_IMMR@l |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 198 | stw r3, IMMRBAR(r4) |
| 199 | mtspr MBAR, r3 /* IMMRBAR is mirrored into the MBAR SPR (311) */ |
| 200 | |
| 201 | /* Initialise the machine */ |
| 202 | bl cpu_early_init |
| 203 | |
| 204 | /* |
| 205 | * Set up Local Access Windows: |
| 206 | * |
| 207 | * 1) Boot/CS0 (boot FLASH) |
| 208 | * 2) On-chip SRAM (initial stack purposes) |
| 209 | */ |
| 210 | |
| 211 | /* Boot CS/CS0 window range */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 212 | lis r3, CONFIG_SYS_IMMR@h |
| 213 | ori r3, r3, CONFIG_SYS_IMMR@l |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 214 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 215 | lis r4, START_REG(CONFIG_SYS_FLASH_BASE) |
| 216 | ori r4, r4, STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE) |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 217 | stw r4, LPCS0AW(r3) |
| 218 | |
| 219 | /* |
| 220 | * The SRAM window has a fixed size (256K), so only the start address |
| 221 | * is necessary |
| 222 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 223 | lis r4, START_REG(CONFIG_SYS_SRAM_BASE) & 0xff00 |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 224 | stw r4, SRAMBAR(r3) |
| 225 | |
Wolfgang Denk | b1b54e3 | 2007-08-02 21:27:46 +0200 | [diff] [blame] | 226 | /* |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 227 | * According to MPC5121e RM, configuring local access windows should |
Wolfgang Denk | b1b54e3 | 2007-08-02 21:27:46 +0200 | [diff] [blame] | 228 | * be followed by a dummy read of the config register that was |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 229 | * modified last and an isync |
Wolfgang Denk | b1b54e3 | 2007-08-02 21:27:46 +0200 | [diff] [blame] | 230 | */ |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 231 | lwz r4, SRAMBAR(r3) |
| 232 | isync |
| 233 | |
| 234 | /* |
| 235 | * Set configuration of the Boot/CS0, the SRAM window does not have a |
| 236 | * config register so no params can be set for it |
| 237 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 238 | lis r3, (CONFIG_SYS_IMMR + LPC_OFFSET)@h |
| 239 | ori r3, r3, (CONFIG_SYS_IMMR + LPC_OFFSET)@l |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 240 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 241 | lis r4, CONFIG_SYS_CS0_CFG@h |
| 242 | ori r4, r4, CONFIG_SYS_CS0_CFG@l |
Wolfgang Denk | b1b54e3 | 2007-08-02 21:27:46 +0200 | [diff] [blame] | 243 | stw r4, CS0_CONFIG(r3) |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 244 | |
| 245 | /* Master enable all CS's */ |
| 246 | lis r4, CS_CTRL_ME@h |
| 247 | ori r4, r4, CS_CTRL_ME@l |
| 248 | stw r4, CS_CTRL(r3) |
| 249 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 250 | lis r4, (CONFIG_SYS_MONITOR_BASE)@h |
| 251 | ori r4, r4, (CONFIG_SYS_MONITOR_BASE)@l |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 252 | addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET |
| 253 | mtlr r5 |
| 254 | blr |
| 255 | |
| 256 | in_flash: |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 257 | lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h |
| 258 | ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 259 | |
| 260 | li r0, 0 /* Make room for stack frame header and */ |
| 261 | stwu r0, -4(r1) /* clear final stack frame so that */ |
| 262 | stwu r0, -4(r1) /* stack backtraces terminate cleanly */ |
| 263 | |
| 264 | /* let the C-code set up the rest */ |
| 265 | /* */ |
| 266 | /* Be careful to keep code relocatable & stack humble */ |
| 267 | /*------------------------------------------------------*/ |
| 268 | |
| 269 | GET_GOT /* initialize GOT access */ |
| 270 | |
| 271 | /* r3: IMMR */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 272 | lis r3, CONFIG_SYS_IMMR@h |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 273 | /* run low-level CPU init code (in Flash) */ |
| 274 | bl cpu_init_f |
| 275 | |
| 276 | /* r3: BOOTFLAG */ |
| 277 | mr r3, r21 |
| 278 | /* run 1st part of board init code (in Flash) */ |
| 279 | bl board_init_f |
| 280 | |
| 281 | /* NOTREACHED - board_init_f() does not return */ |
| 282 | |
| 283 | /* |
| 284 | * This code finishes saving the registers to the exception frame |
| 285 | * and jumps to the appropriate handler for the exception. |
| 286 | * Register r21 is pointer into trap frame, r1 has new stack pointer. |
| 287 | */ |
| 288 | .globl transfer_to_handler |
| 289 | transfer_to_handler: |
| 290 | stw r22,_NIP(r21) |
| 291 | lis r22,MSR_POW@h |
| 292 | andc r23,r23,r22 |
| 293 | stw r23,_MSR(r21) |
| 294 | SAVE_GPR(7, r21) |
| 295 | SAVE_4GPRS(8, r21) |
| 296 | SAVE_8GPRS(12, r21) |
| 297 | SAVE_8GPRS(24, r21) |
| 298 | mflr r23 |
| 299 | andi. r24,r23,0x3f00 /* get vector offset */ |
| 300 | stw r24,TRAP(r21) |
| 301 | li r22,0 |
| 302 | stw r22,RESULT(r21) |
| 303 | lwz r24,0(r23) /* virtual address of handler */ |
| 304 | lwz r23,4(r23) /* where to go when done */ |
| 305 | mtspr SRR0,r24 |
| 306 | mtspr SRR1,r20 |
| 307 | mtlr r23 |
| 308 | SYNC |
| 309 | rfi /* jump to handler, enable MMU */ |
| 310 | |
| 311 | int_return: |
| 312 | mfmsr r28 /* Disable interrupts */ |
| 313 | li r4,0 |
| 314 | ori r4,r4,MSR_EE |
| 315 | andc r28,r28,r4 |
| 316 | SYNC /* Some chip revs need this... */ |
| 317 | mtmsr r28 |
| 318 | SYNC |
| 319 | lwz r2,_CTR(r1) |
| 320 | lwz r0,_LINK(r1) |
| 321 | mtctr r2 |
| 322 | mtlr r0 |
| 323 | lwz r2,_XER(r1) |
| 324 | lwz r0,_CCR(r1) |
| 325 | mtspr XER,r2 |
| 326 | mtcrf 0xFF,r0 |
| 327 | REST_10GPRS(3, r1) |
| 328 | REST_10GPRS(13, r1) |
| 329 | REST_8GPRS(23, r1) |
| 330 | REST_GPR(31, r1) |
| 331 | lwz r2,_NIP(r1) /* Restore environment */ |
| 332 | lwz r0,_MSR(r1) |
| 333 | mtspr SRR0,r2 |
| 334 | mtspr SRR1,r0 |
| 335 | lwz r0,GPR0(r1) |
| 336 | lwz r2,GPR2(r1) |
| 337 | lwz r1,GPR1(r1) |
| 338 | SYNC |
| 339 | rfi |
| 340 | |
| 341 | /* |
| 342 | * This code initialises the machine, it expects original MSR contents to be in r5. |
| 343 | */ |
| 344 | cpu_early_init: |
| 345 | /* Initialize machine status; enable machine check interrupt */ |
| 346 | /*-----------------------------------------------------------*/ |
| 347 | |
| 348 | li r3, MSR_KERNEL /* Set ME and RI flags */ |
| 349 | rlwimi r3, r5, 0, 25, 25 /* preserve IP bit */ |
| 350 | #ifdef DEBUG |
| 351 | rlwimi r3, r5, 0, 21, 22 /* debugger might set SE, BE bits */ |
| 352 | #endif |
| 353 | mtmsr r3 |
| 354 | SYNC |
| 355 | mtspr SRR1, r3 /* Mirror current MSR state in SRR1 */ |
| 356 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 357 | lis r3, CONFIG_SYS_IMMR@h |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 358 | |
| 359 | #if defined(CONFIG_WATCHDOG) |
| 360 | /* Initialise the watchdog and reset it */ |
| 361 | /*--------------------------------------*/ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 362 | lis r4, CONFIG_SYS_WATCHDOG_VALUE |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 363 | ori r4, r4, (SWCRR_SWEN | SWCRR_SWRI | SWCRR_SWPR) |
| 364 | stw r4, SWCRR(r3) |
| 365 | |
| 366 | /* reset */ |
| 367 | li r4, 0x556C |
| 368 | sth r4, SWSRR@l(r3) |
| 369 | li r4, 0x0 |
| 370 | ori r4, r4, 0xAA39 |
| 371 | sth r4, SWSRR@l(r3) |
| 372 | #else |
| 373 | /* Disable the watchdog */ |
| 374 | /*----------------------*/ |
| 375 | lwz r4, SWCRR(r3) |
| 376 | /* |
| 377 | * Check to see if it's enabled for disabling: once disabled by s/w |
| 378 | * it's not possible to re-enable it |
| 379 | */ |
| 380 | andi. r4, r4, 0x4 |
| 381 | beq 1f |
| 382 | xor r4, r4, r4 |
| 383 | stw r4, SWCRR(r3) |
| 384 | 1: |
| 385 | #endif /* CONFIG_WATCHDOG */ |
| 386 | |
| 387 | /* Initialize the Hardware Implementation-dependent Registers */ |
| 388 | /* HID0 also contains cache control */ |
| 389 | /*------------------------------------------------------*/ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 390 | lis r3, CONFIG_SYS_HID0_INIT@h |
| 391 | ori r3, r3, CONFIG_SYS_HID0_INIT@l |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 392 | SYNC |
| 393 | mtspr HID0, r3 |
| 394 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 395 | lis r3, CONFIG_SYS_HID0_FINAL@h |
| 396 | ori r3, r3, CONFIG_SYS_HID0_FINAL@l |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 397 | SYNC |
| 398 | mtspr HID0, r3 |
| 399 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 400 | lis r3, CONFIG_SYS_HID2@h |
| 401 | ori r3, r3, CONFIG_SYS_HID2@l |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 402 | SYNC |
| 403 | mtspr HID2, r3 |
| 404 | sync |
| 405 | blr |
| 406 | |
| 407 | |
| 408 | /* Cache functions. |
| 409 | * |
| 410 | * Note: requires that all cache bits in |
| 411 | * HID0 are in the low half word. |
| 412 | */ |
| 413 | .globl icache_enable |
| 414 | icache_enable: |
| 415 | mfspr r3, HID0 |
| 416 | ori r3, r3, HID0_ICE |
| 417 | lis r4, 0 |
| 418 | ori r4, r4, HID0_ILOCK |
| 419 | andc r3, r3, r4 |
| 420 | ori r4, r3, HID0_ICFI |
| 421 | isync |
| 422 | mtspr HID0, r4 /* sets enable and invalidate, clears lock */ |
| 423 | isync |
| 424 | mtspr HID0, r3 /* clears invalidate */ |
| 425 | blr |
| 426 | |
| 427 | .globl icache_disable |
| 428 | icache_disable: |
| 429 | mfspr r3, HID0 |
| 430 | lis r4, 0 |
| 431 | ori r4, r4, HID0_ICE|HID0_ILOCK |
| 432 | andc r3, r3, r4 |
| 433 | ori r4, r3, HID0_ICFI |
| 434 | isync |
| 435 | mtspr HID0, r4 /* sets invalidate, clears enable and lock*/ |
| 436 | isync |
| 437 | mtspr HID0, r3 /* clears invalidate */ |
| 438 | blr |
| 439 | |
| 440 | .globl icache_status |
| 441 | icache_status: |
| 442 | mfspr r3, HID0 |
| 443 | rlwinm r3, r3, (31 - HID0_ICE_SHIFT + 1), 31, 31 |
| 444 | blr |
| 445 | |
| 446 | .globl dcache_enable |
| 447 | dcache_enable: |
| 448 | mfspr r3, HID0 |
| 449 | li r5, HID0_DCFI|HID0_DLOCK |
| 450 | andc r3, r3, r5 |
| 451 | mtspr HID0, r3 /* no invalidate, unlock */ |
| 452 | ori r3, r3, HID0_DCE |
| 453 | ori r5, r3, HID0_DCFI |
| 454 | mtspr HID0, r5 /* enable + invalidate */ |
| 455 | mtspr HID0, r3 /* enable */ |
| 456 | sync |
| 457 | blr |
| 458 | |
| 459 | .globl dcache_disable |
| 460 | dcache_disable: |
| 461 | mfspr r3, HID0 |
| 462 | lis r4, 0 |
| 463 | ori r4, r4, HID0_DCE|HID0_DLOCK |
| 464 | andc r3, r3, r4 |
| 465 | ori r4, r3, HID0_DCI |
| 466 | sync |
| 467 | mtspr HID0, r4 /* sets invalidate, clears enable and lock */ |
| 468 | sync |
| 469 | mtspr HID0, r3 /* clears invalidate */ |
| 470 | blr |
| 471 | |
| 472 | .globl dcache_status |
| 473 | dcache_status: |
| 474 | mfspr r3, HID0 |
| 475 | rlwinm r3, r3, (31 - HID0_DCE_SHIFT + 1), 31, 31 |
| 476 | blr |
| 477 | |
| 478 | .globl get_pvr |
| 479 | get_pvr: |
| 480 | mfspr r3, PVR |
| 481 | blr |
| 482 | |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 483 | /*-------------------------------------------------------------------*/ |
| 484 | |
| 485 | /* |
| 486 | * void relocate_code (addr_sp, gd, addr_moni) |
| 487 | * |
| 488 | * This "function" does not return, instead it continues in RAM |
| 489 | * after relocating the monitor code. |
| 490 | * |
| 491 | * r3 = dest |
| 492 | * r4 = src |
| 493 | * r5 = length in bytes |
| 494 | * r6 = cachelinesize |
| 495 | */ |
| 496 | .globl relocate_code |
| 497 | relocate_code: |
| 498 | mr r1, r3 /* Set new stack pointer */ |
| 499 | mr r9, r4 /* Save copy of Global Data pointer */ |
| 500 | mr r10, r5 /* Save copy of Destination Address */ |
| 501 | |
| 502 | mr r3, r5 /* Destination Address */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 503 | lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */ |
| 504 | ori r4, r4, CONFIG_SYS_MONITOR_BASE@l |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 505 | lwz r5, GOT(__init_end) |
| 506 | sub r5, r5, r4 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 507 | li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */ |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 508 | |
| 509 | /* |
| 510 | * Fix GOT pointer: |
| 511 | * |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 512 | * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 513 | * + Destination Address |
| 514 | * |
| 515 | * Offset: |
| 516 | */ |
| 517 | sub r15, r10, r4 |
| 518 | |
| 519 | /* First our own GOT */ |
| 520 | add r14, r14, r15 |
| 521 | /* then the one used by the C code */ |
| 522 | add r30, r30, r15 |
| 523 | |
| 524 | /* |
| 525 | * Now relocate code |
| 526 | */ |
| 527 | cmplw cr1,r3,r4 |
| 528 | addi r0,r5,3 |
| 529 | srwi. r0,r0,2 |
| 530 | beq cr1,4f /* In place copy is not necessary */ |
| 531 | beq 7f /* Protect against 0 count */ |
| 532 | mtctr r0 |
| 533 | bge cr1,2f |
| 534 | la r8,-4(r4) |
| 535 | la r7,-4(r3) |
| 536 | |
| 537 | /* copy */ |
| 538 | 1: lwzu r0,4(r8) |
| 539 | stwu r0,4(r7) |
| 540 | bdnz 1b |
| 541 | |
| 542 | addi r0,r5,3 |
| 543 | srwi. r0,r0,2 |
| 544 | mtctr r0 |
| 545 | la r8,-4(r4) |
| 546 | la r7,-4(r3) |
| 547 | |
| 548 | /* and compare */ |
| 549 | 20: lwzu r20,4(r8) |
| 550 | lwzu r21,4(r7) |
| 551 | xor. r22, r20, r21 |
| 552 | bne 30f |
| 553 | bdnz 20b |
| 554 | b 4f |
| 555 | |
| 556 | /* compare failed */ |
| 557 | 30: li r3, 0 |
| 558 | blr |
| 559 | |
| 560 | 2: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */ |
| 561 | add r8,r4,r0 |
| 562 | add r7,r3,r0 |
| 563 | 3: lwzu r0,-4(r8) |
| 564 | stwu r0,-4(r7) |
| 565 | bdnz 3b |
| 566 | |
| 567 | /* |
| 568 | * Now flush the cache: note that we must start from a cache aligned |
| 569 | * address. Otherwise we might miss one cache line. |
| 570 | */ |
| 571 | 4: cmpwi r6,0 |
| 572 | add r5,r3,r5 |
| 573 | beq 7f /* Always flush prefetch queue in any case */ |
| 574 | subi r0,r6,1 |
| 575 | andc r3,r3,r0 |
| 576 | mr r4,r3 |
| 577 | 5: dcbst 0,r4 |
| 578 | add r4,r4,r6 |
| 579 | cmplw r4,r5 |
| 580 | blt 5b |
| 581 | sync /* Wait for all dcbst to complete on bus */ |
| 582 | mr r4,r3 |
| 583 | 6: icbi 0,r4 |
| 584 | add r4,r4,r6 |
| 585 | cmplw r4,r5 |
| 586 | blt 6b |
| 587 | 7: sync /* Wait for all icbi to complete on bus */ |
| 588 | isync |
| 589 | |
| 590 | /* |
| 591 | * We are done. Do not return, instead branch to second part of board |
| 592 | * initialization, now running from RAM. |
| 593 | */ |
| 594 | addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET |
| 595 | mtlr r0 |
| 596 | blr |
| 597 | |
| 598 | in_ram: |
| 599 | /* |
| 600 | * Relocation Function, r14 point to got2+0x8000 |
| 601 | * |
| 602 | * Adjust got2 pointers, no need to check for 0, this code |
| 603 | * already puts a few entries in the table. |
| 604 | */ |
| 605 | li r0,__got2_entries@sectoff@l |
| 606 | la r3,GOT(_GOT2_TABLE_) |
| 607 | lwz r11,GOT(_GOT2_TABLE_) |
| 608 | mtctr r0 |
| 609 | sub r11,r3,r11 |
| 610 | addi r3,r3,-4 |
| 611 | 1: lwzu r0,4(r3) |
| 612 | add r0,r0,r11 |
| 613 | stw r0,0(r3) |
| 614 | bdnz 1b |
| 615 | |
| 616 | /* |
| 617 | * Now adjust the fixups and the pointers to the fixups |
| 618 | * in case we need to move ourselves again. |
| 619 | */ |
| 620 | 2: li r0,__fixup_entries@sectoff@l |
| 621 | lwz r3,GOT(_FIXUP_TABLE_) |
| 622 | cmpwi r0,0 |
| 623 | mtctr r0 |
| 624 | addi r3,r3,-4 |
| 625 | beq 4f |
| 626 | 3: lwzu r4,4(r3) |
| 627 | lwzux r0,r4,r11 |
| 628 | add r0,r0,r11 |
| 629 | stw r10,0(r3) |
| 630 | stw r0,0(r4) |
| 631 | bdnz 3b |
| 632 | 4: |
| 633 | clear_bss: |
| 634 | /* |
| 635 | * Now clear BSS segment |
| 636 | */ |
| 637 | lwz r3,GOT(__bss_start) |
| 638 | lwz r4,GOT(_end) |
| 639 | |
| 640 | cmplw 0, r3, r4 |
| 641 | beq 6f |
| 642 | |
| 643 | li r0, 0 |
| 644 | 5: |
| 645 | stw r0, 0(r3) |
| 646 | addi r3, r3, 4 |
| 647 | cmplw 0, r3, r4 |
| 648 | bne 5b |
| 649 | 6: |
| 650 | mr r3, r9 /* Global Data pointer */ |
| 651 | mr r4, r10 /* Destination Address */ |
| 652 | bl board_init_r |
| 653 | |
| 654 | /* |
| 655 | * Copy exception vector code to low memory |
| 656 | * |
| 657 | * r3: dest_addr |
| 658 | * r7: source address, r8: end address, r9: target address |
| 659 | */ |
| 660 | .globl trap_init |
| 661 | trap_init: |
| 662 | lwz r7, GOT(_start) |
| 663 | lwz r8, GOT(_end_of_vectors) |
| 664 | |
| 665 | li r9, 0x100 /* reset vector at 0x100 */ |
| 666 | |
| 667 | cmplw 0, r7, r8 |
| 668 | bgelr /* return if r7>=r8 - just in case */ |
| 669 | |
| 670 | mflr r4 /* save link register */ |
| 671 | 1: |
| 672 | lwz r0, 0(r7) |
| 673 | stw r0, 0(r9) |
| 674 | addi r7, r7, 4 |
| 675 | addi r9, r9, 4 |
| 676 | cmplw 0, r7, r8 |
| 677 | bne 1b |
| 678 | |
| 679 | /* |
| 680 | * relocate `hdlr' and `int_return' entries |
| 681 | */ |
| 682 | li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET |
| 683 | li r8, Alignment - _start + EXC_OFF_SYS_RESET |
| 684 | 2: |
| 685 | bl trap_reloc |
| 686 | addi r7, r7, 0x100 /* next exception vector */ |
| 687 | cmplw 0, r7, r8 |
| 688 | blt 2b |
| 689 | |
| 690 | li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET |
| 691 | bl trap_reloc |
| 692 | |
| 693 | li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET |
| 694 | bl trap_reloc |
| 695 | |
| 696 | li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET |
| 697 | li r8, SystemCall - _start + EXC_OFF_SYS_RESET |
| 698 | 3: |
| 699 | bl trap_reloc |
| 700 | addi r7, r7, 0x100 /* next exception vector */ |
| 701 | cmplw 0, r7, r8 |
| 702 | blt 3b |
| 703 | |
| 704 | li r7, .L_Trace - _start + EXC_OFF_SYS_RESET |
| 705 | li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET |
| 706 | 4: |
| 707 | bl trap_reloc |
| 708 | addi r7, r7, 0x100 /* next exception vector */ |
| 709 | cmplw 0, r7, r8 |
| 710 | blt 4b |
| 711 | |
| 712 | mfmsr r3 /* now that the vectors have */ |
| 713 | lis r7, MSR_IP@h /* relocated into low memory */ |
| 714 | ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */ |
| 715 | andc r3, r3, r7 /* (if it was on) */ |
| 716 | SYNC /* Some chip revs need this... */ |
| 717 | mtmsr r3 |
| 718 | SYNC |
| 719 | |
| 720 | mtlr r4 /* restore link register */ |
| 721 | blr |
| 722 | |
| 723 | /* |
| 724 | * Function: relocate entries for one exception vector |
| 725 | */ |
| 726 | trap_reloc: |
| 727 | lwz r0, 0(r7) /* hdlr ... */ |
| 728 | add r0, r0, r3 /* ... += dest_addr */ |
| 729 | stw r0, 0(r7) |
| 730 | |
| 731 | lwz r0, 4(r7) /* int_return ... */ |
| 732 | add r0, r0, r3 /* ... += dest_addr */ |
| 733 | stw r0, 4(r7) |
| 734 | |
| 735 | blr |