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