machdep.c revision 1.1.2.3 1 1.1.2.3 thorpej /* $NetBSD: machdep.c,v 1.1.2.3 2002/12/19 18:29:59 thorpej Exp $ */
2 1.1.2.2 thorpej
3 1.1.2.2 thorpej /*
4 1.1.2.2 thorpej * Copyright 2001, 2002 Wasabi Systems, Inc.
5 1.1.2.2 thorpej * All rights reserved.
6 1.1.2.2 thorpej *
7 1.1.2.2 thorpej * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
8 1.1.2.2 thorpej *
9 1.1.2.2 thorpej * Redistribution and use in source and binary forms, with or without
10 1.1.2.2 thorpej * modification, are permitted provided that the following conditions
11 1.1.2.2 thorpej * are met:
12 1.1.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
13 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer.
14 1.1.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
16 1.1.2.2 thorpej * documentation and/or other materials provided with the distribution.
17 1.1.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
18 1.1.2.2 thorpej * must display the following acknowledgement:
19 1.1.2.2 thorpej * This product includes software developed for the NetBSD Project by
20 1.1.2.2 thorpej * Wasabi Systems, Inc.
21 1.1.2.2 thorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1.2.2 thorpej * or promote products derived from this software without specific prior
23 1.1.2.2 thorpej * written permission.
24 1.1.2.2 thorpej *
25 1.1.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1.2.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1.2.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1.2.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1.2.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1.2.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1.2.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1.2.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1.2.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1.2.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
36 1.1.2.2 thorpej */
37 1.1.2.2 thorpej
38 1.1.2.2 thorpej /*
39 1.1.2.2 thorpej * Copyright (C) 1995, 1996 Wolfgang Solfrank.
40 1.1.2.2 thorpej * Copyright (C) 1995, 1996 TooLs GmbH.
41 1.1.2.2 thorpej * All rights reserved.
42 1.1.2.2 thorpej *
43 1.1.2.2 thorpej * Redistribution and use in source and binary forms, with or without
44 1.1.2.2 thorpej * modification, are permitted provided that the following conditions
45 1.1.2.2 thorpej * are met:
46 1.1.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
47 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer.
48 1.1.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
49 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
50 1.1.2.2 thorpej * documentation and/or other materials provided with the distribution.
51 1.1.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
52 1.1.2.2 thorpej * must display the following acknowledgement:
53 1.1.2.2 thorpej * This product includes software developed by TooLs GmbH.
54 1.1.2.2 thorpej * 4. The name of TooLs GmbH may not be used to endorse or promote products
55 1.1.2.2 thorpej * derived from this software without specific prior written permission.
56 1.1.2.2 thorpej *
57 1.1.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
58 1.1.2.2 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 1.1.2.2 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 1.1.2.2 thorpej * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
61 1.1.2.2 thorpej * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
62 1.1.2.2 thorpej * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
63 1.1.2.2 thorpej * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
64 1.1.2.2 thorpej * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
65 1.1.2.2 thorpej * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
66 1.1.2.2 thorpej * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 1.1.2.2 thorpej */
68 1.1.2.2 thorpej
69 1.1.2.2 thorpej #include "opt_compat_netbsd.h"
70 1.1.2.2 thorpej #include "opt_ddb.h"
71 1.1.2.2 thorpej #include "opt_ipkdb.h"
72 1.1.2.2 thorpej
73 1.1.2.2 thorpej #include <sys/param.h>
74 1.1.2.2 thorpej #include <sys/buf.h>
75 1.1.2.2 thorpej #include <sys/exec.h>
76 1.1.2.2 thorpej #include <sys/malloc.h>
77 1.1.2.2 thorpej #include <sys/mbuf.h>
78 1.1.2.2 thorpej #include <sys/mount.h>
79 1.1.2.2 thorpej #include <sys/msgbuf.h>
80 1.1.2.2 thorpej #include <sys/proc.h>
81 1.1.2.2 thorpej #include <sys/reboot.h>
82 1.1.2.3 thorpej #include <sys/sa.h>
83 1.1.2.2 thorpej #include <sys/syscallargs.h>
84 1.1.2.2 thorpej #include <sys/syslog.h>
85 1.1.2.2 thorpej #include <sys/systm.h>
86 1.1.2.2 thorpej #include <sys/kernel.h>
87 1.1.2.2 thorpej #include <sys/user.h>
88 1.1.2.2 thorpej #include <sys/boot_flag.h>
89 1.1.2.2 thorpej #include <sys/properties.h>
90 1.1.2.2 thorpej
91 1.1.2.2 thorpej #include <uvm/uvm_extern.h>
92 1.1.2.2 thorpej
93 1.1.2.2 thorpej #include <net/netisr.h>
94 1.1.2.2 thorpej
95 1.1.2.2 thorpej #include <machine/bus.h>
96 1.1.2.2 thorpej #include <machine/powerpc.h>
97 1.1.2.2 thorpej #include <machine/trap.h>
98 1.1.2.2 thorpej #include <machine/walnut.h>
99 1.1.2.2 thorpej #include <machine/dcr.h>
100 1.1.2.2 thorpej
101 1.1.2.2 thorpej #include <powerpc/spr.h>
102 1.1.2.2 thorpej #include <machine/bus.h>
103 1.1.2.2 thorpej
104 1.1.2.2 thorpej #include <dev/cons.h>
105 1.1.2.2 thorpej
106 1.1.2.2 thorpej #ifdef DDB
107 1.1.2.2 thorpej #include <machine/db_machdep.h>
108 1.1.2.2 thorpej #include <ddb/db_extern.h>
109 1.1.2.2 thorpej #endif
110 1.1.2.2 thorpej
111 1.1.2.2 thorpej #include "com.h"
112 1.1.2.2 thorpej #if NCOM > 0
113 1.1.2.2 thorpej #include <dev/ic/comreg.h> /* For COM_FREQ */
114 1.1.2.2 thorpej #endif
115 1.1.2.2 thorpej
116 1.1.2.2 thorpej /*
117 1.1.2.2 thorpej * Global variables used here and there
118 1.1.2.2 thorpej */
119 1.1.2.2 thorpej struct vm_map *exec_map = NULL;
120 1.1.2.2 thorpej struct vm_map *mb_map = NULL;
121 1.1.2.2 thorpej struct vm_map *phys_map = NULL;
122 1.1.2.2 thorpej
123 1.1.2.2 thorpej /*
124 1.1.2.2 thorpej * This should probably be in autoconf! XXX
125 1.1.2.2 thorpej */
126 1.1.2.2 thorpej char cpu_model[80];
127 1.1.2.2 thorpej char machine[] = MACHINE; /* from <machine/param.h> */
128 1.1.2.2 thorpej char machine_arch[] = MACHINE_ARCH; /* from <machine/param.h> */
129 1.1.2.2 thorpej
130 1.1.2.2 thorpej struct pcb *curpcb;
131 1.1.2.2 thorpej struct pmap *curpm;
132 1.1.2.2 thorpej struct proc *fpuproc; /* XXX - shouldn't need this on fpu-less CPUs */
133 1.1.2.2 thorpej
134 1.1.2.2 thorpej extern struct user *proc0paddr;
135 1.1.2.2 thorpej
136 1.1.2.2 thorpej char bootpath[256];
137 1.1.2.2 thorpej paddr_t msgbuf_paddr;
138 1.1.2.2 thorpej vaddr_t msgbuf_vaddr;
139 1.1.2.2 thorpej
140 1.1.2.2 thorpej #ifdef DDB
141 1.1.2.2 thorpej void *startsym, *endsym;
142 1.1.2.2 thorpej #endif
143 1.1.2.2 thorpej
144 1.1.2.2 thorpej int lcsplx(int);
145 1.1.2.2 thorpej void initppc(u_int, u_int, char *, void *);
146 1.1.2.2 thorpej
147 1.1.2.2 thorpej static void dumpsys(void);
148 1.1.2.2 thorpej static void install_extint(void (*)(void));
149 1.1.2.2 thorpej
150 1.1.2.2 thorpej #define MEMREGIONS 8
151 1.1.2.2 thorpej struct mem_region physmemr[MEMREGIONS]; /* Hard code memory */
152 1.1.2.2 thorpej struct mem_region availmemr[MEMREGIONS]; /* Who's supposed to set these up? */
153 1.1.2.2 thorpej
154 1.1.2.2 thorpej struct board_cfg_data board_data;
155 1.1.2.2 thorpej struct propdb *board_info = NULL;
156 1.1.2.2 thorpej
157 1.1.2.2 thorpej void
158 1.1.2.2 thorpej initppc(u_int startkernel, u_int endkernel, char *args, void *info_block)
159 1.1.2.2 thorpej {
160 1.1.2.2 thorpej extern int defaulttrap, defaultsize;
161 1.1.2.2 thorpej extern int sctrap, scsize;
162 1.1.2.2 thorpej extern int alitrap, alisize;
163 1.1.2.2 thorpej extern int dsitrap, dsisize;
164 1.1.2.2 thorpej extern int isitrap, isisize;
165 1.1.2.2 thorpej extern int mchktrap, mchksize;
166 1.1.2.2 thorpej extern int tlbimiss4xx, tlbim4size;
167 1.1.2.2 thorpej extern int tlbdmiss4xx, tlbdm4size;
168 1.1.2.2 thorpej extern int pitfitwdog, pitfitwdogsize;
169 1.1.2.2 thorpej extern int debugtrap, debugsize;
170 1.1.2.2 thorpej extern int errata51handler, errata51size;
171 1.1.2.2 thorpej #ifdef DDB
172 1.1.2.2 thorpej extern int ddblow, ddbsize;
173 1.1.2.2 thorpej #endif
174 1.1.2.2 thorpej #ifdef IPKDB
175 1.1.2.2 thorpej extern int ipkdblow, ipkdbsize;
176 1.1.2.2 thorpej #endif
177 1.1.2.2 thorpej int exc;
178 1.1.2.2 thorpej extern char _edata, _end;
179 1.1.2.3 thorpej struct cpu_info * const ci = &cpu_info_store;
180 1.1.2.2 thorpej
181 1.1.2.2 thorpej /* Disable all external interrupts */
182 1.1.2.2 thorpej mtdcr(DCR_UIC0_ER, 0);
183 1.1.2.2 thorpej
184 1.1.2.2 thorpej /* Initialize cache info for memcpy, etc. */
185 1.1.2.2 thorpej cpu_probe_cache();
186 1.1.2.2 thorpej
187 1.1.2.2 thorpej memset(&_edata, 0, &_end-&_edata); /* Clear BSS area */
188 1.1.2.2 thorpej
189 1.1.2.2 thorpej /* Save info block */
190 1.1.2.2 thorpej if (info_block == NULL)
191 1.1.2.2 thorpej /* XXX why isn't r3 set correctly?!?!? */
192 1.1.2.2 thorpej info_block = (void *)0x8e10;
193 1.1.2.2 thorpej memcpy(&board_data, info_block, sizeof(board_data));
194 1.1.2.2 thorpej
195 1.1.2.2 thorpej memset(physmemr, 0, sizeof physmemr);
196 1.1.2.2 thorpej memset(availmemr, 0, sizeof availmemr);
197 1.1.2.2 thorpej physmemr[0].start = 0;
198 1.1.2.2 thorpej physmemr[0].size = board_data.mem_size & ~PGOFSET;
199 1.1.2.2 thorpej /* Lower memory reserved by eval board BIOS */
200 1.1.2.2 thorpej availmemr[0].start = startkernel;
201 1.1.2.2 thorpej availmemr[0].size = board_data.mem_size - availmemr[0].start;
202 1.1.2.2 thorpej
203 1.1.2.3 thorpej /*
204 1.1.2.3 thorpej * Initialize lwp0 and current pcb and pmap pointers.
205 1.1.2.3 thorpej */
206 1.1.2.3 thorpej lwp0.l_cpu = ci;
207 1.1.2.3 thorpej lwp0.l_addr = proc0paddr;
208 1.1.2.3 thorpej memset(lwp0.l_addr, 0, sizeof *lwp0.l_addr);
209 1.1.2.2 thorpej
210 1.1.2.2 thorpej curpcb = &proc0paddr->u_pcb;
211 1.1.2.2 thorpej curpm = curpcb->pcb_pmreal = curpcb->pcb_pm = pmap_kernel();
212 1.1.2.2 thorpej
213 1.1.2.2 thorpej /*
214 1.1.2.2 thorpej * Set up trap vectors
215 1.1.2.2 thorpej */
216 1.1.2.2 thorpej for (exc = EXC_RSVD; exc <= EXC_LAST; exc += 0x100)
217 1.1.2.2 thorpej switch (exc) {
218 1.1.2.2 thorpej default:
219 1.1.2.2 thorpej memcpy((void *)exc, &defaulttrap, (size_t)&defaultsize);
220 1.1.2.2 thorpej break;
221 1.1.2.2 thorpej case EXC_EXI:
222 1.1.2.2 thorpej /*
223 1.1.2.2 thorpej * This one is (potentially) installed during autoconf
224 1.1.2.2 thorpej */
225 1.1.2.2 thorpej break;
226 1.1.2.2 thorpej case EXC_SC:
227 1.1.2.2 thorpej memcpy((void *)EXC_SC, &sctrap, (size_t)&scsize);
228 1.1.2.2 thorpej break;
229 1.1.2.2 thorpej case EXC_ALI:
230 1.1.2.2 thorpej memcpy((void *)EXC_ALI, &alitrap, (size_t)&alisize);
231 1.1.2.2 thorpej break;
232 1.1.2.2 thorpej case EXC_DSI:
233 1.1.2.2 thorpej memcpy((void *)EXC_DSI, &dsitrap, (size_t)&dsisize);
234 1.1.2.2 thorpej break;
235 1.1.2.2 thorpej case EXC_ISI:
236 1.1.2.2 thorpej memcpy((void *)EXC_ISI, &isitrap, (size_t)&isisize);
237 1.1.2.2 thorpej break;
238 1.1.2.2 thorpej case EXC_MCHK:
239 1.1.2.2 thorpej memcpy((void *)EXC_MCHK, &mchktrap, (size_t)&mchksize);
240 1.1.2.2 thorpej break;
241 1.1.2.2 thorpej case EXC_ITMISS:
242 1.1.2.2 thorpej memcpy((void *)EXC_ITMISS, &tlbimiss4xx,
243 1.1.2.2 thorpej (size_t)&tlbim4size);
244 1.1.2.2 thorpej break;
245 1.1.2.2 thorpej case EXC_DTMISS:
246 1.1.2.2 thorpej memcpy((void *)EXC_DTMISS, &tlbdmiss4xx,
247 1.1.2.2 thorpej (size_t)&tlbdm4size);
248 1.1.2.2 thorpej break;
249 1.1.2.2 thorpej /*
250 1.1.2.2 thorpej * EXC_PIT, EXC_FIT, EXC_WDOG handlers
251 1.1.2.2 thorpej * are spaced by 0x10 bytes only..
252 1.1.2.2 thorpej */
253 1.1.2.2 thorpej case EXC_PIT:
254 1.1.2.2 thorpej memcpy((void *)EXC_PIT, &pitfitwdog,
255 1.1.2.2 thorpej (size_t)&pitfitwdogsize);
256 1.1.2.2 thorpej break;
257 1.1.2.2 thorpej case EXC_DEBUG:
258 1.1.2.2 thorpej memcpy((void *)EXC_DEBUG, &debugtrap,
259 1.1.2.2 thorpej (size_t)&debugsize);
260 1.1.2.2 thorpej break;
261 1.1.2.2 thorpej case EXC_DTMISS|EXC_ALI:
262 1.1.2.2 thorpej /* PPC405GP Rev D errata item 51 */
263 1.1.2.2 thorpej memcpy((void *)(EXC_DTMISS|EXC_ALI), &errata51handler,
264 1.1.2.2 thorpej (size_t)&errata51size);
265 1.1.2.2 thorpej break;
266 1.1.2.2 thorpej case EXC_PGM:
267 1.1.2.2 thorpej #if defined(DDB)
268 1.1.2.2 thorpej memcpy((void *)exc, &ddblow, (size_t)&ddbsize);
269 1.1.2.2 thorpej #elif defined(IPKDB)
270 1.1.2.2 thorpej memcpy((void *)exc, &ipkdblow, (size_t)&ipkdbsize);
271 1.1.2.2 thorpej #else
272 1.1.2.2 thorpej memcpy((void *)exc, &pgmtrap, (size_t)&pgmsize);
273 1.1.2.2 thorpej #endif
274 1.1.2.2 thorpej break;
275 1.1.2.2 thorpej }
276 1.1.2.2 thorpej
277 1.1.2.2 thorpej __syncicache((void *)EXC_RST, EXC_LAST - EXC_RST + 0x100);
278 1.1.2.2 thorpej mtspr(SPR_EVPR, 0); /* Set Exception vector base */
279 1.1.2.2 thorpej consinit();
280 1.1.2.2 thorpej
281 1.1.2.2 thorpej /* Handle trap instruction as PGM exception */
282 1.1.2.2 thorpej {
283 1.1.2.2 thorpej int dbcr0;
284 1.1.2.2 thorpej asm volatile("mfspr %0,%1":"=r"(dbcr0):"K"(SPR_DBCR0));
285 1.1.2.2 thorpej asm volatile("mtspr %0,%1"::"K"(SPR_DBCR0),"r"(dbcr0 & ~DBCR0_TDE));
286 1.1.2.2 thorpej }
287 1.1.2.2 thorpej
288 1.1.2.2 thorpej /*
289 1.1.2.2 thorpej * external interrupt handler install
290 1.1.2.2 thorpej */
291 1.1.2.2 thorpej install_extint(ext_intr);
292 1.1.2.2 thorpej
293 1.1.2.2 thorpej /*
294 1.1.2.2 thorpej * Now enable translation (and machine checks/recoverable interrupts).
295 1.1.2.2 thorpej */
296 1.1.2.2 thorpej asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
297 1.1.2.2 thorpej : : "r"(0), "K"(PSL_IR|PSL_DR));
298 1.1.2.2 thorpej /* XXXX PSL_ME - With ME set kernel gets stuck... */
299 1.1.2.2 thorpej
300 1.1.2.2 thorpej uvm_setpagesize();
301 1.1.2.2 thorpej
302 1.1.2.2 thorpej /*
303 1.1.2.2 thorpej * Initialize pmap module.
304 1.1.2.2 thorpej */
305 1.1.2.2 thorpej pmap_bootstrap(startkernel, endkernel);
306 1.1.2.2 thorpej
307 1.1.2.2 thorpej consinit();
308 1.1.2.2 thorpej
309 1.1.2.2 thorpej #ifdef DEBUG
310 1.1.2.2 thorpej printf("Board config data:\n");
311 1.1.2.2 thorpej printf(" usr_config_ver = %s\n", board_data.usr_config_ver);
312 1.1.2.2 thorpej printf(" rom_sw_ver = %s\n", board_data.rom_sw_ver);
313 1.1.2.2 thorpej printf(" mem_size = %u\n", board_data.mem_size);
314 1.1.2.2 thorpej printf(" mac_address_local = %02x:%02x:%02x:%02x:%02x:%02x\n",
315 1.1.2.2 thorpej board_data.mac_address_local[0], board_data.mac_address_local[1],
316 1.1.2.2 thorpej board_data.mac_address_local[2], board_data.mac_address_local[3],
317 1.1.2.2 thorpej board_data.mac_address_local[4], board_data.mac_address_local[5]);
318 1.1.2.2 thorpej printf(" mac_address_pci = %02x:%02x:%02x:%02x:%02x:%02x\n",
319 1.1.2.2 thorpej board_data.mac_address_pci[0], board_data.mac_address_pci[1],
320 1.1.2.2 thorpej board_data.mac_address_pci[2], board_data.mac_address_pci[3],
321 1.1.2.2 thorpej board_data.mac_address_pci[4], board_data.mac_address_pci[5]);
322 1.1.2.2 thorpej printf(" processor_speed = %u\n", board_data.processor_speed);
323 1.1.2.2 thorpej printf(" plb_speed = %u\n", board_data.plb_speed);
324 1.1.2.2 thorpej printf(" pci_speed = %u\n", board_data.pci_speed);
325 1.1.2.2 thorpej #endif
326 1.1.2.2 thorpej
327 1.1.2.2 thorpej #ifdef DDB
328 1.1.2.2 thorpej ddb_init((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
329 1.1.2.2 thorpej if (boothowto & RB_KDB)
330 1.1.2.2 thorpej Debugger();
331 1.1.2.2 thorpej #endif
332 1.1.2.2 thorpej #ifdef IPKDB
333 1.1.2.2 thorpej /*
334 1.1.2.2 thorpej * Now trap to IPKDB
335 1.1.2.2 thorpej */
336 1.1.2.2 thorpej ipkdb_init();
337 1.1.2.2 thorpej if (boothowto & RB_KDB)
338 1.1.2.2 thorpej ipkdb_connect(0);
339 1.1.2.2 thorpej #endif
340 1.1.2.2 thorpej fake_mapiodev = 0;
341 1.1.2.2 thorpej }
342 1.1.2.2 thorpej
343 1.1.2.2 thorpej static void
344 1.1.2.2 thorpej install_extint(void (*handler)(void))
345 1.1.2.2 thorpej {
346 1.1.2.2 thorpej extern int extint, extsize;
347 1.1.2.2 thorpej extern u_long extint_call;
348 1.1.2.2 thorpej u_long offset = (u_long)handler - (u_long)&extint_call;
349 1.1.2.2 thorpej int omsr, msr;
350 1.1.2.2 thorpej
351 1.1.2.2 thorpej #ifdef DIAGNOSTIC
352 1.1.2.2 thorpej if (offset > 0x1ffffff)
353 1.1.2.2 thorpej panic("install_extint: too far away");
354 1.1.2.2 thorpej #endif
355 1.1.2.2 thorpej asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
356 1.1.2.2 thorpej : "=r"(omsr), "=r"(msr) : "K"((u_short)~PSL_EE));
357 1.1.2.2 thorpej extint_call = (extint_call & 0xfc000003) | offset;
358 1.1.2.2 thorpej memcpy((void *)EXC_EXI, &extint, (size_t)&extsize);
359 1.1.2.2 thorpej __syncicache((void *)&extint_call, sizeof extint_call);
360 1.1.2.2 thorpej __syncicache((void *)EXC_EXI, (int)&extsize);
361 1.1.2.2 thorpej asm volatile ("mtmsr %0" :: "r"(omsr));
362 1.1.2.2 thorpej }
363 1.1.2.2 thorpej
364 1.1.2.2 thorpej /*
365 1.1.2.2 thorpej * Machine dependent startup code.
366 1.1.2.2 thorpej */
367 1.1.2.2 thorpej
368 1.1.2.2 thorpej char msgbuf[MSGBUFSIZE];
369 1.1.2.2 thorpej
370 1.1.2.2 thorpej void
371 1.1.2.2 thorpej cpu_startup(void)
372 1.1.2.2 thorpej {
373 1.1.2.2 thorpej caddr_t v;
374 1.1.2.2 thorpej vaddr_t minaddr, maxaddr;
375 1.1.2.2 thorpej u_int sz, i, base, residual;
376 1.1.2.2 thorpej char pbuf[9];
377 1.1.2.2 thorpej
378 1.1.2.2 thorpej /*
379 1.1.2.2 thorpej * Initialize error message buffer (at end of core).
380 1.1.2.2 thorpej */
381 1.1.2.2 thorpej #if 0 /* For some reason this fails... --Artem
382 1.1.2.2 thorpej * Besides, do we really have to put it at the end of core?
383 1.1.2.2 thorpej * Let's use static buffer for now
384 1.1.2.2 thorpej */
385 1.1.2.2 thorpej if (!(msgbuf_vaddr = uvm_km_alloc(kernel_map, round_page(MSGBUFSIZE))))
386 1.1.2.2 thorpej panic("startup: no room for message buffer");
387 1.1.2.2 thorpej for (i = 0; i < btoc(MSGBUFSIZE); i++)
388 1.1.2.2 thorpej pmap_kenter_pa(msgbuf_vaddr + i * NBPG,
389 1.1.2.2 thorpej msgbuf_paddr + i * NBPG, VM_PROT_READ|VM_PROT_WRITE);
390 1.1.2.2 thorpej initmsgbuf((caddr_t)msgbuf_vaddr, round_page(MSGBUFSIZE));
391 1.1.2.2 thorpej #else
392 1.1.2.2 thorpej initmsgbuf((caddr_t)msgbuf, round_page(MSGBUFSIZE));
393 1.1.2.2 thorpej #endif
394 1.1.2.2 thorpej
395 1.1.2.2 thorpej
396 1.1.2.2 thorpej printf("%s", version);
397 1.1.2.2 thorpej printf("Walnut PowerPC 405GP Evaluation Board\n");
398 1.1.2.2 thorpej
399 1.1.2.2 thorpej format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
400 1.1.2.2 thorpej printf("total memory = %s\n", pbuf);
401 1.1.2.2 thorpej
402 1.1.2.2 thorpej /*
403 1.1.2.2 thorpej * Find out how much space we need, allocate it,
404 1.1.2.2 thorpej * and then give everything true virtual addresses.
405 1.1.2.2 thorpej */
406 1.1.2.2 thorpej sz = (u_int)allocsys(NULL, NULL);
407 1.1.2.2 thorpej if ((v = (caddr_t)uvm_km_zalloc(kernel_map, round_page(sz))) == 0)
408 1.1.2.2 thorpej panic("startup: no room for tables");
409 1.1.2.2 thorpej if (allocsys(v, NULL) - v != sz)
410 1.1.2.2 thorpej panic("startup: table size inconsistency");
411 1.1.2.2 thorpej
412 1.1.2.2 thorpej /*
413 1.1.2.2 thorpej * Now allocate buffers proper. They are different than the above
414 1.1.2.2 thorpej * in that they usually occupy more virtual memory than physical.
415 1.1.2.2 thorpej */
416 1.1.2.2 thorpej sz = MAXBSIZE * nbuf;
417 1.1.2.2 thorpej minaddr = 0;
418 1.1.2.2 thorpej if (uvm_map(kernel_map, (vaddr_t *)&minaddr, round_page(sz),
419 1.1.2.2 thorpej NULL, UVM_UNKNOWN_OFFSET, 0,
420 1.1.2.2 thorpej UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
421 1.1.2.2 thorpej UVM_ADV_NORMAL, 0)) != 0)
422 1.1.2.2 thorpej panic("startup: cannot allocate VM for buffers");
423 1.1.2.2 thorpej buffers = (char *)minaddr;
424 1.1.2.2 thorpej base = bufpages / nbuf;
425 1.1.2.2 thorpej residual = bufpages % nbuf;
426 1.1.2.2 thorpej if (base >= MAXBSIZE) {
427 1.1.2.2 thorpej /* Don't want to alloc more physical mem than ever needed */
428 1.1.2.2 thorpej base = MAXBSIZE;
429 1.1.2.2 thorpej residual = 0;
430 1.1.2.2 thorpej }
431 1.1.2.2 thorpej for (i = 0; i < nbuf; i++) {
432 1.1.2.2 thorpej vsize_t curbufsize;
433 1.1.2.2 thorpej vaddr_t curbuf;
434 1.1.2.2 thorpej struct vm_page *pg;
435 1.1.2.2 thorpej
436 1.1.2.2 thorpej curbuf = (vaddr_t)buffers + i * MAXBSIZE;
437 1.1.2.2 thorpej curbufsize = NBPG * (i < residual ? base + 1 : base);
438 1.1.2.2 thorpej
439 1.1.2.2 thorpej while (curbufsize) {
440 1.1.2.2 thorpej pg = uvm_pagealloc(NULL, 0, NULL, 0);
441 1.1.2.2 thorpej if (pg == NULL)
442 1.1.2.2 thorpej panic("cpu_startup: not enough memory for "
443 1.1.2.2 thorpej "buffer cache");
444 1.1.2.2 thorpej pmap_kenter_pa(curbuf, VM_PAGE_TO_PHYS(pg),
445 1.1.2.2 thorpej VM_PROT_READ | VM_PROT_WRITE);
446 1.1.2.2 thorpej curbuf += PAGE_SIZE;
447 1.1.2.2 thorpej curbufsize -= PAGE_SIZE;
448 1.1.2.2 thorpej }
449 1.1.2.2 thorpej }
450 1.1.2.2 thorpej
451 1.1.2.2 thorpej /*
452 1.1.2.2 thorpej * Allocate a submap for exec arguments. This map effectively
453 1.1.2.2 thorpej * limits the number of processes exec'ing at any time.
454 1.1.2.2 thorpej */
455 1.1.2.2 thorpej exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
456 1.1.2.2 thorpej 16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
457 1.1.2.2 thorpej
458 1.1.2.2 thorpej /*
459 1.1.2.2 thorpej * Allocate a submap for physio
460 1.1.2.2 thorpej */
461 1.1.2.2 thorpej phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
462 1.1.2.2 thorpej VM_PHYS_SIZE, 0, FALSE, NULL);
463 1.1.2.2 thorpej
464 1.1.2.2 thorpej /*
465 1.1.2.2 thorpej * No need to allocate an mbuf cluster submap. Mbuf clusters
466 1.1.2.2 thorpej * are allocated via the pool allocator, and we use direct-mapped
467 1.1.2.2 thorpej * pool pages.
468 1.1.2.2 thorpej */
469 1.1.2.2 thorpej
470 1.1.2.2 thorpej format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
471 1.1.2.2 thorpej printf("avail memory = %s\n", pbuf);
472 1.1.2.2 thorpej format_bytes(pbuf, sizeof(pbuf), bufpages * NBPG);
473 1.1.2.2 thorpej printf("using %u buffers containing %s of memory\n", nbuf, pbuf);
474 1.1.2.2 thorpej
475 1.1.2.2 thorpej /*
476 1.1.2.2 thorpej * Set up the buffers.
477 1.1.2.2 thorpej */
478 1.1.2.2 thorpej bufinit();
479 1.1.2.2 thorpej
480 1.1.2.2 thorpej /*
481 1.1.2.2 thorpej * Set up the board properties database.
482 1.1.2.2 thorpej */
483 1.1.2.2 thorpej if (!(board_info = propdb_create("board info")))
484 1.1.2.2 thorpej panic("Cannot create board info database");
485 1.1.2.2 thorpej
486 1.1.2.2 thorpej if (board_info_set("mem-size", &board_data.mem_size,
487 1.1.2.2 thorpej sizeof(&board_data.mem_size), PROP_CONST, 0))
488 1.1.2.2 thorpej panic("setting mem-size");
489 1.1.2.2 thorpej if (board_info_set("emac-mac-addr", &board_data.mac_address_local,
490 1.1.2.2 thorpej sizeof(&board_data.mac_address_local), PROP_CONST, 0))
491 1.1.2.2 thorpej panic("setting emac-mac-addr");
492 1.1.2.2 thorpej if (board_info_set("sip0-mac-addr", &board_data.mac_address_pci,
493 1.1.2.2 thorpej sizeof(&board_data.mac_address_pci), PROP_CONST, 0))
494 1.1.2.2 thorpej panic("setting sip0-mac-addr");
495 1.1.2.2 thorpej if (board_info_set("processor-frequency", &board_data.processor_speed,
496 1.1.2.2 thorpej sizeof(&board_data.processor_speed), PROP_CONST, 0))
497 1.1.2.2 thorpej panic("setting processor-frequency");
498 1.1.2.2 thorpej #if NCOM > 0
499 1.1.2.2 thorpej {
500 1.1.2.2 thorpej unsigned int comfreq = COM_FREQ * 6;
501 1.1.2.2 thorpej if (board_info_set("com-opb-frequency", &comfreq,
502 1.1.2.2 thorpej sizeof(&comfreq), 0, 0))
503 1.1.2.2 thorpej panic("setting com-opb-frequency");
504 1.1.2.2 thorpej }
505 1.1.2.2 thorpej #endif
506 1.1.2.2 thorpej }
507 1.1.2.2 thorpej
508 1.1.2.2 thorpej
509 1.1.2.2 thorpej static void
510 1.1.2.2 thorpej dumpsys(void)
511 1.1.2.2 thorpej {
512 1.1.2.2 thorpej
513 1.1.2.2 thorpej printf("dumpsys: TBD\n");
514 1.1.2.2 thorpej }
515 1.1.2.2 thorpej
516 1.1.2.2 thorpej /*
517 1.1.2.2 thorpej * Soft networking interrupts.
518 1.1.2.2 thorpej */
519 1.1.2.2 thorpej void
520 1.1.2.2 thorpej softnet(void)
521 1.1.2.2 thorpej {
522 1.1.2.2 thorpej int isr;
523 1.1.2.2 thorpej
524 1.1.2.2 thorpej isr = netisr;
525 1.1.2.2 thorpej netisr = 0;
526 1.1.2.2 thorpej
527 1.1.2.2 thorpej #define DONETISR(bit, fn) do { \
528 1.1.2.2 thorpej if (isr & (1 << bit)) \
529 1.1.2.2 thorpej fn(); \
530 1.1.2.2 thorpej } while (0)
531 1.1.2.2 thorpej
532 1.1.2.2 thorpej #include <net/netisr_dispatch.h>
533 1.1.2.2 thorpej
534 1.1.2.2 thorpej #undef DONETISR
535 1.1.2.2 thorpej
536 1.1.2.2 thorpej }
537 1.1.2.2 thorpej
538 1.1.2.2 thorpej /*
539 1.1.2.2 thorpej * Soft tty interrupts.
540 1.1.2.2 thorpej */
541 1.1.2.2 thorpej void
542 1.1.2.2 thorpej softserial(void)
543 1.1.2.2 thorpej {
544 1.1.2.2 thorpej #if NCOM > 0
545 1.1.2.2 thorpej void comsoft(void); /* XXX from dev/ic/com.c */
546 1.1.2.2 thorpej
547 1.1.2.2 thorpej comsoft();
548 1.1.2.2 thorpej #endif
549 1.1.2.2 thorpej }
550 1.1.2.2 thorpej
551 1.1.2.2 thorpej /*
552 1.1.2.2 thorpej * Halt or reboot the machine after syncing/dumping according to howto.
553 1.1.2.2 thorpej */
554 1.1.2.2 thorpej void
555 1.1.2.2 thorpej cpu_reboot(int howto, char *what)
556 1.1.2.2 thorpej {
557 1.1.2.2 thorpej static int syncing;
558 1.1.2.2 thorpej static char str[256];
559 1.1.2.2 thorpej char *ap = str, *ap1 = ap;
560 1.1.2.2 thorpej
561 1.1.2.2 thorpej boothowto = howto;
562 1.1.2.2 thorpej if (!cold && !(howto & RB_NOSYNC) && !syncing) {
563 1.1.2.2 thorpej syncing = 1;
564 1.1.2.2 thorpej vfs_shutdown(); /* sync */
565 1.1.2.2 thorpej resettodr(); /* set wall clock */
566 1.1.2.2 thorpej }
567 1.1.2.2 thorpej
568 1.1.2.2 thorpej splhigh();
569 1.1.2.2 thorpej
570 1.1.2.2 thorpej if (!cold && (howto & RB_DUMP))
571 1.1.2.2 thorpej dumpsys();
572 1.1.2.2 thorpej
573 1.1.2.2 thorpej doshutdownhooks();
574 1.1.2.2 thorpej
575 1.1.2.2 thorpej if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
576 1.1.2.2 thorpej /* Power off here if we know how...*/
577 1.1.2.2 thorpej }
578 1.1.2.2 thorpej
579 1.1.2.2 thorpej if (howto & RB_HALT) {
580 1.1.2.2 thorpej printf("halted\n\n");
581 1.1.2.2 thorpej
582 1.1.2.2 thorpej goto reboot; /* XXX for now... */
583 1.1.2.2 thorpej
584 1.1.2.2 thorpej #ifdef DDB
585 1.1.2.2 thorpej printf("dropping to debugger\n");
586 1.1.2.2 thorpej while(1)
587 1.1.2.2 thorpej Debugger();
588 1.1.2.2 thorpej #endif
589 1.1.2.2 thorpej }
590 1.1.2.2 thorpej
591 1.1.2.2 thorpej printf("rebooting\n\n");
592 1.1.2.2 thorpej if (what && *what) {
593 1.1.2.2 thorpej if (strlen(what) > sizeof str - 5)
594 1.1.2.2 thorpej printf("boot string too large, ignored\n");
595 1.1.2.2 thorpej else {
596 1.1.2.2 thorpej strcpy(str, what);
597 1.1.2.2 thorpej ap1 = ap = str + strlen(str);
598 1.1.2.2 thorpej *ap++ = ' ';
599 1.1.2.2 thorpej }
600 1.1.2.2 thorpej }
601 1.1.2.2 thorpej *ap++ = '-';
602 1.1.2.2 thorpej if (howto & RB_SINGLE)
603 1.1.2.2 thorpej *ap++ = 's';
604 1.1.2.2 thorpej if (howto & RB_KDB)
605 1.1.2.2 thorpej *ap++ = 'd';
606 1.1.2.2 thorpej *ap++ = 0;
607 1.1.2.2 thorpej if (ap[-2] == '-')
608 1.1.2.2 thorpej *ap1 = 0;
609 1.1.2.2 thorpej
610 1.1.2.2 thorpej /* flush cache for msgbuf */
611 1.1.2.2 thorpej __syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE));
612 1.1.2.2 thorpej
613 1.1.2.2 thorpej reboot:
614 1.1.2.2 thorpej ppc4xx_reset();
615 1.1.2.2 thorpej
616 1.1.2.2 thorpej printf("ppc4xx_reset() failed!\n");
617 1.1.2.2 thorpej #ifdef DDB
618 1.1.2.2 thorpej while(1)
619 1.1.2.2 thorpej Debugger();
620 1.1.2.2 thorpej #else
621 1.1.2.2 thorpej while (1)
622 1.1.2.2 thorpej /* nothing */;
623 1.1.2.2 thorpej #endif
624 1.1.2.2 thorpej }
625 1.1.2.2 thorpej
626 1.1.2.2 thorpej int
627 1.1.2.2 thorpej lcsplx(int ipl)
628 1.1.2.2 thorpej {
629 1.1.2.2 thorpej
630 1.1.2.2 thorpej return spllower(ipl); /* XXX */
631 1.1.2.2 thorpej }
632 1.1.2.2 thorpej
633 1.1.2.2 thorpej void
634 1.1.2.2 thorpej mem_regions(struct mem_region **mem, struct mem_region **avail)
635 1.1.2.2 thorpej {
636 1.1.2.2 thorpej
637 1.1.2.2 thorpej *mem = physmemr;
638 1.1.2.2 thorpej *avail = availmemr;
639 1.1.2.2 thorpej }
640