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