blob: 2265c8cc11099ed49e2e34ae76feec0512a4341d [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
32#include <config.h>
Peter Tyser561858e2008-11-03 09:30:59 -060033#include <timestamp.h>
Rafal Jaworowski8993e542007-07-27 14:43:59 +020034#include <version.h>
35
36#define CONFIG_521X 1 /* needed for Linux kernel header files*/
37
Wolfgang Denk3b74e7e2009-05-16 10:47:45 +020038#include <asm/immap_512x.h>
39#include "asm-offsets.h"
40
Rafal Jaworowski8993e542007-07-27 14:43:59 +020041#include <ppc_asm.tmpl>
42#include <ppc_defs.h>
43
44#include <asm/cache.h>
45#include <asm/mmu.h>
Peter Tyserd98b0522010-10-14 23:33:24 -050046#include <asm/u-boot.h>
Rafal Jaworowski8993e542007-07-27 14:43:59 +020047
48#ifndef CONFIG_IDENT_STRING
49#define CONFIG_IDENT_STRING "MPC512X"
50#endif
51
52/*
53 * Floating Point enable, Machine Check and Recoverable Interr.
54 */
55#undef MSR_KERNEL
56#ifdef DEBUG
57#define MSR_KERNEL (MSR_FP|MSR_RI)
58#else
59#define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
60#endif
61
62/* Macros for manipulating CSx_START/STOP */
63#define START_REG(start) ((start) >> 16)
64#define STOP_REG(start, size) (((start) + (size) - 1) >> 16)
65
66/*
67 * Set up GOT: Global Offset Table
68 *
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +010069 * Use r12 to access the GOT
Rafal Jaworowski8993e542007-07-27 14:43:59 +020070 */
71 START_GOT
72 GOT_ENTRY(_GOT2_TABLE_)
73 GOT_ENTRY(_FIXUP_TABLE_)
74
75 GOT_ENTRY(_start)
76 GOT_ENTRY(_start_of_vectors)
77 GOT_ENTRY(_end_of_vectors)
78 GOT_ENTRY(transfer_to_handler)
79
80 GOT_ENTRY(__init_end)
81 GOT_ENTRY(_end)
82 GOT_ENTRY(__bss_start)
83 END_GOT
84
85/*
86 * Magic number and version string
87 */
88 .long 0x27051956 /* U-Boot Magic Number */
89 .globl version_string
90version_string:
91 .ascii U_BOOT_VERSION
Peter Tyser561858e2008-11-03 09:30:59 -060092 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
Rafal Jaworowski8993e542007-07-27 14:43:59 +020093 .ascii " ", CONFIG_IDENT_STRING, "\0"
94
95/*
96 * Vector Table
97 */
98 .text
99 . = EXC_OFF_SYS_RESET
100
101 .globl _start
102 /* Start from here after reset/power on */
103_start:
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200104 b boot_cold
105
106 .globl _start_of_vectors
107_start_of_vectors:
108
109/* Machine check */
110 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
111
112/* Data Storage exception. */
113 STD_EXCEPTION(0x300, DataStorage, UnknownException)
114
115/* Instruction Storage exception. */
116 STD_EXCEPTION(0x400, InstStorage, UnknownException)
117
118/* External Interrupt exception. */
119 STD_EXCEPTION(0x500, ExtInterrupt, UnknownException)
120
121/* Alignment exception. */
122 . = 0x600
123Alignment:
124 EXCEPTION_PROLOG(SRR0, SRR1)
125 mfspr r4,DAR
126 stw r4,_DAR(r21)
127 mfspr r5,DSISR
128 stw r5,_DSISR(r21)
129 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlundfc4e1882010-01-19 14:41:55 +0100130 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200131
132/* Program check exception */
133 . = 0x700
134ProgramCheck:
135 EXCEPTION_PROLOG(SRR0, SRR1)
136 addi r3,r1,STACK_FRAME_OVERHEAD
Joakim Tjernlundfc4e1882010-01-19 14:41:55 +0100137 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
138 MSR_KERNEL, COPY_EE)
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200139
140/* Floating Point Unit unavailable exception */
141 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
142
143/* Decrementer */
144 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
145
146/* Critical interrupt */
147 STD_EXCEPTION(0xa00, Critical, UnknownException)
148
149/* System Call */
150 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
151
152/* Trace interrupt */
153 STD_EXCEPTION(0xd00, Trace, UnknownException)
154
155/* Performance Monitor interrupt */
156 STD_EXCEPTION(0xf00, PerfMon, UnknownException)
157
158/* Intruction Translation Miss */
159 STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
160
161/* Data Load Translation Miss */
162 STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
163
164/* Data Store Translation Miss */
165 STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
166
167/* Instruction Address Breakpoint */
168 STD_EXCEPTION(0x1300, InstructionAddrBreakpoint, DebugException)
169
170/* System Management interrupt */
171 STD_EXCEPTION(0x1400, SystemMgmtInterrupt, UnknownException)
172
173 .globl _end_of_vectors
174_end_of_vectors:
175
176 . = 0x3000
177boot_cold:
178 /* Save msr contents */
179 mfmsr r5
180
181 /* Set IMMR area to our preferred location */
182 lis r4, CONFIG_DEFAULT_IMMR@h
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200183 lis r3, CONFIG_SYS_IMMR@h
184 ori r3, r3, CONFIG_SYS_IMMR@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200185 stw r3, IMMRBAR(r4)
186 mtspr MBAR, r3 /* IMMRBAR is mirrored into the MBAR SPR (311) */
187
188 /* Initialise the machine */
189 bl cpu_early_init
190
191 /*
192 * Set up Local Access Windows:
193 *
194 * 1) Boot/CS0 (boot FLASH)
195 * 2) On-chip SRAM (initial stack purposes)
196 */
197
198 /* Boot CS/CS0 window range */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200199 lis r3, CONFIG_SYS_IMMR@h
200 ori r3, r3, CONFIG_SYS_IMMR@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200201
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200202 lis r4, START_REG(CONFIG_SYS_FLASH_BASE)
203 ori r4, r4, STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE)
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200204 stw r4, LPCS0AW(r3)
205
206 /*
207 * The SRAM window has a fixed size (256K), so only the start address
208 * is necessary
209 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200210 lis r4, START_REG(CONFIG_SYS_SRAM_BASE) & 0xff00
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200211 stw r4, SRAMBAR(r3)
212
Wolfgang Denkb1b54e32007-08-02 21:27:46 +0200213 /*
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200214 * According to MPC5121e RM, configuring local access windows should
Wolfgang Denkb1b54e32007-08-02 21:27:46 +0200215 * be followed by a dummy read of the config register that was
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200216 * modified last and an isync
Wolfgang Denkb1b54e32007-08-02 21:27:46 +0200217 */
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200218 lwz r4, SRAMBAR(r3)
219 isync
220
221 /*
222 * Set configuration of the Boot/CS0, the SRAM window does not have a
223 * config register so no params can be set for it
224 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200225 lis r3, (CONFIG_SYS_IMMR + LPC_OFFSET)@h
226 ori r3, r3, (CONFIG_SYS_IMMR + LPC_OFFSET)@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200227
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200228 lis r4, CONFIG_SYS_CS0_CFG@h
229 ori r4, r4, CONFIG_SYS_CS0_CFG@l
Wolfgang Denkb1b54e32007-08-02 21:27:46 +0200230 stw r4, CS0_CONFIG(r3)
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200231
232 /* Master enable all CS's */
233 lis r4, CS_CTRL_ME@h
234 ori r4, r4, CS_CTRL_ME@l
235 stw r4, CS_CTRL(r3)
236
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200237 lis r4, (CONFIG_SYS_MONITOR_BASE)@h
238 ori r4, r4, (CONFIG_SYS_MONITOR_BASE)@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200239 addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET
240 mtlr r5
241 blr
242
243in_flash:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200244 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
245 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200246
247 li r0, 0 /* Make room for stack frame header and */
248 stwu r0, -4(r1) /* clear final stack frame so that */
249 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
250
251 /* let the C-code set up the rest */
252 /* */
253 /* Be careful to keep code relocatable & stack humble */
254 /*------------------------------------------------------*/
255
256 GET_GOT /* initialize GOT access */
257
258 /* r3: IMMR */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200259 lis r3, CONFIG_SYS_IMMR@h
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200260 /* run low-level CPU init code (in Flash) */
261 bl cpu_init_f
262
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200263 /* run 1st part of board init code (in Flash) */
264 bl board_init_f
265
266 /* NOTREACHED - board_init_f() does not return */
267
268/*
269 * This code finishes saving the registers to the exception frame
270 * and jumps to the appropriate handler for the exception.
271 * Register r21 is pointer into trap frame, r1 has new stack pointer.
272 */
273 .globl transfer_to_handler
274transfer_to_handler:
275 stw r22,_NIP(r21)
276 lis r22,MSR_POW@h
277 andc r23,r23,r22
278 stw r23,_MSR(r21)
279 SAVE_GPR(7, r21)
280 SAVE_4GPRS(8, r21)
281 SAVE_8GPRS(12, r21)
282 SAVE_8GPRS(24, r21)
283 mflr r23
284 andi. r24,r23,0x3f00 /* get vector offset */
285 stw r24,TRAP(r21)
286 li r22,0
287 stw r22,RESULT(r21)
288 lwz r24,0(r23) /* virtual address of handler */
289 lwz r23,4(r23) /* where to go when done */
290 mtspr SRR0,r24
291 mtspr SRR1,r20
292 mtlr r23
293 SYNC
294 rfi /* jump to handler, enable MMU */
295
296int_return:
297 mfmsr r28 /* Disable interrupts */
298 li r4,0
299 ori r4,r4,MSR_EE
300 andc r28,r28,r4
301 SYNC /* Some chip revs need this... */
302 mtmsr r28
303 SYNC
304 lwz r2,_CTR(r1)
305 lwz r0,_LINK(r1)
306 mtctr r2
307 mtlr r0
308 lwz r2,_XER(r1)
309 lwz r0,_CCR(r1)
310 mtspr XER,r2
311 mtcrf 0xFF,r0
312 REST_10GPRS(3, r1)
313 REST_10GPRS(13, r1)
314 REST_8GPRS(23, r1)
315 REST_GPR(31, r1)
316 lwz r2,_NIP(r1) /* Restore environment */
317 lwz r0,_MSR(r1)
318 mtspr SRR0,r2
319 mtspr SRR1,r0
320 lwz r0,GPR0(r1)
321 lwz r2,GPR2(r1)
322 lwz r1,GPR1(r1)
323 SYNC
324 rfi
325
326/*
327 * This code initialises the machine, it expects original MSR contents to be in r5.
328 */
329cpu_early_init:
330 /* Initialize machine status; enable machine check interrupt */
331 /*-----------------------------------------------------------*/
332
333 li r3, MSR_KERNEL /* Set ME and RI flags */
334 rlwimi r3, r5, 0, 25, 25 /* preserve IP bit */
335#ifdef DEBUG
336 rlwimi r3, r5, 0, 21, 22 /* debugger might set SE, BE bits */
337#endif
338 mtmsr r3
339 SYNC
340 mtspr SRR1, r3 /* Mirror current MSR state in SRR1 */
341
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200342 lis r3, CONFIG_SYS_IMMR@h
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200343
344#if defined(CONFIG_WATCHDOG)
345 /* Initialise the watchdog and reset it */
346 /*--------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200347 lis r4, CONFIG_SYS_WATCHDOG_VALUE
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200348 ori r4, r4, (SWCRR_SWEN | SWCRR_SWRI | SWCRR_SWPR)
349 stw r4, SWCRR(r3)
350
351 /* reset */
352 li r4, 0x556C
353 sth r4, SWSRR@l(r3)
354 li r4, 0x0
355 ori r4, r4, 0xAA39
356 sth r4, SWSRR@l(r3)
357#else
358 /* Disable the watchdog */
359 /*----------------------*/
360 lwz r4, SWCRR(r3)
361 /*
362 * Check to see if it's enabled for disabling: once disabled by s/w
363 * it's not possible to re-enable it
364 */
365 andi. r4, r4, 0x4
366 beq 1f
367 xor r4, r4, r4
368 stw r4, SWCRR(r3)
3691:
370#endif /* CONFIG_WATCHDOG */
371
372 /* Initialize the Hardware Implementation-dependent Registers */
373 /* HID0 also contains cache control */
374 /*------------------------------------------------------*/
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200375 lis r3, CONFIG_SYS_HID0_INIT@h
376 ori r3, r3, CONFIG_SYS_HID0_INIT@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200377 SYNC
378 mtspr HID0, r3
379
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200380 lis r3, CONFIG_SYS_HID0_FINAL@h
381 ori r3, r3, CONFIG_SYS_HID0_FINAL@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_HID2@h
386 ori r3, r3, CONFIG_SYS_HID2@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200387 SYNC
388 mtspr HID2, r3
389 sync
390 blr
391
392
393/* Cache functions.
394 *
395 * Note: requires that all cache bits in
396 * HID0 are in the low half word.
397 */
398 .globl icache_enable
399icache_enable:
400 mfspr r3, HID0
401 ori r3, r3, HID0_ICE
402 lis r4, 0
403 ori r4, r4, HID0_ILOCK
404 andc r3, r3, r4
405 ori r4, r3, HID0_ICFI
406 isync
407 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
408 isync
409 mtspr HID0, r3 /* clears invalidate */
410 blr
411
412 .globl icache_disable
413icache_disable:
414 mfspr r3, HID0
415 lis r4, 0
416 ori r4, r4, HID0_ICE|HID0_ILOCK
417 andc r3, r3, r4
418 ori r4, r3, HID0_ICFI
419 isync
420 mtspr HID0, r4 /* sets invalidate, clears enable and lock*/
421 isync
422 mtspr HID0, r3 /* clears invalidate */
423 blr
424
425 .globl icache_status
426icache_status:
427 mfspr r3, HID0
428 rlwinm r3, r3, (31 - HID0_ICE_SHIFT + 1), 31, 31
429 blr
430
431 .globl dcache_enable
432dcache_enable:
433 mfspr r3, HID0
434 li r5, HID0_DCFI|HID0_DLOCK
435 andc r3, r3, r5
436 mtspr HID0, r3 /* no invalidate, unlock */
437 ori r3, r3, HID0_DCE
438 ori r5, r3, HID0_DCFI
439 mtspr HID0, r5 /* enable + invalidate */
440 mtspr HID0, r3 /* enable */
441 sync
442 blr
443
444 .globl dcache_disable
445dcache_disable:
446 mfspr r3, HID0
447 lis r4, 0
448 ori r4, r4, HID0_DCE|HID0_DLOCK
449 andc r3, r3, r4
450 ori r4, r3, HID0_DCI
451 sync
452 mtspr HID0, r4 /* sets invalidate, clears enable and lock */
453 sync
454 mtspr HID0, r3 /* clears invalidate */
455 blr
456
457 .globl dcache_status
458dcache_status:
459 mfspr r3, HID0
460 rlwinm r3, r3, (31 - HID0_DCE_SHIFT + 1), 31, 31
461 blr
462
463 .globl get_pvr
464get_pvr:
465 mfspr r3, PVR
466 blr
467
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200468/*-------------------------------------------------------------------*/
469
470/*
471 * void relocate_code (addr_sp, gd, addr_moni)
472 *
473 * This "function" does not return, instead it continues in RAM
474 * after relocating the monitor code.
475 *
476 * r3 = dest
477 * r4 = src
478 * r5 = length in bytes
479 * r6 = cachelinesize
480 */
481 .globl relocate_code
482relocate_code:
483 mr r1, r3 /* Set new stack pointer */
484 mr r9, r4 /* Save copy of Global Data pointer */
485 mr r10, r5 /* Save copy of Destination Address */
486
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100487 GET_GOT
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200488 mr r3, r5 /* Destination Address */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200489 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
490 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200491 lwz r5, GOT(__init_end)
492 sub r5, r5, r4
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200493 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200494
495 /*
496 * Fix GOT pointer:
497 *
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200498 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE)
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200499 * + Destination Address
500 *
501 * Offset:
502 */
503 sub r15, r10, r4
504
505 /* First our own GOT */
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100506 add r12, r12, r15
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200507 /* then the one used by the C code */
508 add r30, r30, r15
509
510 /*
511 * Now relocate code
512 */
513 cmplw cr1,r3,r4
514 addi r0,r5,3
515 srwi. r0,r0,2
516 beq cr1,4f /* In place copy is not necessary */
517 beq 7f /* Protect against 0 count */
518 mtctr r0
519 bge cr1,2f
520 la r8,-4(r4)
521 la r7,-4(r3)
522
523 /* copy */
5241: lwzu r0,4(r8)
525 stwu r0,4(r7)
526 bdnz 1b
527
528 addi r0,r5,3
529 srwi. r0,r0,2
530 mtctr r0
531 la r8,-4(r4)
532 la r7,-4(r3)
533
534 /* and compare */
53520: lwzu r20,4(r8)
536 lwzu r21,4(r7)
537 xor. r22, r20, r21
538 bne 30f
539 bdnz 20b
540 b 4f
541
542 /* compare failed */
54330: li r3, 0
544 blr
545
5462: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */
547 add r8,r4,r0
548 add r7,r3,r0
5493: lwzu r0,-4(r8)
550 stwu r0,-4(r7)
551 bdnz 3b
552
553/*
554 * Now flush the cache: note that we must start from a cache aligned
555 * address. Otherwise we might miss one cache line.
556 */
5574: cmpwi r6,0
558 add r5,r3,r5
559 beq 7f /* Always flush prefetch queue in any case */
560 subi r0,r6,1
561 andc r3,r3,r0
562 mr r4,r3
5635: dcbst 0,r4
564 add r4,r4,r6
565 cmplw r4,r5
566 blt 5b
567 sync /* Wait for all dcbst to complete on bus */
568 mr r4,r3
5696: icbi 0,r4
570 add r4,r4,r6
571 cmplw r4,r5
572 blt 6b
5737: sync /* Wait for all icbi to complete on bus */
574 isync
575
576/*
577 * We are done. Do not return, instead branch to second part of board
578 * initialization, now running from RAM.
579 */
580 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
581 mtlr r0
582 blr
583
584in_ram:
585 /*
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100586 * Relocation Function, r12 point to got2+0x8000
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200587 *
588 * Adjust got2 pointers, no need to check for 0, this code
589 * already puts a few entries in the table.
590 */
591 li r0,__got2_entries@sectoff@l
592 la r3,GOT(_GOT2_TABLE_)
593 lwz r11,GOT(_GOT2_TABLE_)
594 mtctr r0
595 sub r11,r3,r11
596 addi r3,r3,-4
5971: lwzu r0,4(r3)
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +0200598 cmpwi r0,0
599 beq- 2f
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200600 add r0,r0,r11
601 stw r0,0(r3)
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +02006022: bdnz 1b
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200603
604 /*
605 * Now adjust the fixups and the pointers to the fixups
606 * in case we need to move ourselves again.
607 */
Joakim Tjernlundafc3ba02009-10-08 02:03:51 +0200608 li r0,__fixup_entries@sectoff@l
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200609 lwz r3,GOT(_FIXUP_TABLE_)
610 cmpwi r0,0
611 mtctr r0
612 addi r3,r3,-4
613 beq 4f
6143: lwzu r4,4(r3)
615 lwzux r0,r4,r11
Joakim Tjernlundd1e0b102010-10-14 11:51:44 +0200616 cmpwi r0,0
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200617 add r0,r0,r11
618 stw r10,0(r3)
Joakim Tjernlundd1e0b102010-10-14 11:51:44 +0200619 beq- 5f
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200620 stw r0,0(r4)
Joakim Tjernlundd1e0b102010-10-14 11:51:44 +02006215: bdnz 3b
Rafal Jaworowski8993e542007-07-27 14:43:59 +02006224:
623clear_bss:
624 /*
625 * Now clear BSS segment
626 */
627 lwz r3,GOT(__bss_start)
628 lwz r4,GOT(_end)
629
630 cmplw 0, r3, r4
631 beq 6f
632
633 li r0, 0
6345:
635 stw r0, 0(r3)
636 addi r3, r3, 4
637 cmplw 0, r3, r4
638 bne 5b
6396:
640 mr r3, r9 /* Global Data pointer */
641 mr r4, r10 /* Destination Address */
642 bl board_init_r
643
644 /*
645 * Copy exception vector code to low memory
646 *
647 * r3: dest_addr
648 * r7: source address, r8: end address, r9: target address
649 */
650 .globl trap_init
651trap_init:
Joakim Tjernlund0f8aa152010-01-19 14:41:56 +0100652 mflr r4 /* save link register */
653 GET_GOT
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200654 lwz r7, GOT(_start)
655 lwz r8, GOT(_end_of_vectors)
656
657 li r9, 0x100 /* reset vector at 0x100 */
658
659 cmplw 0, r7, r8
660 bgelr /* return if r7>=r8 - just in case */
Rafal Jaworowski8993e542007-07-27 14:43:59 +02006611:
662 lwz r0, 0(r7)
663 stw r0, 0(r9)
664 addi r7, r7, 4
665 addi r9, r9, 4
666 cmplw 0, r7, r8
667 bne 1b
668
669 /*
670 * relocate `hdlr' and `int_return' entries
671 */
672 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
673 li r8, Alignment - _start + EXC_OFF_SYS_RESET
6742:
675 bl trap_reloc
676 addi r7, r7, 0x100 /* next exception vector */
677 cmplw 0, r7, r8
678 blt 2b
679
680 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
681 bl trap_reloc
682
683 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
684 bl trap_reloc
685
686 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
687 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
6883:
689 bl trap_reloc
690 addi r7, r7, 0x100 /* next exception vector */
691 cmplw 0, r7, r8
692 blt 3b
693
694 li r7, .L_Trace - _start + EXC_OFF_SYS_RESET
695 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
6964:
697 bl trap_reloc
698 addi r7, r7, 0x100 /* next exception vector */
699 cmplw 0, r7, r8
700 blt 4b
701
702 mfmsr r3 /* now that the vectors have */
703 lis r7, MSR_IP@h /* relocated into low memory */
704 ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
705 andc r3, r3, r7 /* (if it was on) */
706 SYNC /* Some chip revs need this... */
707 mtmsr r3
708 SYNC
709
710 mtlr r4 /* restore link register */
711 blr