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