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