blob: 632f9674c8e5b00cada62f17a765b3d595de52a4 [file] [log] [blame]
Rafal Jaworowski8993e542007-07-27 14:43:59 +02001/*
2 * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
3 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
Wolfgang Denk3b74e7e2009-05-16 10:47:45 +02004 * Copyright (C) 2000-2009 Wolfgang Denk <wd@denx.de>
Kumar Gala4c2e3da2009-07-28 21:49:52 -05005 * Copyright Freescale Semiconductor, Inc. 2004, 2006.
Rafal Jaworowski8993e542007-07-27 14:43:59 +02006 *
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 * Based on the MPC83xx code.
26 */
27
28/*
29 * U-Boot - Startup Code for MPC512x based Embedded Boards
30 */
31
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +020032#include <asm-offsets.h>
Rafal Jaworowski8993e542007-07-27 14:43:59 +020033#include <config.h>
Peter Tyser561858e2008-11-03 09:30:59 -060034#include <timestamp.h>
Rafal Jaworowski8993e542007-07-27 14:43:59 +020035#include <version.h>
36
37#define CONFIG_521X 1 /* needed for Linux kernel header files*/
38
Wolfgang Denk3b74e7e2009-05-16 10:47:45 +020039#include <asm/immap_512x.h>
40#include "asm-offsets.h"
41
Rafal Jaworowski8993e542007-07-27 14:43:59 +020042#include <ppc_asm.tmpl>
43#include <ppc_defs.h>
44
45#include <asm/cache.h>
46#include <asm/mmu.h>
Peter Tyserd98b0522010-10-14 23:33:24 -050047#include <asm/u-boot.h>
Rafal Jaworowski8993e542007-07-27 14:43:59 +020048
49#ifndef CONFIG_IDENT_STRING
50#define CONFIG_IDENT_STRING "MPC512X"
51#endif
52
53/*
54 * Floating Point enable, Machine Check and Recoverable Interr.
55 */
56#undef MSR_KERNEL
57#ifdef DEBUG
58#define MSR_KERNEL (MSR_FP|MSR_RI)
59#else
60#define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
61#endif
62
63/* Macros for manipulating CSx_START/STOP */
64#define START_REG(start) ((start) >> 16)
65#define STOP_REG(start, size) (((start) + (size) - 1) >> 16)
66
67/*
68 * Set up GOT: Global Offset Table
69 *
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +010070 * Use r12 to access the GOT
Rafal Jaworowski8993e542007-07-27 14:43:59 +020071 */
72 START_GOT
73 GOT_ENTRY(_GOT2_TABLE_)
74 GOT_ENTRY(_FIXUP_TABLE_)
75
76 GOT_ENTRY(_start)
77 GOT_ENTRY(_start_of_vectors)
78 GOT_ENTRY(_end_of_vectors)
79 GOT_ENTRY(transfer_to_handler)
80
81 GOT_ENTRY(__init_end)
Po-Yu Chuang44c6e652011-03-01 22:59:59 +000082 GOT_ENTRY(__bss_end__)
Rafal Jaworowski8993e542007-07-27 14:43:59 +020083 GOT_ENTRY(__bss_start)
84 END_GOT
85
86/*
87 * Magic number and version string
88 */
89 .long 0x27051956 /* U-Boot Magic Number */
90 .globl version_string
91version_string:
92 .ascii U_BOOT_VERSION
Peter Tyser561858e2008-11-03 09:30:59 -060093 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
Rafal Jaworowski8993e542007-07-27 14:43:59 +020094 .ascii " ", CONFIG_IDENT_STRING, "\0"
95
96/*
97 * Vector Table
98 */
99 .text
100 . = EXC_OFF_SYS_RESET
101
102 .globl _start
103 /* Start from here after reset/power on */
104_start:
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200105 b boot_cold
106
107 .globl _start_of_vectors
108_start_of_vectors:
109
110/* Machine check */
111 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
112
113/* Data Storage exception. */
114 STD_EXCEPTION(0x300, DataStorage, UnknownException)
115
116/* Instruction Storage exception. */
117 STD_EXCEPTION(0x400, InstStorage, UnknownException)
118
119/* External Interrupt exception. */
120 STD_EXCEPTION(0x500, ExtInterrupt, UnknownException)
121
122/* Alignment exception. */
123 . = 0x600
124Alignment:
125 EXCEPTION_PROLOG(SRR0, SRR1)
126 mfspr r4,DAR
127 stw r4,_DAR(r21)
128 mfspr r5,DSISR
129 stw r5,_DSISR(r21)
130 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlundfc4e1882010-01-19 14:41:55 +0100131 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200132
133/* Program check exception */
134 . = 0x700
135ProgramCheck:
136 EXCEPTION_PROLOG(SRR0, SRR1)
137 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlundfc4e1882010-01-19 14:41:55 +0100138 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
139 MSR_KERNEL, COPY_EE)
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200140
141/* Floating Point Unit unavailable exception */
142 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
143
144/* Decrementer */
145 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
146
147/* Critical interrupt */
148 STD_EXCEPTION(0xa00, Critical, UnknownException)
149
150/* System Call */
151 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
152
153/* Trace interrupt */
154 STD_EXCEPTION(0xd00, Trace, UnknownException)
155
156/* Performance Monitor interrupt */
157 STD_EXCEPTION(0xf00, PerfMon, UnknownException)
158
159/* Intruction Translation Miss */
160 STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
161
162/* Data Load Translation Miss */
163 STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
164
165/* Data Store Translation Miss */
166 STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
167
168/* Instruction Address Breakpoint */
169 STD_EXCEPTION(0x1300, InstructionAddrBreakpoint, DebugException)
170
171/* System Management interrupt */
172 STD_EXCEPTION(0x1400, SystemMgmtInterrupt, UnknownException)
173
174 .globl _end_of_vectors
175_end_of_vectors:
176
177 . = 0x3000
178boot_cold:
179 /* Save msr contents */
180 mfmsr r5
181
182 /* Set IMMR area to our preferred location */
183 lis r4, CONFIG_DEFAULT_IMMR@h
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200184 lis r3, CONFIG_SYS_IMMR@h
185 ori r3, r3, CONFIG_SYS_IMMR@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200186 stw r3, IMMRBAR(r4)
187 mtspr MBAR, r3 /* IMMRBAR is mirrored into the MBAR SPR (311) */
188
189 /* Initialise the machine */
190 bl cpu_early_init
191
192 /*
193 * Set up Local Access Windows:
194 *
195 * 1) Boot/CS0 (boot FLASH)
196 * 2) On-chip SRAM (initial stack purposes)
197 */
198
199 /* Boot CS/CS0 window range */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200200 lis r3, CONFIG_SYS_IMMR@h
201 ori r3, r3, CONFIG_SYS_IMMR@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200202
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200203 lis r4, START_REG(CONFIG_SYS_FLASH_BASE)
204 ori r4, r4, STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE)
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200205 stw r4, LPCS0AW(r3)
206
207 /*
208 * The SRAM window has a fixed size (256K), so only the start address
209 * is necessary
210 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200211 lis r4, START_REG(CONFIG_SYS_SRAM_BASE) & 0xff00
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200212 stw r4, SRAMBAR(r3)
213
Wolfgang Denkb1b54e32007-08-02 21:27:46 +0200214 /*
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200215 * According to MPC5121e RM, configuring local access windows should
Wolfgang Denkb1b54e32007-08-02 21:27:46 +0200216 * be followed by a dummy read of the config register that was
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200217 * modified last and an isync
Wolfgang Denkb1b54e32007-08-02 21:27:46 +0200218 */
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200219 lwz r4, SRAMBAR(r3)
220 isync
221
222 /*
223 * Set configuration of the Boot/CS0, the SRAM window does not have a
224 * config register so no params can be set for it
225 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200226 lis r3, (CONFIG_SYS_IMMR + LPC_OFFSET)@h
227 ori r3, r3, (CONFIG_SYS_IMMR + LPC_OFFSET)@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200228
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200229 lis r4, CONFIG_SYS_CS0_CFG@h
230 ori r4, r4, CONFIG_SYS_CS0_CFG@l
Wolfgang Denkb1b54e32007-08-02 21:27:46 +0200231 stw r4, CS0_CONFIG(r3)
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200232
233 /* Master enable all CS's */
234 lis r4, CS_CTRL_ME@h
235 ori r4, r4, CS_CTRL_ME@l
236 stw r4, CS_CTRL(r3)
237
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200238 lis r4, (CONFIG_SYS_MONITOR_BASE)@h
239 ori r4, r4, (CONFIG_SYS_MONITOR_BASE)@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200240 addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET
241 mtlr r5
242 blr
243
244in_flash:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200245 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
246 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200247
248 li r0, 0 /* Make room for stack frame header and */
249 stwu r0, -4(r1) /* clear final stack frame so that */
250 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
251
252 /* let the C-code set up the rest */
253 /* */
254 /* Be careful to keep code relocatable & stack humble */
255 /*------------------------------------------------------*/
256
257 GET_GOT /* initialize GOT access */
Joakim Tjernlund39768f72010-12-06 18:35:37 +0100258#if defined(__pic__) && __pic__ == 1
259 /* Needed for upcoming -msingle-pic-base */
260 bl _GLOBAL_OFFSET_TABLE_@local-4
261 mflr r30
262#endif
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200263 /* r3: IMMR */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200264 lis r3, CONFIG_SYS_IMMR@h
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200265 /* run low-level CPU init code (in Flash) */
266 bl cpu_init_f
267
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200268 /* run 1st part of board init code (in Flash) */
269 bl board_init_f
270
271 /* NOTREACHED - board_init_f() does not return */
272
273/*
274 * This code finishes saving the registers to the exception frame
275 * and jumps to the appropriate handler for the exception.
276 * Register r21 is pointer into trap frame, r1 has new stack pointer.
277 */
278 .globl transfer_to_handler
279transfer_to_handler:
280 stw r22,_NIP(r21)
281 lis r22,MSR_POW@h
282 andc r23,r23,r22
283 stw r23,_MSR(r21)
284 SAVE_GPR(7, r21)
285 SAVE_4GPRS(8, r21)
286 SAVE_8GPRS(12, r21)
287 SAVE_8GPRS(24, r21)
288 mflr r23
289 andi. r24,r23,0x3f00 /* get vector offset */
290 stw r24,TRAP(r21)
291 li r22,0
292 stw r22,RESULT(r21)
293 lwz r24,0(r23) /* virtual address of handler */
294 lwz r23,4(r23) /* where to go when done */
295 mtspr SRR0,r24
296 mtspr SRR1,r20
297 mtlr r23
298 SYNC
299 rfi /* jump to handler, enable MMU */
300
301int_return:
302 mfmsr r28 /* Disable interrupts */
303 li r4,0
304 ori r4,r4,MSR_EE
305 andc r28,r28,r4
306 SYNC /* Some chip revs need this... */
307 mtmsr r28
308 SYNC
309 lwz r2,_CTR(r1)
310 lwz r0,_LINK(r1)
311 mtctr r2
312 mtlr r0
313 lwz r2,_XER(r1)
314 lwz r0,_CCR(r1)
315 mtspr XER,r2
316 mtcrf 0xFF,r0
317 REST_10GPRS(3, r1)
318 REST_10GPRS(13, r1)
319 REST_8GPRS(23, r1)
320 REST_GPR(31, r1)
321 lwz r2,_NIP(r1) /* Restore environment */
322 lwz r0,_MSR(r1)
323 mtspr SRR0,r2
324 mtspr SRR1,r0
325 lwz r0,GPR0(r1)
326 lwz r2,GPR2(r1)
327 lwz r1,GPR1(r1)
328 SYNC
329 rfi
330
331/*
332 * This code initialises the machine, it expects original MSR contents to be in r5.
333 */
334cpu_early_init:
335 /* Initialize machine status; enable machine check interrupt */
336 /*-----------------------------------------------------------*/
337
338 li r3, MSR_KERNEL /* Set ME and RI flags */
339 rlwimi r3, r5, 0, 25, 25 /* preserve IP bit */
340#ifdef DEBUG
341 rlwimi r3, r5, 0, 21, 22 /* debugger might set SE, BE bits */
342#endif
343 mtmsr r3
344 SYNC
345 mtspr SRR1, r3 /* Mirror current MSR state in SRR1 */
346
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200347 lis r3, CONFIG_SYS_IMMR@h
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200348
349#if defined(CONFIG_WATCHDOG)
350 /* Initialise the watchdog and reset it */
351 /*--------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200352 lis r4, CONFIG_SYS_WATCHDOG_VALUE
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200353 ori r4, r4, (SWCRR_SWEN | SWCRR_SWRI | SWCRR_SWPR)
354 stw r4, SWCRR(r3)
355
356 /* reset */
357 li r4, 0x556C
358 sth r4, SWSRR@l(r3)
359 li r4, 0x0
360 ori r4, r4, 0xAA39
361 sth r4, SWSRR@l(r3)
362#else
363 /* Disable the watchdog */
364 /*----------------------*/
365 lwz r4, SWCRR(r3)
366 /*
367 * Check to see if it's enabled for disabling: once disabled by s/w
368 * it's not possible to re-enable it
369 */
370 andi. r4, r4, 0x4
371 beq 1f
372 xor r4, r4, r4
373 stw r4, SWCRR(r3)
3741:
375#endif /* CONFIG_WATCHDOG */
376
377 /* Initialize the Hardware Implementation-dependent Registers */
378 /* HID0 also contains cache control */
379 /*------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200380 lis r3, CONFIG_SYS_HID0_INIT@h
381 ori r3, r3, CONFIG_SYS_HID0_INIT@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200382 SYNC
383 mtspr HID0, r3
384
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200385 lis r3, CONFIG_SYS_HID0_FINAL@h
386 ori r3, r3, CONFIG_SYS_HID0_FINAL@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200387 SYNC
388 mtspr HID0, r3
389
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200390 lis r3, CONFIG_SYS_HID2@h
391 ori r3, r3, CONFIG_SYS_HID2@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200392 SYNC
393 mtspr HID2, r3
394 sync
395 blr
396
397
398/* Cache functions.
399 *
400 * Note: requires that all cache bits in
401 * HID0 are in the low half word.
402 */
403 .globl icache_enable
404icache_enable:
405 mfspr r3, HID0
406 ori r3, r3, HID0_ICE
407 lis r4, 0
408 ori r4, r4, HID0_ILOCK
409 andc r3, r3, r4
410 ori r4, r3, HID0_ICFI
411 isync
412 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
413 isync
414 mtspr HID0, r3 /* clears invalidate */
415 blr
416
417 .globl icache_disable
418icache_disable:
419 mfspr r3, HID0
420 lis r4, 0
421 ori r4, r4, HID0_ICE|HID0_ILOCK
422 andc r3, r3, r4
423 ori r4, r3, HID0_ICFI
424 isync
425 mtspr HID0, r4 /* sets invalidate, clears enable and lock*/
426 isync
427 mtspr HID0, r3 /* clears invalidate */
428 blr
429
430 .globl icache_status
431icache_status:
432 mfspr r3, HID0
433 rlwinm r3, r3, (31 - HID0_ICE_SHIFT + 1), 31, 31
434 blr
435
436 .globl dcache_enable
437dcache_enable:
438 mfspr r3, HID0
439 li r5, HID0_DCFI|HID0_DLOCK
440 andc r3, r3, r5
441 mtspr HID0, r3 /* no invalidate, unlock */
442 ori r3, r3, HID0_DCE
443 ori r5, r3, HID0_DCFI
444 mtspr HID0, r5 /* enable + invalidate */
445 mtspr HID0, r3 /* enable */
446 sync
447 blr
448
449 .globl dcache_disable
450dcache_disable:
451 mfspr r3, HID0
452 lis r4, 0
453 ori r4, r4, HID0_DCE|HID0_DLOCK
454 andc r3, r3, r4
455 ori r4, r3, HID0_DCI
456 sync
457 mtspr HID0, r4 /* sets invalidate, clears enable and lock */
458 sync
459 mtspr HID0, r3 /* clears invalidate */
460 blr
461
462 .globl dcache_status
463dcache_status:
464 mfspr r3, HID0
465 rlwinm r3, r3, (31 - HID0_DCE_SHIFT + 1), 31, 31
466 blr
467
468 .globl get_pvr
469get_pvr:
470 mfspr r3, PVR
471 blr
472
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200473/*-------------------------------------------------------------------*/
474
475/*
476 * void relocate_code (addr_sp, gd, addr_moni)
477 *
478 * This "function" does not return, instead it continues in RAM
479 * after relocating the monitor code.
480 *
481 * r3 = dest
482 * r4 = src
483 * r5 = length in bytes
484 * r6 = cachelinesize
485 */
486 .globl relocate_code
487relocate_code:
488 mr r1, r3 /* Set new stack pointer */
489 mr r9, r4 /* Save copy of Global Data pointer */
490 mr r10, r5 /* Save copy of Destination Address */
491
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100492 GET_GOT
Joakim Tjernlund39768f72010-12-06 18:35:37 +0100493#if defined(__pic__) && __pic__ == 1
494 /* Needed for upcoming -msingle-pic-base */
495 bl _GLOBAL_OFFSET_TABLE_@local-4
496 mflr r30
497#endif
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200498 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200499 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
500 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200501 lwz r5, GOT(__init_end)
502 sub r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200503 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200504
505 /*
506 * Fix GOT pointer:
507 *
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200508 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE)
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200509 * + Destination Address
510 *
511 * Offset:
512 */
513 sub r15, r10, r4
514
515 /* First our own GOT */
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100516 add r12, r12, r15
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200517 /* then the one used by the C code */
518 add r30, r30, r15
519
520 /*
521 * Now relocate code
522 */
523 cmplw cr1,r3,r4
524 addi r0,r5,3
525 srwi. r0,r0,2
526 beq cr1,4f /* In place copy is not necessary */
527 beq 7f /* Protect against 0 count */
528 mtctr r0
529 bge cr1,2f
530 la r8,-4(r4)
531 la r7,-4(r3)
532
533 /* copy */
5341: lwzu r0,4(r8)
535 stwu r0,4(r7)
536 bdnz 1b
537
538 addi r0,r5,3
539 srwi. r0,r0,2
540 mtctr r0
541 la r8,-4(r4)
542 la r7,-4(r3)
543
544 /* and compare */
54520: lwzu r20,4(r8)
546 lwzu r21,4(r7)
547 xor. r22, r20, r21
548 bne 30f
549 bdnz 20b
550 b 4f
551
552 /* compare failed */
55330: li r3, 0
554 blr
555
5562: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */
557 add r8,r4,r0
558 add r7,r3,r0
5593: lwzu r0,-4(r8)
560 stwu r0,-4(r7)
561 bdnz 3b
562
563/*
564 * Now flush the cache: note that we must start from a cache aligned
565 * address. Otherwise we might miss one cache line.
566 */
5674: cmpwi r6,0
568 add r5,r3,r5
569 beq 7f /* Always flush prefetch queue in any case */
570 subi r0,r6,1
571 andc r3,r3,r0
572 mr r4,r3
5735: dcbst 0,r4
574 add r4,r4,r6
575 cmplw r4,r5
576 blt 5b
577 sync /* Wait for all dcbst to complete on bus */
578 mr r4,r3
5796: icbi 0,r4
580 add r4,r4,r6
581 cmplw r4,r5
582 blt 6b
5837: sync /* Wait for all icbi to complete on bus */
584 isync
585
586/*
587 * We are done. Do not return, instead branch to second part of board
588 * initialization, now running from RAM.
589 */
590 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
591 mtlr r0
592 blr
593
594in_ram:
595 /*
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100596 * Relocation Function, r12 point to got2+0x8000
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200597 *
598 * Adjust got2 pointers, no need to check for 0, this code
599 * already puts a few entries in the table.
600 */
601 li r0,__got2_entries@sectoff@l
602 la r3,GOT(_GOT2_TABLE_)
603 lwz r11,GOT(_GOT2_TABLE_)
604 mtctr r0
605 sub r11,r3,r11
606 addi r3,r3,-4
6071: lwzu r0,4(r3)
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +0200608 cmpwi r0,0
609 beq- 2f
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200610 add r0,r0,r11
611 stw r0,0(r3)
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +02006122: bdnz 1b
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200613
614 /*
615 * Now adjust the fixups and the pointers to the fixups
616 * in case we need to move ourselves again.
617 */
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +0200618 li r0,__fixup_entries@sectoff@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200619 lwz r3,GOT(_FIXUP_TABLE_)
620 cmpwi r0,0
621 mtctr r0
622 addi r3,r3,-4
623 beq 4f
6243: lwzu r4,4(r3)
625 lwzux r0,r4,r11
Joakim Tjernlundd1e0b102010-10-14 11:51:44 +0200626 cmpwi r0,0
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200627 add r0,r0,r11
Joakim Tjernlund34bbf612010-11-04 19:02:00 +0100628 stw r4,0(r3)
Joakim Tjernlundd1e0b102010-10-14 11:51:44 +0200629 beq- 5f
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200630 stw r0,0(r4)
Joakim Tjernlundd1e0b102010-10-14 11:51:44 +02006315: bdnz 3b
Rafal Jaworowski8993e542007-07-27 14:43:59 +02006324:
633clear_bss:
634 /*
635 * Now clear BSS segment
636 */
637 lwz r3,GOT(__bss_start)
Po-Yu Chuang44c6e652011-03-01 22:59:59 +0000638 lwz r4,GOT(__bss_end__)
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200639
640 cmplw 0, r3, r4
641 beq 6f
642
643 li r0, 0
6445:
645 stw r0, 0(r3)
646 addi r3, r3, 4
647 cmplw 0, r3, r4
648 bne 5b
6496:
650 mr r3, r9 /* Global Data pointer */
651 mr r4, r10 /* Destination Address */
652 bl board_init_r
653
654 /*
655 * Copy exception vector code to low memory
656 *
657 * r3: dest_addr
658 * r7: source address, r8: end address, r9: target address
659 */
660 .globl trap_init
661trap_init:
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100662 mflr r4 /* save link register */
663 GET_GOT
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200664 lwz r7, GOT(_start)
665 lwz r8, GOT(_end_of_vectors)
666
667 li r9, 0x100 /* reset vector at 0x100 */
668
669 cmplw 0, r7, r8
670 bgelr /* return if r7>=r8 - just in case */
Rafal Jaworowski8993e542007-07-27 14:43:59 +02006711:
672 lwz r0, 0(r7)
673 stw r0, 0(r9)
674 addi r7, r7, 4
675 addi r9, r9, 4
676 cmplw 0, r7, r8
677 bne 1b
678
679 /*
680 * relocate `hdlr' and `int_return' entries
681 */
682 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
683 li r8, Alignment - _start + EXC_OFF_SYS_RESET
6842:
685 bl trap_reloc
686 addi r7, r7, 0x100 /* next exception vector */
687 cmplw 0, r7, r8
688 blt 2b
689
690 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
691 bl trap_reloc
692
693 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
694 bl trap_reloc
695
696 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
697 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
6983:
699 bl trap_reloc
700 addi r7, r7, 0x100 /* next exception vector */
701 cmplw 0, r7, r8
702 blt 3b
703
704 li r7, .L_Trace - _start + EXC_OFF_SYS_RESET
705 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
7064:
707 bl trap_reloc
708 addi r7, r7, 0x100 /* next exception vector */
709 cmplw 0, r7, r8
710 blt 4b
711
712 mfmsr r3 /* now that the vectors have */
713 lis r7, MSR_IP@h /* relocated into low memory */
714 ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
715 andc r3, r3, r7 /* (if it was on) */
716 SYNC /* Some chip revs need this... */
717 mtmsr r3
718 SYNC
719
720 mtlr r4 /* restore link register */
721 blr