locore.S revision 1.15 1 /* $NetBSD: locore.S,v 1.15 2010/03/03 00:30:15 pooka Exp $ */
2 /* $OpenBSD: locore.S,v 1.4 1997/01/26 09:06:38 rahnds Exp $ */
3
4 /*
5 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
6 * Copyright (C) 1995, 1996 TooLs GmbH.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by TooLs GmbH.
20 * 4. The name of TooLs GmbH may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include "opt_ddb.h"
36 #include "opt_ipkdb.h"
37 #include "opt_lockdebug.h"
38 #include "opt_modular.h"
39 #include "opt_multiprocessor.h"
40 #include "opt_ppcparam.h"
41 #include "assym.h"
42
43 #include <sys/syscall.h>
44
45 #include <machine/param.h>
46 #include <machine/vmparam.h>
47 #include <machine/pmap.h>
48 #include <machine/psl.h>
49 #include <machine/trap.h>
50 #define _NOREGNAMES
51 #include <machine/asm.h>
52
53 #include <powerpc/spr.h>
54 #include <powerpc/oea/spr.h>
55
56 #include "ksyms.h"
57
58 /*
59 * Some instructions gas doesn't understand (yet?)
60 */
61 #define bdneq bdnzf 2,
62
63 /*
64 * cache bit
65 */
66 #define HID0_BTCD (1<<1)
67 #define HID0_BHTE (1<<2)
68 #define HID0_SIED (1<<7)
69 #define HID0_DCI (1<<10)
70 #define HID0_ICFI (1<<11)
71 #define HID0_DCE (1<<14)
72 #define HID0_ICE (1<<15)
73
74 /*
75 * Globals
76 */
77 GLOBAL(startsym)
78 .long 0 /* start symbol table */
79 GLOBAL(endsym)
80 .long 0 /* end symbol table */
81 GLOBAL(oeacpufeat)
82 .long 0 /* cpu features */
83
84 /*
85 * This symbol is here for the benefit of kvm_mkdb, and is supposed to
86 * mark the start of kernel text.
87 */
88 .text
89 .globl _C_LABEL(kernel_text)
90 _C_LABEL(kernel_text):
91
92 /*
93 * Startup entry. Note, this must be the first thing in the text
94 * segment!
95 */
96 .text
97 .globl __start
98 __start:
99 li 0,0
100 mtmsr 0 /* Disable FPU/MMU/exceptions */
101 isync
102
103 /* compute end of kernel memory */
104 #if NKSYMS || defined(DDB) || defined(MODULAR)
105 lis 7,_C_LABEL(startsym)@ha
106 addi 7,7,_C_LABEL(startsym)@l
107 stw 3,0(7)
108 lis 7,_C_LABEL(endsym)@ha
109 addi 7,7,_C_LABEL(endsym)@l
110 stw 4,0(7)
111 #else
112 lis 4,_C_LABEL(end)@ha
113 addi 4,4,_C_LABEL(end)@l
114 #endif
115
116 INIT_CPUINFO(4,1,9,0)
117
118 lis 3,__start@ha
119 addi 3,3,__start@l
120
121 bl _C_LABEL(initppc)
122
123 /* enable internal i/d-cache */
124 mfpvr 9
125 rlwinm 9,9,16,16,31
126 cmpi 0,9,1
127 beq 3f /* not needed for 601 */
128 mfspr 11,SPR_HID0
129 andi. 0,11,HID0_DCE
130 ori 11,11,HID0_ICE|HID0_DCE
131 ori 8,11,HID0_ICFI
132 bne 1f /* don't invalidate the D-cache */
133 ori 8,8,HID0_DCI /* unless it wasn't enabled */
134 1:
135 sync
136 mtspr SPR_HID0,8 /* enable and invalidate caches */
137 sync
138 mtspr SPR_HID0,11 /* enable caches */
139 sync
140 isync
141 cmpi 0,9,4 /* check for 604 */
142 cmpi 1,9,9 /* or 604e */
143 cmpi 2,9,10 /* or mach5 */
144 cror 2,2,6
145 cror 2,2,10
146 bne 3f
147 ori 11,11,HID0_SIED|HID0_BHTE /* for 604[e], enable */
148 bne 2,2f
149 ori 11,11,HID0_BTCD
150 2:
151 mtspr SPR_HID0,11
152 3:
153 sync
154 isync
155
156 bl _C_LABEL(main)
157
158 loop:
159 b loop /* not reached */
160
161 .globl _C_LABEL(enable_intr)
162 _C_LABEL(enable_intr):
163 mfmsr 3
164 ori 4,3,PSL_EE@l
165 mtmsr 4
166 blr
167
168 .globl _C_LABEL(disable_intr)
169 _C_LABEL(disable_intr):
170 mfmsr 3
171 andi. 4,3,~PSL_EE@l
172 mtmsr 4
173 blr
174
175 /*
176 * Pull in common switch / setfault code.
177 */
178 #include <powerpc/powerpc/locore_subr.S>
179
180 /*
181 * Pull in common trap vector code.
182 */
183 #include <powerpc/powerpc/trap_subr.S>
184
185 /*
186 * Pull in common pio / bus_space code.
187 */
188 #include <powerpc/powerpc/pio_subr.S>
189