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