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