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