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