machdep.c revision 1.68 1 1.68 matt /* $NetBSD: machdep.c,v 1.68 2001/08/26 02:47:41 matt 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.68 matt #include <machine/autoconf.h>
59 1.1 ws #include <machine/bat.h>
60 1.1 ws #include <machine/pmap.h>
61 1.1 ws #include <machine/powerpc.h>
62 1.1 ws #include <machine/trap.h>
63 1.54 thorpej
64 1.68 matt #include <dev/cons.h>
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.68 matt extern int trapcode, trapsize;
120 1.68 matt extern int alitrap, alisize;
121 1.68 matt extern int dsitrap, dsisize;
122 1.68 matt extern int isitrap, isisize;
123 1.68 matt extern int decrint, decrsize;
124 1.68 matt extern int tlbimiss, tlbimsize;
125 1.68 matt extern int tlbdlmiss, tlbdlmsize;
126 1.68 matt extern int tlbdsmiss, tlbdsmsize;
127 1.14 sakamoto #ifdef DDB
128 1.68 matt extern int ddblow, ddbsize;
129 1.68 matt /* extern void *startsym, *endsym; */
130 1.14 sakamoto #endif
131 1.53 ws #ifdef IPKDB
132 1.68 matt extern int ipkdblow, ipkdbsize;
133 1.1 ws #endif
134 1.1 ws int exc, scratch;
135 1.1 ws
136 1.1 ws proc0.p_addr = proc0paddr;
137 1.66 wiz memset(proc0.p_addr, 0, sizeof *proc0.p_addr);
138 1.29 sakamoto
139 1.1 ws curpcb = &proc0paddr->u_pcb;
140 1.29 sakamoto
141 1.1 ws curpm = curpcb->pcb_pmreal = curpcb->pcb_pm = pmap_kernel();
142 1.29 sakamoto
143 1.1 ws /*
144 1.1 ws * i386 port says, that this shouldn't be here,
145 1.1 ws * but I really think the console should be initialized
146 1.1 ws * as early as possible.
147 1.1 ws */
148 1.1 ws consinit();
149 1.1 ws
150 1.1 ws #ifdef __notyet__ /* Needs some rethinking regarding real/virtual OFW */
151 1.1 ws OF_set_callback(callback);
152 1.1 ws #endif
153 1.1 ws /*
154 1.1 ws * Initialize BAT registers to unmapped to not generate
155 1.1 ws * overlapping mappings below.
156 1.1 ws */
157 1.1 ws asm volatile ("mtibatu 0,%0" :: "r"(0));
158 1.1 ws asm volatile ("mtibatu 1,%0" :: "r"(0));
159 1.1 ws asm volatile ("mtibatu 2,%0" :: "r"(0));
160 1.1 ws asm volatile ("mtibatu 3,%0" :: "r"(0));
161 1.1 ws asm volatile ("mtdbatu 0,%0" :: "r"(0));
162 1.1 ws asm volatile ("mtdbatu 1,%0" :: "r"(0));
163 1.1 ws asm volatile ("mtdbatu 2,%0" :: "r"(0));
164 1.1 ws asm volatile ("mtdbatu 3,%0" :: "r"(0));
165 1.29 sakamoto
166 1.1 ws /*
167 1.1 ws * Set up initial BAT table to only map the lowest 256 MB area
168 1.1 ws */
169 1.49 thorpej battable[0].batl = BATL(0x00000000, BAT_M, BAT_PP_RW);
170 1.49 thorpej battable[0].batu = BATU(0x00000000, BAT_BL_256M, BAT_Vs);
171 1.1 ws
172 1.1 ws /*
173 1.1 ws * Now setup fixed bat registers
174 1.1 ws *
175 1.1 ws * Note that we still run in real mode, and the BAT
176 1.1 ws * registers were cleared above.
177 1.1 ws */
178 1.1 ws /* IBAT0 used for initial 256 MB segment */
179 1.1 ws asm volatile ("mtibatl 0,%0; mtibatu 0,%1"
180 1.1 ws :: "r"(battable[0].batl), "r"(battable[0].batu));
181 1.1 ws /* DBAT0 used similar */
182 1.1 ws asm volatile ("mtdbatl 0,%0; mtdbatu 0,%1"
183 1.1 ws :: "r"(battable[0].batl), "r"(battable[0].batu));
184 1.29 sakamoto
185 1.1 ws /*
186 1.1 ws * Set up trap vectors
187 1.1 ws */
188 1.1 ws for (exc = EXC_RSVD; exc <= EXC_LAST; exc += 0x100)
189 1.1 ws switch (exc) {
190 1.1 ws default:
191 1.66 wiz memcpy((void *)exc, &trapcode, (size_t)&trapsize);
192 1.1 ws break;
193 1.1 ws case EXC_EXI:
194 1.1 ws /*
195 1.1 ws * This one is (potentially) installed during autoconf
196 1.1 ws */
197 1.50 danw break;
198 1.50 danw case EXC_ALI:
199 1.66 wiz memcpy((void *)EXC_ALI, &alitrap, (size_t)&alisize);
200 1.1 ws break;
201 1.1 ws case EXC_DSI:
202 1.66 wiz memcpy((void *)EXC_DSI, &dsitrap, (size_t)&dsisize);
203 1.1 ws break;
204 1.1 ws case EXC_ISI:
205 1.66 wiz memcpy((void *)EXC_ISI, &isitrap, (size_t)&isisize);
206 1.1 ws break;
207 1.1 ws case EXC_DECR:
208 1.66 wiz memcpy((void *)EXC_DECR, &decrint, (size_t)&decrsize);
209 1.1 ws break;
210 1.1 ws case EXC_IMISS:
211 1.66 wiz memcpy((void *)EXC_IMISS, &tlbimiss, (size_t)&tlbimsize);
212 1.1 ws break;
213 1.1 ws case EXC_DLMISS:
214 1.66 wiz memcpy((void *)EXC_DLMISS, &tlbdlmiss, (size_t)&tlbdlmsize);
215 1.1 ws break;
216 1.1 ws case EXC_DSMISS:
217 1.66 wiz memcpy((void *)EXC_DSMISS, &tlbdsmiss, (size_t)&tlbdsmsize);
218 1.1 ws break;
219 1.53 ws #if defined(DDB) || defined(IPKDB)
220 1.14 sakamoto case EXC_PGM:
221 1.14 sakamoto case EXC_TRC:
222 1.14 sakamoto case EXC_BPT:
223 1.15 thorpej #if defined(DDB)
224 1.66 wiz memcpy((void *)exc, &ddblow, (size_t)&ddbsize);
225 1.15 thorpej #else
226 1.66 wiz memcpy((void *)exc, &ipkdblow, (size_t)&ipkdbsize);
227 1.14 sakamoto #endif
228 1.1 ws break;
229 1.53 ws #endif /* DDB || IPKDB */
230 1.1 ws }
231 1.1 ws
232 1.38 ws __syncicache((void *)EXC_RST, EXC_LAST - EXC_RST + 0x100);
233 1.1 ws
234 1.1 ws /*
235 1.1 ws * Now enable translation (and machine checks/recoverable interrupts).
236 1.1 ws */
237 1.1 ws asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
238 1.1 ws : "=r"(scratch) : "K"(PSL_IR|PSL_DR|PSL_ME|PSL_RI));
239 1.1 ws
240 1.1 ws /*
241 1.1 ws * Parse arg string.
242 1.1 ws */
243 1.1 ws bootpath = args;
244 1.7 thorpej while (*++args && *args != ' ');
245 1.1 ws if (*args) {
246 1.59 jdolecek for(*args++ = 0; *args; args++)
247 1.59 jdolecek BOOT_FLAG(*args, boothowto);
248 1.29 sakamoto }
249 1.1 ws
250 1.14 sakamoto #ifdef DDB
251 1.31 thorpej /* ddb_init((int)(endsym - startsym), startsym, endsym); */
252 1.14 sakamoto #endif
253 1.53 ws #ifdef IPKDB
254 1.1 ws /*
255 1.4 ws * Now trap to IPKDB
256 1.1 ws */
257 1.4 ws ipkdb_init();
258 1.1 ws if (boothowto & RB_KDB)
259 1.4 ws ipkdb_connect(0);
260 1.1 ws #endif
261 1.16 thorpej
262 1.16 thorpej /*
263 1.16 thorpej * Set the page size.
264 1.16 thorpej */
265 1.19 sakamoto uvm_setpagesize();
266 1.1 ws
267 1.1 ws /*
268 1.1 ws * Initialize pmap module.
269 1.1 ws */
270 1.1 ws pmap_bootstrap(startkernel, endkernel);
271 1.1 ws }
272 1.1 ws
273 1.1 ws /*
274 1.1 ws * This should probably be in autoconf! XXX
275 1.1 ws */
276 1.1 ws int cpu;
277 1.9 veego char machine[] = MACHINE; /* from <machine/param.h> */
278 1.9 veego char machine_arch[] = MACHINE_ARCH; /* from <machine/param.h> */
279 1.1 ws
280 1.1 ws void
281 1.1 ws install_extint(handler)
282 1.1 ws void (*handler) __P((void));
283 1.1 ws {
284 1.68 matt extern int extint, extsize;
285 1.1 ws extern u_long extint_call;
286 1.1 ws u_long offset = (u_long)handler - (u_long)&extint_call;
287 1.1 ws int omsr, msr;
288 1.29 sakamoto
289 1.1 ws #ifdef DIAGNOSTIC
290 1.1 ws if (offset > 0x1ffffff)
291 1.1 ws panic("install_extint: too far away");
292 1.1 ws #endif
293 1.7 thorpej asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
294 1.1 ws : "=r"(omsr), "=r"(msr) : "K"((u_short)~PSL_EE));
295 1.1 ws extint_call = (extint_call & 0xfc000003) | offset;
296 1.66 wiz memcpy((void *)EXC_EXI, &extint, (size_t)&extsize);
297 1.38 ws __syncicache((void *)&extint_call, sizeof extint_call);
298 1.38 ws __syncicache((void *)EXC_EXI, (int)&extsize);
299 1.1 ws asm volatile ("mtmsr %0" :: "r"(omsr));
300 1.1 ws }
301 1.1 ws
302 1.1 ws /*
303 1.1 ws * Machine dependent startup code.
304 1.1 ws */
305 1.1 ws void
306 1.1 ws cpu_startup()
307 1.1 ws {
308 1.1 ws int sz, i;
309 1.1 ws caddr_t v;
310 1.26 sakamoto paddr_t minaddr, maxaddr;
311 1.1 ws int base, residual;
312 1.40 lukem char pbuf[9];
313 1.18 sakamoto
314 1.39 thorpej proc0.p_addr = proc0paddr;
315 1.39 thorpej v = (caddr_t)proc0paddr + USPACE;
316 1.39 thorpej
317 1.18 sakamoto /*
318 1.18 sakamoto * Initialize error message buffer (at end of core).
319 1.18 sakamoto */
320 1.39 thorpej if (!(msgbuf_vaddr = uvm_km_alloc(kernel_map, round_page(MSGBUFSIZE))))
321 1.39 thorpej panic("startup: no room for message buffer");
322 1.39 thorpej for (i = 0; i < btoc(MSGBUFSIZE); i++)
323 1.39 thorpej pmap_enter(pmap_kernel(), msgbuf_vaddr + i * NBPG,
324 1.45 thorpej msgbuf_paddr + i * NBPG, VM_PROT_READ|VM_PROT_WRITE,
325 1.45 thorpej VM_PROT_READ|VM_PROT_WRITE|PMAP_WIRED);
326 1.64 thorpej pmap_update();
327 1.39 thorpej initmsgbuf((caddr_t)msgbuf_vaddr, round_page(MSGBUFSIZE));
328 1.1 ws
329 1.3 christos printf("%s", version);
330 1.68 matt cpu_identify(NULL, 0);
331 1.29 sakamoto
332 1.40 lukem format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
333 1.40 lukem printf("total memory = %s\n", pbuf);
334 1.19 sakamoto
335 1.1 ws /*
336 1.1 ws * Find out how much space we need, allocate it,
337 1.1 ws * and then give everything true virtual addresses.
338 1.1 ws */
339 1.40 lukem sz = (int)allocsys(NULL, NULL);
340 1.19 sakamoto if ((v = (caddr_t)uvm_km_zalloc(kernel_map, round_page(sz))) == 0)
341 1.19 sakamoto panic("startup: no room for tables");
342 1.40 lukem if (allocsys(v, NULL) - v != sz)
343 1.1 ws panic("startup: table size inconsistency");
344 1.19 sakamoto
345 1.1 ws /*
346 1.1 ws * Now allocate buffers proper. They are different than the above
347 1.1 ws * in that they usually occupy more virtual memory than physical.
348 1.1 ws */
349 1.1 ws sz = MAXBSIZE * nbuf;
350 1.26 sakamoto if (uvm_map(kernel_map, (vaddr_t *)&buffers, round_page(sz),
351 1.58 thorpej NULL, UVM_UNKNOWN_OFFSET, 0,
352 1.19 sakamoto UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
353 1.63 chs UVM_ADV_NORMAL, 0)) != 0)
354 1.19 sakamoto panic("startup: cannot allocate VM for buffers");
355 1.29 sakamoto minaddr = (vaddr_t)buffers;
356 1.1 ws base = bufpages / nbuf;
357 1.1 ws residual = bufpages % nbuf;
358 1.1 ws if (base >= MAXBSIZE) {
359 1.1 ws /* Don't want to alloc more physical mem than ever needed */
360 1.1 ws base = MAXBSIZE;
361 1.1 ws residual = 0;
362 1.1 ws }
363 1.1 ws for (i = 0; i < nbuf; i++) {
364 1.26 sakamoto vsize_t curbufsize;
365 1.26 sakamoto vaddr_t curbuf;
366 1.19 sakamoto struct vm_page *pg;
367 1.19 sakamoto
368 1.19 sakamoto /*
369 1.19 sakamoto * Each buffer has MAXBSIZE bytes of VM space allocated. Of
370 1.19 sakamoto * that MAXBSIZE space, we allocate and map (base+1) pages
371 1.19 sakamoto * for the first "residual" buffers, and then we allocate
372 1.19 sakamoto * "base" pages for the rest.
373 1.19 sakamoto */
374 1.26 sakamoto curbuf = (vaddr_t) buffers + (i * MAXBSIZE);
375 1.48 ragge curbufsize = NBPG * ((i < residual) ? (base+1) : base);
376 1.19 sakamoto
377 1.19 sakamoto while (curbufsize) {
378 1.36 chs pg = uvm_pagealloc(NULL, 0, NULL, 0);
379 1.19 sakamoto if (pg == NULL)
380 1.19 sakamoto panic("startup: not enough memory for "
381 1.19 sakamoto "buffer cache");
382 1.67 chs pmap_kenter_pa(curbuf, VM_PAGE_TO_PHYS(pg),
383 1.67 chs VM_PROT_READ | VM_PROT_WRITE);
384 1.19 sakamoto curbuf += PAGE_SIZE;
385 1.19 sakamoto curbufsize -= PAGE_SIZE;
386 1.19 sakamoto }
387 1.1 ws }
388 1.64 thorpej pmap_update();
389 1.1 ws
390 1.1 ws /*
391 1.1 ws * Allocate a submap for exec arguments. This map effectively
392 1.1 ws * limits the number of processes exec'ing at any time.
393 1.1 ws */
394 1.19 sakamoto exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
395 1.41 thorpej 16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
396 1.1 ws
397 1.1 ws /*
398 1.1 ws * Allocate a submap for physio
399 1.1 ws */
400 1.19 sakamoto phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
401 1.41 thorpej VM_PHYS_SIZE, 0, FALSE, NULL);
402 1.19 sakamoto
403 1.1 ws /*
404 1.37 thorpej * No need to allocate an mbuf cluster submap. Mbuf clusters
405 1.37 thorpej * are allocated via the pool allocator, and we use direct-mapped
406 1.37 thorpej * pool pages.
407 1.1 ws */
408 1.19 sakamoto
409 1.40 lukem format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
410 1.40 lukem printf("avail memory = %s\n", pbuf);
411 1.48 ragge format_bytes(pbuf, sizeof(pbuf), bufpages * NBPG);
412 1.40 lukem printf("using %d buffers containing %s of memory\n", nbuf, pbuf);
413 1.29 sakamoto
414 1.1 ws /*
415 1.1 ws * Set up the buffers.
416 1.1 ws */
417 1.1 ws bufinit();
418 1.1 ws
419 1.1 ws /*
420 1.7 thorpej * For now, use soft spl handling.
421 1.7 thorpej */
422 1.7 thorpej {
423 1.7 thorpej extern struct machvec soft_machvec;
424 1.7 thorpej
425 1.7 thorpej machine_interface = soft_machvec;
426 1.7 thorpej }
427 1.7 thorpej
428 1.7 thorpej /*
429 1.1 ws * Now allow hardware interrupts.
430 1.1 ws */
431 1.1 ws {
432 1.1 ws int msr;
433 1.29 sakamoto
434 1.1 ws splhigh();
435 1.7 thorpej asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
436 1.7 thorpej : "=r"(msr) : "K"((u_short)(PSL_EE|PSL_RI)));
437 1.1 ws }
438 1.1 ws }
439 1.1 ws
440 1.1 ws /*
441 1.1 ws * consinit
442 1.1 ws * Initialize system console.
443 1.1 ws */
444 1.1 ws void
445 1.1 ws consinit()
446 1.1 ws {
447 1.1 ws static int initted;
448 1.29 sakamoto
449 1.1 ws if (initted)
450 1.1 ws return;
451 1.1 ws initted = 1;
452 1.1 ws cninit();
453 1.1 ws }
454 1.1 ws
455 1.1 ws /*
456 1.1 ws * Crash dump handling.
457 1.1 ws */
458 1.1 ws
459 1.1 ws void
460 1.1 ws dumpsys()
461 1.1 ws {
462 1.3 christos printf("dumpsys: TBD\n");
463 1.1 ws }
464 1.1 ws
465 1.1 ws /*
466 1.1 ws * Soft networking interrupts.
467 1.1 ws */
468 1.1 ws void
469 1.1 ws softnet()
470 1.1 ws {
471 1.1 ws int isr = netisr;
472 1.1 ws
473 1.1 ws netisr = 0;
474 1.52 erh
475 1.52 erh #define DONETISR(bit, fn) do { \
476 1.52 erh if (isr & (1 << bit)) \
477 1.52 erh fn(); \
478 1.52 erh } while (0)
479 1.52 erh
480 1.52 erh #include <net/netisr_dispatch.h>
481 1.52 erh
482 1.52 erh #undef DONETISR
483 1.1 ws }
484 1.1 ws
485 1.1 ws /*
486 1.1 ws * Stray interrupts.
487 1.1 ws */
488 1.1 ws void
489 1.1 ws strayintr(irq)
490 1.1 ws int irq;
491 1.1 ws {
492 1.1 ws log(LOG_ERR, "stray interrupt %d\n", irq);
493 1.1 ws }
494 1.1 ws
495 1.1 ws /*
496 1.1 ws * Halt or reboot the machine after syncing/dumping according to howto.
497 1.1 ws */
498 1.1 ws void
499 1.5 gwr cpu_reboot(howto, what)
500 1.1 ws int howto;
501 1.1 ws char *what;
502 1.1 ws {
503 1.1 ws static int syncing;
504 1.1 ws static char str[256];
505 1.1 ws char *ap = str, *ap1 = ap;
506 1.1 ws
507 1.1 ws boothowto = howto;
508 1.1 ws if (!cold && !(howto & RB_NOSYNC) && !syncing) {
509 1.1 ws syncing = 1;
510 1.1 ws vfs_shutdown(); /* sync */
511 1.1 ws resettodr(); /* set wall clock */
512 1.1 ws }
513 1.1 ws splhigh();
514 1.1 ws if (howto & RB_HALT) {
515 1.1 ws doshutdownhooks();
516 1.3 christos printf("halted\n\n");
517 1.1 ws ppc_exit();
518 1.1 ws }
519 1.1 ws if (!cold && (howto & RB_DUMP))
520 1.1 ws dumpsys();
521 1.1 ws doshutdownhooks();
522 1.3 christos printf("rebooting\n\n");
523 1.1 ws if (what && *what) {
524 1.1 ws if (strlen(what) > sizeof str - 5)
525 1.3 christos printf("boot string too large, ignored\n");
526 1.1 ws else {
527 1.1 ws strcpy(str, what);
528 1.1 ws ap1 = ap = str + strlen(str);
529 1.1 ws *ap++ = ' ';
530 1.1 ws }
531 1.1 ws }
532 1.1 ws *ap++ = '-';
533 1.1 ws if (howto & RB_SINGLE)
534 1.1 ws *ap++ = 's';
535 1.1 ws if (howto & RB_KDB)
536 1.1 ws *ap++ = 'd';
537 1.1 ws *ap++ = 0;
538 1.1 ws if (ap[-2] == '-')
539 1.1 ws *ap1 = 0;
540 1.1 ws ppc_boot(str);
541 1.1 ws }
542 1.1 ws
543 1.68 matt #ifdef notyet
544 1.1 ws /*
545 1.1 ws * OpenFirmware callback routine
546 1.1 ws */
547 1.1 ws void
548 1.1 ws callback(p)
549 1.1 ws void *p;
550 1.1 ws {
551 1.1 ws panic("callback"); /* for now XXX */
552 1.60 thorpej }
553 1.68 matt #endif
554 1.60 thorpej
555 1.60 thorpej /*
556 1.60 thorpej * Perform an `splx()' for locore.
557 1.60 thorpej */
558 1.60 thorpej int
559 1.60 thorpej lcsplx(int ipl)
560 1.60 thorpej {
561 1.60 thorpej
562 1.60 thorpej return (splx(ipl));
563 1.1 ws }
564 1.1 ws
565 1.1 ws /*
566 1.7 thorpej * Initial Machine Interface.
567 1.1 ws */
568 1.7 thorpej static int
569 1.7 thorpej fake_spl()
570 1.7 thorpej {
571 1.7 thorpej int scratch;
572 1.7 thorpej
573 1.7 thorpej asm volatile ("mfmsr %0; andi. %0,%0,%1; mtmsr %0; isync"
574 1.7 thorpej : "=r"(scratch) : "K"((u_short)~(PSL_EE|PSL_ME)));
575 1.29 sakamoto return (-1);
576 1.7 thorpej }
577 1.7 thorpej
578 1.1 ws static void
579 1.7 thorpej fake_setsoft()
580 1.7 thorpej {
581 1.7 thorpej /* Do nothing */
582 1.7 thorpej }
583 1.7 thorpej
584 1.7 thorpej static int
585 1.1 ws fake_splx(new)
586 1.1 ws int new;
587 1.1 ws {
588 1.29 sakamoto return (fake_spl());
589 1.7 thorpej }
590 1.7 thorpej
591 1.7 thorpej static void
592 1.7 thorpej fake_clock_return(frame, nticks)
593 1.7 thorpej struct clockframe *frame;
594 1.7 thorpej int nticks;
595 1.7 thorpej {
596 1.7 thorpej /* Do nothing */
597 1.1 ws }
598 1.1 ws
599 1.1 ws static void
600 1.1 ws fake_irq_establish(irq, level, handler, arg)
601 1.1 ws int irq, level;
602 1.1 ws void (*handler) __P((void *));
603 1.1 ws void *arg;
604 1.1 ws {
605 1.1 ws panic("fake_irq_establish");
606 1.1 ws }
607