]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/mpc5xxx/start.S
SAMSUNG: serial: modify name from s5pc1xx to s5p
[karo-tx-uboot.git] / cpu / mpc5xxx / start.S
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 - 2003 Wolfgang Denk <wd@denx.de>
5  *
6  * See file CREDITS for list of people who contributed to this
7  * project.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22  * MA 02111-1307 USA
23  */
24
25 /*
26  *  U-Boot - Startup Code for MPC5xxx CPUs
27  */
28 #include <config.h>
29 #include <mpc5xxx.h>
30 #include <timestamp.h>
31 #include <version.h>
32
33 #define CONFIG_MPC5xxx 1        /* needed for Linux kernel header files */
34 #define _LINUX_CONFIG_H 1       /* avoid reading Linux autoconf.h file  */
35
36 #include <ppc_asm.tmpl>
37 #include <ppc_defs.h>
38
39 #include <asm/cache.h>
40 #include <asm/mmu.h>
41
42 #ifndef  CONFIG_IDENT_STRING
43 #define  CONFIG_IDENT_STRING ""
44 #endif
45
46 /* We don't want the  MMU yet.
47 */
48 #undef  MSR_KERNEL
49 /* Floating Point enable, Machine Check and Recoverable Interr. */
50 #ifdef DEBUG
51 #define MSR_KERNEL (MSR_FP|MSR_RI)
52 #else
53 #define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
54 #endif
55
56 /*
57  * Set up GOT: Global Offset Table
58  *
59  * Use r12 to access the GOT
60  */
61         START_GOT
62         GOT_ENTRY(_GOT2_TABLE_)
63         GOT_ENTRY(_FIXUP_TABLE_)
64
65         GOT_ENTRY(_start)
66         GOT_ENTRY(_start_of_vectors)
67         GOT_ENTRY(_end_of_vectors)
68         GOT_ENTRY(transfer_to_handler)
69
70         GOT_ENTRY(__init_end)
71         GOT_ENTRY(_end)
72         GOT_ENTRY(__bss_start)
73         END_GOT
74
75 /*
76  * Version string
77  */
78         .data
79         .globl  version_string
80 version_string:
81         .ascii U_BOOT_VERSION
82         .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
83         .ascii CONFIG_IDENT_STRING, "\0"
84
85 /*
86  * Exception vectors
87  */
88         .text
89         . = EXC_OFF_SYS_RESET
90         .globl  _start
91 _start:
92         li      r21, BOOTFLAG_COLD      /* Normal Power-On              */
93         nop
94         b       boot_cold
95
96         . = EXC_OFF_SYS_RESET + 0x10
97
98         .globl  _start_warm
99 _start_warm:
100         li      r21, BOOTFLAG_WARM      /* Software reboot              */
101         b       boot_warm
102
103 boot_cold:
104 boot_warm:
105         mfmsr   r5                      /* save msr contents            */
106
107         /* Move CSBoot and adjust instruction pointer                   */
108         /*--------------------------------------------------------------*/
109
110 #if defined(CONFIG_SYS_LOWBOOT)
111 # if defined(CONFIG_SYS_RAMBOOT)
112 #  error CONFIG_SYS_LOWBOOT is incompatible with CONFIG_SYS_RAMBOOT
113 # endif /* CONFIG_SYS_RAMBOOT */
114 # if defined(CONFIG_MGT5100)
115 #  error CONFIG_SYS_LOWBOOT is incompatible with MGT5100
116 # endif /* CONFIG_MGT5100 */
117         lis     r4, CONFIG_SYS_DEFAULT_MBAR@h
118         lis     r3,     START_REG(CONFIG_SYS_BOOTCS_START)@h
119         ori     r3, r3, START_REG(CONFIG_SYS_BOOTCS_START)@l
120         stw     r3, 0x4(r4)             /* CS0 start */
121         lis     r3,     STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@h
122         ori     r3, r3, STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@l
123         stw     r3, 0x8(r4)             /* CS0 stop */
124         lis     r3,     0x02010000@h
125         ori     r3, r3, 0x02010000@l
126         stw     r3, 0x54(r4)            /* CS0 and Boot enable */
127
128         lis     r3,     lowboot_reentry@h       /* jump from bootlow address space (0x0000xxxx) */
129         ori     r3, r3, lowboot_reentry@l       /* to the address space the linker used */
130         mtlr    r3
131         blr
132
133 lowboot_reentry:
134         lis     r3,     START_REG(CONFIG_SYS_BOOTCS_START)@h
135         ori     r3, r3, START_REG(CONFIG_SYS_BOOTCS_START)@l
136         stw     r3, 0x4c(r4)            /* Boot start */
137         lis     r3,     STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@h
138         ori     r3, r3, STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@l
139         stw     r3, 0x50(r4)            /* Boot stop */
140         lis     r3,     0x02000001@h
141         ori     r3, r3, 0x02000001@l
142         stw     r3, 0x54(r4)            /* Boot enable, CS0 disable */
143 #endif  /* CONFIG_SYS_LOWBOOT */
144
145 #if defined(CONFIG_SYS_DEFAULT_MBAR) && !defined(CONFIG_SYS_RAMBOOT)
146         lis     r3, CONFIG_SYS_MBAR@h
147         ori     r3, r3, CONFIG_SYS_MBAR@l
148 #if defined(CONFIG_MPC5200)
149         /* MBAR is mirrored into the MBAR SPR */
150         mtspr   MBAR,r3
151         rlwinm  r3, r3, 16, 16, 31
152 #endif
153 #if defined(CONFIG_MGT5100)
154         rlwinm  r3, r3, 17, 15, 31
155 #endif
156         lis     r4, CONFIG_SYS_DEFAULT_MBAR@h
157         stw     r3, 0(r4)
158 #endif /* CONFIG_SYS_DEFAULT_MBAR */
159
160         /* Initialise the MPC5xxx processor core                        */
161         /*--------------------------------------------------------------*/
162
163         bl      init_5xxx_core
164
165         /* initialize some things that are hard to access from C        */
166         /*--------------------------------------------------------------*/
167
168         /* set up stack in on-chip SRAM */
169         lis     r3, CONFIG_SYS_INIT_RAM_ADDR@h
170         ori     r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
171         ori     r1, r3, CONFIG_SYS_INIT_SP_OFFSET
172         li      r0, 0                   /* Make room for stack frame header and */
173         stwu    r0, -4(r1)              /* clear final stack frame so that      */
174         stwu    r0, -4(r1)              /* stack backtraces terminate cleanly   */
175
176         /* let the C-code set up the rest                               */
177         /*                                                              */
178         /* Be careful to keep code relocatable !                        */
179         /*--------------------------------------------------------------*/
180
181         GET_GOT                 /* initialize GOT access                */
182
183         /* r3: IMMR */
184         bl      cpu_init_f      /* run low-level CPU init code (in Flash)*/
185
186         mr      r3, r21
187         /* r3: BOOTFLAG */
188         bl      board_init_f    /* run 1st part of board init code (in Flash)*/
189
190 /*
191  * Vector Table
192  */
193
194         .globl  _start_of_vectors
195 _start_of_vectors:
196
197 /* Machine check */
198         STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
199
200 /* Data Storage exception. */
201         STD_EXCEPTION(0x300, DataStorage, UnknownException)
202
203 /* Instruction Storage exception. */
204         STD_EXCEPTION(0x400, InstStorage, UnknownException)
205
206 /* External Interrupt exception. */
207         STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
208
209 /* Alignment exception. */
210         . = 0x600
211 Alignment:
212         EXCEPTION_PROLOG(SRR0, SRR1)
213         mfspr   r4,DAR
214         stw     r4,_DAR(r21)
215         mfspr   r5,DSISR
216         stw     r5,_DSISR(r21)
217         addi    r3,r1,STACK_FRAME_OVERHEAD
218         EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
219
220 /* Program check exception */
221         . = 0x700
222 ProgramCheck:
223         EXCEPTION_PROLOG(SRR0, SRR1)
224         addi    r3,r1,STACK_FRAME_OVERHEAD
225         EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
226                 MSR_KERNEL, COPY_EE)
227
228         STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
229
230         /* I guess we could implement decrementer, and may have
231          * to someday for timekeeping.
232          */
233         STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
234
235         STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
236         STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
237         STD_EXCEPTION(0xc00, SystemCall, UnknownException)
238         STD_EXCEPTION(0xd00, SingleStep, UnknownException)
239
240         STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
241         STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
242
243         STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
244         STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
245         STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
246 #ifdef DEBUG
247         . = 0x1300
248         /*
249          * This exception occurs when the program counter matches the
250          * Instruction Address Breakpoint Register (IABR).
251          *
252          * I want the cpu to halt if this occurs so I can hunt around
253          * with the debugger and look at things.
254          *
255          * When DEBUG is defined, both machine check enable (in the MSR)
256          * and checkstop reset enable (in the reset mode register) are
257          * turned off and so a checkstop condition will result in the cpu
258          * halting.
259          *
260          * I force the cpu into a checkstop condition by putting an illegal
261          * instruction here (at least this is the theory).
262          *
263          * well - that didnt work, so just do an infinite loop!
264          */
265 1:      b       1b
266 #else
267         STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
268 #endif
269         STD_EXCEPTION(0x1400, SMI, UnknownException)
270
271         STD_EXCEPTION(0x1500, Trap_15, UnknownException)
272         STD_EXCEPTION(0x1600, Trap_16, UnknownException)
273         STD_EXCEPTION(0x1700, Trap_17, UnknownException)
274         STD_EXCEPTION(0x1800, Trap_18, UnknownException)
275         STD_EXCEPTION(0x1900, Trap_19, UnknownException)
276         STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
277         STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
278         STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
279         STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
280         STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
281         STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
282         STD_EXCEPTION(0x2000, Trap_20, UnknownException)
283         STD_EXCEPTION(0x2100, Trap_21, UnknownException)
284         STD_EXCEPTION(0x2200, Trap_22, UnknownException)
285         STD_EXCEPTION(0x2300, Trap_23, UnknownException)
286         STD_EXCEPTION(0x2400, Trap_24, UnknownException)
287         STD_EXCEPTION(0x2500, Trap_25, UnknownException)
288         STD_EXCEPTION(0x2600, Trap_26, UnknownException)
289         STD_EXCEPTION(0x2700, Trap_27, UnknownException)
290         STD_EXCEPTION(0x2800, Trap_28, UnknownException)
291         STD_EXCEPTION(0x2900, Trap_29, UnknownException)
292         STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
293         STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
294         STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
295         STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
296         STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
297         STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
298
299
300         .globl  _end_of_vectors
301 _end_of_vectors:
302
303         . = 0x3000
304
305 /*
306  * This code finishes saving the registers to the exception frame
307  * and jumps to the appropriate handler for the exception.
308  * Register r21 is pointer into trap frame, r1 has new stack pointer.
309  */
310         .globl  transfer_to_handler
311 transfer_to_handler:
312         stw     r22,_NIP(r21)
313         lis     r22,MSR_POW@h
314         andc    r23,r23,r22
315         stw     r23,_MSR(r21)
316         SAVE_GPR(7, r21)
317         SAVE_4GPRS(8, r21)
318         SAVE_8GPRS(12, r21)
319         SAVE_8GPRS(24, r21)
320         mflr    r23
321         andi.   r24,r23,0x3f00          /* get vector offset */
322         stw     r24,TRAP(r21)
323         li      r22,0
324         stw     r22,RESULT(r21)
325         lwz     r24,0(r23)              /* virtual address of handler */
326         lwz     r23,4(r23)              /* where to go when done */
327         mtspr   SRR0,r24
328         mtspr   SRR1,r20
329         mtlr    r23
330         SYNC
331         rfi                             /* jump to handler, enable MMU */
332
333 int_return:
334         mfmsr   r28             /* Disable interrupts */
335         li      r4,0
336         ori     r4,r4,MSR_EE
337         andc    r28,r28,r4
338         SYNC                    /* Some chip revs need this... */
339         mtmsr   r28
340         SYNC
341         lwz     r2,_CTR(r1)
342         lwz     r0,_LINK(r1)
343         mtctr   r2
344         mtlr    r0
345         lwz     r2,_XER(r1)
346         lwz     r0,_CCR(r1)
347         mtspr   XER,r2
348         mtcrf   0xFF,r0
349         REST_10GPRS(3, r1)
350         REST_10GPRS(13, r1)
351         REST_8GPRS(23, r1)
352         REST_GPR(31, r1)
353         lwz     r2,_NIP(r1)     /* Restore environment */
354         lwz     r0,_MSR(r1)
355         mtspr   SRR0,r2
356         mtspr   SRR1,r0
357         lwz     r0,GPR0(r1)
358         lwz     r2,GPR2(r1)
359         lwz     r1,GPR1(r1)
360         SYNC
361         rfi
362
363 /*
364  * This code initialises the MPC5xxx processor core
365  * (conforms to PowerPC 603e spec)
366  * Note: expects original MSR contents to be in r5.
367  */
368
369         .globl  init_5xx_core
370 init_5xxx_core:
371
372         /* Initialize machine status; enable machine check interrupt    */
373         /*--------------------------------------------------------------*/
374
375         li      r3, MSR_KERNEL          /* Set ME and RI flags */
376         rlwimi  r3, r5, 0, 25, 25       /* preserve IP bit set by HRCW */
377 #ifdef DEBUG
378         rlwimi  r3, r5, 0, 21, 22       /* debugger might set SE & BE bits */
379 #endif
380         SYNC                            /* Some chip revs need this... */
381         mtmsr   r3
382         SYNC
383         mtspr   SRR1, r3                /* Make SRR1 match MSR */
384
385         /* Initialize the Hardware Implementation-dependent Registers   */
386         /* HID0 also contains cache control                             */
387         /*--------------------------------------------------------------*/
388
389         lis     r3, CONFIG_SYS_HID0_INIT@h
390         ori     r3, r3, CONFIG_SYS_HID0_INIT@l
391         SYNC
392         mtspr   HID0, r3
393
394         lis     r3, CONFIG_SYS_HID0_FINAL@h
395         ori     r3, r3, CONFIG_SYS_HID0_FINAL@l
396         SYNC
397         mtspr   HID0, r3
398
399         /* clear all BAT's                                              */
400         /*--------------------------------------------------------------*/
401
402         li      r0, 0
403         mtspr   DBAT0U, r0
404         mtspr   DBAT0L, r0
405         mtspr   DBAT1U, r0
406         mtspr   DBAT1L, r0
407         mtspr   DBAT2U, r0
408         mtspr   DBAT2L, r0
409         mtspr   DBAT3U, r0
410         mtspr   DBAT3L, r0
411         mtspr   DBAT4U, r0
412         mtspr   DBAT4L, r0
413         mtspr   DBAT5U, r0
414         mtspr   DBAT5L, r0
415         mtspr   DBAT6U, r0
416         mtspr   DBAT6L, r0
417         mtspr   DBAT7U, r0
418         mtspr   DBAT7L, r0
419         mtspr   IBAT0U, r0
420         mtspr   IBAT0L, r0
421         mtspr   IBAT1U, r0
422         mtspr   IBAT1L, r0
423         mtspr   IBAT2U, r0
424         mtspr   IBAT2L, r0
425         mtspr   IBAT3U, r0
426         mtspr   IBAT3L, r0
427         mtspr   IBAT4U, r0
428         mtspr   IBAT4L, r0
429         mtspr   IBAT5U, r0
430         mtspr   IBAT5L, r0
431         mtspr   IBAT6U, r0
432         mtspr   IBAT6L, r0
433         mtspr   IBAT7U, r0
434         mtspr   IBAT7L, r0
435         SYNC
436
437         /* invalidate all tlb's                                         */
438         /*                                                              */
439         /* From the 603e User Manual: "The 603e provides the ability to */
440         /* invalidate a TLB entry. The TLB Invalidate Entry (tlbie)     */
441         /* instruction invalidates the TLB entry indexed by the EA, and */
442         /* operates on both the instruction and data TLBs simultaneously*/
443         /* invalidating four TLB entries (both sets in each TLB). The   */
444         /* index corresponds to bits 15-19 of the EA. To invalidate all */
445         /* entries within both TLBs, 32 tlbie instructions should be    */
446         /* issued, incrementing this field by one each time."           */
447         /*                                                              */
448         /* "Note that the tlbia instruction is not implemented on the   */
449         /* 603e."                                                       */
450         /*                                                              */
451         /* bits 15-19 correspond to addresses 0x00000000 to 0x0001F000  */
452         /* incrementing by 0x1000 each time. The code below is sort of  */
453         /* based on code in "flush_tlbs" from arch/ppc/kernel/head.S    */
454         /*                                                              */
455         /*--------------------------------------------------------------*/
456
457         li      r3, 32
458         mtctr   r3
459         li      r3, 0
460 1:      tlbie   r3
461         addi    r3, r3, 0x1000
462         bdnz    1b
463         SYNC
464
465         /* Done!                                                        */
466         /*--------------------------------------------------------------*/
467
468         blr
469
470 /* Cache functions.
471  *
472  * Note: requires that all cache bits in
473  * HID0 are in the low half word.
474  */
475         .globl  icache_enable
476 icache_enable:
477         mfspr   r3, HID0
478         ori     r3, r3, HID0_ICE
479         lis     r4, 0
480         ori     r4, r4, HID0_ILOCK
481         andc    r3, r3, r4
482         ori     r4, r3, HID0_ICFI
483         isync
484         mtspr   HID0, r4        /* sets enable and invalidate, clears lock */
485         isync
486         mtspr   HID0, r3        /* clears invalidate */
487         blr
488
489         .globl  icache_disable
490 icache_disable:
491         mfspr   r3, HID0
492         lis     r4, 0
493         ori     r4, r4, HID0_ICE|HID0_ILOCK
494         andc    r3, r3, r4
495         ori     r4, r3, HID0_ICFI
496         isync
497         mtspr   HID0, r4        /* sets invalidate, clears enable and lock */
498         isync
499         mtspr   HID0, r3        /* clears invalidate */
500         blr
501
502         .globl  icache_status
503 icache_status:
504         mfspr   r3, HID0
505         rlwinm  r3, r3, HID0_ICE_BITPOS + 1, 31, 31
506         blr
507
508         .globl  dcache_enable
509 dcache_enable:
510         mfspr   r3, HID0
511         ori     r3, r3, HID0_DCE
512         lis     r4, 0
513         ori     r4, r4, HID0_DLOCK
514         andc    r3, r3, r4
515         ori     r4, r3, HID0_DCI
516         sync
517         mtspr   HID0, r4        /* sets enable and invalidate, clears lock */
518         sync
519         mtspr   HID0, r3        /* clears invalidate */
520         blr
521
522         .globl  dcache_disable
523 dcache_disable:
524         mfspr   r3, HID0
525         lis     r4, 0
526         ori     r4, r4, HID0_DCE|HID0_DLOCK
527         andc    r3, r3, r4
528         ori     r4, r3, HID0_DCI
529         sync
530         mtspr   HID0, r4        /* sets invalidate, clears enable and lock */
531         sync
532         mtspr   HID0, r3        /* clears invalidate */
533         blr
534
535         .globl  dcache_status
536 dcache_status:
537         mfspr   r3, HID0
538         rlwinm  r3, r3, HID0_DCE_BITPOS + 1, 31, 31
539         blr
540
541         .globl get_svr
542 get_svr:
543         mfspr   r3, SVR
544         blr
545
546         .globl get_pvr
547 get_pvr:
548         mfspr   r3, PVR
549         blr
550
551 /*------------------------------------------------------------------------------*/
552
553 /*
554  * void relocate_code (addr_sp, gd, addr_moni)
555  *
556  * This "function" does not return, instead it continues in RAM
557  * after relocating the monitor code.
558  *
559  * r3 = dest
560  * r4 = src
561  * r5 = length in bytes
562  * r6 = cachelinesize
563  */
564         .globl  relocate_code
565 relocate_code:
566         mr      r1,  r3         /* Set new stack pointer                */
567         mr      r9,  r4         /* Save copy of Global Data pointer     */
568         mr      r10, r5         /* Save copy of Destination Address     */
569
570         GET_GOT
571         mr      r3,  r5                         /* Destination Address  */
572         lis     r4, CONFIG_SYS_MONITOR_BASE@h           /* Source      Address  */
573         ori     r4, r4, CONFIG_SYS_MONITOR_BASE@l
574         lwz     r5, GOT(__init_end)
575         sub     r5, r5, r4
576         li      r6, CONFIG_SYS_CACHELINE_SIZE           /* Cache Line Size      */
577
578         /*
579          * Fix GOT pointer:
580          *
581          * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
582          *
583          * Offset:
584          */
585         sub     r15, r10, r4
586
587         /* First our own GOT */
588         add     r12, r12, r15
589         /* then the one used by the C code */
590         add     r30, r30, r15
591
592         /*
593          * Now relocate code
594          */
595
596         cmplw   cr1,r3,r4
597         addi    r0,r5,3
598         srwi.   r0,r0,2
599         beq     cr1,4f          /* In place copy is not necessary       */
600         beq     7f              /* Protect against 0 count              */
601         mtctr   r0
602         bge     cr1,2f
603
604         la      r8,-4(r4)
605         la      r7,-4(r3)
606 1:      lwzu    r0,4(r8)
607         stwu    r0,4(r7)
608         bdnz    1b
609         b       4f
610
611 2:      slwi    r0,r0,2
612         add     r8,r4,r0
613         add     r7,r3,r0
614 3:      lwzu    r0,-4(r8)
615         stwu    r0,-4(r7)
616         bdnz    3b
617
618 /*
619  * Now flush the cache: note that we must start from a cache aligned
620  * address. Otherwise we might miss one cache line.
621  */
622 4:      cmpwi   r6,0
623         add     r5,r3,r5
624         beq     7f              /* Always flush prefetch queue in any case */
625         subi    r0,r6,1
626         andc    r3,r3,r0
627         mfspr   r7,HID0         /* don't do dcbst if dcache is disabled */
628         rlwinm  r7,r7,HID0_DCE_BITPOS+1,31,31
629         cmpwi   r7,0
630         beq     9f
631         mr      r4,r3
632 5:      dcbst   0,r4
633         add     r4,r4,r6
634         cmplw   r4,r5
635         blt     5b
636         sync                    /* Wait for all dcbst to complete on bus */
637 9:      mfspr   r7,HID0         /* don't do icbi if icache is disabled */
638         rlwinm  r7,r7,HID0_ICE_BITPOS+1,31,31
639         cmpwi   r7,0
640         beq     7f
641         mr      r4,r3
642 6:      icbi    0,r4
643         add     r4,r4,r6
644         cmplw   r4,r5
645         blt     6b
646 7:      sync                    /* Wait for all icbi to complete on bus */
647         isync
648
649 /*
650  * We are done. Do not return, instead branch to second part of board
651  * initialization, now running from RAM.
652  */
653
654         addi    r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
655         mtlr    r0
656         blr
657
658 in_ram:
659
660         /*
661          * Relocation Function, r12 point to got2+0x8000
662          *
663          * Adjust got2 pointers, no need to check for 0, this code
664          * already puts a few entries in the table.
665          */
666         li      r0,__got2_entries@sectoff@l
667         la      r3,GOT(_GOT2_TABLE_)
668         lwz     r11,GOT(_GOT2_TABLE_)
669         mtctr   r0
670         sub     r11,r3,r11
671         addi    r3,r3,-4
672 1:      lwzu    r0,4(r3)
673         cmpwi   r0,0
674         beq-    2f
675         add     r0,r0,r11
676         stw     r0,0(r3)
677 2:      bdnz    1b
678
679         /*
680          * Now adjust the fixups and the pointers to the fixups
681          * in case we need to move ourselves again.
682          */
683         li      r0,__fixup_entries@sectoff@l
684         lwz     r3,GOT(_FIXUP_TABLE_)
685         cmpwi   r0,0
686         mtctr   r0
687         addi    r3,r3,-4
688         beq     4f
689 3:      lwzu    r4,4(r3)
690         lwzux   r0,r4,r11
691         add     r0,r0,r11
692         stw     r10,0(r3)
693         stw     r0,0(r4)
694         bdnz    3b
695 4:
696 clear_bss:
697         /*
698          * Now clear BSS segment
699          */
700         lwz     r3,GOT(__bss_start)
701         lwz     r4,GOT(_end)
702
703         cmplw   0, r3, r4
704         beq     6f
705
706         li      r0, 0
707 5:
708         stw     r0, 0(r3)
709         addi    r3, r3, 4
710         cmplw   0, r3, r4
711         bne     5b
712 6:
713
714         mr      r3, r9          /* Global Data pointer          */
715         mr      r4, r10         /* Destination Address          */
716         bl      board_init_r
717
718         /*
719          * Copy exception vector code to low memory
720          *
721          * r3: dest_addr
722          * r7: source address, r8: end address, r9: target address
723          */
724         .globl  trap_init
725 trap_init:
726         mflr    r4                      /* save link register           */
727         GET_GOT
728         lwz     r7, GOT(_start)
729         lwz     r8, GOT(_end_of_vectors)
730
731         li      r9, 0x100               /* reset vector always at 0x100 */
732
733         cmplw   0, r7, r8
734         bgelr                           /* return if r7>=r8 - just in case */
735 1:
736         lwz     r0, 0(r7)
737         stw     r0, 0(r9)
738         addi    r7, r7, 4
739         addi    r9, r9, 4
740         cmplw   0, r7, r8
741         bne     1b
742
743         /*
744          * relocate `hdlr' and `int_return' entries
745          */
746         li      r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
747         li      r8, Alignment - _start + EXC_OFF_SYS_RESET
748 2:
749         bl      trap_reloc
750         addi    r7, r7, 0x100           /* next exception vector        */
751         cmplw   0, r7, r8
752         blt     2b
753
754         li      r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
755         bl      trap_reloc
756
757         li      r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
758         bl      trap_reloc
759
760         li      r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
761         li      r8, SystemCall - _start + EXC_OFF_SYS_RESET
762 3:
763         bl      trap_reloc
764         addi    r7, r7, 0x100           /* next exception vector        */
765         cmplw   0, r7, r8
766         blt     3b
767
768         li      r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
769         li      r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
770 4:
771         bl      trap_reloc
772         addi    r7, r7, 0x100           /* next exception vector        */
773         cmplw   0, r7, r8
774         blt     4b
775
776         mfmsr   r3                      /* now that the vectors have    */
777         lis     r7, MSR_IP@h            /* relocated into low memory    */
778         ori     r7, r7, MSR_IP@l        /* MSR[IP] can be turned off    */
779         andc    r3, r3, r7              /* (if it was on)               */
780         SYNC                            /* Some chip revs need this... */
781         mtmsr   r3
782         SYNC
783
784         mtlr    r4                      /* restore link register    */
785         blr