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