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