wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [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 Wolfgang Denk <wd@denx.de> |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | /* U-Boot - Startup Code for PowerPC based Embedded Boards |
| 26 | * |
| 27 | * |
| 28 | * The processor starts at 0x00000100 and the code is executed |
| 29 | * from flash. The code is organized to be at an other address |
| 30 | * in memory, but as long we don't jump around before relocating. |
| 31 | * board_init lies at a quite high address and when the cpu has |
| 32 | * jumped there, everything is ok. |
| 33 | * This works because the cpu gives the FLASH (CS0) the whole |
| 34 | * address space at startup, and board_init lies as a echo of |
| 35 | * the flash somewhere up there in the memorymap. |
| 36 | * |
| 37 | * board_init will change CS0 to be positioned at the correct |
| 38 | * address and (s)dram will be positioned at address 0 |
| 39 | */ |
| 40 | #include <config.h> |
| 41 | #include <mpc8xx.h> |
| 42 | #include <version.h> |
| 43 | |
| 44 | #define CONFIG_8xx 1 /* needed for Linux kernel header files */ |
| 45 | #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */ |
| 46 | |
| 47 | #include <ppc_asm.tmpl> |
| 48 | #include <ppc_defs.h> |
| 49 | |
| 50 | #include <asm/cache.h> |
| 51 | #include <asm/mmu.h> |
| 52 | |
| 53 | #ifndef CONFIG_IDENT_STRING |
| 54 | #define CONFIG_IDENT_STRING "" |
| 55 | #endif |
| 56 | |
| 57 | /* We don't want the MMU yet. |
| 58 | */ |
| 59 | #undef MSR_KERNEL |
| 60 | #define MSR_KERNEL ( MSR_ME | MSR_RI ) /* Machine Check and Recoverable Interr. */ |
| 61 | |
| 62 | /* |
| 63 | * Set up GOT: Global Offset Table |
| 64 | * |
| 65 | * Use r14 to access the GOT |
| 66 | */ |
| 67 | START_GOT |
| 68 | GOT_ENTRY(_GOT2_TABLE_) |
| 69 | GOT_ENTRY(_FIXUP_TABLE_) |
| 70 | |
| 71 | GOT_ENTRY(_start) |
| 72 | GOT_ENTRY(_start_of_vectors) |
| 73 | GOT_ENTRY(_end_of_vectors) |
| 74 | GOT_ENTRY(transfer_to_handler) |
| 75 | |
| 76 | GOT_ENTRY(_end) |
| 77 | GOT_ENTRY(.bss) |
| 78 | #if defined(CONFIG_FADS) || defined(CONFIG_ICU862) |
| 79 | GOT_ENTRY(environment) |
| 80 | #endif |
| 81 | END_GOT |
| 82 | |
| 83 | /* |
| 84 | * r3 - 1st arg to board_init(): IMMP pointer |
| 85 | * r4 - 2nd arg to board_init(): boot flag |
| 86 | */ |
| 87 | .text |
| 88 | .long 0x27051956 /* U-Boot Magic Number */ |
| 89 | .globl version_string |
| 90 | version_string: |
| 91 | .ascii U_BOOT_VERSION |
| 92 | .ascii " (", __DATE__, " - ", __TIME__, ")" |
| 93 | .ascii CONFIG_IDENT_STRING, "\0" |
| 94 | |
| 95 | . = EXC_OFF_SYS_RESET |
| 96 | .globl _start |
| 97 | _start: |
| 98 | lis r3, CFG_IMMR@h /* position IMMR */ |
| 99 | mtspr 638, r3 |
| 100 | li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */ |
| 101 | b boot_cold |
| 102 | |
| 103 | . = EXC_OFF_SYS_RESET + 0x10 |
| 104 | |
| 105 | .globl _start_warm |
| 106 | _start_warm: |
| 107 | li r21, BOOTFLAG_WARM /* Software reboot */ |
| 108 | b boot_warm |
| 109 | |
| 110 | boot_cold: |
| 111 | boot_warm: |
| 112 | |
| 113 | /* Initialize machine status; enable machine check interrupt */ |
| 114 | /*----------------------------------------------------------------------*/ |
| 115 | li r3, MSR_KERNEL /* Set ME, RI flags */ |
| 116 | mtmsr r3 |
| 117 | mtspr SRR1, r3 /* Make SRR1 match MSR */ |
| 118 | |
| 119 | mfspr r3, ICR /* clear Interrupt Cause Register */ |
| 120 | |
| 121 | /* Initialize debug port registers */ |
| 122 | /*----------------------------------------------------------------------*/ |
| 123 | xor r0, r0, r0 /* Clear R0 */ |
| 124 | mtspr LCTRL1, r0 /* Initialize debug port regs */ |
| 125 | mtspr LCTRL2, r0 |
| 126 | mtspr COUNTA, r0 |
| 127 | mtspr COUNTB, r0 |
| 128 | |
| 129 | /* Reset the caches */ |
| 130 | /*----------------------------------------------------------------------*/ |
| 131 | |
| 132 | mfspr r3, IC_CST /* Clear error bits */ |
| 133 | mfspr r3, DC_CST |
| 134 | |
| 135 | lis r3, IDC_UNALL@h /* Unlock all */ |
| 136 | mtspr IC_CST, r3 |
| 137 | mtspr DC_CST, r3 |
| 138 | |
| 139 | lis r3, IDC_INVALL@h /* Invalidate all */ |
| 140 | mtspr IC_CST, r3 |
| 141 | mtspr DC_CST, r3 |
| 142 | |
| 143 | lis r3, IDC_DISABLE@h /* Disable data cache */ |
| 144 | mtspr DC_CST, r3 |
| 145 | |
| 146 | #if !(defined(CONFIG_IP860) || defined(CONFIG_PCU_E) || defined (CONFIG_FLAGADM)) |
| 147 | /* On IP860 and PCU E, |
| 148 | * we cannot enable IC yet |
| 149 | */ |
| 150 | lis r3, IDC_ENABLE@h /* Enable instruction cache */ |
| 151 | #endif |
| 152 | mtspr IC_CST, r3 |
| 153 | |
| 154 | /* invalidate all tlb's */ |
| 155 | /*----------------------------------------------------------------------*/ |
| 156 | |
| 157 | tlbia |
| 158 | isync |
| 159 | |
| 160 | /* |
| 161 | * Calculate absolute address in FLASH and jump there |
| 162 | *----------------------------------------------------------------------*/ |
| 163 | |
| 164 | lis r3, CFG_MONITOR_BASE@h |
| 165 | ori r3, r3, CFG_MONITOR_BASE@l |
| 166 | addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET |
| 167 | mtlr r3 |
| 168 | blr |
| 169 | |
| 170 | in_flash: |
| 171 | |
| 172 | /* initialize some SPRs that are hard to access from C */ |
| 173 | /*----------------------------------------------------------------------*/ |
| 174 | |
| 175 | lis r3, CFG_IMMR@h /* pass IMMR as arg1 to C routine */ |
| 176 | ori r1, r3, CFG_INIT_SP_OFFSET /* set up the stack in internal DPRAM */ |
| 177 | /* Note: R0 is still 0 here */ |
| 178 | stwu r0, -4(r1) /* clear final stack frame so that */ |
| 179 | stwu r0, -4(r1) /* stack backtraces terminate cleanly */ |
| 180 | |
| 181 | /* |
| 182 | * Disable serialized ifetch and show cycles |
| 183 | * (i.e. set processor to normal mode). |
| 184 | * This is also a silicon bug workaround, see errata |
| 185 | */ |
| 186 | |
| 187 | li r2, 0x0007 |
| 188 | mtspr ICTRL, r2 |
| 189 | |
| 190 | /* Set up debug mode entry */ |
| 191 | |
| 192 | lis r2, CFG_DER@h |
| 193 | ori r2, r2, CFG_DER@l |
| 194 | mtspr DER, r2 |
| 195 | |
| 196 | /* let the C-code set up the rest */ |
| 197 | /* */ |
| 198 | /* Be careful to keep code relocatable ! */ |
| 199 | /*----------------------------------------------------------------------*/ |
| 200 | |
| 201 | GET_GOT /* initialize GOT access */ |
| 202 | |
| 203 | /* r3: IMMR */ |
| 204 | bl cpu_init_f /* run low-level CPU init code (from Flash) */ |
| 205 | |
| 206 | mr r3, r21 |
| 207 | /* r3: BOOTFLAG */ |
| 208 | bl board_init_f /* run 1st part of board init code (from Flash) */ |
| 209 | |
| 210 | |
| 211 | |
| 212 | .globl _start_of_vectors |
| 213 | _start_of_vectors: |
| 214 | |
| 215 | /* Machine check */ |
| 216 | STD_EXCEPTION(0x200, MachineCheck, MachineCheckException) |
| 217 | |
| 218 | /* Data Storage exception. "Never" generated on the 860. */ |
| 219 | STD_EXCEPTION(0x300, DataStorage, UnknownException) |
| 220 | |
| 221 | /* Instruction Storage exception. "Never" generated on the 860. */ |
| 222 | STD_EXCEPTION(0x400, InstStorage, UnknownException) |
| 223 | |
| 224 | /* External Interrupt exception. */ |
| 225 | STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt) |
| 226 | |
| 227 | /* Alignment exception. */ |
| 228 | . = 0x600 |
| 229 | Alignment: |
| 230 | EXCEPTION_PROLOG |
| 231 | mfspr r4,DAR |
| 232 | stw r4,_DAR(r21) |
| 233 | mfspr r5,DSISR |
| 234 | stw r5,_DSISR(r21) |
| 235 | addi r3,r1,STACK_FRAME_OVERHEAD |
| 236 | li r20,MSR_KERNEL |
| 237 | rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */ |
| 238 | lwz r6,GOT(transfer_to_handler) |
| 239 | mtlr r6 |
| 240 | blrl |
| 241 | .L_Alignment: |
| 242 | .long AlignmentException - _start + EXC_OFF_SYS_RESET |
| 243 | .long int_return - _start + EXC_OFF_SYS_RESET |
| 244 | |
| 245 | /* Program check exception */ |
| 246 | . = 0x700 |
| 247 | ProgramCheck: |
| 248 | EXCEPTION_PROLOG |
| 249 | addi r3,r1,STACK_FRAME_OVERHEAD |
| 250 | li r20,MSR_KERNEL |
| 251 | rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */ |
| 252 | lwz r6,GOT(transfer_to_handler) |
| 253 | mtlr r6 |
| 254 | blrl |
| 255 | .L_ProgramCheck: |
| 256 | .long ProgramCheckException - _start + EXC_OFF_SYS_RESET |
| 257 | .long int_return - _start + EXC_OFF_SYS_RESET |
| 258 | |
| 259 | /* No FPU on MPC8xx. This exception is not supposed to happen. |
| 260 | */ |
| 261 | STD_EXCEPTION(0x800, FPUnavailable, UnknownException) |
| 262 | |
| 263 | /* I guess we could implement decrementer, and may have |
| 264 | * to someday for timekeeping. |
| 265 | */ |
| 266 | STD_EXCEPTION(0x900, Decrementer, timer_interrupt) |
| 267 | STD_EXCEPTION(0xa00, Trap_0a, UnknownException) |
| 268 | STD_EXCEPTION(0xb00, Trap_0b, UnknownException) |
| 269 | |
| 270 | . = 0xc00 |
| 271 | /* |
| 272 | * r0 - SYSCALL number |
| 273 | * r3-... arguments |
| 274 | */ |
| 275 | SystemCall: |
| 276 | addis r11,r0,0 /* get functions table addr */ |
| 277 | ori r11,r11,0 /* Note: this code is patched in trap_init */ |
| 278 | addis r12,r0,0 /* get number of functions */ |
| 279 | ori r12,r12,0 |
| 280 | |
| 281 | cmplw 0, r0, r12 |
| 282 | bge 1f |
| 283 | |
| 284 | rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */ |
| 285 | add r11,r11,r0 |
| 286 | lwz r11,0(r11) |
| 287 | |
| 288 | li r12,0xd00-4*3 /* save LR & SRRx */ |
| 289 | mflr r0 |
| 290 | stw r0,0(r12) |
| 291 | mfspr r0,SRR0 |
| 292 | stw r0,4(r12) |
| 293 | mfspr r0,SRR1 |
| 294 | stw r0,8(r12) |
| 295 | |
| 296 | li r12,0xc00+_back-SystemCall |
| 297 | mtlr r12 |
| 298 | mtspr SRR0,r11 |
| 299 | |
| 300 | 1: SYNC |
| 301 | rfi |
| 302 | |
| 303 | _back: |
| 304 | |
| 305 | mfmsr r11 /* Disable interrupts */ |
| 306 | li r12,0 |
| 307 | ori r12,r12,MSR_EE |
| 308 | andc r11,r11,r12 |
| 309 | SYNC /* Some chip revs need this... */ |
| 310 | mtmsr r11 |
| 311 | SYNC |
| 312 | |
| 313 | li r12,0xd00-4*3 /* restore regs */ |
| 314 | lwz r11,0(r12) |
| 315 | mtlr r11 |
| 316 | lwz r11,4(r12) |
| 317 | mtspr SRR0,r11 |
| 318 | lwz r11,8(r12) |
| 319 | mtspr SRR1,r11 |
| 320 | |
| 321 | SYNC |
| 322 | rfi |
| 323 | |
| 324 | STD_EXCEPTION(0xd00, SingleStep, UnknownException) |
| 325 | |
| 326 | STD_EXCEPTION(0xe00, Trap_0e, UnknownException) |
| 327 | STD_EXCEPTION(0xf00, Trap_0f, UnknownException) |
| 328 | |
| 329 | /* On the MPC8xx, this is a software emulation interrupt. It occurs |
| 330 | * for all unimplemented and illegal instructions. |
| 331 | */ |
| 332 | STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException) |
| 333 | |
| 334 | STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException) |
| 335 | STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException) |
| 336 | STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException) |
| 337 | STD_EXCEPTION(0x1400, DataTLBError, UnknownException) |
| 338 | |
| 339 | STD_EXCEPTION(0x1500, Reserved5, UnknownException) |
| 340 | STD_EXCEPTION(0x1600, Reserved6, UnknownException) |
| 341 | STD_EXCEPTION(0x1700, Reserved7, UnknownException) |
| 342 | STD_EXCEPTION(0x1800, Reserved8, UnknownException) |
| 343 | STD_EXCEPTION(0x1900, Reserved9, UnknownException) |
| 344 | STD_EXCEPTION(0x1a00, ReservedA, UnknownException) |
| 345 | STD_EXCEPTION(0x1b00, ReservedB, UnknownException) |
| 346 | |
| 347 | STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException) |
| 348 | STD_EXCEPTION(0x1d00, InstructionBreakpoint, DebugException) |
| 349 | STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException) |
| 350 | STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException) |
| 351 | |
| 352 | |
| 353 | .globl _end_of_vectors |
| 354 | _end_of_vectors: |
| 355 | |
| 356 | |
| 357 | . = 0x2000 |
| 358 | |
| 359 | /* |
| 360 | * This code finishes saving the registers to the exception frame |
| 361 | * and jumps to the appropriate handler for the exception. |
| 362 | * Register r21 is pointer into trap frame, r1 has new stack pointer. |
| 363 | */ |
| 364 | .globl transfer_to_handler |
| 365 | transfer_to_handler: |
| 366 | stw r22,_NIP(r21) |
| 367 | lis r22,MSR_POW@h |
| 368 | andc r23,r23,r22 |
| 369 | stw r23,_MSR(r21) |
| 370 | SAVE_GPR(7, r21) |
| 371 | SAVE_4GPRS(8, r21) |
| 372 | SAVE_8GPRS(12, r21) |
| 373 | SAVE_8GPRS(24, r21) |
| 374 | mflr r23 |
| 375 | andi. r24,r23,0x3f00 /* get vector offset */ |
| 376 | stw r24,TRAP(r21) |
| 377 | li r22,0 |
| 378 | stw r22,RESULT(r21) |
| 379 | mtspr SPRG2,r22 /* r1 is now kernel sp */ |
| 380 | lwz r24,0(r23) /* virtual address of handler */ |
| 381 | lwz r23,4(r23) /* where to go when done */ |
| 382 | mtspr SRR0,r24 |
| 383 | mtspr SRR1,r20 |
| 384 | mtlr r23 |
| 385 | SYNC |
| 386 | rfi /* jump to handler, enable MMU */ |
| 387 | |
| 388 | int_return: |
| 389 | mfmsr r28 /* Disable interrupts */ |
| 390 | li r4,0 |
| 391 | ori r4,r4,MSR_EE |
| 392 | andc r28,r28,r4 |
| 393 | SYNC /* Some chip revs need this... */ |
| 394 | mtmsr r28 |
| 395 | SYNC |
| 396 | lwz r2,_CTR(r1) |
| 397 | lwz r0,_LINK(r1) |
| 398 | mtctr r2 |
| 399 | mtlr r0 |
| 400 | lwz r2,_XER(r1) |
| 401 | lwz r0,_CCR(r1) |
| 402 | mtspr XER,r2 |
| 403 | mtcrf 0xFF,r0 |
| 404 | REST_10GPRS(3, r1) |
| 405 | REST_10GPRS(13, r1) |
| 406 | REST_8GPRS(23, r1) |
| 407 | REST_GPR(31, r1) |
| 408 | lwz r2,_NIP(r1) /* Restore environment */ |
| 409 | lwz r0,_MSR(r1) |
| 410 | mtspr SRR0,r2 |
| 411 | mtspr SRR1,r0 |
| 412 | lwz r0,GPR0(r1) |
| 413 | lwz r2,GPR2(r1) |
| 414 | lwz r1,GPR1(r1) |
| 415 | SYNC |
| 416 | rfi |
| 417 | |
| 418 | /* Cache functions. |
| 419 | */ |
| 420 | .globl icache_enable |
| 421 | icache_enable: |
| 422 | SYNC |
| 423 | lis r3, IDC_INVALL@h |
| 424 | mtspr IC_CST, r3 |
| 425 | lis r3, IDC_ENABLE@h |
| 426 | mtspr IC_CST, r3 |
| 427 | blr |
| 428 | |
| 429 | .globl icache_disable |
| 430 | icache_disable: |
| 431 | SYNC |
| 432 | lis r3, IDC_DISABLE@h |
| 433 | mtspr IC_CST, r3 |
| 434 | blr |
| 435 | |
| 436 | .globl icache_status |
| 437 | icache_status: |
| 438 | mfspr r3, IC_CST |
| 439 | srwi r3, r3, 31 /* >>31 => select bit 0 */ |
| 440 | blr |
| 441 | |
| 442 | .globl dcache_enable |
| 443 | dcache_enable: |
| 444 | #if 0 |
| 445 | SYNC |
| 446 | #endif |
| 447 | #if 1 |
| 448 | lis r3, 0x0400 /* Set cache mode with MMU off */ |
| 449 | mtspr MD_CTR, r3 |
| 450 | #endif |
| 451 | |
| 452 | lis r3, IDC_INVALL@h |
| 453 | mtspr DC_CST, r3 |
| 454 | #if 0 |
| 455 | lis r3, DC_SFWT@h |
| 456 | mtspr DC_CST, r3 |
| 457 | #endif |
| 458 | lis r3, IDC_ENABLE@h |
| 459 | mtspr DC_CST, r3 |
| 460 | blr |
| 461 | |
| 462 | .globl dcache_disable |
| 463 | dcache_disable: |
| 464 | SYNC |
| 465 | lis r3, IDC_DISABLE@h |
| 466 | mtspr DC_CST, r3 |
| 467 | lis r3, IDC_INVALL@h |
| 468 | mtspr DC_CST, r3 |
| 469 | blr |
| 470 | |
| 471 | .globl dcache_status |
| 472 | dcache_status: |
| 473 | mfspr r3, DC_CST |
| 474 | srwi r3, r3, 31 /* >>31 => select bit 0 */ |
| 475 | blr |
| 476 | |
| 477 | .globl dc_read |
| 478 | dc_read: |
| 479 | mtspr DC_ADR, r3 |
| 480 | mfspr r3, DC_DAT |
| 481 | blr |
| 482 | |
| 483 | /* |
| 484 | * unsigned int get_immr (unsigned int mask) |
| 485 | * |
| 486 | * return (mask ? (IMMR & mask) : IMMR); |
| 487 | */ |
| 488 | .globl get_immr |
| 489 | get_immr: |
| 490 | mr r4,r3 /* save mask */ |
| 491 | mfspr r3, IMMR /* IMMR */ |
| 492 | cmpwi 0,r4,0 /* mask != 0 ? */ |
| 493 | beq 4f |
| 494 | and r3,r3,r4 /* IMMR & mask */ |
| 495 | 4: |
| 496 | blr |
| 497 | |
| 498 | .globl get_pvr |
| 499 | get_pvr: |
| 500 | mfspr r3, PVR |
| 501 | blr |
| 502 | |
| 503 | |
| 504 | .globl wr_ic_cst |
| 505 | wr_ic_cst: |
| 506 | mtspr IC_CST, r3 |
| 507 | blr |
| 508 | |
| 509 | .globl rd_ic_cst |
| 510 | rd_ic_cst: |
| 511 | mfspr r3, IC_CST |
| 512 | blr |
| 513 | |
| 514 | .globl wr_ic_adr |
| 515 | wr_ic_adr: |
| 516 | mtspr IC_ADR, r3 |
| 517 | blr |
| 518 | |
| 519 | |
| 520 | .globl wr_dc_cst |
| 521 | wr_dc_cst: |
| 522 | mtspr DC_CST, r3 |
| 523 | blr |
| 524 | |
| 525 | .globl rd_dc_cst |
| 526 | rd_dc_cst: |
| 527 | mfspr r3, DC_CST |
| 528 | blr |
| 529 | |
| 530 | .globl wr_dc_adr |
| 531 | wr_dc_adr: |
| 532 | mtspr DC_ADR, r3 |
| 533 | blr |
| 534 | |
| 535 | /*------------------------------------------------------------------------------*/ |
| 536 | |
| 537 | /* |
| 538 | * void relocate_code (addr_sp, gd, addr_moni) |
| 539 | * |
| 540 | * This "function" does not return, instead it continues in RAM |
| 541 | * after relocating the monitor code. |
| 542 | * |
| 543 | * r3 = dest |
| 544 | * r4 = src |
| 545 | * r5 = length in bytes |
| 546 | * r6 = cachelinesize |
| 547 | */ |
| 548 | .globl relocate_code |
| 549 | relocate_code: |
| 550 | mr r1, r3 /* Set new stack pointer */ |
| 551 | mr r9, r4 /* Save copy of Global Data pointer */ |
| 552 | mr r10, r5 /* Save copy of Destination Address */ |
| 553 | |
| 554 | mr r3, r5 /* Destination Address */ |
| 555 | lis r4, CFG_MONITOR_BASE@h /* Source Address */ |
| 556 | ori r4, r4, CFG_MONITOR_BASE@l |
| 557 | lis r5, CFG_MONITOR_LEN@h /* Length in Bytes */ |
| 558 | ori r5, r5, CFG_MONITOR_LEN@l |
| 559 | li r6, CFG_CACHELINE_SIZE /* Cache Line Size */ |
| 560 | |
| 561 | /* |
| 562 | * Fix GOT pointer: |
| 563 | * |
| 564 | * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address |
| 565 | * |
| 566 | * Offset: |
| 567 | */ |
| 568 | sub r15, r10, r4 |
| 569 | |
| 570 | /* First our own GOT */ |
| 571 | add r14, r14, r15 |
| 572 | /* the the one used by the C code */ |
| 573 | add r30, r30, r15 |
| 574 | |
| 575 | /* |
| 576 | * Now relocate code |
| 577 | */ |
| 578 | |
| 579 | cmplw cr1,r3,r4 |
| 580 | addi r0,r5,3 |
| 581 | srwi. r0,r0,2 |
| 582 | beq cr1,4f /* In place copy is not necessary */ |
| 583 | beq 7f /* Protect against 0 count */ |
| 584 | mtctr r0 |
| 585 | bge cr1,2f |
| 586 | |
| 587 | la r8,-4(r4) |
| 588 | la r7,-4(r3) |
| 589 | 1: lwzu r0,4(r8) |
| 590 | stwu r0,4(r7) |
| 591 | bdnz 1b |
| 592 | b 4f |
| 593 | |
| 594 | 2: slwi r0,r0,2 |
| 595 | add r8,r4,r0 |
| 596 | add r7,r3,r0 |
| 597 | 3: lwzu r0,-4(r8) |
| 598 | stwu r0,-4(r7) |
| 599 | bdnz 3b |
| 600 | |
| 601 | /* |
| 602 | * Now flush the cache: note that we must start from a cache aligned |
| 603 | * address. Otherwise we might miss one cache line. |
| 604 | */ |
| 605 | 4: cmpwi r6,0 |
| 606 | add r5,r3,r5 |
| 607 | beq 7f /* Always flush prefetch queue in any case */ |
| 608 | subi r0,r6,1 |
| 609 | andc r3,r3,r0 |
| 610 | mr r4,r3 |
| 611 | 5: dcbst 0,r4 |
| 612 | add r4,r4,r6 |
| 613 | cmplw r4,r5 |
| 614 | blt 5b |
| 615 | sync /* Wait for all dcbst to complete on bus */ |
| 616 | mr r4,r3 |
| 617 | 6: icbi 0,r4 |
| 618 | add r4,r4,r6 |
| 619 | cmplw r4,r5 |
| 620 | blt 6b |
| 621 | 7: sync /* Wait for all icbi to complete on bus */ |
| 622 | isync |
| 623 | |
| 624 | /* |
| 625 | * We are done. Do not return, instead branch to second part of board |
| 626 | * initialization, now running from RAM. |
| 627 | */ |
| 628 | |
| 629 | addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET |
| 630 | mtlr r0 |
| 631 | blr |
| 632 | |
| 633 | in_ram: |
| 634 | |
| 635 | /* |
| 636 | * Relocation Function, r14 point to got2+0x8000 |
| 637 | * |
| 638 | * Adjust got2 pointers, no need to check for 0, this code |
| 639 | * already puts a few entries in the table. |
| 640 | */ |
| 641 | li r0,__got2_entries@sectoff@l |
| 642 | la r3,GOT(_GOT2_TABLE_) |
| 643 | lwz r11,GOT(_GOT2_TABLE_) |
| 644 | mtctr r0 |
| 645 | sub r11,r3,r11 |
| 646 | addi r3,r3,-4 |
| 647 | 1: lwzu r0,4(r3) |
| 648 | add r0,r0,r11 |
| 649 | stw r0,0(r3) |
| 650 | bdnz 1b |
| 651 | |
| 652 | /* |
| 653 | * Now adjust the fixups and the pointers to the fixups |
| 654 | * in case we need to move ourselves again. |
| 655 | */ |
| 656 | 2: li r0,__fixup_entries@sectoff@l |
| 657 | lwz r3,GOT(_FIXUP_TABLE_) |
| 658 | cmpwi r0,0 |
| 659 | mtctr r0 |
| 660 | addi r3,r3,-4 |
| 661 | beq 4f |
| 662 | 3: lwzu r4,4(r3) |
| 663 | lwzux r0,r4,r11 |
| 664 | add r0,r0,r11 |
| 665 | stw r10,0(r3) |
| 666 | stw r0,0(r4) |
| 667 | bdnz 3b |
| 668 | 4: |
| 669 | clear_bss: |
| 670 | /* |
| 671 | * Now clear BSS segment |
| 672 | */ |
| 673 | lwz r3,GOT(.bss) |
| 674 | #if defined(CONFIG_FADS) || defined(CONFIG_ICU862) |
| 675 | /* |
| 676 | * For the FADS - the environment is the very last item in flash. |
| 677 | * The real .bss stops just before environment starts, so only |
| 678 | * clear up to that point. |
| 679 | */ |
| 680 | lwz r4,GOT(environment) |
| 681 | #else |
| 682 | lwz r4,GOT(_end) |
| 683 | #endif |
| 684 | |
| 685 | cmplw 0, r3, r4 |
| 686 | beq 6f |
| 687 | |
| 688 | li r0, 0 |
| 689 | 5: |
| 690 | stw r0, 0(r3) |
| 691 | addi r3, r3, 4 |
| 692 | cmplw 0, r3, r4 |
| 693 | bne 5b |
| 694 | 6: |
| 695 | |
| 696 | mr r3, r9 /* Global Data pointer */ |
| 697 | mr r4, r10 /* Destination Address */ |
| 698 | bl board_init_r |
| 699 | |
| 700 | /* Problems accessing "end" in C, so do it here */ |
| 701 | .globl get_endaddr |
| 702 | get_endaddr: |
| 703 | lwz r3,GOT(_end) |
| 704 | blr |
| 705 | |
| 706 | /* |
| 707 | * Copy exception vector code to low memory |
| 708 | * |
| 709 | * r3: dest_addr |
| 710 | * r7: source address, r8: end address, r9: target address |
| 711 | */ |
| 712 | .globl trap_init |
| 713 | trap_init: |
| 714 | lwz r7, GOT(_start) |
| 715 | lwz r8, GOT(_end_of_vectors) |
| 716 | |
| 717 | rlwinm r9, r7, 0, 22, 31 /* _start & 0x3FF */ |
| 718 | |
| 719 | cmplw 0, r7, r8 |
| 720 | bgelr /* return if r7>=r8 - just in case */ |
| 721 | |
| 722 | mflr r4 /* save link register */ |
| 723 | 1: |
| 724 | lwz r0, 0(r7) |
| 725 | stw r0, 0(r9) |
| 726 | addi r7, r7, 4 |
| 727 | addi r9, r9, 4 |
| 728 | cmplw 0, r7, r8 |
| 729 | bne 1b |
| 730 | |
| 731 | /* |
| 732 | * relocate `hdlr' and `int_return' entries |
| 733 | */ |
| 734 | li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET |
| 735 | li r8, Alignment - _start + EXC_OFF_SYS_RESET |
| 736 | 2: |
| 737 | bl trap_reloc |
| 738 | addi r7, r7, 0x100 /* next exception vector */ |
| 739 | cmplw 0, r7, r8 |
| 740 | blt 2b |
| 741 | |
| 742 | li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET |
| 743 | bl trap_reloc |
| 744 | |
| 745 | li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET |
| 746 | bl trap_reloc |
| 747 | |
| 748 | li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET |
| 749 | li r8, SystemCall - _start + EXC_OFF_SYS_RESET |
| 750 | 3: |
| 751 | bl trap_reloc |
| 752 | addi r7, r7, 0x100 /* next exception vector */ |
| 753 | cmplw 0, r7, r8 |
| 754 | blt 3b |
| 755 | |
| 756 | li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET |
| 757 | li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET |
| 758 | 4: |
| 759 | bl trap_reloc |
| 760 | addi r7, r7, 0x100 /* next exception vector */ |
| 761 | cmplw 0, r7, r8 |
| 762 | blt 4b |
| 763 | |
| 764 | mtlr r4 /* restore link register */ |
| 765 | blr |
| 766 | |
| 767 | /* |
| 768 | * Function: relocate entries for one exception vector |
| 769 | */ |
| 770 | trap_reloc: |
| 771 | lwz r0, 0(r7) /* hdlr ... */ |
| 772 | add r0, r0, r3 /* ... += dest_addr */ |
| 773 | stw r0, 0(r7) |
| 774 | |
| 775 | lwz r0, 4(r7) /* int_return ... */ |
| 776 | add r0, r0, r3 /* ... += dest_addr */ |
| 777 | stw r0, 4(r7) |
| 778 | |
| 779 | sync |
| 780 | isync |
| 781 | |
| 782 | blr |