wdenk | 0db5bca | 2003-03-31 17:27:09 +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 | * Copyright (C) 2003 Martin Winistoerfer, martinwinistoerfer@gmx.ch. |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 6 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * File: start.S |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 12 | * |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 13 | * Discription: startup code |
| 14 | * |
| 15 | */ |
| 16 | |
Wolfgang Denk | 25ddd1f | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 17 | #include <asm-offsets.h> |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 18 | #include <config.h> |
| 19 | #include <mpc5xx.h> |
| 20 | #include <version.h> |
| 21 | |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 22 | #include <ppc_asm.tmpl> |
| 23 | #include <ppc_defs.h> |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 24 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 25 | #include <asm/processor.h> |
Peter Tyser | d98b052 | 2010-10-14 23:33:24 -0500 | [diff] [blame] | 26 | #include <asm/u-boot.h> |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 27 | |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 28 | /* We don't have a MMU. |
| 29 | */ |
| 30 | #undef MSR_KERNEL |
| 31 | #define MSR_KERNEL ( MSR_ME | MSR_RI ) /* Machine Check and Recoverable Interr. */ |
| 32 | |
| 33 | /* |
| 34 | * Set up GOT: Global Offset Table |
| 35 | * |
Joakim Tjernlund | 0f8aa15 | 2010-01-19 14:41:56 +0100 | [diff] [blame] | 36 | * Use r12 to access the GOT |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 37 | */ |
| 38 | START_GOT |
| 39 | GOT_ENTRY(_GOT2_TABLE_) |
| 40 | GOT_ENTRY(_FIXUP_TABLE_) |
| 41 | |
| 42 | GOT_ENTRY(_start) |
| 43 | GOT_ENTRY(_start_of_vectors) |
| 44 | GOT_ENTRY(_end_of_vectors) |
| 45 | GOT_ENTRY(transfer_to_handler) |
| 46 | |
wdenk | 3b57fe0 | 2003-05-30 12:48:29 +0000 | [diff] [blame] | 47 | GOT_ENTRY(__init_end) |
Simon Glass | 3929fb0 | 2013-03-14 06:54:53 +0000 | [diff] [blame] | 48 | GOT_ENTRY(__bss_end) |
wdenk | 5d232d0 | 2003-05-22 22:52:13 +0000 | [diff] [blame] | 49 | GOT_ENTRY(__bss_start) |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 50 | END_GOT |
| 51 | |
| 52 | /* |
| 53 | * r3 - 1st arg to board_init(): IMMP pointer |
| 54 | * r4 - 2nd arg to board_init(): boot flag |
| 55 | */ |
| 56 | .text |
| 57 | .long 0x27051956 /* U-Boot Magic Number */ |
| 58 | .globl version_string |
| 59 | version_string: |
Andreas Bießmann | 09c2e90 | 2011-07-18 20:24:04 +0200 | [diff] [blame] | 60 | .ascii U_BOOT_VERSION_STRING, "\0" |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 61 | |
| 62 | . = EXC_OFF_SYS_RESET |
| 63 | .globl _start |
| 64 | _start: |
| 65 | mfspr r3, 638 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 66 | li r4, CONFIG_SYS_ISB /* Set ISB bit */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 67 | or r3, r3, r4 |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 68 | mtspr 638, r3 |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 69 | |
| 70 | /* Initialize machine status; enable machine check interrupt */ |
| 71 | /*----------------------------------------------------------------------*/ |
| 72 | li r3, MSR_KERNEL /* Set ME, RI flags */ |
| 73 | mtmsr r3 |
| 74 | mtspr SRR1, r3 /* Make SRR1 match MSR */ |
| 75 | |
| 76 | /* Initialize debug port registers */ |
| 77 | /*----------------------------------------------------------------------*/ |
| 78 | xor r0, r0, r0 /* Clear R0 */ |
| 79 | mtspr LCTRL1, r0 /* Initialize debug port regs */ |
| 80 | mtspr LCTRL2, r0 |
| 81 | mtspr COUNTA, r0 |
| 82 | mtspr COUNTB, r0 |
| 83 | |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 84 | #if defined(CONFIG_PATI) |
| 85 | /* the external flash access on PATI fails if programming the PLL to 40MHz. |
| 86 | * Copy the PLL programming code to the internal RAM and execute it |
| 87 | *----------------------------------------------------------------------*/ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 88 | lis r3, CONFIG_SYS_MONITOR_BASE@h |
| 89 | ori r3, r3, CONFIG_SYS_MONITOR_BASE@l |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 90 | addi r3, r3, pll_prog_code_start - _start + EXC_OFF_SYS_RESET |
| 91 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 92 | lis r4, CONFIG_SYS_INIT_RAM_ADDR@h |
| 93 | ori r4, r4, CONFIG_SYS_INIT_RAM_ADDR@l |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 94 | mtlr r4 |
| 95 | addis r5,0,0x0 |
| 96 | ori r5,r5,((pll_prog_code_end - pll_prog_code_start) >>2) |
| 97 | mtctr r5 |
| 98 | addi r3, r3, -4 |
| 99 | addi r4, r4, -4 |
| 100 | 0: |
| 101 | lwzu r0,4(r3) |
| 102 | stwu r0,4(r4) |
| 103 | bdnz 0b /* copy loop */ |
| 104 | blrl |
| 105 | #endif |
| 106 | |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 107 | /* |
| 108 | * Calculate absolute address in FLASH and jump there |
| 109 | *----------------------------------------------------------------------*/ |
| 110 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 111 | lis r3, CONFIG_SYS_MONITOR_BASE@h |
| 112 | ori r3, r3, CONFIG_SYS_MONITOR_BASE@l |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 113 | addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET |
| 114 | mtlr r3 |
| 115 | blr |
| 116 | |
| 117 | in_flash: |
| 118 | |
| 119 | /* Initialize some SPRs that are hard to access from C */ |
| 120 | /*----------------------------------------------------------------------*/ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 121 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 122 | lis r3, CONFIG_SYS_IMMR@h /* Pass IMMR as arg1 to C routine */ |
| 123 | lis r2, CONFIG_SYS_INIT_SP_ADDR@h |
| 124 | ori r1, r2, CONFIG_SYS_INIT_SP_ADDR@l /* Set up the stack in internal SRAM */ |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 125 | /* Note: R0 is still 0 here */ |
| 126 | stwu r0, -4(r1) /* Clear final stack frame so that */ |
| 127 | stwu r0, -4(r1) /* stack backtraces terminate cleanly */ |
| 128 | |
| 129 | /* |
| 130 | * Disable serialized ifetch and show cycles |
| 131 | * (i.e. set processor to normal mode) for maximum |
| 132 | * performance. |
| 133 | */ |
| 134 | |
| 135 | li r2, 0x0007 |
| 136 | mtspr ICTRL, r2 |
| 137 | |
| 138 | /* Set up debug mode entry */ |
| 139 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 140 | lis r2, CONFIG_SYS_DER@h |
| 141 | ori r2, r2, CONFIG_SYS_DER@l |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 142 | mtspr DER, r2 |
| 143 | |
| 144 | /* Let the C-code set up the rest */ |
| 145 | /* */ |
| 146 | /* Be careful to keep code relocatable ! */ |
| 147 | /*----------------------------------------------------------------------*/ |
| 148 | |
| 149 | GET_GOT /* initialize GOT access */ |
Wolfgang Denk | 8c4734e | 2011-04-20 22:11:21 +0200 | [diff] [blame] | 150 | |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 151 | /* r3: IMMR */ |
| 152 | bl cpu_init_f /* run low-level CPU init code (from Flash) */ |
| 153 | |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 154 | bl board_init_f /* run 1st part of board init code (from Flash) */ |
| 155 | |
Peter Tyser | 52ebd9c | 2010-09-14 19:13:53 -0500 | [diff] [blame] | 156 | /* NOTREACHED - board_init_f() does not return */ |
| 157 | |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 158 | |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 159 | .globl _start_of_vectors |
| 160 | _start_of_vectors: |
| 161 | |
| 162 | /* Machine check */ |
| 163 | STD_EXCEPTION(0x200, MachineCheck, MachineCheckException) |
| 164 | |
| 165 | /* Data Storage exception. "Never" generated on the 860. */ |
| 166 | STD_EXCEPTION(0x300, DataStorage, UnknownException) |
| 167 | |
| 168 | /* Instruction Storage exception. "Never" generated on the 860. */ |
| 169 | STD_EXCEPTION(0x400, InstStorage, UnknownException) |
| 170 | |
| 171 | /* External Interrupt exception. */ |
| 172 | STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt) |
| 173 | |
| 174 | /* Alignment exception. */ |
| 175 | . = 0x600 |
| 176 | Alignment: |
Rafal Jaworowski | 02032e8 | 2007-06-22 14:58:04 +0200 | [diff] [blame] | 177 | EXCEPTION_PROLOG(SRR0, SRR1) |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 178 | mfspr r4,DAR |
| 179 | stw r4,_DAR(r21) |
| 180 | mfspr r5,DSISR |
| 181 | stw r5,_DSISR(r21) |
| 182 | addi r3,r1,STACK_FRAME_OVERHEAD |
Joakim Tjernlund | fc4e188 | 2010-01-19 14:41:55 +0100 | [diff] [blame] | 183 | EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE) |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 184 | |
| 185 | /* Program check exception */ |
| 186 | . = 0x700 |
| 187 | ProgramCheck: |
Rafal Jaworowski | 02032e8 | 2007-06-22 14:58:04 +0200 | [diff] [blame] | 188 | EXCEPTION_PROLOG(SRR0, SRR1) |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 189 | addi r3,r1,STACK_FRAME_OVERHEAD |
Joakim Tjernlund | fc4e188 | 2010-01-19 14:41:55 +0100 | [diff] [blame] | 190 | EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException, |
| 191 | MSR_KERNEL, COPY_EE) |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 192 | |
| 193 | /* FPU on MPC5xx available. We will use it later. |
| 194 | */ |
| 195 | STD_EXCEPTION(0x800, FPUnavailable, UnknownException) |
| 196 | |
| 197 | /* I guess we could implement decrementer, and may have |
| 198 | * to someday for timekeeping. |
| 199 | */ |
| 200 | STD_EXCEPTION(0x900, Decrementer, timer_interrupt) |
| 201 | STD_EXCEPTION(0xa00, Trap_0a, UnknownException) |
| 202 | STD_EXCEPTION(0xb00, Trap_0b, UnknownException) |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 203 | STD_EXCEPTION(0xc00, SystemCall, UnknownException) |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 204 | STD_EXCEPTION(0xd00, SingleStep, UnknownException) |
| 205 | |
| 206 | STD_EXCEPTION(0xe00, Trap_0e, UnknownException) |
| 207 | STD_EXCEPTION(0xf00, Trap_0f, UnknownException) |
| 208 | |
| 209 | /* On the MPC8xx, this is a software emulation interrupt. It occurs |
| 210 | * for all unimplemented and illegal instructions. |
| 211 | */ |
| 212 | STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException) |
| 213 | STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException) |
| 214 | STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException) |
| 215 | STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException) |
| 216 | STD_EXCEPTION(0x1400, DataTLBError, UnknownException) |
| 217 | |
| 218 | STD_EXCEPTION(0x1500, Reserved5, UnknownException) |
| 219 | STD_EXCEPTION(0x1600, Reserved6, UnknownException) |
| 220 | STD_EXCEPTION(0x1700, Reserved7, UnknownException) |
| 221 | STD_EXCEPTION(0x1800, Reserved8, UnknownException) |
| 222 | STD_EXCEPTION(0x1900, Reserved9, UnknownException) |
| 223 | STD_EXCEPTION(0x1a00, ReservedA, UnknownException) |
| 224 | STD_EXCEPTION(0x1b00, ReservedB, UnknownException) |
| 225 | |
| 226 | STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException) |
| 227 | STD_EXCEPTION(0x1d00, InstructionBreakpoint, DebugException) |
| 228 | STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException) |
| 229 | STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException) |
| 230 | |
| 231 | |
| 232 | .globl _end_of_vectors |
| 233 | _end_of_vectors: |
| 234 | |
| 235 | |
| 236 | . = 0x2000 |
| 237 | |
| 238 | /* |
| 239 | * This code finishes saving the registers to the exception frame |
| 240 | * and jumps to the appropriate handler for the exception. |
| 241 | * Register r21 is pointer into trap frame, r1 has new stack pointer. |
| 242 | */ |
| 243 | .globl transfer_to_handler |
| 244 | transfer_to_handler: |
| 245 | stw r22,_NIP(r21) |
| 246 | lis r22,MSR_POW@h |
| 247 | andc r23,r23,r22 |
| 248 | stw r23,_MSR(r21) |
| 249 | SAVE_GPR(7, r21) |
| 250 | SAVE_4GPRS(8, r21) |
| 251 | SAVE_8GPRS(12, r21) |
| 252 | SAVE_8GPRS(24, r21) |
| 253 | mflr r23 |
| 254 | andi. r24,r23,0x3f00 /* get vector offset */ |
| 255 | stw r24,TRAP(r21) |
| 256 | li r22,0 |
| 257 | stw r22,RESULT(r21) |
| 258 | mtspr SPRG2,r22 /* r1 is now kernel sp */ |
| 259 | lwz r24,0(r23) /* virtual address of handler */ |
| 260 | lwz r23,4(r23) /* where to go when done */ |
| 261 | mtspr SRR0,r24 |
| 262 | mtspr SRR1,r20 |
| 263 | mtlr r23 |
| 264 | SYNC |
| 265 | rfi /* jump to handler, enable MMU */ |
| 266 | |
| 267 | int_return: |
| 268 | mfmsr r28 /* Disable interrupts */ |
| 269 | li r4,0 |
| 270 | ori r4,r4,MSR_EE |
| 271 | andc r28,r28,r4 |
| 272 | SYNC /* Some chip revs need this... */ |
| 273 | mtmsr r28 |
| 274 | SYNC |
| 275 | lwz r2,_CTR(r1) |
| 276 | lwz r0,_LINK(r1) |
| 277 | mtctr r2 |
| 278 | mtlr r0 |
| 279 | lwz r2,_XER(r1) |
| 280 | lwz r0,_CCR(r1) |
| 281 | mtspr XER,r2 |
| 282 | mtcrf 0xFF,r0 |
| 283 | REST_10GPRS(3, r1) |
| 284 | REST_10GPRS(13, r1) |
| 285 | REST_8GPRS(23, r1) |
| 286 | REST_GPR(31, r1) |
| 287 | lwz r2,_NIP(r1) /* Restore environment */ |
| 288 | lwz r0,_MSR(r1) |
| 289 | mtspr SRR0,r2 |
| 290 | mtspr SRR1,r0 |
| 291 | lwz r0,GPR0(r1) |
| 292 | lwz r2,GPR2(r1) |
| 293 | lwz r1,GPR1(r1) |
| 294 | SYNC |
| 295 | rfi |
| 296 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 297 | |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 298 | /* |
| 299 | * unsigned int get_immr (unsigned int mask) |
| 300 | * |
| 301 | * return (mask ? (IMMR & mask) : IMMR); |
| 302 | */ |
| 303 | .globl get_immr |
| 304 | get_immr: |
| 305 | mr r4,r3 /* save mask */ |
| 306 | mfspr r3, IMMR /* IMMR */ |
| 307 | cmpwi 0,r4,0 /* mask != 0 ? */ |
| 308 | beq 4f |
| 309 | and r3,r3,r4 /* IMMR & mask */ |
| 310 | 4: |
| 311 | blr |
| 312 | |
| 313 | .globl get_pvr |
| 314 | get_pvr: |
| 315 | mfspr r3, PVR |
| 316 | blr |
| 317 | |
| 318 | |
| 319 | /*------------------------------------------------------------------------------*/ |
| 320 | |
| 321 | /* |
| 322 | * void relocate_code (addr_sp, gd, addr_moni) |
| 323 | * |
| 324 | * This "function" does not return, instead it continues in RAM |
| 325 | * after relocating the monitor code. |
| 326 | * |
| 327 | * r3 = dest |
| 328 | * r4 = src |
| 329 | * r5 = length in bytes |
| 330 | * r6 = cachelinesize |
| 331 | */ |
| 332 | .globl relocate_code |
| 333 | relocate_code: |
| 334 | mr r1, r3 /* Set new stack pointer in SRAM */ |
| 335 | mr r9, r4 /* Save copy of global data pointer in SRAM */ |
| 336 | mr r10, r5 /* Save copy of monitor destination Address in SRAM */ |
| 337 | |
Joakim Tjernlund | 0f8aa15 | 2010-01-19 14:41:56 +0100 | [diff] [blame] | 338 | GET_GOT |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 339 | mr r3, r5 /* Destination Address */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 340 | lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */ |
| 341 | ori r4, r4, CONFIG_SYS_MONITOR_BASE@l |
wdenk | 3b57fe0 | 2003-05-30 12:48:29 +0000 | [diff] [blame] | 342 | lwz r5, GOT(__init_end) |
| 343 | sub r5, r5, r4 |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 344 | |
| 345 | /* |
| 346 | * Fix GOT pointer: |
| 347 | * |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 348 | * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 349 | * |
| 350 | * Offset: |
| 351 | */ |
| 352 | sub r15, r10, r4 |
| 353 | |
| 354 | /* First our own GOT */ |
Joakim Tjernlund | 0f8aa15 | 2010-01-19 14:41:56 +0100 | [diff] [blame] | 355 | add r12, r12, r15 |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 356 | /* the the one used by the C code */ |
| 357 | add r30, r30, r15 |
| 358 | |
| 359 | /* |
| 360 | * Now relocate code |
| 361 | */ |
| 362 | |
| 363 | cmplw cr1,r3,r4 |
| 364 | addi r0,r5,3 |
| 365 | srwi. r0,r0,2 |
| 366 | beq cr1,4f /* In place copy is not necessary */ |
| 367 | beq 4f /* Protect against 0 count */ |
| 368 | mtctr r0 |
| 369 | bge cr1,2f |
| 370 | |
| 371 | la r8,-4(r4) |
| 372 | la r7,-4(r3) |
| 373 | 1: lwzu r0,4(r8) |
| 374 | stwu r0,4(r7) |
| 375 | bdnz 1b |
| 376 | b 4f |
| 377 | |
| 378 | 2: slwi r0,r0,2 |
| 379 | add r8,r4,r0 |
| 380 | add r7,r3,r0 |
| 381 | 3: lwzu r0,-4(r8) |
| 382 | stwu r0,-4(r7) |
| 383 | bdnz 3b |
| 384 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 385 | 4: sync |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 386 | isync |
| 387 | |
| 388 | /* |
| 389 | * We are done. Do not return, instead branch to second part of board |
| 390 | * initialization, now running from RAM. |
| 391 | */ |
| 392 | |
| 393 | addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET |
| 394 | mtlr r0 |
| 395 | blr |
| 396 | |
| 397 | in_ram: |
| 398 | |
| 399 | /* |
Joakim Tjernlund | 0f8aa15 | 2010-01-19 14:41:56 +0100 | [diff] [blame] | 400 | * Relocation Function, r12 point to got2+0x8000 |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 401 | * |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 402 | * Adjust got2 pointers, no need to check for 0, this code |
| 403 | * already puts a few entries in the table. |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 404 | */ |
| 405 | li r0,__got2_entries@sectoff@l |
| 406 | la r3,GOT(_GOT2_TABLE_) |
| 407 | lwz r11,GOT(_GOT2_TABLE_) |
| 408 | mtctr r0 |
| 409 | sub r11,r3,r11 |
| 410 | addi r3,r3,-4 |
| 411 | 1: lwzu r0,4(r3) |
Joakim Tjernlund | afc3ba0 | 2009-10-08 02:03:51 +0200 | [diff] [blame] | 412 | cmpwi r0,0 |
| 413 | beq- 2f |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 414 | add r0,r0,r11 |
| 415 | stw r0,0(r3) |
Joakim Tjernlund | afc3ba0 | 2009-10-08 02:03:51 +0200 | [diff] [blame] | 416 | 2: bdnz 1b |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 417 | |
| 418 | /* |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 419 | * Now adjust the fixups and the pointers to the fixups |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 420 | * in case we need to move ourselves again. |
| 421 | */ |
Joakim Tjernlund | afc3ba0 | 2009-10-08 02:03:51 +0200 | [diff] [blame] | 422 | li r0,__fixup_entries@sectoff@l |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 423 | lwz r3,GOT(_FIXUP_TABLE_) |
| 424 | cmpwi r0,0 |
| 425 | mtctr r0 |
| 426 | addi r3,r3,-4 |
| 427 | beq 4f |
| 428 | 3: lwzu r4,4(r3) |
| 429 | lwzux r0,r4,r11 |
Joakim Tjernlund | d1e0b10 | 2010-10-14 11:51:44 +0200 | [diff] [blame] | 430 | cmpwi r0,0 |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 431 | add r0,r0,r11 |
Joakim Tjernlund | 34bbf61 | 2010-11-04 19:02:00 +0100 | [diff] [blame] | 432 | stw r4,0(r3) |
Joakim Tjernlund | d1e0b10 | 2010-10-14 11:51:44 +0200 | [diff] [blame] | 433 | beq- 5f |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 434 | stw r0,0(r4) |
Joakim Tjernlund | d1e0b10 | 2010-10-14 11:51:44 +0200 | [diff] [blame] | 435 | 5: bdnz 3b |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 436 | 4: |
| 437 | clear_bss: |
| 438 | /* |
| 439 | * Now clear BSS segment |
| 440 | */ |
wdenk | 5d232d0 | 2003-05-22 22:52:13 +0000 | [diff] [blame] | 441 | lwz r3,GOT(__bss_start) |
Simon Glass | 3929fb0 | 2013-03-14 06:54:53 +0000 | [diff] [blame] | 442 | lwz r4,GOT(__bss_end) |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 443 | cmplw 0, r3, r4 |
| 444 | beq 6f |
| 445 | |
| 446 | li r0, 0 |
| 447 | 5: |
| 448 | stw r0, 0(r3) |
| 449 | addi r3, r3, 4 |
| 450 | cmplw 0, r3, r4 |
| 451 | bne 5b |
| 452 | 6: |
| 453 | |
| 454 | mr r3, r9 /* Global Data pointer */ |
| 455 | mr r4, r10 /* Destination Address */ |
| 456 | bl board_init_r |
| 457 | |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 458 | /* |
| 459 | * Copy exception vector code to low memory |
| 460 | * |
| 461 | * r3: dest_addr |
| 462 | * r7: source address, r8: end address, r9: target address |
| 463 | */ |
| 464 | .globl trap_init |
| 465 | trap_init: |
Joakim Tjernlund | 0f8aa15 | 2010-01-19 14:41:56 +0100 | [diff] [blame] | 466 | mflr r4 /* save link register */ |
| 467 | GET_GOT |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 468 | lwz r7, GOT(_start) |
| 469 | lwz r8, GOT(_end_of_vectors) |
| 470 | |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 471 | li r9, 0x100 /* reset vector always at 0x100 */ |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 472 | |
| 473 | cmplw 0, r7, r8 |
| 474 | bgelr /* return if r7>=r8 - just in case */ |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 475 | 1: |
| 476 | lwz r0, 0(r7) |
| 477 | stw r0, 0(r9) |
| 478 | addi r7, r7, 4 |
| 479 | addi r9, r9, 4 |
| 480 | cmplw 0, r7, r8 |
| 481 | bne 1b |
| 482 | |
| 483 | /* |
| 484 | * relocate `hdlr' and `int_return' entries |
| 485 | */ |
| 486 | li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET |
| 487 | li r8, Alignment - _start + EXC_OFF_SYS_RESET |
| 488 | 2: |
| 489 | bl trap_reloc |
| 490 | addi r7, r7, 0x100 /* next exception vector */ |
| 491 | cmplw 0, r7, r8 |
| 492 | blt 2b |
| 493 | |
| 494 | li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET |
| 495 | bl trap_reloc |
| 496 | |
| 497 | li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET |
| 498 | bl trap_reloc |
| 499 | |
| 500 | li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET |
| 501 | li r8, SystemCall - _start + EXC_OFF_SYS_RESET |
| 502 | 3: |
| 503 | bl trap_reloc |
| 504 | addi r7, r7, 0x100 /* next exception vector */ |
| 505 | cmplw 0, r7, r8 |
| 506 | blt 3b |
| 507 | |
| 508 | li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET |
| 509 | li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET |
| 510 | 4: |
| 511 | bl trap_reloc |
| 512 | addi r7, r7, 0x100 /* next exception vector */ |
| 513 | cmplw 0, r7, r8 |
| 514 | blt 4b |
| 515 | |
| 516 | mtlr r4 /* restore link register */ |
| 517 | blr |
| 518 | |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 519 | #if defined(CONFIG_PATI) |
| 520 | /* Program the PLL */ |
| 521 | pll_prog_code_start: |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 522 | lis r4, (CONFIG_SYS_IMMR + 0x002fc384)@h |
| 523 | ori r4, r4, (CONFIG_SYS_IMMR + 0x002fc384)@l |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 524 | lis r3, (0x55ccaa33)@h |
| 525 | ori r3, r3, (0x55ccaa33)@l |
| 526 | stw r3, 0(r4) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 527 | lis r4, (CONFIG_SYS_IMMR + 0x002fc284)@h |
| 528 | ori r4, r4, (CONFIG_SYS_IMMR + 0x002fc284)@l |
| 529 | lis r3, CONFIG_SYS_PLPRCR@h |
| 530 | ori r3, r3, CONFIG_SYS_PLPRCR@l |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 531 | stw r3, 0(r4) |
| 532 | addis r3,0,0x0 |
| 533 | ori r3,r3,0xA000 |
| 534 | mtctr r3 |
| 535 | ..spinlp: |
| 536 | bdnz ..spinlp /* spin loop */ |
| 537 | blr |
| 538 | pll_prog_code_end: |
| 539 | nop |
| 540 | blr |
| 541 | #endif |