]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/mpc85xx/start.S
e8e5eb297de7cf97aacac084b5bcf091b1015e01
[karo-tx-uboot.git] / cpu / mpc85xx / start.S
1 /*
2  * Copyright 2004, 2007 Freescale Semiconductor.
3  * Copyright (C) 2003  Motorola,Inc.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 /* U-Boot Startup Code for Motorola 85xx PowerPC based Embedded Boards
25  *
26  * The processor starts at 0xfffffffc and the code is first executed in the
27  * last 4K page(0xfffff000-0xffffffff) in flash/rom.
28  *
29  */
30
31 #include <config.h>
32 #include <mpc85xx.h>
33 #include <version.h>
34
35 #define _LINUX_CONFIG_H 1       /* avoid reading Linux autoconf.h file  */
36
37 #include <ppc_asm.tmpl>
38 #include <ppc_defs.h>
39
40 #include <asm/cache.h>
41 #include <asm/mmu.h>
42
43 #ifndef  CONFIG_IDENT_STRING
44 #define  CONFIG_IDENT_STRING ""
45 #endif
46
47 #undef  MSR_KERNEL
48 #define MSR_KERNEL ( MSR_ME )   /* Machine Check */
49
50 /*
51  * Set up GOT: Global Offset Table
52  *
53  * Use r14 to access the GOT
54  */
55         START_GOT
56         GOT_ENTRY(_GOT2_TABLE_)
57         GOT_ENTRY(_FIXUP_TABLE_)
58
59         GOT_ENTRY(_start)
60         GOT_ENTRY(_start_of_vectors)
61         GOT_ENTRY(_end_of_vectors)
62         GOT_ENTRY(transfer_to_handler)
63
64         GOT_ENTRY(__init_end)
65         GOT_ENTRY(_end)
66         GOT_ENTRY(__bss_start)
67         END_GOT
68
69 /*
70  * e500 Startup -- after reset only the last 4KB of the effective
71  * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg
72  * section is located at THIS LAST page and basically does three
73  * things: clear some registers, set up exception tables and
74  * add more TLB entries for 'larger spaces'(e.g. the boot rom) to
75  * continue the boot procedure.
76
77  * Once the boot rom is mapped by TLB entries we can proceed
78  * with normal startup.
79  *
80  */
81
82         .section .bootpg,"ax"
83         .globl _start_e500
84
85 _start_e500:
86
87 /* clear registers/arrays not reset by hardware */
88
89         /* L1 */
90         li      r0,2
91         mtspr   L1CSR0,r0       /* invalidate d-cache */
92         mtspr   L1CSR1,r0       /* invalidate i-cache */
93
94         mfspr   r1,DBSR
95         mtspr   DBSR,r1         /* Clear all valid bits */
96
97         /*
98          *      Enable L1 Caches early
99          *
100          */
101
102         lis     r2,L1CSR0_CPE@H /* enable parity */
103         ori     r2,r2,L1CSR0_DCE
104         mtspr   L1CSR0,r2       /* enable L1 Dcache */
105         isync
106         mtspr   L1CSR1,r2       /* enable L1 Icache */
107         isync
108         msync
109
110         /* Setup interrupt vectors */
111         lis     r1,TEXT_BASE@h
112         mtspr   IVPR,r1
113
114         li      r1,0x0100
115         mtspr   IVOR0,r1        /* 0: Critical input */
116         li      r1,0x0200
117         mtspr   IVOR1,r1        /* 1: Machine check */
118         li      r1,0x0300
119         mtspr   IVOR2,r1        /* 2: Data storage */
120         li      r1,0x0400
121         mtspr   IVOR3,r1        /* 3: Instruction storage */
122         li      r1,0x0500
123         mtspr   IVOR4,r1        /* 4: External interrupt */
124         li      r1,0x0600
125         mtspr   IVOR5,r1        /* 5: Alignment */
126         li      r1,0x0700
127         mtspr   IVOR6,r1        /* 6: Program check */
128         li      r1,0x0800
129         mtspr   IVOR7,r1        /* 7: floating point unavailable */
130         li      r1,0x0900
131         mtspr   IVOR8,r1        /* 8: System call */
132         /* 9: Auxiliary processor unavailable(unsupported) */
133         li      r1,0x0a00
134         mtspr   IVOR10,r1       /* 10: Decrementer */
135         li      r1,0x0b00
136         mtspr   IVOR11,r1       /* 11: Interval timer */
137         li      r1,0x0c00
138         mtspr   IVOR12,r1       /* 12: Watchdog timer */
139         li      r1,0x0d00
140         mtspr   IVOR13,r1       /* 13: Data TLB error */
141         li      r1,0x0e00
142         mtspr   IVOR14,r1       /* 14: Instruction TLB error */
143         li      r1,0x0f00
144         mtspr   IVOR15,r1       /* 15: Debug */
145
146         /* Clear and set up some registers. */
147         li      r0,0x0000
148         lis     r1,0xffff
149         mtspr   DEC,r0                  /* prevent dec exceptions */
150         mttbl   r0                      /* prevent fit & wdt exceptions */
151         mttbu   r0
152         mtspr   TSR,r1                  /* clear all timer exception status */
153         mtspr   TCR,r0                  /* disable all */
154         mtspr   ESR,r0                  /* clear exception syndrome register */
155         mtspr   MCSR,r0                 /* machine check syndrome register */
156         mtxer   r0                      /* clear integer exception register */
157
158         /* Enable Time Base and Select Time Base Clock */
159         lis     r0,HID0_EMCP@h          /* Enable machine check */
160 #if defined(CONFIG_ENABLE_36BIT_PHYS)
161         ori     r0,r0,HID0_ENMAS7@l     /* Enable MAS7 */
162 #endif
163         ori     r0,r0,HID0_TBEN@l       /* Enable Timebase */
164         mtspr   HID0,r0
165
166         li      r0,(HID1_ASTME|HID1_ABE)@l      /* Addr streaming & broadcast */
167         mtspr   HID1,r0
168
169         /* Enable Branch Prediction */
170 #if defined(CONFIG_BTB)
171         li      r0,0x201                /* BBFI = 1, BPEN = 1 */
172         mtspr   BUCSR,r0
173 #endif
174
175 #if defined(CFG_INIT_DBCR)
176         lis     r1,0xffff
177         ori     r1,r1,0xffff
178         mtspr   DBSR,r1                 /* Clear all status bits */
179         lis     r0,CFG_INIT_DBCR@h      /* DBCR0[IDM] must be set */
180         ori     r0,r0,CFG_INIT_DBCR@l
181         mtspr   DBCR0,r0
182 #endif
183
184         /* create a temp mapping in AS=1 to the boot window */
185         lis     r6,FSL_BOOKE_MAS0(1, 15, 0)@h
186         ori     r6,r6,FSL_BOOKE_MAS0(1, 15, 0)@l
187
188         lis     r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16M)@h
189         ori     r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16M)@l
190
191         lis     r8,FSL_BOOKE_MAS2(TEXT_BASE, (MAS2_I|MAS2_G))@h
192         ori     r8,r8,FSL_BOOKE_MAS2(TEXT_BASE, (MAS2_I|MAS2_G))@l
193
194         lis     r9,FSL_BOOKE_MAS3(0xff800000, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h
195         ori     r9,r9,FSL_BOOKE_MAS3(0xff800000, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l
196
197         mtspr   MAS0,r6
198         mtspr   MAS1,r7
199         mtspr   MAS2,r8
200         mtspr   MAS3,r9
201         isync
202         msync
203         tlbwe
204
205         /* create a temp mapping in AS=1 to the stack */
206         lis     r6,FSL_BOOKE_MAS0(1, 14, 0)@h
207         ori     r6,r6,FSL_BOOKE_MAS0(1, 14, 0)@l
208
209         lis     r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16K)@h
210         ori     r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16K)@l
211
212         lis     r8,FSL_BOOKE_MAS2(CFG_INIT_RAM_ADDR, 0)@h
213         ori     r8,r8,FSL_BOOKE_MAS2(CFG_INIT_RAM_ADDR, 0)@l
214
215         lis     r9,FSL_BOOKE_MAS3(CFG_INIT_RAM_ADDR, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h
216         ori     r9,r9,FSL_BOOKE_MAS3(CFG_INIT_RAM_ADDR, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l
217
218         mtspr   MAS0,r6
219         mtspr   MAS1,r7
220         mtspr   MAS2,r8
221         mtspr   MAS3,r9
222         isync
223         msync
224         tlbwe
225
226         lis     r6,MSR_CE|MSR_ME|MSR_DE|MSR_IS|MSR_DS@h
227         ori     r6,r6,MSR_CE|MSR_ME|MSR_DE|MSR_IS|MSR_DS@l
228         lis     r7,switch_as@h
229         ori     r7,r7,switch_as@l
230
231         mtspr   SPRN_SRR0,r7
232         mtspr   SPRN_SRR1,r6
233         rfi
234
235 switch_as:
236 /* L1 DCache is used for initial RAM */
237
238         /* Allocate Initial RAM in data cache.
239          */
240         lis     r3,CFG_INIT_RAM_ADDR@h
241         ori     r3,r3,CFG_INIT_RAM_ADDR@l
242         mfspr   r2, L1CFG0
243         andi.   r2, r2, 0x1ff
244         /* cache size * 1024 / (2 * L1 line size) */
245         slwi    r2, r2, (10 - 1 - L1_CACHE_SHIFT)
246         mtctr   r2
247         li      r0,0
248 1:
249         dcbz    r0,r3
250         dcbtls  0,r0,r3
251         addi    r3,r3,CFG_CACHELINE_SIZE
252         bdnz    1b
253
254         /* Jump out the last 4K page and continue to 'normal' start */
255 #ifdef CFG_RAMBOOT
256         b       _start_cont
257 #else
258         /* Calculate absolute address in FLASH and jump there           */
259         /*--------------------------------------------------------------*/
260         lis     r3,CFG_MONITOR_BASE@h
261         ori     r3,r3,CFG_MONITOR_BASE@l
262         addi    r3,r3,_start_cont - _start + _START_OFFSET
263         mtlr    r3
264         blr
265 #endif
266
267         .text
268         .globl  _start
269 _start:
270         .long   0x27051956              /* U-BOOT Magic Number */
271         .globl  version_string
272 version_string:
273         .ascii U_BOOT_VERSION
274         .ascii " (", __DATE__, " - ", __TIME__, ")"
275         .ascii CONFIG_IDENT_STRING, "\0"
276
277         .align  4
278         .globl  _start_cont
279 _start_cont:
280         /* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
281         lis     r1,CFG_INIT_RAM_ADDR@h
282         ori     r1,r1,CFG_INIT_SP_OFFSET@l
283
284         li      r0,0
285         stwu    r0,-4(r1)
286         stwu    r0,-4(r1)               /* Terminate call chain */
287
288         stwu    r1,-8(r1)               /* Save back chain and move SP */
289         lis     r0,RESET_VECTOR@h       /* Address of reset vector */
290         ori     r0,r0,RESET_VECTOR@l
291         stwu    r1,-8(r1)               /* Save back chain and move SP */
292         stw     r0,+12(r1)              /* Save return addr (underflow vect) */
293
294         GET_GOT
295         bl      cpu_init_early_f
296
297         /* switch back to AS = 0 */
298         lis     r3,(MSR_CE|MSR_ME|MSR_DE)@h
299         ori     r3,r3,(MSR_CE|MSR_ME|MSR_DE)@l
300         mtmsr   r3
301         isync
302
303         bl      cpu_init_f
304         bl      board_init_f
305         isync
306
307         . = EXC_OFF_SYS_RESET
308         .globl  _start_of_vectors
309 _start_of_vectors:
310
311 /* Critical input. */
312         CRIT_EXCEPTION(0x0100, CriticalInput, CritcalInputException)
313
314 /* Machine check */
315         MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
316
317 /* Data Storage exception. */
318         STD_EXCEPTION(0x0300, DataStorage, UnknownException)
319
320 /* Instruction Storage exception. */
321         STD_EXCEPTION(0x0400, InstStorage, UnknownException)
322
323 /* External Interrupt exception. */
324         STD_EXCEPTION(0x0500, ExtInterrupt, ExtIntException)
325
326 /* Alignment exception. */
327         . = 0x0600
328 Alignment:
329         EXCEPTION_PROLOG(SRR0, SRR1)
330         mfspr   r4,DAR
331         stw     r4,_DAR(r21)
332         mfspr   r5,DSISR
333         stw     r5,_DSISR(r21)
334         addi    r3,r1,STACK_FRAME_OVERHEAD
335         li      r20,MSR_KERNEL
336         rlwimi  r20,r23,0,16,16         /* copy EE bit from saved MSR */
337         lwz     r6,GOT(transfer_to_handler)
338         mtlr    r6
339         blrl
340 .L_Alignment:
341         .long   AlignmentException - _start + _START_OFFSET
342         .long   int_return - _start + _START_OFFSET
343
344 /* Program check exception */
345         . = 0x0700
346 ProgramCheck:
347         EXCEPTION_PROLOG(SRR0, SRR1)
348         addi    r3,r1,STACK_FRAME_OVERHEAD
349         li      r20,MSR_KERNEL
350         rlwimi  r20,r23,0,16,16         /* copy EE bit from saved MSR */
351         lwz     r6,GOT(transfer_to_handler)
352         mtlr    r6
353         blrl
354 .L_ProgramCheck:
355         .long   ProgramCheckException - _start + _START_OFFSET
356         .long   int_return - _start + _START_OFFSET
357
358         /* No FPU on MPC85xx.  This exception is not supposed to happen.
359         */
360         STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
361
362         . = 0x0900
363 /*
364  * r0 - SYSCALL number
365  * r3-... arguments
366  */
367 SystemCall:
368         addis   r11,r0,0        /* get functions table addr */
369         ori     r11,r11,0       /* Note: this code is patched in trap_init */
370         addis   r12,r0,0        /* get number of functions */
371         ori     r12,r12,0
372
373         cmplw   0,r0,r12
374         bge     1f
375
376         rlwinm  r0,r0,2,0,31    /* fn_addr = fn_tbl[r0] */
377         add     r11,r11,r0
378         lwz     r11,0(r11)
379
380         li      r20,0xd00-4     /* Get stack pointer */
381         lwz     r12,0(r20)
382         subi    r12,r12,12      /* Adjust stack pointer */
383         li      r0,0xc00+_end_back-SystemCall
384         cmplw   0,r0,r12        /* Check stack overflow */
385         bgt     1f
386         stw     r12,0(r20)
387
388         mflr    r0
389         stw     r0,0(r12)
390         mfspr   r0,SRR0
391         stw     r0,4(r12)
392         mfspr   r0,SRR1
393         stw     r0,8(r12)
394
395         li      r12,0xc00+_back-SystemCall
396         mtlr    r12
397         mtspr   SRR0,r11
398
399 1:      SYNC
400         rfi
401 _back:
402
403         mfmsr   r11                     /* Disable interrupts */
404         li      r12,0
405         ori     r12,r12,MSR_EE
406         andc    r11,r11,r12
407         SYNC                            /* Some chip revs need this... */
408         mtmsr   r11
409         SYNC
410
411         li      r12,0xd00-4             /* restore regs */
412         lwz     r12,0(r12)
413
414         lwz     r11,0(r12)
415         mtlr    r11
416         lwz     r11,4(r12)
417         mtspr   SRR0,r11
418         lwz     r11,8(r12)
419         mtspr   SRR1,r11
420
421         addi    r12,r12,12              /* Adjust stack pointer */
422         li      r20,0xd00-4
423         stw     r12,0(r20)
424
425         SYNC
426         rfi
427 _end_back:
428
429         STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt)
430         STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException)
431         STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException)
432
433         STD_EXCEPTION(0x0d00, DataTLBError, UnknownException)
434         STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException)
435
436         CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException )
437
438         .globl  _end_of_vectors
439 _end_of_vectors:
440
441
442         . = . + (0x100 - ( . & 0xff ))  /* align for debug */
443
444 /*
445  * This code finishes saving the registers to the exception frame
446  * and jumps to the appropriate handler for the exception.
447  * Register r21 is pointer into trap frame, r1 has new stack pointer.
448  */
449         .globl  transfer_to_handler
450 transfer_to_handler:
451         stw     r22,_NIP(r21)
452         lis     r22,MSR_POW@h
453         andc    r23,r23,r22
454         stw     r23,_MSR(r21)
455         SAVE_GPR(7, r21)
456         SAVE_4GPRS(8, r21)
457         SAVE_8GPRS(12, r21)
458         SAVE_8GPRS(24, r21)
459
460         mflr    r23
461         andi.   r24,r23,0x3f00          /* get vector offset */
462         stw     r24,TRAP(r21)
463         li      r22,0
464         stw     r22,RESULT(r21)
465         mtspr   SPRG2,r22               /* r1 is now kernel sp */
466
467         lwz     r24,0(r23)              /* virtual address of handler */
468         lwz     r23,4(r23)              /* where to go when done */
469         mtspr   SRR0,r24
470         mtspr   SRR1,r20
471         mtlr    r23
472         SYNC
473         rfi                             /* jump to handler, enable MMU */
474
475 int_return:
476         mfmsr   r28             /* Disable interrupts */
477         li      r4,0
478         ori     r4,r4,MSR_EE
479         andc    r28,r28,r4
480         SYNC                    /* Some chip revs need this... */
481         mtmsr   r28
482         SYNC
483         lwz     r2,_CTR(r1)
484         lwz     r0,_LINK(r1)
485         mtctr   r2
486         mtlr    r0
487         lwz     r2,_XER(r1)
488         lwz     r0,_CCR(r1)
489         mtspr   XER,r2
490         mtcrf   0xFF,r0
491         REST_10GPRS(3, r1)
492         REST_10GPRS(13, r1)
493         REST_8GPRS(23, r1)
494         REST_GPR(31, r1)
495         lwz     r2,_NIP(r1)     /* Restore environment */
496         lwz     r0,_MSR(r1)
497         mtspr   SRR0,r2
498         mtspr   SRR1,r0
499         lwz     r0,GPR0(r1)
500         lwz     r2,GPR2(r1)
501         lwz     r1,GPR1(r1)
502         SYNC
503         rfi
504
505 crit_return:
506         mfmsr   r28             /* Disable interrupts */
507         li      r4,0
508         ori     r4,r4,MSR_EE
509         andc    r28,r28,r4
510         SYNC                    /* Some chip revs need this... */
511         mtmsr   r28
512         SYNC
513         lwz     r2,_CTR(r1)
514         lwz     r0,_LINK(r1)
515         mtctr   r2
516         mtlr    r0
517         lwz     r2,_XER(r1)
518         lwz     r0,_CCR(r1)
519         mtspr   XER,r2
520         mtcrf   0xFF,r0
521         REST_10GPRS(3, r1)
522         REST_10GPRS(13, r1)
523         REST_8GPRS(23, r1)
524         REST_GPR(31, r1)
525         lwz     r2,_NIP(r1)     /* Restore environment */
526         lwz     r0,_MSR(r1)
527         mtspr   SPRN_CSRR0,r2
528         mtspr   SPRN_CSRR1,r0
529         lwz     r0,GPR0(r1)
530         lwz     r2,GPR2(r1)
531         lwz     r1,GPR1(r1)
532         SYNC
533         rfci
534
535 mck_return:
536         mfmsr   r28             /* Disable interrupts */
537         li      r4,0
538         ori     r4,r4,MSR_EE
539         andc    r28,r28,r4
540         SYNC                    /* Some chip revs need this... */
541         mtmsr   r28
542         SYNC
543         lwz     r2,_CTR(r1)
544         lwz     r0,_LINK(r1)
545         mtctr   r2
546         mtlr    r0
547         lwz     r2,_XER(r1)
548         lwz     r0,_CCR(r1)
549         mtspr   XER,r2
550         mtcrf   0xFF,r0
551         REST_10GPRS(3, r1)
552         REST_10GPRS(13, r1)
553         REST_8GPRS(23, r1)
554         REST_GPR(31, r1)
555         lwz     r2,_NIP(r1)     /* Restore environment */
556         lwz     r0,_MSR(r1)
557         mtspr   SPRN_MCSRR0,r2
558         mtspr   SPRN_MCSRR1,r0
559         lwz     r0,GPR0(r1)
560         lwz     r2,GPR2(r1)
561         lwz     r1,GPR1(r1)
562         SYNC
563         rfmci
564
565 /* Cache functions.
566 */
567 invalidate_icache:
568         mfspr   r0,L1CSR1
569         ori     r0,r0,L1CSR1_ICFI
570         msync
571         isync
572         mtspr   L1CSR1,r0
573         isync
574         blr                             /* entire I cache */
575
576 invalidate_dcache:
577         mfspr   r0,L1CSR0
578         ori     r0,r0,L1CSR0_DCFI
579         msync
580         isync
581         mtspr   L1CSR0,r0
582         isync
583         blr
584
585         .globl  icache_enable
586 icache_enable:
587         mflr    r8
588         bl      invalidate_icache
589         mtlr    r8
590         isync
591         mfspr   r4,L1CSR1
592         ori     r4,r4,0x0001
593         oris    r4,r4,0x0001
594         mtspr   L1CSR1,r4
595         isync
596         blr
597
598         .globl  icache_disable
599 icache_disable:
600         mfspr   r0,L1CSR1
601         lis     r3,0
602         ori     r3,r3,L1CSR1_ICE
603         andc    r0,r0,r3
604         mtspr   L1CSR1,r0
605         isync
606         blr
607
608         .globl  icache_status
609 icache_status:
610         mfspr   r3,L1CSR1
611         andi.   r3,r3,L1CSR1_ICE
612         blr
613
614         .globl  dcache_enable
615 dcache_enable:
616         mflr    r8
617         bl      invalidate_dcache
618         mtlr    r8
619         isync
620         mfspr   r0,L1CSR0
621         ori     r0,r0,0x0001
622         oris    r0,r0,0x0001
623         msync
624         isync
625         mtspr   L1CSR0,r0
626         isync
627         blr
628
629         .globl  dcache_disable
630 dcache_disable:
631         mfspr   r3,L1CSR0
632         lis     r4,0
633         ori     r4,r4,L1CSR0_DCE
634         andc    r3,r3,r4
635         mtspr   L1CSR0,r0
636         isync
637         blr
638
639         .globl  dcache_status
640 dcache_status:
641         mfspr   r3,L1CSR0
642         andi.   r3,r3,L1CSR0_DCE
643         blr
644
645         .globl get_pir
646 get_pir:
647         mfspr   r3,PIR
648         blr
649
650         .globl get_pvr
651 get_pvr:
652         mfspr   r3,PVR
653         blr
654
655         .globl get_svr
656 get_svr:
657         mfspr   r3,SVR
658         blr
659
660         .globl wr_tcr
661 wr_tcr:
662         mtspr   TCR,r3
663         blr
664
665 /*------------------------------------------------------------------------------- */
666 /* Function:     in8 */
667 /* Description:  Input 8 bits */
668 /*------------------------------------------------------------------------------- */
669         .globl  in8
670 in8:
671         lbz     r3,0x0000(r3)
672         blr
673
674 /*------------------------------------------------------------------------------- */
675 /* Function:     out8 */
676 /* Description:  Output 8 bits */
677 /*------------------------------------------------------------------------------- */
678         .globl  out8
679 out8:
680         stb     r4,0x0000(r3)
681         sync
682         blr
683
684 /*------------------------------------------------------------------------------- */
685 /* Function:     out16 */
686 /* Description:  Output 16 bits */
687 /*------------------------------------------------------------------------------- */
688         .globl  out16
689 out16:
690         sth     r4,0x0000(r3)
691         sync
692         blr
693
694 /*------------------------------------------------------------------------------- */
695 /* Function:     out16r */
696 /* Description:  Byte reverse and output 16 bits */
697 /*------------------------------------------------------------------------------- */
698         .globl  out16r
699 out16r:
700         sthbrx  r4,r0,r3
701         sync
702         blr
703
704 /*------------------------------------------------------------------------------- */
705 /* Function:     out32 */
706 /* Description:  Output 32 bits */
707 /*------------------------------------------------------------------------------- */
708         .globl  out32
709 out32:
710         stw     r4,0x0000(r3)
711         sync
712         blr
713
714 /*------------------------------------------------------------------------------- */
715 /* Function:     out32r */
716 /* Description:  Byte reverse and output 32 bits */
717 /*------------------------------------------------------------------------------- */
718         .globl  out32r
719 out32r:
720         stwbrx  r4,r0,r3
721         sync
722         blr
723
724 /*------------------------------------------------------------------------------- */
725 /* Function:     in16 */
726 /* Description:  Input 16 bits */
727 /*------------------------------------------------------------------------------- */
728         .globl  in16
729 in16:
730         lhz     r3,0x0000(r3)
731         blr
732
733 /*------------------------------------------------------------------------------- */
734 /* Function:     in16r */
735 /* Description:  Input 16 bits and byte reverse */
736 /*------------------------------------------------------------------------------- */
737         .globl  in16r
738 in16r:
739         lhbrx   r3,r0,r3
740         blr
741
742 /*------------------------------------------------------------------------------- */
743 /* Function:     in32 */
744 /* Description:  Input 32 bits */
745 /*------------------------------------------------------------------------------- */
746         .globl  in32
747 in32:
748         lwz     3,0x0000(3)
749         blr
750
751 /*------------------------------------------------------------------------------- */
752 /* Function:     in32r */
753 /* Description:  Input 32 bits and byte reverse */
754 /*------------------------------------------------------------------------------- */
755         .globl  in32r
756 in32r:
757         lwbrx   r3,r0,r3
758         blr
759
760 /*------------------------------------------------------------------------------- */
761 /* Function:     ppcDcbf */
762 /* Description:  Data Cache block flush */
763 /* Input:        r3 = effective address */
764 /* Output:       none. */
765 /*------------------------------------------------------------------------------- */
766         .globl  ppcDcbf
767 ppcDcbf:
768         dcbf    r0,r3
769         blr
770
771 /*------------------------------------------------------------------------------- */
772 /* Function:     ppcDcbi */
773 /* Description:  Data Cache block Invalidate */
774 /* Input:        r3 = effective address */
775 /* Output:       none. */
776 /*------------------------------------------------------------------------------- */
777         .globl  ppcDcbi
778 ppcDcbi:
779         dcbi    r0,r3
780         blr
781
782 /*--------------------------------------------------------------------------
783  * Function:     ppcDcbz
784  * Description:  Data Cache block zero.
785  * Input:        r3 = effective address
786  * Output:       none.
787  *-------------------------------------------------------------------------- */
788
789         .globl  ppcDcbz
790 ppcDcbz:
791         dcbz    r0,r3
792         blr
793
794 /*------------------------------------------------------------------------------- */
795 /* Function:     ppcSync */
796 /* Description:  Processor Synchronize */
797 /* Input:        none. */
798 /* Output:       none. */
799 /*------------------------------------------------------------------------------- */
800         .globl  ppcSync
801 ppcSync:
802         sync
803         blr
804
805 /*------------------------------------------------------------------------------*/
806
807 /*
808  * void relocate_code (addr_sp, gd, addr_moni)
809  *
810  * This "function" does not return, instead it continues in RAM
811  * after relocating the monitor code.
812  *
813  * r3 = dest
814  * r4 = src
815  * r5 = length in bytes
816  * r6 = cachelinesize
817  */
818         .globl  relocate_code
819 relocate_code:
820         mr      r1,r3           /* Set new stack pointer                */
821         mr      r9,r4           /* Save copy of Init Data pointer       */
822         mr      r10,r5          /* Save copy of Destination Address     */
823
824         mr      r3,r5                           /* Destination Address  */
825         lis     r4,CFG_MONITOR_BASE@h           /* Source      Address  */
826         ori     r4,r4,CFG_MONITOR_BASE@l
827         lwz     r5,GOT(__init_end)
828         sub     r5,r5,r4
829         li      r6,CFG_CACHELINE_SIZE           /* Cache Line Size      */
830
831         /*
832          * Fix GOT pointer:
833          *
834          * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
835          *
836          * Offset:
837          */
838         sub     r15,r10,r4
839
840         /* First our own GOT */
841         add     r14,r14,r15
842         /* the the one used by the C code */
843         add     r30,r30,r15
844
845         /*
846          * Now relocate code
847          */
848
849         cmplw   cr1,r3,r4
850         addi    r0,r5,3
851         srwi.   r0,r0,2
852         beq     cr1,4f          /* In place copy is not necessary       */
853         beq     7f              /* Protect against 0 count              */
854         mtctr   r0
855         bge     cr1,2f
856
857         la      r8,-4(r4)
858         la      r7,-4(r3)
859 1:      lwzu    r0,4(r8)
860         stwu    r0,4(r7)
861         bdnz    1b
862         b       4f
863
864 2:      slwi    r0,r0,2
865         add     r8,r4,r0
866         add     r7,r3,r0
867 3:      lwzu    r0,-4(r8)
868         stwu    r0,-4(r7)
869         bdnz    3b
870
871 /*
872  * Now flush the cache: note that we must start from a cache aligned
873  * address. Otherwise we might miss one cache line.
874  */
875 4:      cmpwi   r6,0
876         add     r5,r3,r5
877         beq     7f              /* Always flush prefetch queue in any case */
878         subi    r0,r6,1
879         andc    r3,r3,r0
880         mr      r4,r3
881 5:      dcbst   0,r4
882         add     r4,r4,r6
883         cmplw   r4,r5
884         blt     5b
885         sync                    /* Wait for all dcbst to complete on bus */
886         mr      r4,r3
887 6:      icbi    0,r4
888         add     r4,r4,r6
889         cmplw   r4,r5
890         blt     6b
891 7:      sync                    /* Wait for all icbi to complete on bus */
892         isync
893
894         /*
895          * Re-point the IVPR at RAM
896          */
897         mtspr   IVPR,r10
898
899 /*
900  * We are done. Do not return, instead branch to second part of board
901  * initialization, now running from RAM.
902  */
903
904         addi    r0,r10,in_ram - _start + _START_OFFSET
905         mtlr    r0
906         blr                             /* NEVER RETURNS! */
907         .globl  in_ram
908 in_ram:
909
910         /*
911          * Relocation Function, r14 point to got2+0x8000
912          *
913          * Adjust got2 pointers, no need to check for 0, this code
914          * already puts a few entries in the table.
915          */
916         li      r0,__got2_entries@sectoff@l
917         la      r3,GOT(_GOT2_TABLE_)
918         lwz     r11,GOT(_GOT2_TABLE_)
919         mtctr   r0
920         sub     r11,r3,r11
921         addi    r3,r3,-4
922 1:      lwzu    r0,4(r3)
923         add     r0,r0,r11
924         stw     r0,0(r3)
925         bdnz    1b
926
927         /*
928          * Now adjust the fixups and the pointers to the fixups
929          * in case we need to move ourselves again.
930          */
931 2:      li      r0,__fixup_entries@sectoff@l
932         lwz     r3,GOT(_FIXUP_TABLE_)
933         cmpwi   r0,0
934         mtctr   r0
935         addi    r3,r3,-4
936         beq     4f
937 3:      lwzu    r4,4(r3)
938         lwzux   r0,r4,r11
939         add     r0,r0,r11
940         stw     r10,0(r3)
941         stw     r0,0(r4)
942         bdnz    3b
943 4:
944 clear_bss:
945         /*
946          * Now clear BSS segment
947          */
948         lwz     r3,GOT(__bss_start)
949         lwz     r4,GOT(_end)
950
951         cmplw   0,r3,r4
952         beq     6f
953
954         li      r0,0
955 5:
956         stw     r0,0(r3)
957         addi    r3,r3,4
958         cmplw   0,r3,r4
959         bne     5b
960 6:
961
962         mr      r3,r9           /* Init Data pointer            */
963         mr      r4,r10          /* Destination Address          */
964         bl      board_init_r
965
966         /*
967          * Copy exception vector code to low memory
968          *
969          * r3: dest_addr
970          * r7: source address, r8: end address, r9: target address
971          */
972         .globl  trap_init
973 trap_init:
974         lwz     r7,GOT(_start_of_vectors)
975         lwz     r8,GOT(_end_of_vectors)
976
977         li      r9,0x100                /* reset vector always at 0x100 */
978
979         cmplw   0,r7,r8
980         bgelr                           /* return if r7>=r8 - just in case */
981
982         mflr    r4                      /* save link register           */
983 1:
984         lwz     r0,0(r7)
985         stw     r0,0(r9)
986         addi    r7,r7,4
987         addi    r9,r9,4
988         cmplw   0,r7,r8
989         bne     1b
990
991         /*
992          * relocate `hdlr' and `int_return' entries
993          */
994         li      r7,.L_CriticalInput - _start + _START_OFFSET
995         bl      trap_reloc
996         li      r7,.L_MachineCheck - _start + _START_OFFSET
997         bl      trap_reloc
998         li      r7,.L_DataStorage - _start + _START_OFFSET
999         bl      trap_reloc
1000         li      r7,.L_InstStorage - _start + _START_OFFSET
1001         bl      trap_reloc
1002         li      r7,.L_ExtInterrupt - _start + _START_OFFSET
1003         bl      trap_reloc
1004         li      r7,.L_Alignment - _start + _START_OFFSET
1005         bl      trap_reloc
1006         li      r7,.L_ProgramCheck - _start + _START_OFFSET
1007         bl      trap_reloc
1008         li      r7,.L_FPUnavailable - _start + _START_OFFSET
1009         bl      trap_reloc
1010         li      r7,.L_Decrementer - _start + _START_OFFSET
1011         bl      trap_reloc
1012         li      r7,.L_IntervalTimer - _start + _START_OFFSET
1013         li      r8,_end_of_vectors - _start + _START_OFFSET
1014 2:
1015         bl      trap_reloc
1016         addi    r7,r7,0x100             /* next exception vector        */
1017         cmplw   0,r7,r8
1018         blt     2b
1019
1020         lis     r7,0x0
1021         mtspr   IVPR,r7
1022
1023         mtlr    r4                      /* restore link register        */
1024         blr
1025
1026         /*
1027          * Function: relocate entries for one exception vector
1028          */
1029 trap_reloc:
1030         lwz     r0,0(r7)                /* hdlr ...                     */
1031         add     r0,r0,r3                /*  ... += dest_addr            */
1032         stw     r0,0(r7)
1033
1034         lwz     r0,4(r7)                /* int_return ...               */
1035         add     r0,r0,r3                /*  ... += dest_addr            */
1036         stw     r0,4(r7)
1037
1038         blr
1039
1040 #ifdef CFG_INIT_RAM_LOCK
1041 .globl unlock_ram_in_cache
1042 unlock_ram_in_cache:
1043         /* invalidate the INIT_RAM section */
1044         lis     r3,(CFG_INIT_RAM_ADDR & ~31)@h
1045         ori     r3,r3,(CFG_INIT_RAM_ADDR & ~31)@l
1046         mfspr   r4,L1CFG0
1047         andi.   r4,r4,0x1ff
1048         slwi    r4,r4,(10 - 1 - L1_CACHE_SHIFT)
1049         mtctr   r4
1050 1:      icbi    r0,r3
1051         dcbi    r0,r3
1052         addi    r3,r3,CFG_CACHELINE_SIZE
1053         bdnz    1b
1054         sync                    /* Wait for all icbi to complete on bus */
1055         isync
1056         blr
1057 #endif