machdep.c revision 1.34 1 /* $NetBSD: machdep.c,v 1.34 1999/03/26 23:41:33 mycroft Exp $ */
2
3 /*
4 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 * Copyright (C) 1995, 1996 TooLs GmbH.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by TooLs GmbH.
19 * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include "opt_compat_netbsd.h"
35 #include "opt_ddb.h"
36 #include "opt_inet.h"
37 #include "opt_ccitt.h"
38 #include "opt_iso.h"
39 #include "opt_ns.h"
40 #include "opt_sysv.h"
41 #include "ipkdb.h"
42
43 #include <sys/param.h>
44 #include <sys/buf.h>
45 #include <sys/callout.h>
46 #include <sys/exec.h>
47 #include <sys/malloc.h>
48 #include <sys/map.h>
49 #include <sys/mbuf.h>
50 #include <sys/mount.h>
51 #include <sys/msgbuf.h>
52 #include <sys/proc.h>
53 #include <sys/reboot.h>
54 #include <sys/syscallargs.h>
55 #include <sys/syslog.h>
56 #include <sys/systm.h>
57 #include <sys/user.h>
58
59 #include <vm/vm.h>
60 #include <vm/vm_kern.h>
61
62 #include <uvm/uvm_extern.h>
63
64 #include <net/netisr.h>
65
66 #include <machine/bat.h>
67 #include <machine/pmap.h>
68 #include <machine/powerpc.h>
69 #include <machine/trap.h>
70
71 /*
72 * Global variables used here and there
73 */
74 vm_map_t exec_map = NULL;
75 vm_map_t mb_map = NULL;
76 vm_map_t phys_map = NULL;
77
78 struct pcb *curpcb;
79 struct pmap *curpm;
80 struct proc *fpuproc;
81
82 extern struct user *proc0paddr;
83
84 struct bat battable[16];
85
86 int astpending;
87
88 char *bootpath;
89
90 #define MSGBUFADDR 0x3000
91
92 caddr_t allocsys __P((caddr_t));
93
94 static int fake_spl __P((void));
95 static int fake_splx __P((int));
96 static void fake_setsoft __P((void));
97 static void fake_clock_return __P((struct clockframe *, int));
98 static void fake_irq_establish __P((int, int, void (*)(void *), void *));
99
100 struct machvec machine_interface = {
101 fake_spl,
102 fake_spl,
103 fake_spl,
104 fake_spl,
105 fake_spl,
106 fake_spl,
107 fake_spl,
108 fake_spl,
109 fake_spl,
110 fake_splx,
111 fake_setsoft,
112 fake_setsoft,
113 fake_clock_return,
114 fake_irq_establish,
115 };
116
117 int cold = 1;
118
119 void
120 initppc(startkernel, endkernel, args)
121 u_int startkernel, endkernel;
122 char *args;
123 {
124 int phandle, qhandle;
125 char name[32];
126 struct machvec *mp;
127 extern trapcode, trapsize;
128 extern dsitrap, dsisize;
129 extern isitrap, isisize;
130 extern decrint, decrsize;
131 extern tlbimiss, tlbimsize;
132 extern tlbdlmiss, tlbdlmsize;
133 extern tlbdsmiss, tlbdsmsize;
134 #ifdef DDB
135 extern ddblow, ddbsize;
136 extern void *startsym, *endsym;
137 #endif
138 #if NIPKDB > 0
139 extern ipkdblow, ipkdbsize;
140 #endif
141 extern void consinit __P((void));
142 extern void callback __P((void *));
143 int exc, scratch;
144
145 proc0.p_addr = proc0paddr;
146 bzero(proc0.p_addr, sizeof *proc0.p_addr);
147
148 curpcb = &proc0paddr->u_pcb;
149
150 curpm = curpcb->pcb_pmreal = curpcb->pcb_pm = pmap_kernel();
151
152 /*
153 * i386 port says, that this shouldn't be here,
154 * but I really think the console should be initialized
155 * as early as possible.
156 */
157 consinit();
158
159 #ifdef __notyet__ /* Needs some rethinking regarding real/virtual OFW */
160 OF_set_callback(callback);
161 #endif
162 /*
163 * Initialize BAT registers to unmapped to not generate
164 * overlapping mappings below.
165 */
166 asm volatile ("mtibatu 0,%0" :: "r"(0));
167 asm volatile ("mtibatu 1,%0" :: "r"(0));
168 asm volatile ("mtibatu 2,%0" :: "r"(0));
169 asm volatile ("mtibatu 3,%0" :: "r"(0));
170 asm volatile ("mtdbatu 0,%0" :: "r"(0));
171 asm volatile ("mtdbatu 1,%0" :: "r"(0));
172 asm volatile ("mtdbatu 2,%0" :: "r"(0));
173 asm volatile ("mtdbatu 3,%0" :: "r"(0));
174
175 /*
176 * Set up initial BAT table to only map the lowest 256 MB area
177 */
178 battable[0].batl = BATL(0x00000000, BAT_M);
179 battable[0].batu = BATU(0x00000000);
180
181 /*
182 * Now setup fixed bat registers
183 *
184 * Note that we still run in real mode, and the BAT
185 * registers were cleared above.
186 */
187 /* IBAT0 used for initial 256 MB segment */
188 asm volatile ("mtibatl 0,%0; mtibatu 0,%1"
189 :: "r"(battable[0].batl), "r"(battable[0].batu));
190 /* DBAT0 used similar */
191 asm volatile ("mtdbatl 0,%0; mtdbatu 0,%1"
192 :: "r"(battable[0].batl), "r"(battable[0].batu));
193
194 /*
195 * Set up trap vectors
196 */
197 for (exc = EXC_RSVD; exc <= EXC_LAST; exc += 0x100)
198 switch (exc) {
199 default:
200 bcopy(&trapcode, (void *)exc, (size_t)&trapsize);
201 break;
202 case EXC_EXI:
203 /*
204 * This one is (potentially) installed during autoconf
205 */
206 break;
207 case EXC_DSI:
208 bcopy(&dsitrap, (void *)EXC_DSI, (size_t)&dsisize);
209 break;
210 case EXC_ISI:
211 bcopy(&isitrap, (void *)EXC_ISI, (size_t)&isisize);
212 break;
213 case EXC_DECR:
214 bcopy(&decrint, (void *)EXC_DECR, (size_t)&decrsize);
215 break;
216 case EXC_IMISS:
217 bcopy(&tlbimiss, (void *)EXC_IMISS, (size_t)&tlbimsize);
218 break;
219 case EXC_DLMISS:
220 bcopy(&tlbdlmiss, (void *)EXC_DLMISS, (size_t)&tlbdlmsize);
221 break;
222 case EXC_DSMISS:
223 bcopy(&tlbdsmiss, (void *)EXC_DSMISS, (size_t)&tlbdsmsize);
224 break;
225 #if defined(DDB) || NIPKDB > 0
226 case EXC_PGM:
227 case EXC_TRC:
228 case EXC_BPT:
229 #if defined(DDB)
230 bcopy(&ddblow, (void *)exc, (size_t)&ddbsize);
231 #else
232 bcopy(&ipkdblow, (void *)exc, (size_t)&ipkdbsize);
233 #endif
234 break;
235 #endif /* DDB || NIPKDB > 0 */
236 }
237
238 syncicache((void *)EXC_RST, EXC_LAST - EXC_RST + 0x100);
239
240 /*
241 * Now enable translation (and machine checks/recoverable interrupts).
242 */
243 asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
244 : "=r"(scratch) : "K"(PSL_IR|PSL_DR|PSL_ME|PSL_RI));
245
246 /*
247 * Parse arg string.
248 */
249 bootpath = args;
250 while (*++args && *args != ' ');
251 if (*args) {
252 *args++ = 0;
253 while (*args) {
254 switch (*args++) {
255 case 'a':
256 boothowto |= RB_ASKNAME;
257 break;
258 case 's':
259 boothowto |= RB_SINGLE;
260 break;
261 case 'd':
262 boothowto |= RB_KDB;
263 break;
264 }
265 }
266 }
267
268 #ifdef DDB
269 /* ddb_init((int)(endsym - startsym), startsym, endsym); */
270 #endif
271 #if NIPKDB > 0
272 /*
273 * Now trap to IPKDB
274 */
275 ipkdb_init();
276 if (boothowto & RB_KDB)
277 ipkdb_connect(0);
278 #endif
279
280 /*
281 * Set the page size.
282 */
283 uvm_setpagesize();
284
285 /*
286 * Initialize pmap module.
287 */
288 pmap_bootstrap(startkernel, endkernel);
289 }
290
291 /*
292 * This should probably be in autoconf! XXX
293 */
294 int cpu;
295 char cpu_model[80];
296 char machine[] = MACHINE; /* from <machine/param.h> */
297 char machine_arch[] = MACHINE_ARCH; /* from <machine/param.h> */
298
299 void
300 identifycpu()
301 {
302 int phandle, pvr;
303 char name[32];
304
305 /*
306 * Find cpu type (Do it by OpenFirmware?)
307 */
308 asm ("mfpvr %0" : "=r"(pvr));
309 cpu = pvr >> 16;
310 switch (cpu) {
311 case 1:
312 sprintf(cpu_model, "601");
313 break;
314 case 3:
315 sprintf(cpu_model, "603");
316 break;
317 case 4:
318 sprintf(cpu_model, "604");
319 break;
320 case 5:
321 sprintf(cpu_model, "602");
322 break;
323 case 6:
324 sprintf(cpu_model, "603e");
325 break;
326 case 7:
327 sprintf(cpu_model, "603ev");
328 break;
329 case 9:
330 sprintf(cpu_model, "604ev");
331 break;
332 case 20:
333 sprintf(cpu_model, "620");
334 break;
335 default:
336 sprintf(cpu_model, "Version %x", cpu);
337 break;
338 }
339 sprintf(cpu_model + strlen(cpu_model), " (Revision %x)", pvr & 0xffff);
340 printf("CPU: %s\n", cpu_model);
341 }
342
343 void
344 install_extint(handler)
345 void (*handler) __P((void));
346 {
347 extern extint, extsize;
348 extern u_long extint_call;
349 u_long offset = (u_long)handler - (u_long)&extint_call;
350 int omsr, msr;
351
352 #ifdef DIAGNOSTIC
353 if (offset > 0x1ffffff)
354 panic("install_extint: too far away");
355 #endif
356 asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
357 : "=r"(omsr), "=r"(msr) : "K"((u_short)~PSL_EE));
358 extint_call = (extint_call & 0xfc000003) | offset;
359 bcopy(&extint, (void *)EXC_EXI, (size_t)&extsize);
360 syncicache((void *)&extint_call, sizeof extint_call);
361 syncicache((void *)EXC_EXI, (int)&extsize);
362 asm volatile ("mtmsr %0" :: "r"(omsr));
363 }
364
365 /*
366 * Machine dependent startup code.
367 */
368 void
369 cpu_startup()
370 {
371 int sz, i;
372 caddr_t v;
373 paddr_t minaddr, maxaddr;
374 int base, residual;
375
376 /*
377 * Initialize error message buffer (at end of core).
378 */
379 initmsgbuf((caddr_t)MSGBUFADDR, round_page(MSGBUFSIZE));
380
381 proc0.p_addr = proc0paddr;
382 v = (caddr_t)proc0paddr + USPACE;
383
384 printf("%s", version);
385 identifycpu();
386
387 printf("real mem = %d\n", ctob(physmem));
388
389 /*
390 * Find out how much space we need, allocate it,
391 * and then give everything true virtual addresses.
392 */
393 sz = (int)allocsys((caddr_t)0);
394 if ((v = (caddr_t)uvm_km_zalloc(kernel_map, round_page(sz))) == 0)
395 panic("startup: no room for tables");
396 if (allocsys(v) - v != sz)
397 panic("startup: table size inconsistency");
398
399 /*
400 * Now allocate buffers proper. They are different than the above
401 * in that they usually occupy more virtual memory than physical.
402 */
403 sz = MAXBSIZE * nbuf;
404 if (uvm_map(kernel_map, (vaddr_t *)&buffers, round_page(sz),
405 NULL, UVM_UNKNOWN_OFFSET,
406 UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
407 UVM_ADV_NORMAL, 0)) != KERN_SUCCESS)
408 panic("startup: cannot allocate VM for buffers");
409 minaddr = (vaddr_t)buffers;
410 base = bufpages / nbuf;
411 residual = bufpages % nbuf;
412 if (base >= MAXBSIZE) {
413 /* Don't want to alloc more physical mem than ever needed */
414 base = MAXBSIZE;
415 residual = 0;
416 }
417 for (i = 0; i < nbuf; i++) {
418 vsize_t curbufsize;
419 vaddr_t curbuf;
420 struct vm_page *pg;
421
422 /*
423 * Each buffer has MAXBSIZE bytes of VM space allocated. Of
424 * that MAXBSIZE space, we allocate and map (base+1) pages
425 * for the first "residual" buffers, and then we allocate
426 * "base" pages for the rest.
427 */
428 curbuf = (vaddr_t) buffers + (i * MAXBSIZE);
429 curbufsize = CLBYTES * ((i < residual) ? (base+1) : base);
430
431 while (curbufsize) {
432 pg = uvm_pagealloc(NULL, 0, NULL);
433 if (pg == NULL)
434 panic("startup: not enough memory for "
435 "buffer cache");
436 pmap_enter(kernel_map->pmap, curbuf,
437 VM_PAGE_TO_PHYS(pg), VM_PROT_READ|VM_PROT_WRITE,
438 TRUE, VM_PROT_READ|VM_PROT_WRITE);
439 curbuf += PAGE_SIZE;
440 curbufsize -= PAGE_SIZE;
441 }
442 }
443
444 /*
445 * Allocate a submap for exec arguments. This map effectively
446 * limits the number of processes exec'ing at any time.
447 */
448 exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
449 16*NCARGS, TRUE, FALSE, NULL);
450
451 /*
452 * Allocate a submap for physio
453 */
454 phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
455 VM_PHYS_SIZE, TRUE, FALSE, NULL);
456
457 /*
458 * Finally, allocate mbuf cluster submap.
459 */
460 mb_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
461 VM_MBUF_SIZE, FALSE, FALSE, NULL);
462
463 /*
464 * Initialize callouts.
465 */
466 callfree = callout;
467 for (i = 1; i < ncallout; i++)
468 callout[i - 1].c_next = &callout[i];
469
470 printf("avail memory = %d\n", ptoa(uvmexp.free));
471 printf("using %d buffers containing %d bytes of memory\n",
472 nbuf, bufpages * CLBYTES);
473
474 /*
475 * Set up the buffers.
476 */
477 bufinit();
478
479 /*
480 * For now, use soft spl handling.
481 */
482 {
483 extern struct machvec soft_machvec;
484
485 machine_interface = soft_machvec;
486 }
487
488 /*
489 * Now allow hardware interrupts.
490 */
491 {
492 int msr;
493
494 splhigh();
495 asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
496 : "=r"(msr) : "K"((u_short)(PSL_EE|PSL_RI)));
497 }
498
499 /*
500 * Configure devices.
501 */
502 configure();
503 }
504
505 /*
506 * Allocate space for system data structures.
507 */
508 caddr_t
509 allocsys(v)
510 caddr_t v;
511 {
512 #define valloc(name, type, num) \
513 v = (caddr_t)(((name) = (type *)v) + (num))
514
515 valloc(callout, struct callout, ncallout);
516 #ifdef SYSVSHM
517 valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
518 #endif
519 #ifdef SYSVSEM
520 valloc(sema, struct semid_ds, seminfo.semmni);
521 valloc(sem, struct sem, seminfo.semmns);
522 valloc(semu, int, (seminfo.semmnu * seminfo.semusz) / sizeof (int));
523 #endif
524 #ifdef SYSVMSG
525 valloc(msgpool, char, msginfo.msgmax);
526 valloc(msgmaps, struct msgmap, msginfo.msgseg);
527 valloc(msghdrs, struct msg, msginfo.msgtql);
528 valloc(msqids, struct msqid_ds, msginfo.msgmni);
529 #endif
530
531 /*
532 * Decide on buffer space to use.
533 */
534 if (bufpages == 0)
535 bufpages = (physmem / 20) / CLSIZE;
536 if (nbuf == 0) {
537 nbuf = bufpages;
538 if (nbuf < 16)
539 nbuf = 16;
540 }
541 if (nswbuf == 0) {
542 nswbuf = (nbuf / 2) & ~1;
543 if (nswbuf > 256)
544 nswbuf = 256;
545 }
546 valloc(buf, struct buf, nbuf);
547
548 return (v);
549 }
550
551 /*
552 * consinit
553 * Initialize system console.
554 */
555 void
556 consinit()
557 {
558 static int initted;
559
560 if (initted)
561 return;
562 initted = 1;
563 cninit();
564 }
565
566 /*
567 * Set set up registers on exec.
568 */
569 void
570 setregs(p, pack, stack)
571 struct proc *p;
572 struct exec_package *pack;
573 u_long stack;
574 {
575 struct trapframe *tf = trapframe(p);
576 struct ps_strings arginfo;
577
578 bzero(tf, sizeof *tf);
579 tf->fixreg[1] = -roundup(-stack + 8, 16);
580
581 /*
582 * XXX Machine-independent code has already copied arguments and
583 * XXX environment to userland. Get them back here.
584 */
585 (void)copyin((char *)PS_STRINGS, &arginfo, sizeof (arginfo));
586
587 /*
588 * Set up arguments for _start():
589 * _start(argc, argv, envp, obj, cleanup, ps_strings);
590 *
591 * Notes:
592 * - obj and cleanup are the auxilliary and termination
593 * vectors. They are fixed up by ld.elf_so.
594 * - ps_strings is a NetBSD extention, and will be
595 * ignored by executables which are strictly
596 * compliant with the SVR4 ABI.
597 *
598 * XXX We have to set both regs and retval here due to different
599 * XXX calling convention in trap.c and init_main.c.
600 */
601 tf->fixreg[3] = arginfo.ps_nargvstr;
602 tf->fixreg[4] = (register_t)arginfo.ps_argvstr;
603 tf->fixreg[5] = (register_t)arginfo.ps_envstr;
604 tf->fixreg[6] = 0; /* auxillary vector */
605 tf->fixreg[7] = 0; /* termination vector */
606 tf->fixreg[8] = (register_t)PS_STRINGS; /* NetBSD extension */
607
608 tf->srr0 = pack->ep_entry;
609 tf->srr1 = PSL_MBO | PSL_USERSET | PSL_FE_DFLT;
610 p->p_addr->u_pcb.pcb_flags = 0;
611 }
612
613 /*
614 * Send a signal to process.
615 */
616 void
617 sendsig(catcher, sig, mask, code)
618 sig_t catcher;
619 int sig;
620 sigset_t *mask;
621 u_long code;
622 {
623 struct proc *p = curproc;
624 struct trapframe *tf;
625 struct sigframe *fp, frame;
626 struct sigacts *psp = p->p_sigacts;
627 int onstack;
628
629 tf = trapframe(p);
630
631 /* Do we need to jump onto the signal stack? */
632 onstack =
633 (psp->ps_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
634 (psp->ps_sigact[sig].sa_flags & SA_ONSTACK) != 0;
635
636 /* Allocate space for the signal handler context. */
637 if (onstack)
638 fp = (struct sigframe *)((caddr_t)psp->ps_sigstk.ss_sp +
639 psp->ps_sigstk.ss_size);
640 else
641 fp = (struct sigframe *)tf->fixreg[1];
642 fp = (struct sigframe *)((int)(fp - 1) & ~0xf);
643
644 /* Build stack frame for signal trampoline. */
645 frame.sf_signum = sig;
646 frame.sf_code = code;
647
648 /* Save register context. */
649 bcopy(tf, &frame.sf_sc.sc_frame, sizeof *tf);
650
651 /* Save signal stack. */
652 frame.sf_sc.sc_onstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
653
654 /* Save signal mask. */
655 frame.sf_sc.sc_mask = *mask;
656
657 #ifdef COMPAT_13
658 /*
659 * XXX We always have to save an old style signal mask because
660 * XXX we might be delivering a signal to a process which will
661 * XXX escape from the signal in a non-standard way and invoke
662 * XXX sigreturn() directly.
663 */
664 native_sigset_to_sigset13(mask, &frame.sf_sc.__sc_mask13);
665 #endif
666
667 if (copyout(&frame, fp, sizeof frame) != 0) {
668 /*
669 * Process has trashed its stack; give it an illegal
670 * instructoin to halt it in its tracks.
671 */
672 sigexit(p, SIGILL);
673 /* NOTREACHED */
674 }
675
676 /*
677 * Build context to run handler in.
678 */
679 tf->fixreg[1] = (int)fp;
680 tf->lr = (int)catcher;
681 tf->fixreg[3] = (int)sig;
682 tf->fixreg[4] = (int)code;
683 tf->fixreg[5] = (int)&frame.sf_sc;
684 tf->srr0 = (int)psp->ps_sigcode;
685
686 /* Remember that we're now on the signal stack. */
687 if (onstack)
688 psp->ps_sigstk.ss_flags |= SS_ONSTACK;
689 }
690
691 /*
692 * System call to cleanup state after a signal handler returns.
693 */
694 int
695 sys___sigreturn14(p, v, retval)
696 struct proc *p;
697 void *v;
698 register_t *retval;
699 {
700 struct sys___sigreturn14_args /* {
701 syscallarg(struct sigcontext *) sigcntxp;
702 } */ *uap = v;
703 struct sigcontext sc;
704 struct trapframe *tf;
705 int error;
706
707 /*
708 * The trampoline hands us the context.
709 * It is unsafe to keep track of it ourselves, in the event that a
710 * program jumps out of a signal hander.
711 */
712 if ((error = copyin(SCARG(uap, sigcntxp), &sc, sizeof sc)) != 0)
713 return (error);
714
715 /* Restore the register context. */
716 tf = trapframe(p);
717 if ((sc.sc_frame.srr1 & PSL_USERSTATIC) != (tf->srr1 & PSL_USERSTATIC))
718 return (EINVAL);
719 bcopy(&sc.sc_frame, tf, sizeof *tf);
720
721 /* Restore signal stack. */
722 if (sc.sc_onstack & SS_ONSTACK)
723 p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
724 else
725 p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
726
727 /* Restore signal mask. */
728 (void) sigprocmask1(p, SIG_SETMASK, &sc.sc_mask, 0);
729
730 return (EJUSTRETURN);
731 }
732
733 /*
734 * Machine dependent system variables.
735 * None for now.
736 */
737 int
738 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
739 int *name;
740 u_int namelen;
741 void *oldp;
742 size_t *oldlenp;
743 void *newp;
744 size_t newlen;
745 struct proc *p;
746 {
747 /* all sysctl names at this level are terminal */
748 if (namelen != 1)
749 return (ENOTDIR);
750 switch (name[0]) {
751 default:
752 return (EOPNOTSUPP);
753 }
754 }
755
756 /*
757 * Crash dump handling.
758 */
759 u_long dumpmag = 0x8fca0101; /* magic number */
760 int dumpsize = 0; /* size of dump in pages */
761 long dumplo = -1; /* blocks */
762
763 void
764 dumpsys()
765 {
766 printf("dumpsys: TBD\n");
767 }
768
769 /*
770 * Soft networking interrupts.
771 */
772 void
773 softnet()
774 {
775 int isr = netisr;
776
777 netisr = 0;
778 #ifdef INET
779 #include "arp.h"
780 #if NARP > 0
781 if (isr & (1 << NETISR_ARP))
782 arpintr();
783 #endif
784 if (isr & (1 << NETISR_IP))
785 ipintr();
786 #endif
787 #ifdef IMP
788 if (isr & (1 << NETISR_IMP))
789 impintr();
790 #endif
791 #ifdef NS
792 if (isr & (1 << NETISR_NS))
793 nsintr();
794 #endif
795 #ifdef ISO
796 if (isr & (1 << NETISR_ISO))
797 clnlintr();
798 #endif
799 #ifdef CCITT
800 if (isr & (1 << NETISR_CCITT))
801 ccittintr();
802 #endif
803 #include "ppp.h"
804 #if NPPP > 0
805 if (isr & (1 << NETISR_PPP))
806 pppintr();
807 #endif
808 }
809
810 /*
811 * Stray interrupts.
812 */
813 void
814 strayintr(irq)
815 int irq;
816 {
817 log(LOG_ERR, "stray interrupt %d\n", irq);
818 }
819
820 /*
821 * Halt or reboot the machine after syncing/dumping according to howto.
822 */
823 void
824 cpu_reboot(howto, what)
825 int howto;
826 char *what;
827 {
828 static int syncing;
829 static char str[256];
830 char *ap = str, *ap1 = ap;
831
832 boothowto = howto;
833 if (!cold && !(howto & RB_NOSYNC) && !syncing) {
834 syncing = 1;
835 vfs_shutdown(); /* sync */
836 resettodr(); /* set wall clock */
837 }
838 splhigh();
839 if (howto & RB_HALT) {
840 doshutdownhooks();
841 printf("halted\n\n");
842 ppc_exit();
843 }
844 if (!cold && (howto & RB_DUMP))
845 dumpsys();
846 doshutdownhooks();
847 printf("rebooting\n\n");
848 if (what && *what) {
849 if (strlen(what) > sizeof str - 5)
850 printf("boot string too large, ignored\n");
851 else {
852 strcpy(str, what);
853 ap1 = ap = str + strlen(str);
854 *ap++ = ' ';
855 }
856 }
857 *ap++ = '-';
858 if (howto & RB_SINGLE)
859 *ap++ = 's';
860 if (howto & RB_KDB)
861 *ap++ = 'd';
862 *ap++ = 0;
863 if (ap[-2] == '-')
864 *ap1 = 0;
865 ppc_boot(str);
866 }
867
868 /*
869 * OpenFirmware callback routine
870 */
871 void
872 callback(p)
873 void *p;
874 {
875 panic("callback"); /* for now XXX */
876 }
877
878 /*
879 * Initial Machine Interface.
880 */
881 static int
882 fake_spl()
883 {
884 int scratch;
885
886 asm volatile ("mfmsr %0; andi. %0,%0,%1; mtmsr %0; isync"
887 : "=r"(scratch) : "K"((u_short)~(PSL_EE|PSL_ME)));
888 return (-1);
889 }
890
891 static void
892 fake_setsoft()
893 {
894 /* Do nothing */
895 }
896
897 static int
898 fake_splx(new)
899 int new;
900 {
901 return (fake_spl());
902 }
903
904 static void
905 fake_clock_return(frame, nticks)
906 struct clockframe *frame;
907 int nticks;
908 {
909 /* Do nothing */
910 }
911
912 static void
913 fake_irq_establish(irq, level, handler, arg)
914 int irq, level;
915 void (*handler) __P((void *));
916 void *arg;
917 {
918 panic("fake_irq_establish");
919 }
920