mpc85xx_start.S revision 1.2.4.3 1 /* $NetBSD: mpc85xx_start.S,v 1.2.4.3 2011/06/12 00:23:57 rmind Exp $ */
2 /*-
3 * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
8 * Agency and which was developed by Matt Thomas of 3am Software Foundry.
9 *
10 * This material is based upon work supported by the Defense Advanced Research
11 * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
12 * Contract No. N66001-09-C-2073.
13 * Approved for Public Release, Distribution Unlimited
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 #include <sys/cdefs.h>
38 #include <powerpc/asm.h>
39
40 RCSID("$NetBSD: mpc85xx_start.S,v 1.2.4.3 2011/06/12 00:23:57 rmind Exp $")
41
42 #include "opt_altivec.h"
43 #include "opt_ddb.h"
44 #include "opt_ipkdb.h"
45 #include "opt_lockdebug.h"
46 #include "opt_modular.h"
47 #include "opt_multiprocessor.h"
48 #include "opt_ppcarch.h"
49 #include "opt_ppcparam.h"
50
51 #include "ksyms.h"
52
53 #include <sys/param.h>
54
55 #include <powerpc/spr.h>
56 #include <powerpc/trap.h>
57 #include <powerpc/booke/pte.h>
58 #include <powerpc/booke/spr.h>
59 #define LBC_PRIVATE
60 #include <powerpc/booke/e500reg.h>
61
62 #include "assym.h"
63
64 #define INTSTK 0
65
66 .machine e500
67 /*
68 * This symbol is here for the benefit of kvm_mkdb, and is supposed to
69 * mark the start of kernel text.
70 */
71 .text
72 .globl _C_LABEL(kernel_text)
73 _C_LABEL(kernel_text):
74 .globl __start
75 __start:
76
77 /*
78 * Startup entry. Note, this must be the first thing in the text segment!
79 */
80 mr %r8,%r6
81 mr %r7,%r5
82 mr %r6,%r4
83 mr %r5,%r3
84 #ifdef DEBUG
85 /*
86 * Set all the registers we don't care about to a known junk value.
87 */
88 lis %r2,0xdeadbeef@ha
89 addi %r2,%r2,0xdeadbeef@l
90 mr %r9,%r2
91 mr %r10,%r9
92 mr %r11,%r9
93 mr %r12,%r9
94 mr %r13,%r9
95 mr %r14,%r9
96 mr %r15,%r9
97 mr %r16,%r9
98 mr %r17,%r9
99 mr %r18,%r9
100 mr %r19,%r9
101 mr %r20,%r9
102 mr %r21,%r9
103 mr %r22,%r9
104 mr %r23,%r9
105 mr %r24,%r9
106 mr %r25,%r9
107 mr %r26,%r9
108 mr %r27,%r9
109 mr %r28,%r9
110 mr %r29,%r9
111 mr %r30,%r9
112 mr %r31,%r9
113 #endif /* DEBUG */
114
115 li %r0,0
116 mtmsr %r0 /* Disable FPU/MMU/exceptions */
117 isync
118
119 /* get start of bss */
120 lis %r15,_C_LABEL(_edata)-4@ha
121 addi %r15,%r15,_C_LABEL(_edata)-4@l
122 /* get end of kernel memory */
123 lis %r16,_C_LABEL(end)@ha
124 addi %r16,%r16,_C_LABEL(end)@l
125 /* zero bss */
126 sub %r17,%r16,%r15
127 addi %r17,%r17,3+USPACE
128 rlwinm %r3,%r17,32-2,2,31 /* srwl %r3,%r17,2 */
129 mtctr %r3
130 li %r0,0
131 2: stwu %r0,4(%r15)
132 bdnz 2b
133
134 #if NKSYMS || defined(DDB) || defined(MODULAR)
135 /* If we had symbol table location we'd store it here and would've adjusted r8 here */
136 lis %r17,_C_LABEL(startsym)@ha
137 stw %r18,_C_LABEL(startsym)@l(%r17)
138 lis %r17,_C_LABEL(endsym)@ha
139 stw %r18,_C_LABEL(endsym)@l(%r17)
140 #endif
141
142 /* Set kernel MMU context. */
143 li %r0,KERNEL_PID
144 mtpid %r0
145 isync
146
147 INIT_CPUINFO(16,1,18,17) /* r16 has &_end */
148 mr %r4,%r16 /* remember kernelend */
149 mtsprg2 %r13 /* r13 has &lwp0, put into sprg2 */
150 GET_CPUINFO(%r17)
151 addi %r17,%r17,CI_SAVELIFO
152 mtsprg3 %r17
153 mr %r18,%r31 /* make deadbeef again */
154 mr %r17,%r31 /* make deadbeef again */
155 mr %r16,%r31 /* make deadbeef again */
156 mr %r15,%r31 /* make deadbeef again */
157
158 #if defined(GXEMUL)
159 /*
160 * This is used to step through the external interrupt vector
161 * to validate it.
162 */
163 lis %r29,3f@ha
164 addi %r29,%r29,3f@l
165 mtsrr0 %r29
166 mfmsr %r0
167 mtsrr1 %r0
168 lis %r31,0xdeadf231@ha
169 addi %r31,%r31,0xdeadf231@l
170 mtlr %r31
171 addi %r31,%r31,-0x10
172 mtcr %r31
173 addi %r31,%r31,-0x10
174 mtctr %r31
175 addi %r31,%r31,-0x10
176 mtxer %r31
177 addi %r31,%r31,-0x10
178 addi %r30,%r31,-0x10
179 addi %r29,%r30,-0x10
180 addi %r28,%r29,-0x10
181 addi %r27,%r28,-0x10
182 addi %r26,%r27,-0x10
183 addi %r25,%r26,-0x10
184 addi %r24,%r25,-0x10
185 addi %r23,%r24,-0x10
186 addi %r22,%r23,-0x10
187 addi %r21,%r22,-0x10
188 addi %r20,%r21,-0x10
189 addi %r19,%r20,-0x10
190 addi %r18,%r19,-0x10
191 addi %r17,%r18,-0x10
192 addi %r16,%r17,-0x10
193 addi %r15,%r16,-0x10
194 addi %r14,%r15,-0x10
195 addi %r13,%r14,-0x10
196 addi %r12,%r13,-0x10
197 addi %r11,%r12,-0x10
198 addi %r10,%r11,-0x10
199 addi %r9,%r10,-0x10
200 addi %r8,%r9,-0x10
201 addi %r7,%r8,-0x10
202 addi %r6,%r7,-0x10
203 addi %r5,%r6,-0x10
204 addi %r4,%r5,-0x10
205 addi %r3,%r4,-0x10
206 addi %r2,%r3,-0x10
207 /* leave r1 alone */
208 addi %r0,%r2,-0x20
209 b _C_LABEL(instruction_tlb_error_vector)
210 //b _C_LABEL(program_vector)
211 //b _C_LABEL(external_input_vector)
212 3:
213 #endif
214
215 /*
216 * TB is 50Mhz, watchdog should be ~10 seconds which makes that
217 * 500 million or 0x20000000. Since it takes 3 bit transitions
218 * we really want 0x10000000. That's bit 63-28 or 35. This
219 * means we want WPEXT,WP to be 0b10_0011.
220 */
221 lis %r3,(TCR_WRC_RESET|TCR_WP_2_N(0x23))@ha
222 addi %r3,%r3,(TCR_WRC_RESET|TCR_WP_2_N(0x23))@l
223 mtspr SPR_TCR, %r3
224 li %r0, 0
225 mtspr SPR_TBL, %r0
226 mtspr SPR_TBU, %r0
227 mtspr SPR_DBCR0, %r0
228
229 #if 0
230 /*
231 * Force all dirty lines in the kernel area to memory.
232 */
233 lis %r8,kernel_text@ha
234 addi %r8,%r8,kernel_text@l
235 4: dcbst %r0,%r8
236 addi %r8,%r8,32
237 cmplw %r8,%r4
238 blt %cr0,4b
239 mbar 1
240 msync
241
242 /*
243 * Turn off the data cache, and then invalidate it.
244 */
245 li %r3, 0
246 mtspr SPR_L1CSR0, %r3
247 li %r3, L1CSR_CFI
248 mtspr SPR_L1CSR0, %r3
249 #endif
250
251 #if 1
252 /*
253 * Clear any locks from the data or instruction caches.
254 */
255 mfspr %r3, SPR_L1CSR0
256 ori %r3, %r3, L1CSR_CLFR
257 mtspr SPR_L1CSR0, %r3
258 mfspr %r3, SPR_L1CSR1
259 ori %r3, %r3, L1CSR_CLFR
260 mtspr SPR_L1CSR1, %r3
261 #endif
262
263 lis %r3,__start@ha
264 addi %r3,%r3,__start@l
265
266 bl _C_LABEL(initppc)
267 bl _C_LABEL(main)
268
269 loop: b loop /* XXX not reached */
270
271 #include <powerpc/booke/trap_subr.S>
272 #include <powerpc/powerpc/locore_subr.S>
273 #include <powerpc/powerpc/pio_subr.S>
274 #ifdef PPC_HAVE_SPE
275 #include <powerpc/booke/spe_subr.S>
276 #endif
277 #if defined(MULTIPROCESSOR)
278 #include <powerpc/booke/e500_mpsubr.S>
279 #endif
280
281 #if 0
282 .p2align 5
283 ENTRY(tlbwe)
284 isync
285 tlbwe
286 isync
287 blr
288 #endif
289