machdep.c revision 1.3 1 /* $NetBSD: machdep.c,v 1.3 1996/10/13 03:31:36 christos 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 "kgdb.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 NKGDB > 0
110 extern kgdblow, kgdbsize;
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 NKGDB > 0
197 case EXC_PGM:
198 case EXC_TRC:
199 case EXC_BPT:
200 bcopy(&kgdblow, (void *)exc, (size_t)&kgdbsize);
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 NKGDB > 0
236 /*
237 * Now trap to KGDB
238 */
239 kgdb_init();
240 if (boothowto & RB_KDB)
241 kgdb_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 * Allocate mbuf pool.
394 */
395 mclrefcnt = (char *)malloc(NMBCLUSTERS + CLBYTES/MCLBYTES,
396 M_MBUF, M_NOWAIT);
397 bzero(mclrefcnt, NMBCLUSTERS + CLBYTES/MCLBYTES);
398 mb_map = kmem_suballoc(kernel_map, (vm_offset_t *)&mbutl, &maxaddr,
399 VM_MBUF_SIZE, FALSE);
400
401 /*
402 * Initialize callouts.
403 */
404 callfree = callout;
405 for (i = 1; i < ncallout; i++)
406 callout[i - 1].c_next = &callout[i];
407
408 printf("avail mem = %d\n", ptoa(cnt.v_free_count));
409 printf("using %d buffers containing %d bytes of memory\n",
410 nbuf, bufpages * CLBYTES);
411
412 /*
413 * Set up the buffers.
414 */
415 bufinit();
416
417 /*
418 * Now allow hardware interrupts.
419 */
420 {
421 int msr;
422
423 splhigh();
424 asm volatile ("mfmsr %0; ori %0, %0, %1; mtmsr %0"
425 : "=r"(msr) : "K"(PSL_EE));
426 }
427
428 /*
429 * Configure devices.
430 */
431 configure();
432
433 }
434
435 /*
436 * Allocate space for system data structures.
437 */
438 caddr_t
439 allocsys(v)
440 caddr_t v;
441 {
442 #define valloc(name, type, num) \
443 v = (caddr_t)(((name) = (type *)v) + (num))
444
445 valloc(callout, struct callout, ncallout);
446 valloc(swapmap, struct map, nswapmap = maxproc * 2);
447 #ifdef SYSVSHM
448 valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
449 #endif
450 #ifdef SYSVSEM
451 valloc(sema, struct semid_ds, seminfo.semmni);
452 valloc(sem, struct sem, seminfo.semmns);
453 valloc(semu, int, (seminfo.semmnu * seminfo.semusz) / sizeof(int));
454 #endif
455 #ifdef SYSVMSG
456 valloc(msgpool, char, msginfo.msgmax);
457 valloc(msgmaps, struct msgmap, msginfo.msgseg);
458 valloc(msghdrs, struct msg, msginfo.msgtql);
459 valloc(msqids, struct msqid_ds, msginfo.msgmni);
460 #endif
461
462 /*
463 * Decide on buffer space to use.
464 */
465 if (bufpages == 0)
466 bufpages = (physmem / 20) / CLSIZE;
467 if (nbuf == 0) {
468 nbuf = bufpages;
469 if (nbuf < 16)
470 nbuf = 16;
471 }
472 if (nswbuf == 0) {
473 nswbuf = (nbuf / 2) & ~1;
474 if (nswbuf > 256)
475 nswbuf = 256;
476 }
477 valloc(swbuf, struct buf, nswbuf);
478 valloc(buf, struct buf, nbuf);
479
480 return v;
481 }
482
483 /*
484 * consinit
485 * Initialize system console.
486 */
487 void
488 consinit()
489 {
490 static int initted;
491
492 if (initted)
493 return;
494 initted = 1;
495 cninit();
496 }
497
498 /*
499 * Clear registers on exec
500 */
501 void
502 setregs(p, pack, stack, retval)
503 struct proc *p;
504 struct exec_package *pack;
505 u_long stack;
506 register_t *retval;
507 {
508 struct trapframe *tf = trapframe(p);
509
510 bzero(tf, sizeof *tf);
511 tf->fixreg[1] = -roundup(-stack + 8, 16);
512 tf->fixreg[3] = *retval = stack; /* bug in init_main.c XXX */
513 tf->srr0 = pack->ep_entry;
514 tf->srr1 = PSL_MBO | PSL_USERSET | PSL_FE_DFLT;
515 p->p_addr->u_pcb.pcb_flags = 0;
516 }
517
518 /*
519 * Send a signal to process.
520 */
521 void
522 sendsig(catcher, sig, mask, code)
523 sig_t catcher;
524 int sig, mask;
525 u_long code;
526 {
527 struct proc *p = curproc;
528 struct trapframe *tf;
529 struct sigframe *fp, frame;
530 struct sigacts *psp = p->p_sigacts;
531 int oldonstack;
532
533 frame.sf_signum = sig;
534
535 tf = trapframe(p);
536 oldonstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
537
538 /*
539 * Allocate stack space for signal handler.
540 */
541 if ((psp->ps_flags & SAS_ALTSTACK)
542 && !oldonstack
543 && (psp->ps_sigonstack & sigmask(sig))) {
544 fp = (struct sigframe *)(psp->ps_sigstk.ss_sp
545 + psp->ps_sigstk.ss_size);
546 psp->ps_sigstk.ss_flags |= SS_ONSTACK;
547 } else
548 fp = (struct sigframe *)tf->fixreg[1];
549 fp = (struct sigframe *)((int)(fp - 1) & ~0xf);
550
551 frame.sf_code = code;
552
553 /*
554 * Generate signal context for SYS_sigreturn.
555 */
556 frame.sf_sc.sc_onstack = oldonstack;
557 frame.sf_sc.sc_mask = mask;
558 bcopy(tf, &frame.sf_sc.sc_frame, sizeof *tf);
559 if (copyout(&frame, fp, sizeof frame) != 0)
560 sigexit(p, SIGILL);
561
562 tf->fixreg[1] = (int)fp;
563 tf->lr = (int)catcher;
564 tf->fixreg[3] = (int)sig;
565 tf->fixreg[4] = (int)code;
566 tf->fixreg[5] = (int)&frame.sf_sc;
567 tf->srr0 = (int)(((char *)PS_STRINGS)
568 - (p->p_emul->e_esigcode - p->p_emul->e_sigcode));
569 }
570
571 /*
572 * System call to cleanup state after a signal handler returns.
573 */
574 int
575 sys_sigreturn(p, v, retval)
576 struct proc *p;
577 void *v;
578 register_t *retval;
579 {
580 struct sys_sigreturn_args /* {
581 syscallarg(struct sigcontext *) sigcntxp;
582 } */ *uap = v;
583 struct sigcontext sc;
584 struct trapframe *tf;
585 int error;
586
587 if (error = copyin(SCARG(uap, sigcntxp), &sc, sizeof sc))
588 return error;
589 tf = trapframe(p);
590 if ((sc.sc_frame.srr1 & PSL_USERSTATIC) != (tf->srr1 & PSL_USERSTATIC))
591 return EINVAL;
592 bcopy(&sc.sc_frame, tf, sizeof *tf);
593 if (sc.sc_onstack & 1)
594 p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
595 else
596 p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
597 p->p_sigmask = sc.sc_mask & ~sigcantmask;
598 return EJUSTRETURN;
599 }
600
601 /*
602 * Machine dependent system variables.
603 * None for now.
604 */
605 int
606 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
607 int *name;
608 u_int namelen;
609 void *oldp;
610 size_t *oldlenp;
611 void *newp;
612 size_t newlen;
613 struct proc *p;
614 {
615 /* all sysctl names at this level are terminal */
616 if (namelen != 1)
617 return ENOTDIR;
618 switch (name[0]) {
619 default:
620 return EOPNOTSUPP;
621 }
622 }
623
624 /*
625 * Crash dump handling.
626 */
627 u_long dumpmag = 0x8fca0101; /* magic number */
628 int dumpsize = 0; /* size of dump in pages */
629 long dumplo = -1; /* blocks */
630
631 void
632 dumpsys()
633 {
634 printf("dumpsys: TBD\n");
635 }
636
637 int cpl;
638 int clockpending, softclockpending, softnetpending;
639
640 /*
641 * Soft networking interrupts.
642 */
643 void
644 softnet()
645 {
646 int isr = netisr;
647
648 netisr = 0;
649 #ifdef INET
650 #include "ether.h"
651 #if NETHER > 0
652 if (isr & (1 << NETISR_ARP))
653 arpintr();
654 #endif
655 if (isr & (1 << NETISR_IP))
656 ipintr();
657 #endif
658 #ifdef IMP
659 if (isr & (1 << NETISR_IMP))
660 impintr();
661 #endif
662 #ifdef NS
663 if (isr & (1 << NETISR_NS))
664 nsintr();
665 #endif
666 #ifdef ISO
667 if (isr & (1 << NETISR_ISO))
668 clnlintr();
669 #endif
670 #ifdef CCITT
671 if (isr & (1 << NETISR_CCITT))
672 ccittintr();
673 #endif
674 #include "ppp.h"
675 #if NPPP > 0
676 if (isr & (1 << NETISR_PPP))
677 pppintr();
678 #endif
679 }
680
681 /*
682 * Stray interrupts.
683 */
684 void
685 strayintr(irq)
686 int irq;
687 {
688 log(LOG_ERR, "stray interrupt %d\n", irq);
689 }
690
691 int
692 splraise(bits)
693 int bits;
694 {
695 int old;
696
697 old = cpl;
698 cpl |= bits;
699
700 if ((bits & SPLMACHINE) & ~old)
701 (*machine_interface.splx)(cpl & SPLMACHINE);
702
703 return old;
704 }
705
706 int
707 splx(new)
708 int new;
709 {
710 int pending, old = cpl;
711 int emsr, dmsr;
712
713 asm ("mfmsr %0" : "=r"(emsr));
714 dmsr = emsr & ~PSL_EE;
715
716 cpl = new;
717
718 if ((new & SPLMACHINE) != (old & SPLMACHINE))
719 (*machine_interface.splx)(new & SPLMACHINE);
720
721 while (1) {
722 cpl = new;
723
724 asm volatile ("mtmsr %0" :: "r"(dmsr));
725 if (clockpending && !(cpl & SPLCLOCK)) {
726 struct clockframe frame;
727 extern int intr_depth;
728
729 cpl |= SPLCLOCK;
730 clockpending--;
731 asm volatile ("mtmsr %0" :: "r"(emsr));
732
733 /*
734 * Fake a clock interrupt frame
735 */
736 frame.pri = new;
737 frame.depth = intr_depth + 1;
738 frame.srr1 = 0;
739 frame.srr0 = (int)splx;
740 /*
741 * Do standard timer interrupt stuff
742 */
743 hardclock(&frame);
744 continue;
745 }
746 if (softclockpending && !(cpl & SPLSOFTCLOCK)) {
747
748 cpl |= SPLSOFTCLOCK;
749 softclockpending = 0;
750 asm volatile ("mtmsr %0" :: "r"(emsr));
751
752 softclock();
753 continue;
754 }
755 if (softnetpending && !(cpl & SPLSOFTNET)) {
756 cpl |= SPLSOFTNET;
757 softnetpending = 0;
758 asm volatile ("mtmsr %0" :: "r"(emsr));
759 softnet();
760 continue;
761 }
762
763 asm volatile ("mtmsr %0" :: "r"(emsr));
764
765 return old;
766 }
767 }
768
769 /*
770 * This one is similar to the above, but returns with interrupts disabled.
771 * It is intended for use during interrupt exit (as the name implies :-)).
772 */
773 void
774 intr_return(level)
775 int level;
776 {
777 int pending, old = cpl;
778 int emsr, dmsr;
779
780 asm ("mfmsr %0" : "=r"(emsr));
781 dmsr = emsr & ~PSL_EE;
782
783 cpl = level;
784
785 if ((level & SPLMACHINE) != (old & SPLMACHINE))
786 (*machine_interface.splx)(level & SPLMACHINE);
787
788 while (1) {
789 cpl = level;
790
791 asm volatile ("mtmsr %0" :: "r"(dmsr));
792 if (clockpending && !(cpl & SPLCLOCK)) {
793 struct clockframe frame;
794 extern int intr_depth;
795
796 cpl |= SPLCLOCK;
797 clockpending--;
798 asm volatile ("mtmsr %0" :: "r"(emsr));
799
800 /*
801 * Fake a clock interrupt frame
802 */
803 frame.pri = level | (clockpending ? SPLSOFTCLOCK : 0);
804 frame.depth = intr_depth + 1;
805 frame.srr1 = 0;
806 frame.srr0 = (int)splx;
807 /*
808 * Do standard timer interrupt stuff
809 */
810 hardclock(&frame);
811 continue;
812 }
813 if (softclockpending && !(cpl & SPLSOFTCLOCK)) {
814
815 cpl |= SPLSOFTCLOCK;
816 softclockpending = 0;
817 asm volatile ("mtmsr %0" :: "r"(emsr));
818
819 softclock();
820 continue;
821 }
822 if (softnetpending && !(cpl & SPLSOFTNET)) {
823 cpl |= SPLSOFTNET;
824 softnetpending = 0;
825 asm volatile ("mtmsr %0" :: "r"(emsr));
826 softnet();
827 continue;
828 }
829 break;
830 }
831 }
832
833 /*
834 * Halt or reboot the machine after syncing/dumping according to howto.
835 */
836 void
837 boot(howto, what)
838 int howto;
839 char *what;
840 {
841 static int syncing;
842 static char str[256];
843 char *ap = str, *ap1 = ap;
844
845 boothowto = howto;
846 if (!cold && !(howto & RB_NOSYNC) && !syncing) {
847 syncing = 1;
848 vfs_shutdown(); /* sync */
849 resettodr(); /* set wall clock */
850 }
851 splhigh();
852 if (howto & RB_HALT) {
853 doshutdownhooks();
854 printf("halted\n\n");
855 ppc_exit();
856 }
857 if (!cold && (howto & RB_DUMP))
858 dumpsys();
859 doshutdownhooks();
860 printf("rebooting\n\n");
861 if (what && *what) {
862 if (strlen(what) > sizeof str - 5)
863 printf("boot string too large, ignored\n");
864 else {
865 strcpy(str, what);
866 ap1 = ap = str + strlen(str);
867 *ap++ = ' ';
868 }
869 }
870 *ap++ = '-';
871 if (howto & RB_SINGLE)
872 *ap++ = 's';
873 if (howto & RB_KDB)
874 *ap++ = 'd';
875 *ap++ = 0;
876 if (ap[-2] == '-')
877 *ap1 = 0;
878 ppc_boot(str);
879 }
880
881 /*
882 * OpenFirmware callback routine
883 */
884 void
885 callback(p)
886 void *p;
887 {
888 panic("callback"); /* for now XXX */
889 }
890
891 /*
892 * Fake routines for spl/interrupt handling before autoconfig
893 */
894 static void
895 fake_splx(new)
896 int new;
897 {
898 }
899
900 static void
901 fake_irq_establish(irq, level, handler, arg)
902 int irq, level;
903 void (*handler) __P((void *));
904 void *arg;
905 {
906 panic("fake_irq_establish");
907 }
908