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