]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/powerpc/cpu/mpc824x/start.S
Merge branch 'master' of git://git.denx.de/u-boot-x86
[karo-tx-uboot.git] / arch / powerpc / cpu / mpc824x / 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,2001,2002 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 /* U-Boot - Startup Code for PowerPC based Embedded Boards
26  *
27  *
28  * The processor starts at 0x00000100 and the code is executed
29  * from flash. The code is organized to be at an other address
30  * in memory, but as long we don't jump around before relocating.
31  * board_init lies at a quite high address and when the cpu has
32  * jumped there, everything is ok.
33  * This works because the cpu gives the FLASH (CS0) the whole
34  * address space at startup, and board_init lies as a echo of
35  * the flash somewhere up there in the memorymap.
36  *
37  * board_init will change CS0 to be positioned at the correct
38  * address and (s)dram will be positioned at address 0
39  */
40 #include <asm-offsets.h>
41 #include <config.h>
42 #include <mpc824x.h>
43 #include <timestamp.h>
44 #include <version.h>
45
46 #define _LINUX_CONFIG_H 1       /* avoid reading Linux autoconf.h file  */
47
48 #include <ppc_asm.tmpl>
49 #include <ppc_defs.h>
50
51 #include <asm/cache.h>
52 #include <asm/mmu.h>
53 #include <asm/u-boot.h>
54
55 #ifndef CONFIG_IDENT_STRING
56 #define CONFIG_IDENT_STRING ""
57 #endif
58
59 /* We don't want the MMU yet.
60 */
61 #undef  MSR_KERNEL
62 /* FP, Machine Check and Recoverable Interr. */
63 #define MSR_KERNEL ( MSR_FP | MSR_ME | MSR_RI )
64
65 /*
66  * Set up GOT: Global Offset Table
67  *
68  * Use r12 to access the GOT
69  */
70         START_GOT
71         GOT_ENTRY(_GOT2_TABLE_)
72         GOT_ENTRY(_FIXUP_TABLE_)
73
74         GOT_ENTRY(_start)
75         GOT_ENTRY(_start_of_vectors)
76         GOT_ENTRY(_end_of_vectors)
77         GOT_ENTRY(transfer_to_handler)
78
79         GOT_ENTRY(__init_end)
80         GOT_ENTRY(__bss_end__)
81         GOT_ENTRY(__bss_start)
82 #if defined(CONFIG_FADS)
83         GOT_ENTRY(environment)
84 #endif
85         END_GOT
86
87 /*
88  * r3 - 1st arg to board_init(): IMMP pointer
89  * r4 - 2nd arg to board_init(): boot flag
90  */
91         .text
92         .long   0x27051956              /* U-Boot Magic Number                  */
93         .globl  version_string
94 version_string:
95         .ascii U_BOOT_VERSION
96         .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
97         .ascii CONFIG_IDENT_STRING, "\0"
98
99         . = EXC_OFF_SYS_RESET
100         .globl  _start
101 _start:
102         /* Initialize machine status; enable machine check interrupt            */
103         /*----------------------------------------------------------------------*/
104         li      r3, MSR_KERNEL          /* Set FP, ME, RI flags */
105         mtmsr   r3
106         mtspr   SRR1, r3                /* Make SRR1 match MSR */
107
108         addis   r0,0,0x0000             /* lets make sure that r0 is really 0 */
109         mtspr   HID0, r0                /* disable I and D caches */
110
111         mfspr   r3, ICR                 /* clear Interrupt Cause Register */
112
113         mfmsr   r3                      /* turn off address translation */
114         addis   r4,0,0xffff
115         ori     r4,r4,0xffcf
116         and     r3,r3,r4
117         mtmsr   r3
118         isync
119         sync                            /* the MMU should be off... */
120
121
122 in_flash:
123 #if defined(CONFIG_BMW)
124         bl early_init_f /* Must be ASM: no stack yet! */
125 #endif
126         /*
127          * Setup BATs - cannot be done in C since we don't have a stack yet
128          */
129         bl      setup_bats
130
131         /* Enable MMU.
132          */
133         mfmsr   r3
134         ori     r3, r3, (MSR_IR | MSR_DR)
135         mtmsr   r3
136 #if !defined(CONFIG_BMW)
137         /* Enable and invalidate data cache.
138          */
139         mfspr   r3, HID0
140         mr      r2, r3
141         ori     r3, r3, HID0_DCE | HID0_DCI
142         ori     r2, r2, HID0_DCE
143         sync
144         mtspr   HID0, r3
145         mtspr   HID0, r2
146         sync
147
148         /* Allocate Initial RAM in data cache.
149          */
150         lis     r3, CONFIG_SYS_INIT_RAM_ADDR@h
151         ori     r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
152         li      r2, 128
153         mtctr   r2
154 1:
155         dcbz    r0, r3
156         addi    r3, r3, 32
157         bdnz    1b
158
159         /* Lock way0 in data cache.
160          */
161         mfspr   r3, 1011
162         lis     r2, 0xffff
163         ori     r2, r2, 0xff1f
164         and     r3, r3, r2
165         ori     r3, r3, 0x0080
166         sync
167         mtspr   1011, r3
168 #endif /* !CONFIG_BMW */
169         /*
170          * Thisk the stack pointer *somewhere* sensible. Doesnt
171          * matter much where as we'll move it when we relocate
172          */
173         lis     r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
174         ori     r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
175
176         li      r0, 0                   /* Make room for stack frame header and */
177         stwu    r0, -4(r1)              /* clear final stack frame so that      */
178         stwu    r0, -4(r1)              /* stack backtraces terminate cleanly   */
179
180         /* let the C-code set up the rest                                       */
181         /*                                                                      */
182         /* Be careful to keep code relocatable !                                */
183         /*----------------------------------------------------------------------*/
184
185         GET_GOT                 /* initialize GOT access                        */
186 #if defined(__pic__) && __pic__ == 1
187         /* Needed for upcoming -msingle-pic-base */
188         bl      _GLOBAL_OFFSET_TABLE_@local-4
189         mflr    r30
190 #endif
191         /* r3: IMMR */
192         bl      cpu_init_f      /* run low-level CPU init code     (from Flash) */
193
194         bl      board_init_f    /* run 1st part of board init code (from Flash) */
195
196         /* NOTREACHED - board_init_f() does not return */
197
198
199         .globl  _start_of_vectors
200 _start_of_vectors:
201
202 /* Machine check */
203         STD_EXCEPTION(EXC_OFF_MACH_CHCK, MachineCheck, MachineCheckException)
204
205 /* Data Storage exception.  "Never" generated on the 860. */
206         STD_EXCEPTION(EXC_OFF_DATA_STOR, DataStorage, UnknownException)
207
208 /* Instruction Storage exception.  "Never" generated on the 860. */
209         STD_EXCEPTION(EXC_OFF_INS_STOR, InstStorage, UnknownException)
210
211 /* External Interrupt exception. */
212         STD_EXCEPTION(EXC_OFF_EXTERNAL, ExtInterrupt, external_interrupt)
213
214 /* Alignment exception. */
215         . = EXC_OFF_ALIGN
216 Alignment:
217         EXCEPTION_PROLOG(SRR0, SRR1)
218         mfspr   r4,DAR
219         stw     r4,_DAR(r21)
220         mfspr   r5,DSISR
221         stw     r5,_DSISR(r21)
222         addi    r3,r1,STACK_FRAME_OVERHEAD
223         EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
224
225 /* Program check exception */
226         . = EXC_OFF_PROGRAM
227 ProgramCheck:
228         EXCEPTION_PROLOG(SRR0, SRR1)
229         addi    r3,r1,STACK_FRAME_OVERHEAD
230         EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
231                 MSR_KERNEL, COPY_EE)
232
233         /* No FPU on MPC8xx. This exception is not supposed to happen.
234         */
235         STD_EXCEPTION(EXC_OFF_FPUNAVAIL, FPUnavailable, UnknownException)
236
237         /* I guess we could implement decrementer, and may have
238          * to someday for timekeeping.
239          */
240         STD_EXCEPTION(EXC_OFF_DECR, Decrementer, timer_interrupt)
241         STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
242         STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
243         STD_EXCEPTION(0xc00, SystemCall, UnknownException)
244
245         STD_EXCEPTION(EXC_OFF_TRACE, SingleStep, UnknownException)
246
247         STD_EXCEPTION(EXC_OFF_FPUNASSIST, Trap_0e, UnknownException)
248         STD_EXCEPTION(EXC_OFF_PMI, Trap_0f, UnknownException)
249
250         STD_EXCEPTION(EXC_OFF_ITME, InstructionTransMiss, UnknownException)
251         STD_EXCEPTION(EXC_OFF_DLTME, DataLoadTransMiss, UnknownException)
252         STD_EXCEPTION(EXC_OFF_DSTME, DataStoreTransMiss, UnknownException)
253         STD_EXCEPTION(EXC_OFF_IABE, InstructionBreakpoint, DebugException)
254         STD_EXCEPTION(EXC_OFF_SMIE, SysManageInt, UnknownException)
255         STD_EXCEPTION(0x1500, Reserved5, UnknownException)
256         STD_EXCEPTION(0x1600, Reserved6, UnknownException)
257         STD_EXCEPTION(0x1700, Reserved7, UnknownException)
258         STD_EXCEPTION(0x1800, Reserved8, UnknownException)
259         STD_EXCEPTION(0x1900, Reserved9, UnknownException)
260         STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
261         STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
262         STD_EXCEPTION(0x1c00, ReservedC, UnknownException)
263         STD_EXCEPTION(0x1d00, ReservedD, UnknownException)
264         STD_EXCEPTION(0x1e00, ReservedE, UnknownException)
265         STD_EXCEPTION(0x1f00, ReservedF, UnknownException)
266
267         STD_EXCEPTION(EXC_OFF_RMTE, RunModeTrace, UnknownException)
268
269         .globl  _end_of_vectors
270 _end_of_vectors:
271
272
273         . = 0x3000
274
275 /*
276  * This code finishes saving the registers to the exception frame
277  * and jumps to the appropriate handler for the exception.
278  * Register r21 is pointer into trap frame, r1 has new stack pointer.
279  */
280         .globl  transfer_to_handler
281 transfer_to_handler:
282         stw     r22,_NIP(r21)
283         lis     r22,MSR_POW@h
284         andc    r23,r23,r22
285         stw     r23,_MSR(r21)
286         SAVE_GPR(7, r21)
287         SAVE_4GPRS(8, r21)
288         SAVE_8GPRS(12, r21)
289         SAVE_8GPRS(24, r21)
290 #if 0
291         andi.   r23,r23,MSR_PR
292         mfspr   r23,SPRG3               /* if from user, fix up tss.regs */
293         beq     2f
294         addi    r24,r1,STACK_FRAME_OVERHEAD
295         stw     r24,PT_REGS(r23)
296 2:      addi    r2,r23,-TSS             /* set r2 to current */
297         tovirt(r2,r2,r23)
298 #endif
299         mflr    r23
300         andi.   r24,r23,0x3f00          /* get vector offset */
301         stw     r24,TRAP(r21)
302         li      r22,0
303         stw     r22,RESULT(r21)
304         mtspr   SPRG2,r22               /* r1 is now kernel sp */
305 #if 0
306         addi    r24,r2,TASK_STRUCT_SIZE /* check for kernel stack overflow */
307         cmplw   0,r1,r2
308         cmplw   1,r1,r24
309         crand   1,1,4
310         bgt     stack_ovf               /* if r2 < r1 < r2+TASK_STRUCT_SIZE */
311 #endif
312         lwz     r24,0(r23)              /* virtual address of handler */
313         lwz     r23,4(r23)              /* where to go when done */
314         mtspr   SRR0,r24
315         ori     r20,r20,0x30            /* enable IR, DR */
316         mtspr   SRR1,r20
317         mtlr    r23
318         SYNC
319         rfi                             /* jump to handler, enable MMU */
320
321 int_return:
322         mfmsr   r28             /* Disable interrupts */
323         li      r4,0
324         ori     r4,r4,MSR_EE
325         andc    r28,r28,r4
326         SYNC                    /* Some chip revs need this... */
327         mtmsr   r28
328         SYNC
329         lwz     r2,_CTR(r1)
330         lwz     r0,_LINK(r1)
331         mtctr   r2
332         mtlr    r0
333         lwz     r2,_XER(r1)
334         lwz     r0,_CCR(r1)
335         mtspr   XER,r2
336         mtcrf   0xFF,r0
337         REST_10GPRS(3, r1)
338         REST_10GPRS(13, r1)
339         REST_8GPRS(23, r1)
340         REST_GPR(31, r1)
341         lwz     r2,_NIP(r1)     /* Restore environment */
342         lwz     r0,_MSR(r1)
343         mtspr   SRR0,r2
344         mtspr   SRR1,r0
345         lwz     r0,GPR0(r1)
346         lwz     r2,GPR2(r1)
347         lwz     r1,GPR1(r1)
348         SYNC
349         rfi
350
351 /* Cache functions.
352 */
353         .globl  icache_enable
354 icache_enable:
355         mfspr   r5,HID0         /* turn on the I cache. */
356         ori     r5,r5,0x8800    /* Instruction cache only! */
357         addis   r6,0,0xFFFF
358         ori     r6,r6,0xF7FF
359         and     r6,r5,r6        /* clear the invalidate bit */
360         sync
361         mtspr   HID0,r5
362         mtspr   HID0,r6
363         isync
364         sync
365         blr
366
367         .globl  icache_disable
368 icache_disable:
369         mfspr   r5,HID0
370         addis   r6,0,0xFFFF
371         ori     r6,r6,0x7FFF
372         and     r5,r5,r6
373         sync
374         mtspr   HID0,r5
375         isync
376         sync
377         blr
378
379         .globl  icache_status
380 icache_status:
381         mfspr   r3, HID0
382         srwi    r3, r3, 15      /* >>15 & 1=> select bit 16 */
383         andi.   r3, r3, 1
384         blr
385
386         .globl  dcache_enable
387 dcache_enable:
388         mfspr   r5,HID0         /* turn on the D cache. */
389         ori     r5,r5,0x4400    /* Data cache only! */
390         mfspr   r4, PVR         /* read PVR */
391         srawi   r3, r4, 16      /* shift off the least 16 bits */
392         cmpi    0, 0, r3, 0xC   /* Check for Max pvr */
393         bne     NotMax
394         ori     r5,r5,0x0040    /* setting the DCFA bit, for Max rev 1 errata */
395 NotMax:
396         addis   r6,0,0xFFFF
397         ori     r6,r6,0xFBFF
398         and     r6,r5,r6        /* clear the invalidate bit */
399         sync
400         mtspr   HID0,r5
401         mtspr   HID0,r6
402         isync
403         sync
404         blr
405
406         .globl  dcache_disable
407 dcache_disable:
408         mfspr   r5,HID0
409         addis   r6,0,0xFFFF
410         ori     r6,r6,0xBFFF
411         and     r5,r5,r6
412         sync
413         mtspr   HID0,r5
414         isync
415         sync
416         blr
417
418         .globl  dcache_status
419 dcache_status:
420         mfspr   r3, HID0
421         srwi    r3, r3, 14      /* >>14 & 1=> select bit 17 */
422         andi.   r3, r3, 1
423         blr
424
425         .globl  dc_read
426 dc_read:
427 /*TODO : who uses this, what should it do?
428 */
429         blr
430
431
432         .globl get_pvr
433 get_pvr:
434         mfspr   r3, PVR
435         blr
436
437
438 /*------------------------------------------------------------------------------*/
439
440 /*
441  * void relocate_code (addr_sp, gd, addr_moni)
442  *
443  * This "function" does not return, instead it continues in RAM
444  * after relocating the monitor code.
445  *
446  * r3 = dest
447  * r4 = src
448  * r5 = length in bytes
449  * r6 = cachelinesize
450  */
451         .globl  relocate_code
452 relocate_code:
453
454         mr      r1,  r3         /* Set new stack pointer                */
455         mr      r9,  r4         /* Save copy of Global Data pointer     */
456         mr      r10, r5         /* Save copy of Destination Address     */
457
458         GET_GOT
459 #if defined(__pic__) && __pic__ == 1
460         /* Needed for upcoming -msingle-pic-base */
461         bl      _GLOBAL_OFFSET_TABLE_@local-4
462         mflr    r30
463 #endif
464         mr      r3,  r5                         /* Destination Address  */
465 #ifdef CONFIG_SYS_RAMBOOT
466         lis     r4, CONFIG_SYS_SDRAM_BASE@h             /* Source      Address  */
467         ori     r4, r4, CONFIG_SYS_SDRAM_BASE@l
468 #else
469         lis     r4, CONFIG_SYS_MONITOR_BASE@h           /* Source      Address  */
470         ori     r4, r4, CONFIG_SYS_MONITOR_BASE@l
471 #endif
472         lwz     r5, GOT(__init_end)
473         sub     r5, r5, r4
474         li      r6, CONFIG_SYS_CACHELINE_SIZE           /* Cache Line Size      */
475
476         /*
477          * Fix GOT pointer:
478          *
479          * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
480          *
481          * Offset:
482          */
483         sub     r15, r10, r4
484
485         /* First our own GOT */
486         add     r12, r12, r15
487         /* the the one used by the C code */
488         add     r30, r30, r15
489
490         /*
491          * Now relocate code
492          */
493
494         cmplw   cr1,r3,r4
495         addi    r0,r5,3
496         srwi.   r0,r0,2
497         beq     cr1,4f          /* In place copy is not necessary       */
498         beq     7f              /* Protect against 0 count              */
499         mtctr   r0
500         bge     cr1,2f
501
502         la      r8,-4(r4)
503         la      r7,-4(r3)
504 1:      lwzu    r0,4(r8)
505         stwu    r0,4(r7)
506         bdnz    1b
507         b       4f
508
509 2:      slwi    r0,r0,2
510         add     r8,r4,r0
511         add     r7,r3,r0
512 3:      lwzu    r0,-4(r8)
513         stwu    r0,-4(r7)
514         bdnz    3b
515
516 4:
517 #if !defined(CONFIG_BMW)
518 /* Unlock the data cache and invalidate locked area */
519         xor     r0, r0, r0
520         mtspr   1011, r0
521         lis     r4, CONFIG_SYS_INIT_RAM_ADDR@h
522         ori     r4, r4, CONFIG_SYS_INIT_RAM_ADDR@l
523         li      r0, 128
524         mtctr   r0
525 41:
526         dcbi    r0, r4
527         addi    r4, r4, 32
528         bdnz    41b
529 #endif
530
531 /*
532  * Now flush the cache: note that we must start from a cache aligned
533  * address. Otherwise we might miss one cache line.
534  */
535         cmpwi   r6,0
536         add     r5,r3,r5
537         beq     7f              /* Always flush prefetch queue in any case */
538         subi    r0,r6,1
539         andc    r3,r3,r0
540         mr      r4,r3
541 5:      dcbst   0,r4
542         add     r4,r4,r6
543         cmplw   r4,r5
544         blt     5b
545         sync                    /* Wait for all dcbst to complete on bus */
546         mr      r4,r3
547 6:      icbi    0,r4
548         add     r4,r4,r6
549         cmplw   r4,r5
550         blt     6b
551 7:      sync                    /* Wait for all icbi to complete on bus */
552         isync
553
554 /*
555  * We are done. Do not return, instead branch to second part of board
556  * initialization, now running from RAM.
557  */
558
559         addi    r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
560         mtlr    r0
561         blr
562
563 in_ram:
564
565         /*
566          * Relocation Function, r12 point to got2+0x8000
567          *
568          * Adjust got2 pointers, no need to check for 0, this code
569          * already puts a few entries in the table.
570          */
571         li      r0,__got2_entries@sectoff@l
572         la      r3,GOT(_GOT2_TABLE_)
573         lwz     r11,GOT(_GOT2_TABLE_)
574         mtctr   r0
575         sub     r11,r3,r11
576         addi    r3,r3,-4
577 1:      lwzu    r0,4(r3)
578         cmpwi   r0,0
579         beq-    2f
580         add     r0,r0,r11
581         stw     r0,0(r3)
582 2:      bdnz    1b
583
584         /*
585          * Now adjust the fixups and the pointers to the fixups
586          * in case we need to move ourselves again.
587          */
588         li      r0,__fixup_entries@sectoff@l
589         lwz     r3,GOT(_FIXUP_TABLE_)
590         cmpwi   r0,0
591         mtctr   r0
592         addi    r3,r3,-4
593         beq     4f
594 3:      lwzu    r4,4(r3)
595         lwzux   r0,r4,r11
596         cmpwi   r0,0
597         add     r0,r0,r11
598         stw     r4,0(r3)
599         beq-    5f
600         stw     r0,0(r4)
601 5:      bdnz    3b
602 4:
603 clear_bss:
604         /*
605          * Now clear BSS segment
606          */
607         lwz     r3,GOT(__bss_start)
608         lwz     r4,GOT(__bss_end__)
609
610         cmplw   0, r3, r4
611         beq     6f
612
613         li      r0, 0
614 5:
615         stw     r0, 0(r3)
616         addi    r3, r3, 4
617         cmplw   0, r3, r4
618         blt     5b
619 6:
620
621         mr      r3, r9          /* Global Data pointer          */
622         mr      r4, r10         /* Destination Address          */
623         bl      board_init_r
624
625         /*
626          * Copy exception vector code to low memory
627          *
628          * r3: dest_addr
629          * r7: source address, r8: end address, r9: target address
630          */
631         .globl  trap_init
632 trap_init:
633         mflr    r4                      /* save link register           */
634         GET_GOT
635         lwz     r7, GOT(_start)
636         lwz     r8, GOT(_end_of_vectors)
637
638         li      r9, 0x100               /* reset vector always at 0x100 */
639
640         cmplw   0, r7, r8
641         bgelr                           /* return if r7>=r8 - just in case */
642 1:
643         lwz     r0, 0(r7)
644         stw     r0, 0(r9)
645         addi    r7, r7, 4
646         addi    r9, r9, 4
647         cmplw   0, r7, r8
648         bne     1b
649
650         /*
651          * relocate `hdlr' and `int_return' entries
652          */
653         li      r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
654         li      r8, Alignment - _start + EXC_OFF_SYS_RESET
655 2:
656         bl      trap_reloc
657         addi    r7, r7, 0x100           /* next exception vector        */
658         cmplw   0, r7, r8
659         blt     2b
660
661         li      r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
662         bl      trap_reloc
663
664         li      r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
665         bl      trap_reloc
666
667         li      r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
668         li      r8, SystemCall - _start + EXC_OFF_SYS_RESET
669 3:
670         bl      trap_reloc
671         addi    r7, r7, 0x100           /* next exception vector        */
672         cmplw   0, r7, r8
673         blt     3b
674
675         li      r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
676         li      r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
677 4:
678         bl      trap_reloc
679         addi    r7, r7, 0x100           /* next exception vector        */
680         cmplw   0, r7, r8
681         blt     4b
682
683         mtlr    r4                      /* restore link register        */
684         blr
685
686         /* Setup the BAT registers.
687          */
688 setup_bats:
689         lis     r4, CONFIG_SYS_IBAT0L@h
690         ori     r4, r4, CONFIG_SYS_IBAT0L@l
691         lis     r3, CONFIG_SYS_IBAT0U@h
692         ori     r3, r3, CONFIG_SYS_IBAT0U@l
693         mtspr   IBAT0L, r4
694         mtspr   IBAT0U, r3
695         isync
696
697         lis     r4, CONFIG_SYS_DBAT0L@h
698         ori     r4, r4, CONFIG_SYS_DBAT0L@l
699         lis     r3, CONFIG_SYS_DBAT0U@h
700         ori     r3, r3, CONFIG_SYS_DBAT0U@l
701         mtspr   DBAT0L, r4
702         mtspr   DBAT0U, r3
703         isync
704
705         lis     r4, CONFIG_SYS_IBAT1L@h
706         ori     r4, r4, CONFIG_SYS_IBAT1L@l
707         lis     r3, CONFIG_SYS_IBAT1U@h
708         ori     r3, r3, CONFIG_SYS_IBAT1U@l
709         mtspr   IBAT1L, r4
710         mtspr   IBAT1U, r3
711         isync
712
713         lis     r4, CONFIG_SYS_DBAT1L@h
714         ori     r4, r4, CONFIG_SYS_DBAT1L@l
715         lis     r3, CONFIG_SYS_DBAT1U@h
716         ori     r3, r3, CONFIG_SYS_DBAT1U@l
717         mtspr   DBAT1L, r4
718         mtspr   DBAT1U, r3
719         isync
720
721         lis     r4, CONFIG_SYS_IBAT2L@h
722         ori     r4, r4, CONFIG_SYS_IBAT2L@l
723         lis     r3, CONFIG_SYS_IBAT2U@h
724         ori     r3, r3, CONFIG_SYS_IBAT2U@l
725         mtspr   IBAT2L, r4
726         mtspr   IBAT2U, r3
727         isync
728
729         lis     r4, CONFIG_SYS_DBAT2L@h
730         ori     r4, r4, CONFIG_SYS_DBAT2L@l
731         lis     r3, CONFIG_SYS_DBAT2U@h
732         ori     r3, r3, CONFIG_SYS_DBAT2U@l
733         mtspr   DBAT2L, r4
734         mtspr   DBAT2U, r3
735         isync
736
737         lis     r4, CONFIG_SYS_IBAT3L@h
738         ori     r4, r4, CONFIG_SYS_IBAT3L@l
739         lis     r3, CONFIG_SYS_IBAT3U@h
740         ori     r3, r3, CONFIG_SYS_IBAT3U@l
741         mtspr   IBAT3L, r4
742         mtspr   IBAT3U, r3
743         isync
744
745         lis     r4, CONFIG_SYS_DBAT3L@h
746         ori     r4, r4, CONFIG_SYS_DBAT3L@l
747         lis     r3, CONFIG_SYS_DBAT3U@h
748         ori     r3, r3, CONFIG_SYS_DBAT3U@l
749         mtspr   DBAT3L, r4
750         mtspr   DBAT3U, r3
751         isync
752
753         /* Invalidate TLBs.
754          * -> for (val = 0; val < 0x20000; val+=0x1000)
755          * ->   tlbie(val);
756          */
757         lis     r3, 0
758         lis     r5, 2
759
760 1:
761         tlbie   r3
762         addi    r3, r3, 0x1000
763         cmp     0, 0, r3, r5
764         blt     1b
765
766         blr