machdep.c revision 1.65 1 1.65 chs /* $NetBSD: machdep.c,v 1.65 2001/06/02 18:09:18 chs Exp $ */
2 1.1 ws
3 1.1 ws /*
4 1.1 ws * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 1.1 ws * Copyright (C) 1995, 1996 TooLs GmbH.
6 1.1 ws * All rights reserved.
7 1.1 ws *
8 1.1 ws * Redistribution and use in source and binary forms, with or without
9 1.1 ws * modification, are permitted provided that the following conditions
10 1.1 ws * are met:
11 1.1 ws * 1. Redistributions of source code must retain the above copyright
12 1.1 ws * notice, this list of conditions and the following disclaimer.
13 1.1 ws * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 ws * notice, this list of conditions and the following disclaimer in the
15 1.1 ws * documentation and/or other materials provided with the distribution.
16 1.1 ws * 3. All advertising materials mentioning features or use of this software
17 1.1 ws * must display the following acknowledgement:
18 1.1 ws * This product includes software developed by TooLs GmbH.
19 1.1 ws * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 1.1 ws * derived from this software without specific prior written permission.
21 1.1 ws *
22 1.1 ws * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 1.1 ws * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 ws * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 ws * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 1.1 ws * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 1.1 ws * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 1.1 ws * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 1.1 ws * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 1.1 ws * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 1.1 ws * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 ws */
33 1.21 jonathan
34 1.27 thorpej #include "opt_compat_netbsd.h"
35 1.21 jonathan #include "opt_ddb.h"
36 1.1 ws
37 1.1 ws #include <sys/param.h>
38 1.1 ws #include <sys/buf.h>
39 1.1 ws #include <sys/exec.h>
40 1.1 ws #include <sys/malloc.h>
41 1.1 ws #include <sys/map.h>
42 1.1 ws #include <sys/mbuf.h>
43 1.1 ws #include <sys/mount.h>
44 1.1 ws #include <sys/msgbuf.h>
45 1.1 ws #include <sys/proc.h>
46 1.1 ws #include <sys/reboot.h>
47 1.1 ws #include <sys/syscallargs.h>
48 1.1 ws #include <sys/syslog.h>
49 1.1 ws #include <sys/systm.h>
50 1.43 thorpej #include <sys/kernel.h>
51 1.1 ws #include <sys/user.h>
52 1.59 jdolecek #include <sys/boot_flag.h>
53 1.1 ws
54 1.19 sakamoto #include <uvm/uvm_extern.h>
55 1.19 sakamoto
56 1.1 ws #include <net/netisr.h>
57 1.1 ws
58 1.1 ws #include <machine/bat.h>
59 1.1 ws #include <machine/pmap.h>
60 1.1 ws #include <machine/powerpc.h>
61 1.1 ws #include <machine/trap.h>
62 1.54 thorpej
63 1.54 thorpej /* Our exported CPU info; we can have only one. */
64 1.54 thorpej struct cpu_info cpu_info_store;
65 1.1 ws
66 1.1 ws /*
67 1.1 ws * Global variables used here and there
68 1.1 ws */
69 1.65 chs struct vm_map *exec_map = NULL;
70 1.65 chs struct vm_map *mb_map = NULL;
71 1.65 chs struct vm_map *phys_map = NULL;
72 1.19 sakamoto
73 1.1 ws struct pcb *curpcb;
74 1.1 ws struct pmap *curpm;
75 1.1 ws struct proc *fpuproc;
76 1.1 ws
77 1.1 ws extern struct user *proc0paddr;
78 1.1 ws
79 1.1 ws struct bat battable[16];
80 1.1 ws
81 1.1 ws int astpending;
82 1.1 ws
83 1.1 ws char *bootpath;
84 1.1 ws
85 1.39 thorpej paddr_t msgbuf_paddr;
86 1.39 thorpej vaddr_t msgbuf_vaddr;
87 1.18 sakamoto
88 1.60 thorpej int lcsplx(int); /* called from locore.S */
89 1.60 thorpej
90 1.7 thorpej static int fake_spl __P((void));
91 1.7 thorpej static int fake_splx __P((int));
92 1.7 thorpej static void fake_setsoft __P((void));
93 1.7 thorpej static void fake_clock_return __P((struct clockframe *, int));
94 1.1 ws static void fake_irq_establish __P((int, int, void (*)(void *), void *));
95 1.1 ws
96 1.1 ws struct machvec machine_interface = {
97 1.44 wrstuden fake_spl,
98 1.7 thorpej fake_spl,
99 1.7 thorpej fake_spl,
100 1.7 thorpej fake_spl,
101 1.7 thorpej fake_spl,
102 1.7 thorpej fake_spl,
103 1.7 thorpej fake_spl,
104 1.7 thorpej fake_spl,
105 1.7 thorpej fake_spl,
106 1.7 thorpej fake_spl,
107 1.1 ws fake_splx,
108 1.7 thorpej fake_setsoft,
109 1.7 thorpej fake_setsoft,
110 1.7 thorpej fake_clock_return,
111 1.1 ws fake_irq_establish,
112 1.1 ws };
113 1.1 ws
114 1.1 ws void
115 1.1 ws initppc(startkernel, endkernel, args)
116 1.1 ws u_int startkernel, endkernel;
117 1.1 ws char *args;
118 1.1 ws {
119 1.1 ws int phandle, qhandle;
120 1.1 ws char name[32];
121 1.1 ws struct machvec *mp;
122 1.1 ws extern trapcode, trapsize;
123 1.50 danw extern alitrap, alisize;
124 1.1 ws extern dsitrap, dsisize;
125 1.1 ws extern isitrap, isisize;
126 1.1 ws extern decrint, decrsize;
127 1.1 ws extern tlbimiss, tlbimsize;
128 1.1 ws extern tlbdlmiss, tlbdlmsize;
129 1.1 ws extern tlbdsmiss, tlbdsmsize;
130 1.14 sakamoto #ifdef DDB
131 1.14 sakamoto extern ddblow, ddbsize;
132 1.14 sakamoto extern void *startsym, *endsym;
133 1.14 sakamoto #endif
134 1.53 ws #ifdef IPKDB
135 1.4 ws extern ipkdblow, ipkdbsize;
136 1.1 ws #endif
137 1.1 ws extern void consinit __P((void));
138 1.1 ws extern void callback __P((void *));
139 1.1 ws int exc, scratch;
140 1.1 ws
141 1.1 ws proc0.p_addr = proc0paddr;
142 1.1 ws bzero(proc0.p_addr, sizeof *proc0.p_addr);
143 1.29 sakamoto
144 1.1 ws curpcb = &proc0paddr->u_pcb;
145 1.29 sakamoto
146 1.1 ws curpm = curpcb->pcb_pmreal = curpcb->pcb_pm = pmap_kernel();
147 1.29 sakamoto
148 1.1 ws /*
149 1.1 ws * i386 port says, that this shouldn't be here,
150 1.1 ws * but I really think the console should be initialized
151 1.1 ws * as early as possible.
152 1.1 ws */
153 1.1 ws consinit();
154 1.1 ws
155 1.1 ws #ifdef __notyet__ /* Needs some rethinking regarding real/virtual OFW */
156 1.1 ws OF_set_callback(callback);
157 1.1 ws #endif
158 1.1 ws /*
159 1.1 ws * Initialize BAT registers to unmapped to not generate
160 1.1 ws * overlapping mappings below.
161 1.1 ws */
162 1.1 ws asm volatile ("mtibatu 0,%0" :: "r"(0));
163 1.1 ws asm volatile ("mtibatu 1,%0" :: "r"(0));
164 1.1 ws asm volatile ("mtibatu 2,%0" :: "r"(0));
165 1.1 ws asm volatile ("mtibatu 3,%0" :: "r"(0));
166 1.1 ws asm volatile ("mtdbatu 0,%0" :: "r"(0));
167 1.1 ws asm volatile ("mtdbatu 1,%0" :: "r"(0));
168 1.1 ws asm volatile ("mtdbatu 2,%0" :: "r"(0));
169 1.1 ws asm volatile ("mtdbatu 3,%0" :: "r"(0));
170 1.29 sakamoto
171 1.1 ws /*
172 1.1 ws * Set up initial BAT table to only map the lowest 256 MB area
173 1.1 ws */
174 1.49 thorpej battable[0].batl = BATL(0x00000000, BAT_M, BAT_PP_RW);
175 1.49 thorpej battable[0].batu = BATU(0x00000000, BAT_BL_256M, BAT_Vs);
176 1.1 ws
177 1.1 ws /*
178 1.1 ws * Now setup fixed bat registers
179 1.1 ws *
180 1.1 ws * Note that we still run in real mode, and the BAT
181 1.1 ws * registers were cleared above.
182 1.1 ws */
183 1.1 ws /* IBAT0 used for initial 256 MB segment */
184 1.1 ws asm volatile ("mtibatl 0,%0; mtibatu 0,%1"
185 1.1 ws :: "r"(battable[0].batl), "r"(battable[0].batu));
186 1.1 ws /* DBAT0 used similar */
187 1.1 ws asm volatile ("mtdbatl 0,%0; mtdbatu 0,%1"
188 1.1 ws :: "r"(battable[0].batl), "r"(battable[0].batu));
189 1.29 sakamoto
190 1.1 ws /*
191 1.1 ws * Set up trap vectors
192 1.1 ws */
193 1.1 ws for (exc = EXC_RSVD; exc <= EXC_LAST; exc += 0x100)
194 1.1 ws switch (exc) {
195 1.1 ws default:
196 1.1 ws bcopy(&trapcode, (void *)exc, (size_t)&trapsize);
197 1.1 ws break;
198 1.1 ws case EXC_EXI:
199 1.1 ws /*
200 1.1 ws * This one is (potentially) installed during autoconf
201 1.1 ws */
202 1.50 danw break;
203 1.50 danw case EXC_ALI:
204 1.50 danw bcopy(&alitrap, (void *)EXC_ALI, (size_t)&alisize);
205 1.1 ws break;
206 1.1 ws case EXC_DSI:
207 1.1 ws bcopy(&dsitrap, (void *)EXC_DSI, (size_t)&dsisize);
208 1.1 ws break;
209 1.1 ws case EXC_ISI:
210 1.1 ws bcopy(&isitrap, (void *)EXC_ISI, (size_t)&isisize);
211 1.1 ws break;
212 1.1 ws case EXC_DECR:
213 1.1 ws bcopy(&decrint, (void *)EXC_DECR, (size_t)&decrsize);
214 1.1 ws break;
215 1.1 ws case EXC_IMISS:
216 1.1 ws bcopy(&tlbimiss, (void *)EXC_IMISS, (size_t)&tlbimsize);
217 1.1 ws break;
218 1.1 ws case EXC_DLMISS:
219 1.1 ws bcopy(&tlbdlmiss, (void *)EXC_DLMISS, (size_t)&tlbdlmsize);
220 1.1 ws break;
221 1.1 ws case EXC_DSMISS:
222 1.1 ws bcopy(&tlbdsmiss, (void *)EXC_DSMISS, (size_t)&tlbdsmsize);
223 1.1 ws break;
224 1.53 ws #if defined(DDB) || defined(IPKDB)
225 1.14 sakamoto case EXC_PGM:
226 1.14 sakamoto case EXC_TRC:
227 1.14 sakamoto case EXC_BPT:
228 1.15 thorpej #if defined(DDB)
229 1.14 sakamoto bcopy(&ddblow, (void *)exc, (size_t)&ddbsize);
230 1.15 thorpej #else
231 1.15 thorpej bcopy(&ipkdblow, (void *)exc, (size_t)&ipkdbsize);
232 1.14 sakamoto #endif
233 1.1 ws break;
234 1.53 ws #endif /* DDB || IPKDB */
235 1.1 ws }
236 1.1 ws
237 1.38 ws __syncicache((void *)EXC_RST, EXC_LAST - EXC_RST + 0x100);
238 1.1 ws
239 1.1 ws /*
240 1.1 ws * Now enable translation (and machine checks/recoverable interrupts).
241 1.1 ws */
242 1.1 ws asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
243 1.1 ws : "=r"(scratch) : "K"(PSL_IR|PSL_DR|PSL_ME|PSL_RI));
244 1.1 ws
245 1.1 ws /*
246 1.1 ws * Parse arg string.
247 1.1 ws */
248 1.1 ws bootpath = args;
249 1.7 thorpej while (*++args && *args != ' ');
250 1.1 ws if (*args) {
251 1.59 jdolecek for(*args++ = 0; *args; args++)
252 1.59 jdolecek BOOT_FLAG(*args, boothowto);
253 1.29 sakamoto }
254 1.1 ws
255 1.14 sakamoto #ifdef DDB
256 1.31 thorpej /* ddb_init((int)(endsym - startsym), startsym, endsym); */
257 1.14 sakamoto #endif
258 1.53 ws #ifdef IPKDB
259 1.1 ws /*
260 1.4 ws * Now trap to IPKDB
261 1.1 ws */
262 1.4 ws ipkdb_init();
263 1.1 ws if (boothowto & RB_KDB)
264 1.4 ws ipkdb_connect(0);
265 1.1 ws #endif
266 1.16 thorpej
267 1.16 thorpej /*
268 1.16 thorpej * Set the page size.
269 1.16 thorpej */
270 1.19 sakamoto uvm_setpagesize();
271 1.1 ws
272 1.1 ws /*
273 1.1 ws * Initialize pmap module.
274 1.1 ws */
275 1.1 ws pmap_bootstrap(startkernel, endkernel);
276 1.1 ws }
277 1.1 ws
278 1.1 ws /*
279 1.1 ws * This should probably be in autoconf! XXX
280 1.1 ws */
281 1.1 ws int cpu;
282 1.1 ws char cpu_model[80];
283 1.9 veego char machine[] = MACHINE; /* from <machine/param.h> */
284 1.9 veego char machine_arch[] = MACHINE_ARCH; /* from <machine/param.h> */
285 1.1 ws
286 1.1 ws void
287 1.1 ws identifycpu()
288 1.1 ws {
289 1.1 ws int phandle, pvr;
290 1.1 ws char name[32];
291 1.1 ws
292 1.1 ws /*
293 1.1 ws * Find cpu type (Do it by OpenFirmware?)
294 1.1 ws */
295 1.1 ws asm ("mfpvr %0" : "=r"(pvr));
296 1.1 ws cpu = pvr >> 16;
297 1.1 ws switch (cpu) {
298 1.1 ws case 1:
299 1.3 christos sprintf(cpu_model, "601");
300 1.1 ws break;
301 1.1 ws case 3:
302 1.3 christos sprintf(cpu_model, "603");
303 1.1 ws break;
304 1.1 ws case 4:
305 1.3 christos sprintf(cpu_model, "604");
306 1.1 ws break;
307 1.1 ws case 5:
308 1.3 christos sprintf(cpu_model, "602");
309 1.1 ws break;
310 1.1 ws case 6:
311 1.3 christos sprintf(cpu_model, "603e");
312 1.1 ws break;
313 1.1 ws case 7:
314 1.3 christos sprintf(cpu_model, "603ev");
315 1.1 ws break;
316 1.1 ws case 9:
317 1.3 christos sprintf(cpu_model, "604ev");
318 1.1 ws break;
319 1.1 ws case 20:
320 1.3 christos sprintf(cpu_model, "620");
321 1.1 ws break;
322 1.1 ws default:
323 1.3 christos sprintf(cpu_model, "Version %x", cpu);
324 1.1 ws break;
325 1.1 ws }
326 1.1 ws sprintf(cpu_model + strlen(cpu_model), " (Revision %x)", pvr & 0xffff);
327 1.3 christos printf("CPU: %s\n", cpu_model);
328 1.1 ws }
329 1.1 ws
330 1.1 ws void
331 1.1 ws install_extint(handler)
332 1.1 ws void (*handler) __P((void));
333 1.1 ws {
334 1.1 ws extern extint, extsize;
335 1.1 ws extern u_long extint_call;
336 1.1 ws u_long offset = (u_long)handler - (u_long)&extint_call;
337 1.1 ws int omsr, msr;
338 1.29 sakamoto
339 1.1 ws #ifdef DIAGNOSTIC
340 1.1 ws if (offset > 0x1ffffff)
341 1.1 ws panic("install_extint: too far away");
342 1.1 ws #endif
343 1.7 thorpej asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
344 1.1 ws : "=r"(omsr), "=r"(msr) : "K"((u_short)~PSL_EE));
345 1.1 ws extint_call = (extint_call & 0xfc000003) | offset;
346 1.1 ws bcopy(&extint, (void *)EXC_EXI, (size_t)&extsize);
347 1.38 ws __syncicache((void *)&extint_call, sizeof extint_call);
348 1.38 ws __syncicache((void *)EXC_EXI, (int)&extsize);
349 1.1 ws asm volatile ("mtmsr %0" :: "r"(omsr));
350 1.1 ws }
351 1.1 ws
352 1.1 ws /*
353 1.1 ws * Machine dependent startup code.
354 1.1 ws */
355 1.1 ws void
356 1.1 ws cpu_startup()
357 1.1 ws {
358 1.1 ws int sz, i;
359 1.1 ws caddr_t v;
360 1.26 sakamoto paddr_t minaddr, maxaddr;
361 1.1 ws int base, residual;
362 1.40 lukem char pbuf[9];
363 1.18 sakamoto
364 1.39 thorpej proc0.p_addr = proc0paddr;
365 1.39 thorpej v = (caddr_t)proc0paddr + USPACE;
366 1.39 thorpej
367 1.18 sakamoto /*
368 1.18 sakamoto * Initialize error message buffer (at end of core).
369 1.18 sakamoto */
370 1.39 thorpej if (!(msgbuf_vaddr = uvm_km_alloc(kernel_map, round_page(MSGBUFSIZE))))
371 1.39 thorpej panic("startup: no room for message buffer");
372 1.39 thorpej for (i = 0; i < btoc(MSGBUFSIZE); i++)
373 1.39 thorpej pmap_enter(pmap_kernel(), msgbuf_vaddr + i * NBPG,
374 1.45 thorpej msgbuf_paddr + i * NBPG, VM_PROT_READ|VM_PROT_WRITE,
375 1.45 thorpej VM_PROT_READ|VM_PROT_WRITE|PMAP_WIRED);
376 1.64 thorpej pmap_update();
377 1.39 thorpej initmsgbuf((caddr_t)msgbuf_vaddr, round_page(MSGBUFSIZE));
378 1.1 ws
379 1.3 christos printf("%s", version);
380 1.1 ws identifycpu();
381 1.29 sakamoto
382 1.40 lukem format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
383 1.40 lukem printf("total memory = %s\n", pbuf);
384 1.19 sakamoto
385 1.1 ws /*
386 1.1 ws * Find out how much space we need, allocate it,
387 1.1 ws * and then give everything true virtual addresses.
388 1.1 ws */
389 1.40 lukem sz = (int)allocsys(NULL, NULL);
390 1.19 sakamoto if ((v = (caddr_t)uvm_km_zalloc(kernel_map, round_page(sz))) == 0)
391 1.19 sakamoto panic("startup: no room for tables");
392 1.40 lukem if (allocsys(v, NULL) - v != sz)
393 1.1 ws panic("startup: table size inconsistency");
394 1.19 sakamoto
395 1.1 ws /*
396 1.1 ws * Now allocate buffers proper. They are different than the above
397 1.1 ws * in that they usually occupy more virtual memory than physical.
398 1.1 ws */
399 1.1 ws sz = MAXBSIZE * nbuf;
400 1.26 sakamoto if (uvm_map(kernel_map, (vaddr_t *)&buffers, round_page(sz),
401 1.58 thorpej NULL, UVM_UNKNOWN_OFFSET, 0,
402 1.19 sakamoto UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
403 1.63 chs UVM_ADV_NORMAL, 0)) != 0)
404 1.19 sakamoto panic("startup: cannot allocate VM for buffers");
405 1.29 sakamoto minaddr = (vaddr_t)buffers;
406 1.1 ws base = bufpages / nbuf;
407 1.1 ws residual = bufpages % nbuf;
408 1.1 ws if (base >= MAXBSIZE) {
409 1.1 ws /* Don't want to alloc more physical mem than ever needed */
410 1.1 ws base = MAXBSIZE;
411 1.1 ws residual = 0;
412 1.1 ws }
413 1.1 ws for (i = 0; i < nbuf; i++) {
414 1.26 sakamoto vsize_t curbufsize;
415 1.26 sakamoto vaddr_t curbuf;
416 1.19 sakamoto struct vm_page *pg;
417 1.19 sakamoto
418 1.19 sakamoto /*
419 1.19 sakamoto * Each buffer has MAXBSIZE bytes of VM space allocated. Of
420 1.19 sakamoto * that MAXBSIZE space, we allocate and map (base+1) pages
421 1.19 sakamoto * for the first "residual" buffers, and then we allocate
422 1.19 sakamoto * "base" pages for the rest.
423 1.19 sakamoto */
424 1.26 sakamoto curbuf = (vaddr_t) buffers + (i * MAXBSIZE);
425 1.48 ragge curbufsize = NBPG * ((i < residual) ? (base+1) : base);
426 1.19 sakamoto
427 1.19 sakamoto while (curbufsize) {
428 1.36 chs pg = uvm_pagealloc(NULL, 0, NULL, 0);
429 1.19 sakamoto if (pg == NULL)
430 1.19 sakamoto panic("startup: not enough memory for "
431 1.19 sakamoto "buffer cache");
432 1.19 sakamoto pmap_enter(kernel_map->pmap, curbuf,
433 1.34 mycroft VM_PAGE_TO_PHYS(pg), VM_PROT_READ|VM_PROT_WRITE,
434 1.46 kleink VM_PROT_READ|VM_PROT_WRITE|PMAP_WIRED);
435 1.19 sakamoto curbuf += PAGE_SIZE;
436 1.19 sakamoto curbufsize -= PAGE_SIZE;
437 1.19 sakamoto }
438 1.1 ws }
439 1.64 thorpej pmap_update();
440 1.1 ws
441 1.1 ws /*
442 1.1 ws * Allocate a submap for exec arguments. This map effectively
443 1.1 ws * limits the number of processes exec'ing at any time.
444 1.1 ws */
445 1.19 sakamoto exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
446 1.41 thorpej 16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
447 1.1 ws
448 1.1 ws /*
449 1.1 ws * Allocate a submap for physio
450 1.1 ws */
451 1.19 sakamoto phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
452 1.41 thorpej VM_PHYS_SIZE, 0, FALSE, NULL);
453 1.19 sakamoto
454 1.1 ws /*
455 1.37 thorpej * No need to allocate an mbuf cluster submap. Mbuf clusters
456 1.37 thorpej * are allocated via the pool allocator, and we use direct-mapped
457 1.37 thorpej * pool pages.
458 1.1 ws */
459 1.19 sakamoto
460 1.40 lukem format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
461 1.40 lukem printf("avail memory = %s\n", pbuf);
462 1.48 ragge format_bytes(pbuf, sizeof(pbuf), bufpages * NBPG);
463 1.40 lukem printf("using %d buffers containing %s of memory\n", nbuf, pbuf);
464 1.29 sakamoto
465 1.1 ws /*
466 1.1 ws * Set up the buffers.
467 1.1 ws */
468 1.1 ws bufinit();
469 1.1 ws
470 1.1 ws /*
471 1.7 thorpej * For now, use soft spl handling.
472 1.7 thorpej */
473 1.7 thorpej {
474 1.7 thorpej extern struct machvec soft_machvec;
475 1.7 thorpej
476 1.7 thorpej machine_interface = soft_machvec;
477 1.7 thorpej }
478 1.7 thorpej
479 1.7 thorpej /*
480 1.1 ws * Now allow hardware interrupts.
481 1.1 ws */
482 1.1 ws {
483 1.1 ws int msr;
484 1.29 sakamoto
485 1.1 ws splhigh();
486 1.7 thorpej asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
487 1.7 thorpej : "=r"(msr) : "K"((u_short)(PSL_EE|PSL_RI)));
488 1.1 ws }
489 1.1 ws }
490 1.1 ws
491 1.1 ws /*
492 1.1 ws * consinit
493 1.1 ws * Initialize system console.
494 1.1 ws */
495 1.1 ws void
496 1.1 ws consinit()
497 1.1 ws {
498 1.1 ws static int initted;
499 1.29 sakamoto
500 1.1 ws if (initted)
501 1.1 ws return;
502 1.1 ws initted = 1;
503 1.1 ws cninit();
504 1.1 ws }
505 1.1 ws
506 1.1 ws /*
507 1.1 ws * Crash dump handling.
508 1.1 ws */
509 1.1 ws
510 1.1 ws void
511 1.1 ws dumpsys()
512 1.1 ws {
513 1.3 christos printf("dumpsys: TBD\n");
514 1.1 ws }
515 1.1 ws
516 1.1 ws /*
517 1.1 ws * Soft networking interrupts.
518 1.1 ws */
519 1.1 ws void
520 1.1 ws softnet()
521 1.1 ws {
522 1.1 ws int isr = netisr;
523 1.1 ws
524 1.1 ws netisr = 0;
525 1.52 erh
526 1.52 erh #define DONETISR(bit, fn) do { \
527 1.52 erh if (isr & (1 << bit)) \
528 1.52 erh fn(); \
529 1.52 erh } while (0)
530 1.52 erh
531 1.52 erh #include <net/netisr_dispatch.h>
532 1.52 erh
533 1.52 erh #undef DONETISR
534 1.1 ws }
535 1.1 ws
536 1.1 ws /*
537 1.1 ws * Stray interrupts.
538 1.1 ws */
539 1.1 ws void
540 1.1 ws strayintr(irq)
541 1.1 ws int irq;
542 1.1 ws {
543 1.1 ws log(LOG_ERR, "stray interrupt %d\n", irq);
544 1.1 ws }
545 1.1 ws
546 1.1 ws /*
547 1.1 ws * Halt or reboot the machine after syncing/dumping according to howto.
548 1.1 ws */
549 1.1 ws void
550 1.5 gwr cpu_reboot(howto, what)
551 1.1 ws int howto;
552 1.1 ws char *what;
553 1.1 ws {
554 1.1 ws static int syncing;
555 1.1 ws static char str[256];
556 1.1 ws char *ap = str, *ap1 = ap;
557 1.1 ws
558 1.1 ws boothowto = howto;
559 1.1 ws if (!cold && !(howto & RB_NOSYNC) && !syncing) {
560 1.1 ws syncing = 1;
561 1.1 ws vfs_shutdown(); /* sync */
562 1.1 ws resettodr(); /* set wall clock */
563 1.1 ws }
564 1.1 ws splhigh();
565 1.1 ws if (howto & RB_HALT) {
566 1.1 ws doshutdownhooks();
567 1.3 christos printf("halted\n\n");
568 1.1 ws ppc_exit();
569 1.1 ws }
570 1.1 ws if (!cold && (howto & RB_DUMP))
571 1.1 ws dumpsys();
572 1.1 ws doshutdownhooks();
573 1.3 christos printf("rebooting\n\n");
574 1.1 ws if (what && *what) {
575 1.1 ws if (strlen(what) > sizeof str - 5)
576 1.3 christos printf("boot string too large, ignored\n");
577 1.1 ws else {
578 1.1 ws strcpy(str, what);
579 1.1 ws ap1 = ap = str + strlen(str);
580 1.1 ws *ap++ = ' ';
581 1.1 ws }
582 1.1 ws }
583 1.1 ws *ap++ = '-';
584 1.1 ws if (howto & RB_SINGLE)
585 1.1 ws *ap++ = 's';
586 1.1 ws if (howto & RB_KDB)
587 1.1 ws *ap++ = 'd';
588 1.1 ws *ap++ = 0;
589 1.1 ws if (ap[-2] == '-')
590 1.1 ws *ap1 = 0;
591 1.1 ws ppc_boot(str);
592 1.1 ws }
593 1.1 ws
594 1.1 ws /*
595 1.1 ws * OpenFirmware callback routine
596 1.1 ws */
597 1.1 ws void
598 1.1 ws callback(p)
599 1.1 ws void *p;
600 1.1 ws {
601 1.1 ws panic("callback"); /* for now XXX */
602 1.60 thorpej }
603 1.60 thorpej
604 1.60 thorpej /*
605 1.60 thorpej * Perform an `splx()' for locore.
606 1.60 thorpej */
607 1.60 thorpej int
608 1.60 thorpej lcsplx(int ipl)
609 1.60 thorpej {
610 1.60 thorpej
611 1.60 thorpej return (splx(ipl));
612 1.1 ws }
613 1.1 ws
614 1.1 ws /*
615 1.7 thorpej * Initial Machine Interface.
616 1.1 ws */
617 1.7 thorpej static int
618 1.7 thorpej fake_spl()
619 1.7 thorpej {
620 1.7 thorpej int scratch;
621 1.7 thorpej
622 1.7 thorpej asm volatile ("mfmsr %0; andi. %0,%0,%1; mtmsr %0; isync"
623 1.7 thorpej : "=r"(scratch) : "K"((u_short)~(PSL_EE|PSL_ME)));
624 1.29 sakamoto return (-1);
625 1.7 thorpej }
626 1.7 thorpej
627 1.1 ws static void
628 1.7 thorpej fake_setsoft()
629 1.7 thorpej {
630 1.7 thorpej /* Do nothing */
631 1.7 thorpej }
632 1.7 thorpej
633 1.7 thorpej static int
634 1.1 ws fake_splx(new)
635 1.1 ws int new;
636 1.1 ws {
637 1.29 sakamoto return (fake_spl());
638 1.7 thorpej }
639 1.7 thorpej
640 1.7 thorpej static void
641 1.7 thorpej fake_clock_return(frame, nticks)
642 1.7 thorpej struct clockframe *frame;
643 1.7 thorpej int nticks;
644 1.7 thorpej {
645 1.7 thorpej /* Do nothing */
646 1.1 ws }
647 1.1 ws
648 1.1 ws static void
649 1.1 ws fake_irq_establish(irq, level, handler, arg)
650 1.1 ws int irq, level;
651 1.1 ws void (*handler) __P((void *));
652 1.1 ws void *arg;
653 1.1 ws {
654 1.1 ws panic("fake_irq_establish");
655 1.1 ws }
656