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