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