import of ftp.dlink.com/GPL/DSMG-600_reB/ppclinux.tar.gz
[linux-2.4.21-pre4.git] / arch / ppc / boot / prep / head.S
1 /*
2  * BK Id: SCCS/s.head.S 1.13 08/07/01 17:57:15 trini
3  */
4
5 #include <asm/ppc_asm.h>
6 #include <asm/processor.h>
7 #include <asm/cache.h>
8
9         .text
10
11 /*
12  * Boot loader philosophy:
13  *      ROM loads us to some arbitrary location
14  *      Move the boot code to the link address (8M)
15  *      Call decompress_kernel()
16  *         Relocate the initrd, zimage and residual data to 8M
17  *         Decompress the kernel to 0
18  *      Jump to the kernel entry
19  *            -- Cort
20  */
21         .globl  start
22 start:
23         bl      start_
24 start_:
25
26         /* Enable, invalidate, Disable L1 icache/dcache */
27         li      r8, 0
28         ori     r8, r8, (HID0_ICE|HID0_DCE|HID0_ICFI|HID0_DCI)
29         mfspr   r11,HID0
30         or      r11,r11,r8
31         andc    r10,r11,r8
32         isync
33         mtspr   HID0,r8
34         sync
35         isync
36         mtspr   HID0,r10
37         sync
38         isync
39
40         mr      r11,r3          /* Save pointer to residual/board data */
41
42         /* Establish default MSR value */
43         li      r3,MSR_IP|MSR_FP
44         mtmsr   r3
45
46         /* compute the size of the whole image in words. */
47         lis     r4,start@h
48         ori     r4,r4,start@l
49         lis     r5,end@h
50         ori     r5,r5,end@l
51         addi    r5,r5,3         /* round up */
52         sub     r5,r5,r4        /* end - start */
53         srwi    r5,r5,2
54         mr      r7,r5           /* Save for later use. */
55
56         /* check if we need to relocate ourselves to the link addr or were
57          * we loaded there to begin with -- Cort */
58         mflr    r3
59         subi    r3,r3,4         /* we get the nip, not the ip of the branch */
60         mr      r8,r3
61         cmp     0,r3,r4
62         beq     start_ldr       /* If 0, we don't need to relocate */
63 /*
64  * no matter where we're loaded, move ourselves to -Ttext address
65  */
66 relocate:
67         mflr    r3              /* Compute code bias */
68         subi    r3,r3,4
69         mr      r8,r3
70         lis     r4,start@h
71         ori     r4,r4,start@l
72         mr      r5,r7           /* Get the # of longwords again */
73         mtctr   r5              /* Setup for loop */
74         li      r6,0
75         subi    r3,r3,4
76         subi    r4,r4,4
77 00:     lwzu    r5,4(r3)
78         stwu    r5,4(r4)
79         xor     r6,r6,r5
80         bdnz    00b
81         lis     r3,start_ldr@h
82         ori     r3,r3,start_ldr@l
83         mtlr    r3              /* Easiest way to do an absolute jump */
84         blr
85
86 start_ldr:
87 /* Some boards don't boot up with the I-cache enabled.  Do that
88  * now because the decompress runs much faster that way.
89  * As a side effect, we have to ensure the data cache is not enabled
90  * so we can access the serial I/O without trouble.
91  */
92         bl      flush_instruction_cache
93
94 /* Clear all of BSS */
95         lis     r3,edata@h
96         ori     r3,r3,edata@l
97         lis     r4,end@h
98         ori     r4,r4,end@l
99         subi    r3,r3,4
100         subi    r4,r4,4
101         li      r0,0
102 50:     stwu    r0,4(r3)
103         cmp     0,r3,r4
104         bne     50b
105 90:     mr      r9,r1                   /* Save old stack pointer (in case it matters) */
106         lis     r1,.stack@h
107         ori     r1,r1,.stack@l
108         addi    r1,r1,4096*2
109         subi    r1,r1,256
110         li      r2,0x000F               /* Mask pointer to 16-byte boundary */
111         andc    r1,r1,r2
112
113 /* Run loader */
114         mr      r3,r8                   /* Load point */
115         mr      r4,r7                   /* Program length */
116         mr      r5,r6                   /* Checksum */
117         mr      r6,r11                  /* Residual data */
118         bl      decompress_kernel
119
120         /*
121          * We have to do this after decompress_kernel, just to make
122          * sure we don't wipe out things mapped in BATs which we need.
123          * -- Tom
124          */
125         li      r6,0
126         /* Test for a 601 */
127         mfspr   r9,PVR
128         srwi    r9,r9,16
129         cmpi    0,r9,1          /* 601 ? */
130         beq     .clearbats_601
131
132         /* Clear BATS */
133         mtspr   DBAT0U,r6
134         mtspr   DBAT0L,r6
135         mtspr   DBAT1U,r6
136         mtspr   DBAT1L,r6
137         mtspr   DBAT2U,r6
138         mtspr   DBAT2L,r6
139         mtspr   DBAT3U,r6
140         mtspr   DBAT3L,r6
141 .clearbats_601:
142         mtspr   IBAT0U,r6
143         mtspr   IBAT0L,r6
144         mtspr   IBAT1U,r6
145         mtspr   IBAT1L,r6
146         mtspr   IBAT2U,r6
147         mtspr   IBAT2L,r6
148         mtspr   IBAT3U,r6
149         mtspr   IBAT3L,r6
150         isync
151         sync
152         sync
153
154         /* Set segment registers */
155         li      r6,16           /* load up segment register values */
156         mtctr   r6              /* for context 0 */
157         lis     r6,0x2000       /* Ku = 1, VSID = 0 */
158         li      r10,0
159 3:      mtsrin  r6,r10
160         addi    r6,r6,0x111     /* increment VSID */
161         addis   r10,r10,0x1000  /* address of next segment */
162         bdnz    3b
163
164         /* tell kernel we're prep, by putting 0xdeadc0de at KERNELLOAD,
165          * and tell the kernel to start on the 4th instruction since we
166          * overwrite the first 3 sometimes (which are 'nop').
167          */
168         li      r9,0xc
169         mtlr    r9
170         lis     r10,0xdeadc0de@h
171         ori     r10,r10,0xdeadc0de@l
172         li      r9,0
173         stw     r10,0(r9)
174         blr
175
176         .comm   .stack,4096*2,4