machdep.c revision 1.17 1 /* $NetBSD: machdep.c,v 1.17 1996/04/18 00:59:11 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/signalvar.h>
33 #include <sys/kernel.h>
34 #include <sys/map.h>
35 #include <sys/proc.h>
36 #include <sys/buf.h>
37 #include <sys/reboot.h>
38 #include <sys/conf.h>
39 #include <sys/file.h>
40 #ifdef REAL_CLISTS
41 #include <sys/clist.h>
42 #endif
43 #include <sys/callout.h>
44 #include <sys/malloc.h>
45 #include <sys/mbuf.h>
46 #include <sys/msgbuf.h>
47 #include <sys/ioctl.h>
48 #include <sys/tty.h>
49 #include <sys/user.h>
50 #include <sys/exec.h>
51 #include <sys/exec_ecoff.h>
52 #include <sys/sysctl.h>
53 #ifdef SYSVMSG
54 #include <sys/msg.h>
55 #endif
56 #ifdef SYSVSEM
57 #include <sys/sem.h>
58 #endif
59 #ifdef SYSVSHM
60 #include <sys/shm.h>
61 #endif
62
63 #include <sys/mount.h>
64 #include <sys/syscallargs.h>
65
66 #include <vm/vm_kern.h>
67
68 #include <dev/cons.h>
69
70 #include <machine/cpu.h>
71 #include <machine/reg.h>
72 #include <machine/rpb.h>
73 #include <machine/prom.h>
74
75 #ifdef DEC_3000_500
76 #include <alpha/alpha/dec_3000_500.h>
77 #endif
78 #ifdef DEC_3000_300
79 #include <alpha/alpha/dec_3000_300.h>
80 #endif
81 #ifdef DEC_2100_A50
82 #include <alpha/alpha/dec_2100_a50.h>
83 #endif
84 #ifdef DEC_KN20AA
85 #include <alpha/alpha/dec_kn20aa.h>
86 #endif
87 #ifdef DEC_AXPPCI_33
88 #include <alpha/alpha/dec_axppci_33.h>
89 #endif
90 #ifdef DEC_21000
91 #include <alpha/alpha/dec_21000.h>
92 #endif
93
94 #include <net/netisr.h>
95 #include "ether.h"
96
97 #include "le_ioasic.h" /* for le_iomem creation */
98
99 vm_map_t buffer_map;
100
101 void dumpsys __P((void));
102
103 /*
104 * Declare these as initialized data so we can patch them.
105 */
106 int nswbuf = 0;
107 #ifdef NBUF
108 int nbuf = NBUF;
109 #else
110 int nbuf = 0;
111 #endif
112 #ifdef BUFPAGES
113 int bufpages = BUFPAGES;
114 #else
115 int bufpages = 0;
116 #endif
117 int msgbufmapped = 0; /* set when safe to use msgbuf */
118 int maxmem; /* max memory per process */
119
120 int totalphysmem; /* total amount of physical memory in system */
121 int physmem; /* physical memory used by NetBSD + some rsvd */
122 int firstusablepage; /* first usable memory page */
123 int lastusablepage; /* last usable memory page */
124 int resvmem; /* amount of memory reserved for PROM */
125 int unusedmem; /* amount of memory for OS that we don't use */
126 int unknownmem; /* amount of memory with an unknown use */
127
128 int cputype; /* system type, from the RPB */
129
130 /*
131 * XXX We need an address to which we can assign things so that they
132 * won't be optimized away because we didn't use the value.
133 */
134 u_int32_t no_optimize;
135
136 /* the following is used externally (sysctl_hw) */
137 char machine[] = "alpha";
138 char *cpu_model;
139 char *model_names[] = {
140 "UNKNOWN (0)",
141 "Alpha Demonstration Unit",
142 "DEC 4000 (\"Cobra\")",
143 "DEC 7000 (\"Ruby\")",
144 "DEC 3000/500 (\"Flamingo\") family",
145 "UNKNOWN (5)",
146 "DEC 2000/300 (\"Jensen\")",
147 "DEC 3000/300 (\"Pelican\")",
148 "UNKNOWN (8)",
149 "DEC 2100/A500 (\"Sable\")",
150 "AXPvme 64",
151 "AXPpci 33 (\"NoName\")",
152 "DEC 21000 (\"TurboLaser\")",
153 "DEC 2100/A50 (\"Avanti\") family",
154 "Mustang",
155 "DEC KN20AA",
156 "UNKNOWN (16)",
157 "DEC 1000 (\"Mikasa\")",
158 };
159 int nmodel_names = sizeof model_names/sizeof model_names[0];
160
161 struct user *proc0paddr;
162
163 /* Number of machine cycles per microsecond */
164 u_int64_t cycles_per_usec;
165
166 /* some memory areas for device DMA. "ick." */
167 caddr_t le_iomem; /* XXX iomem for LANCE DMA */
168
169 /* Interrupt vectors (in locore) */
170 extern int XentInt(), XentArith(), XentMM(), XentIF(), XentUna(), XentSys();
171
172 /* number of cpus in the box. really! */
173 int ncpus;
174
175 /* various CPU-specific functions. */
176 char *(*cpu_modelname) __P((void));
177 void (*cpu_consinit) __P((char *));
178 dev_t (*cpu_bootdev) __P((char *));
179 char *cpu_iobus;
180
181 char *boot_file, *boot_flags, *boot_console, *boot_dev;
182
183 int
184 alpha_init(pfn, ptb, argc, argv, envp)
185 u_long pfn; /* first free PFN number */
186 u_long ptb; /* PFN of current level 1 page table */
187 u_long argc;
188 char *argv[], *envp[];
189 {
190 extern char _end[];
191 caddr_t start, v;
192 struct mddt *mddtp;
193 int i, mddtweird;
194 char *p;
195
196 /*
197 * Turn off interrupts and floating point.
198 * Make sure the instruction and data streams are consistent.
199 */
200 (void)splhigh();
201 pal_wrfen(0);
202 TBIA();
203 IMB();
204
205 /*
206 * get address of the restart block, while we the bootstrap
207 * mapping is still around.
208 */
209 hwrpb = (struct rpb *) phystok0seg(*(struct rpb **)HWRPB_ADDR);
210
211 /*
212 * Remember how many cycles there are per microsecond,
213 * so that we can use delay(). Round up, for safety.
214 */
215 cycles_per_usec = (hwrpb->rpb_cc_freq + 999999) / 1000000;
216
217 /*
218 * Init the PROM interface, so we can use printf
219 * until PROM mappings go away in consinit.
220 */
221 init_prom_interface();
222
223 /*
224 * Point interrupt/exception vectors to our own.
225 */
226 pal_wrent(XentInt, 0);
227 pal_wrent(XentArith, 1);
228 pal_wrent(XentMM, 2);
229 pal_wrent(XentIF, 3);
230 pal_wrent(XentUna, 4);
231 pal_wrent(XentSys, 5);
232
233 /*
234 * Find out how much memory is available, by looking at
235 * the memory cluster descriptors. This also tries to do
236 * its best to detect things things that have never been seen
237 * before...
238 *
239 * XXX Assumes that the first "system" cluster is the
240 * only one we can use. Is the second (etc.) system cluster
241 * (if one happens to exist) guaranteed to be contiguous? or...?
242 */
243 mddtp = (struct mddt *)(((caddr_t)hwrpb) + hwrpb->rpb_memdat_off);
244
245 /*
246 * BEGIN MDDT WEIRDNESS CHECKING
247 */
248 mddtweird = 0;
249
250 #define cnt mddtp->mddt_cluster_cnt
251 #define usage(n) mddtp->mddt_clusters[(n)].mddt_usage
252 if (cnt != 2 && cnt != 3) {
253 printf("WARNING: weird number (%d) of mem clusters\n", cnt);
254 mddtweird = 1;
255 } else if (usage(0) != MDDT_PALCODE ||
256 usage(1) != MDDT_SYSTEM ||
257 (cnt == 3 && usage(2) != MDDT_PALCODE)) {
258 mddtweird = 1;
259 printf("WARNING: %d mem clusters, but weird config\n", cnt);
260 }
261
262 for (i = 0; i < cnt; i++) {
263 if ((usage(i) & MDDT_mbz) != 0) {
264 printf("WARNING: mem cluster %d has weird usage %lx\n",
265 i, usage(i));
266 mddtweird = 1;
267 }
268 if (mddtp->mddt_clusters[i].mddt_pg_cnt == 0) {
269 printf("WARNING: mem cluster %d has pg cnt == 0\n", i);
270 mddtweird = 1;
271 }
272 /* XXX other things to check? */
273 }
274 #undef cnt
275 #undef usage
276
277 if (mddtweird) {
278 printf("\n");
279 printf("complete memory cluster information:\n");
280 for (i = 0; i < mddtp->mddt_cluster_cnt; i++) {
281 printf("mddt %d:\n", i);
282 printf("\tpfn %lx\n",
283 mddtp->mddt_clusters[i].mddt_pfn);
284 printf("\tcnt %lx\n",
285 mddtp->mddt_clusters[i].mddt_pg_cnt);
286 printf("\ttest %lx\n",
287 mddtp->mddt_clusters[i].mddt_pg_test);
288 printf("\tbva %lx\n",
289 mddtp->mddt_clusters[i].mddt_v_bitaddr);
290 printf("\tbpa %lx\n",
291 mddtp->mddt_clusters[i].mddt_p_bitaddr);
292 printf("\tbcksum %lx\n",
293 mddtp->mddt_clusters[i].mddt_bit_cksum);
294 printf("\tusage %lx\n",
295 mddtp->mddt_clusters[i].mddt_usage);
296 }
297 printf("\n");
298 }
299 /*
300 * END MDDT WEIRDNESS CHECKING
301 */
302
303 for (i = 0; i < mddtp->mddt_cluster_cnt; i++) {
304 totalphysmem += mddtp->mddt_clusters[i].mddt_pg_cnt;
305 #define usage(n) mddtp->mddt_clusters[(n)].mddt_usage
306 #define pgcnt(n) mddtp->mddt_clusters[(n)].mddt_pg_cnt
307 if ((usage(i) & MDDT_mbz) != 0)
308 unknownmem += pgcnt(i);
309 else if ((usage(i) & ~MDDT_mbz) == MDDT_PALCODE)
310 resvmem += pgcnt(i);
311 else if ((usage(i) & ~MDDT_mbz) == MDDT_SYSTEM) {
312 /*
313 * assumes that the system cluster listed is
314 * one we're in...
315 */
316 if (physmem != resvmem) {
317 physmem += pgcnt(i);
318 firstusablepage =
319 mddtp->mddt_clusters[i].mddt_pfn;
320 lastusablepage = firstusablepage + pgcnt(i) - 1;
321 } else
322 unusedmem += pgcnt(i);
323 }
324 #undef usage
325 #undef pgcnt
326 }
327 if (totalphysmem == 0)
328 panic("can't happen: system seems to have no memory!");
329 maxmem = physmem;
330
331 #if 0
332 printf("totalphysmem = %d\n", totalphysmem);
333 printf("physmem = %d\n", physmem);
334 printf("firstusablepage = %d\n", firstusablepage);
335 printf("lastusablepage = %d\n", lastusablepage);
336 printf("resvmem = %d\n", resvmem);
337 printf("unusedmem = %d\n", unusedmem);
338 printf("unknownmem = %d\n", unknownmem);
339 #endif
340
341 /*
342 * find out this CPU's page size
343 */
344 PAGE_SIZE = hwrpb->rpb_page_size;
345 if (PAGE_SIZE != 8192)
346 panic("page size %d != 8192?!", PAGE_SIZE);
347
348 v = (caddr_t)alpha_round_page(_end);
349 /*
350 * Init mapping for u page(s) for proc 0
351 */
352 start = v;
353 curproc->p_addr = proc0paddr = (struct user *)v;
354 v += UPAGES * NBPG;
355
356 /*
357 * Find out what hardware we're on, and remember its type name.
358 */
359 cputype = hwrpb->rpb_type;
360 switch (cputype) {
361 #ifdef DEC_3000_500 /* and 400, [6-9]00 */
362 case ST_DEC_3000_500:
363 cpu_modelname = dec_3000_500_modelname;
364 cpu_consinit = dec_3000_500_consinit;
365 cpu_bootdev = dec_3000_500_bootdev;
366 cpu_iobus = "tcasic";
367 break;
368 #endif
369
370 #ifdef DEC_3000_300
371 case ST_DEC_3000_300:
372 cpu_modelname = dec_3000_300_modelname;
373 cpu_consinit = dec_3000_300_consinit;
374 cpu_bootdev = dec_3000_300_bootdev;
375 cpu_iobus = "tcasic";
376 break;
377 #endif
378
379 #ifdef DEC_2100_A50
380 case ST_DEC_2100_A50:
381 cpu_modelname = dec_2100_a50_modelname;
382 cpu_consinit = dec_2100_a50_consinit;
383 cpu_bootdev = dec_2100_a50_bootdev;
384 cpu_iobus = "apecs";
385 break;
386 #endif
387
388 #ifdef DEC_KN20AA
389 case ST_DEC_KN20AA:
390 cpu_modelname = dec_kn20aa_modelname;
391 cpu_consinit = dec_kn20aa_consinit;
392 cpu_bootdev = dec_kn20aa_bootdev;
393 cpu_iobus = "cia";
394 break;
395 #endif
396
397 #ifdef DEC_AXPPCI_33
398 case ST_DEC_AXPPCI_33:
399 cpu_modelname = dec_axppci_33_modelname;
400 cpu_consinit = dec_axppci_33_consinit;
401 cpu_bootdev = dec_axppci_33_bootdev;
402 cpu_iobus = "lca";
403 break;
404 #endif
405
406 #ifdef DEC_2000_300
407 case ST_DEC_2000_300:
408 cpu_modelname = dec_2000_300_modelname;
409 cpu_consinit = dec_2000_300_consinit;
410 cpu_bootdev = dec_2000_300_bootdev;
411 cpu_iobus = "ibus";
412 XXX DEC 2000/300 NOT SUPPORTED
413 break;
414 #endif
415
416 #ifdef DEC_21000
417 case ST_DEC_21000:
418 cpu_modelname = dec_21000_modelname;
419 cpu_consinit = dec_21000_consinit;
420 cpu_bootdev = dec_21000_bootdev;
421 cpu_iobus = "tlsb";
422 break;
423 #endif
424
425 default:
426 if (cputype > nmodel_names)
427 panic("Unknown system type %d", cputype);
428 else
429 panic("Support for %s system type not in kernel.",
430 model_names[cputype]);
431 }
432
433 cpu_model = (*cpu_modelname)();
434 if (cpu_model == NULL)
435 cpu_model = model_names[cputype];
436
437 #if NLE_IOASIC > 0
438 /*
439 * Grab 128K at the top of physical memory for the lance chip
440 * on machines where it does dma through the I/O ASIC.
441 * It must be physically contiguous and aligned on a 128K boundary.
442 *
443 * Note that since this is conditional on the presence of
444 * IOASIC-attached 'le' units in the kernel config, the
445 * message buffer may move on these systems. This shouldn't
446 * be a problem, because once people have a kernel config that
447 * they use, they're going to stick with it.
448 */
449 if (cputype == ST_DEC_3000_500 ||
450 cputype == ST_DEC_3000_300) { /* XXX possibly others? */
451 lastusablepage -= btoc(128 * 1024);
452 le_iomem = (caddr_t)phystok0seg(ctob(lastusablepage + 1));
453 }
454 #endif /* NLE_IOASIC */
455
456 /*
457 * Initialize error message buffer (at end of core).
458 */
459 lastusablepage -= btoc(sizeof (struct msgbuf));
460 msgbufp = (struct msgbuf *)phystok0seg(ctob(lastusablepage + 1));
461 msgbufmapped = 1;
462
463 /*
464 * Allocate space for system data structures.
465 * The first available kernel virtual address is in "v".
466 * As pages of kernel virtual memory are allocated, "v" is incremented.
467 *
468 * These data structures are allocated here instead of cpu_startup()
469 * because physical memory is directly addressable. We don't have
470 * to map these into virtual address space.
471 */
472 #define valloc(name, type, num) \
473 (name) = (type *)v; v = (caddr_t)ALIGN((name)+(num))
474 #define valloclim(name, type, num, lim) \
475 (name) = (type *)v; v = (caddr_t)ALIGN((lim) = ((name)+(num)))
476 #ifdef REAL_CLISTS
477 valloc(cfree, struct cblock, nclist);
478 #endif
479 valloc(callout, struct callout, ncallout);
480 valloc(swapmap, struct map, nswapmap = maxproc * 2);
481 #ifdef SYSVSHM
482 valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
483 #endif
484 #ifdef SYSVSEM
485 valloc(sema, struct semid_ds, seminfo.semmni);
486 valloc(sem, struct sem, seminfo.semmns);
487 /* This is pretty disgusting! */
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 * Determine how many buffers to allocate.
499 * We allocate the BSD standard of 10% of memory for the first
500 * 2 Meg, and 5% of remaining memory for buffer space. Insure a
501 * minimum of 16 buffers. We allocate 1/2 as many swap buffer
502 * headers as file i/o buffers.
503 */
504 if (bufpages == 0)
505 bufpages = (btoc(2 * 1024 * 1024) + physmem) /
506 (20 * CLSIZE);
507 if (nbuf == 0) {
508 nbuf = bufpages;
509 if (nbuf < 16)
510 nbuf = 16;
511 }
512 if (nswbuf == 0) {
513 nswbuf = (nbuf / 2) &~ 1; /* force even */
514 if (nswbuf > 256)
515 nswbuf = 256; /* sanity */
516 }
517 valloc(swbuf, struct buf, nswbuf);
518 valloc(buf, struct buf, nbuf);
519
520 /*
521 * Clear allocated memory.
522 */
523 bzero(start, v - start);
524
525 /*
526 * Initialize the virtual memory system, and set the
527 * page table base register in proc 0's PCB.
528 */
529 pmap_bootstrap((vm_offset_t)v, phystok0seg(ptb << PGSHIFT));
530
531 /*
532 * Initialize the rest of proc 0's PCB, and cache its physical
533 * address.
534 */
535 proc0.p_md.md_pcbpaddr =
536 (struct pcb *)k0segtophys(&proc0paddr->u_pcb);
537
538 /*
539 * Set the kernel sp, reserving space for an (empty) trapframe,
540 * and make proc0's trapframe pointer point to it for sanity.
541 */
542 proc0paddr->u_pcb.pcb_ksp =
543 (u_int64_t)proc0paddr + USPACE - sizeof(struct trapframe);
544 proc0.p_md.md_tf = (struct trapframe *)proc0paddr->u_pcb.pcb_ksp;
545
546 /*
547 * figure out what arguments we have
548 */
549 switch (argc) {
550 default:
551 printf("weird number of arguments from boot: %d\n", argc);
552 if (argc < 1)
553 break;
554 /* FALLTHRU */
555 case 4:
556 boot_dev = argv[3];
557 /* FALLTHRU */
558 case 3:
559 boot_console = argv[2];
560 /* FALLTHRU */
561 case 2:
562 boot_flags = argv[1];
563 /* FALLTHRU */
564 case 1:
565 boot_file = argv[0];
566 /* FALLTHRU */
567 }
568
569 /*
570 * Look at arguments and compute bootdev.
571 * XXX NOT HERE.
572 */
573 #if 0
574 { /* XXX */
575 extern dev_t bootdev; /* XXX */
576 bootdev = (*cpu_bootdev)(boot_dev);
577 } /* XXX */
578 #endif
579
580 /*
581 * Look at arguments passed to us and compute boothowto.
582 */
583 boothowto = RB_SINGLE;
584 #ifdef GENERIC
585 boothowto |= RB_ASKNAME;
586 #endif
587 #ifdef KADB
588 boothowto |= RB_KDB;
589 #endif
590 for (p = boot_flags; p && *p != '\0'; p++) {
591 switch (*p) {
592 case 'a': /* autoboot */
593 case 'A': /* DEC's notion of autoboot */
594 boothowto &= ~RB_SINGLE;
595 break;
596
597 case 'd': /* use compiled in default root */
598 boothowto |= RB_DFLTROOT;
599 break;
600
601 case 'm': /* mini root present in memory */
602 boothowto |= RB_MINIROOT;
603 break;
604
605 case 'n': /* ask for names */
606 boothowto |= RB_ASKNAME;
607 break;
608
609 case 'N': /* don't ask for names */
610 boothowto &= ~RB_ASKNAME;
611 }
612 }
613
614 /*
615 * Figure out the number of cpus in the box, from RPB fields.
616 * Really. We mean it.
617 */
618 for (i = 0; i < hwrpb->rpb_pcs_cnt; i++) {
619 struct pcs *pcsp;
620
621 pcsp = (struct pcs *)((char *)hwrpb + hwrpb->rpb_pcs_off +
622 (i * hwrpb->rpb_pcs_size));
623 if ((pcsp->pcs_flags & PCS_PP) != 0)
624 ncpus++;
625 }
626
627 return (0);
628 }
629
630 consinit()
631 {
632
633 (*cpu_consinit)(boot_console);
634 pmap_unmap_prom();
635 }
636
637 cpu_startup()
638 {
639 register unsigned i;
640 register caddr_t v;
641 int base, residual;
642 vm_offset_t minaddr, maxaddr;
643 vm_size_t size;
644 #ifdef DEBUG
645 extern int pmapdebug;
646 int opmapdebug = pmapdebug;
647
648 pmapdebug = 0;
649 #endif
650
651 /*
652 * Good {morning,afternoon,evening,night}.
653 */
654 printf(version);
655 identifycpu();
656 printf("real mem = %d (%d reserved for PROM, %d used by NetBSD)\n",
657 ctob(totalphysmem), ctob(resvmem), ctob(physmem));
658 if (unusedmem)
659 printf("WARNING: unused memory = %d bytes\n", ctob(unusedmem));
660 if (unknownmem)
661 printf("WARNING: %d bytes of memory with unknown purpose\n",
662 ctob(unknownmem));
663
664 /*
665 * Allocate virtual address space for file I/O buffers.
666 * Note they are different than the array of headers, 'buf',
667 * and usually occupy more virtual memory than physical.
668 */
669 size = MAXBSIZE * nbuf;
670 buffer_map = kmem_suballoc(kernel_map, (vm_offset_t *)&buffers,
671 &maxaddr, size, TRUE);
672 minaddr = (vm_offset_t)buffers;
673 if (vm_map_find(buffer_map, vm_object_allocate(size), (vm_offset_t)0,
674 &minaddr, size, FALSE) != KERN_SUCCESS)
675 panic("startup: cannot allocate buffers");
676 base = bufpages / nbuf;
677 residual = bufpages % nbuf;
678 for (i = 0; i < nbuf; i++) {
679 vm_size_t curbufsize;
680 vm_offset_t curbuf;
681
682 /*
683 * First <residual> buffers get (base+1) physical pages
684 * allocated for them. The rest get (base) physical pages.
685 *
686 * The rest of each buffer occupies virtual space,
687 * but has no physical memory allocated for it.
688 */
689 curbuf = (vm_offset_t)buffers + i * MAXBSIZE;
690 curbufsize = CLBYTES * (i < residual ? base+1 : base);
691 vm_map_pageable(buffer_map, curbuf, curbuf+curbufsize, FALSE);
692 vm_map_simplify(buffer_map, curbuf);
693 }
694 /*
695 * Allocate a submap for exec arguments. This map effectively
696 * limits the number of processes exec'ing at any time.
697 */
698 exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
699 16 * NCARGS, TRUE);
700
701 /*
702 * Allocate a submap for physio
703 */
704 phys_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
705 VM_PHYS_SIZE, TRUE);
706
707 /*
708 * Finally, allocate mbuf pool. Since mclrefcnt is an off-size
709 * we use the more space efficient malloc in place of kmem_alloc.
710 */
711 mclrefcnt = (char *)malloc(NMBCLUSTERS+CLBYTES/MCLBYTES,
712 M_MBUF, M_NOWAIT);
713 bzero(mclrefcnt, NMBCLUSTERS+CLBYTES/MCLBYTES);
714 mb_map = kmem_suballoc(kernel_map, (vm_offset_t *)&mbutl, &maxaddr,
715 VM_MBUF_SIZE, FALSE);
716 /*
717 * Initialize callouts
718 */
719 callfree = callout;
720 for (i = 1; i < ncallout; i++)
721 callout[i-1].c_next = &callout[i];
722 callout[i-1].c_next = NULL;
723
724 #ifdef DEBUG
725 pmapdebug = opmapdebug;
726 #endif
727 printf("avail mem = %ld\n", (long)ptoa(cnt.v_free_count));
728 printf("using %ld buffers containing %ld bytes of memory\n",
729 (long)nbuf, (long)(bufpages * CLBYTES));
730
731 /*
732 * Set up buffers, so they can be used to read disk labels.
733 */
734 bufinit();
735
736 /*
737 * Configure the system.
738 */
739 configure();
740 }
741
742 identifycpu()
743 {
744
745 /*
746 * print out CPU identification information.
747 */
748 printf("%s, %dMHz\n", cpu_model,
749 hwrpb->rpb_cc_freq / 1000000); /* XXX true for 21164? */
750 printf("%d byte page size, %d processor%s.\n",
751 hwrpb->rpb_page_size, ncpus, ncpus == 1 ? "" : "s");
752 #if 0
753 /* this isn't defined for any systems that we run on? */
754 printf("serial number 0x%lx 0x%lx\n",
755 ((long *)hwrpb->rpb_ssn)[0], ((long *)hwrpb->rpb_ssn)[1]);
756
757 /* and these aren't particularly useful! */
758 printf("variation: 0x%lx, revision 0x%lx\n",
759 hwrpb->rpb_variation, *(long *)hwrpb->rpb_revision);
760 #endif
761 }
762
763 int waittime = -1;
764 struct pcb dumppcb;
765
766 boot(howto)
767 int howto;
768 {
769 extern int cold;
770
771 /* If system is cold, just halt. */
772 if (cold) {
773 howto |= RB_HALT;
774 goto haltsys;
775 }
776
777 boothowto = howto;
778 if ((howto & RB_NOSYNC) == 0 && waittime < 0) {
779 waittime = 0;
780 vfs_shutdown();
781 /*
782 * If we've been adjusting the clock, the todr
783 * will be out of synch; adjust it now.
784 */
785 resettodr();
786 }
787
788 /* Disable interrupts. */
789 splhigh();
790
791 /* If rebooting and a dump is requested do it. */
792 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) {
793 savectx(&dumppcb, 0);
794 dumpsys();
795 }
796
797 haltsys:
798
799 /* run any shutdown hooks */
800 doshutdownhooks();
801
802 #ifdef BOOTKEY
803 printf("hit any key to %s...\n", howto & RB_HALT ? "halt" : "reboot");
804 cngetc();
805 printf("\n");
806 #endif
807
808 /* Finally, halt/reboot the system. */
809 printf("%s\n\n", howto & RB_HALT ? "halted." : "rebooting...");
810 prom_halt(howto & RB_HALT);
811 /*NOTREACHED*/
812 }
813
814 /*
815 * These variables are needed by /sbin/savecore
816 */
817 u_long dumpmag = 0x8fca0101; /* magic number */
818 int dumpsize = 0; /* pages */
819 long dumplo = 0; /* blocks */
820
821 /*
822 * This is called by configure to set dumplo and dumpsize.
823 * Dumps always skip the first CLBYTES of disk space
824 * in case there might be a disk label stored there.
825 * If there is extra space, put dump at the end to
826 * reduce the chance that swapping trashes it.
827 */
828 void
829 dumpconf()
830 {
831 int nblks; /* size of dump area */
832 int maj;
833
834 if (dumpdev == NODEV)
835 return;
836 maj = major(dumpdev);
837 if (maj < 0 || maj >= nblkdev)
838 panic("dumpconf: bad dumpdev=0x%x", dumpdev);
839 if (bdevsw[maj].d_psize == NULL)
840 return;
841 nblks = (*bdevsw[maj].d_psize)(dumpdev);
842 if (nblks <= ctod(1))
843 return;
844
845 /* XXX XXX XXX STARTING MEMORY LOCATION */
846 dumpsize = physmem;
847
848 /* Always skip the first CLBYTES, in case there is a label there. */
849 if (dumplo < ctod(1))
850 dumplo = ctod(1);
851
852 /* Put dump at end of partition, and make it fit. */
853 if (dumpsize > dtoc(nblks - dumplo))
854 dumpsize = dtoc(nblks - dumplo);
855 if (dumplo < nblks - ctod(dumpsize))
856 dumplo = nblks - ctod(dumpsize);
857 }
858
859 /*
860 * Doadump comes here after turning off memory management and
861 * getting on the dump stack, either when called above, or by
862 * the auto-restart code.
863 */
864 void
865 dumpsys()
866 {
867
868 msgbufmapped = 0;
869 if (dumpdev == NODEV)
870 return;
871 if (dumpsize == 0) {
872 dumpconf();
873 if (dumpsize == 0)
874 return;
875 }
876 printf("\ndumping to dev %x, offset %d\n", dumpdev, dumplo);
877
878 printf("dump ");
879 switch ((*bdevsw[major(dumpdev)].d_dump)(dumpdev)) {
880
881 case ENXIO:
882 printf("device bad\n");
883 break;
884
885 case EFAULT:
886 printf("device not ready\n");
887 break;
888
889 case EINVAL:
890 printf("area improper\n");
891 break;
892
893 case EIO:
894 printf("i/o error\n");
895 break;
896
897 case EINTR:
898 printf("aborted from console\n");
899 break;
900
901 default:
902 printf("succeeded\n");
903 break;
904 }
905 printf("\n\n");
906 delay(1000);
907 }
908
909 void
910 frametoreg(framep, regp)
911 struct trapframe *framep;
912 struct reg *regp;
913 {
914
915 regp->r_regs[R_V0] = framep->tf_regs[FRAME_V0];
916 regp->r_regs[R_T0] = framep->tf_regs[FRAME_T0];
917 regp->r_regs[R_T1] = framep->tf_regs[FRAME_T1];
918 regp->r_regs[R_T2] = framep->tf_regs[FRAME_T2];
919 regp->r_regs[R_T3] = framep->tf_regs[FRAME_T3];
920 regp->r_regs[R_T4] = framep->tf_regs[FRAME_T4];
921 regp->r_regs[R_T5] = framep->tf_regs[FRAME_T5];
922 regp->r_regs[R_T6] = framep->tf_regs[FRAME_T6];
923 regp->r_regs[R_T7] = framep->tf_regs[FRAME_T7];
924 regp->r_regs[R_S0] = framep->tf_regs[FRAME_S0];
925 regp->r_regs[R_S1] = framep->tf_regs[FRAME_S1];
926 regp->r_regs[R_S2] = framep->tf_regs[FRAME_S2];
927 regp->r_regs[R_S3] = framep->tf_regs[FRAME_S3];
928 regp->r_regs[R_S4] = framep->tf_regs[FRAME_S4];
929 regp->r_regs[R_S5] = framep->tf_regs[FRAME_S5];
930 regp->r_regs[R_S6] = framep->tf_regs[FRAME_S6];
931 regp->r_regs[R_A0] = framep->tf_a0;
932 regp->r_regs[R_A1] = framep->tf_a1;
933 regp->r_regs[R_A2] = framep->tf_a2;
934 regp->r_regs[R_A3] = framep->tf_regs[FRAME_A3];
935 regp->r_regs[R_A4] = framep->tf_regs[FRAME_A4];
936 regp->r_regs[R_A5] = framep->tf_regs[FRAME_A5];
937 regp->r_regs[R_T8] = framep->tf_regs[FRAME_T8];
938 regp->r_regs[R_T9] = framep->tf_regs[FRAME_T9];
939 regp->r_regs[R_T10] = framep->tf_regs[FRAME_T10];
940 regp->r_regs[R_T11] = framep->tf_regs[FRAME_T11];
941 regp->r_regs[R_RA] = framep->tf_regs[FRAME_RA];
942 regp->r_regs[R_T12] = framep->tf_regs[FRAME_T12];
943 regp->r_regs[R_AT] = framep->tf_regs[FRAME_AT];
944 regp->r_regs[R_GP] = framep->tf_gp;
945 regp->r_regs[R_SP] = framep->tf_regs[FRAME_SP];
946 regp->r_regs[R_ZERO] = 0;
947 }
948
949 void
950 regtoframe(regp, framep)
951 struct reg *regp;
952 struct trapframe *framep;
953 {
954
955 framep->tf_regs[FRAME_V0] = regp->r_regs[R_V0];
956 framep->tf_regs[FRAME_T0] = regp->r_regs[R_T0];
957 framep->tf_regs[FRAME_T1] = regp->r_regs[R_T1];
958 framep->tf_regs[FRAME_T2] = regp->r_regs[R_T2];
959 framep->tf_regs[FRAME_T3] = regp->r_regs[R_T3];
960 framep->tf_regs[FRAME_T4] = regp->r_regs[R_T4];
961 framep->tf_regs[FRAME_T5] = regp->r_regs[R_T5];
962 framep->tf_regs[FRAME_T6] = regp->r_regs[R_T6];
963 framep->tf_regs[FRAME_T7] = regp->r_regs[R_T7];
964 framep->tf_regs[FRAME_S0] = regp->r_regs[R_S0];
965 framep->tf_regs[FRAME_S1] = regp->r_regs[R_S1];
966 framep->tf_regs[FRAME_S2] = regp->r_regs[R_S2];
967 framep->tf_regs[FRAME_S3] = regp->r_regs[R_S3];
968 framep->tf_regs[FRAME_S4] = regp->r_regs[R_S4];
969 framep->tf_regs[FRAME_S5] = regp->r_regs[R_S5];
970 framep->tf_regs[FRAME_S6] = regp->r_regs[R_S6];
971 framep->tf_a0 = regp->r_regs[R_A0];
972 framep->tf_a1 = regp->r_regs[R_A1];
973 framep->tf_a2 = regp->r_regs[R_A2];
974 framep->tf_regs[FRAME_A3] = regp->r_regs[R_A3];
975 framep->tf_regs[FRAME_A4] = regp->r_regs[R_A4];
976 framep->tf_regs[FRAME_A5] = regp->r_regs[R_A5];
977 framep->tf_regs[FRAME_T8] = regp->r_regs[R_T8];
978 framep->tf_regs[FRAME_T9] = regp->r_regs[R_T9];
979 framep->tf_regs[FRAME_T10] = regp->r_regs[R_T10];
980 framep->tf_regs[FRAME_T11] = regp->r_regs[R_T11];
981 framep->tf_regs[FRAME_RA] = regp->r_regs[R_RA];
982 framep->tf_regs[FRAME_T12] = regp->r_regs[R_T12];
983 framep->tf_regs[FRAME_AT] = regp->r_regs[R_AT];
984 framep->tf_gp = regp->r_regs[R_GP];
985 framep->tf_regs[FRAME_SP] = regp->r_regs[R_SP];
986 /* ??? = regp->r_regs[R_ZERO]; */
987 }
988
989 void
990 printregs(regp)
991 struct reg *regp;
992 {
993 int i;
994
995 for (i = 0; i < 32; i++)
996 printf("R%d:\t0x%016lx%s", i, regp->r_regs[i],
997 i & 1 ? "\n" : "\t");
998 }
999
1000 void
1001 regdump(framep)
1002 struct trapframe *framep;
1003 {
1004 struct reg reg;
1005
1006 frametoreg(framep, ®);
1007 printf("REGISTERS:\n");
1008 printregs(®);
1009 }
1010
1011 #ifdef DEBUG
1012 int sigdebug = 0;
1013 int sigpid = 0;
1014 #define SDB_FOLLOW 0x01
1015 #define SDB_KSTACK 0x02
1016 #endif
1017
1018 /*
1019 * Send an interrupt to process.
1020 */
1021 void
1022 sendsig(catcher, sig, mask, code)
1023 sig_t catcher;
1024 int sig, mask;
1025 u_long code;
1026 {
1027 struct proc *p = curproc;
1028 struct sigcontext *scp, ksc;
1029 struct trapframe *frame;
1030 struct sigacts *psp = p->p_sigacts;
1031 int oonstack, fsize, rndfsize;
1032 extern char sigcode[], esigcode[];
1033 extern struct proc *fpcurproc;
1034
1035 frame = p->p_md.md_tf;
1036 oonstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
1037 fsize = sizeof ksc;
1038 rndfsize = ((fsize + 15) / 16) * 16;
1039 /*
1040 * Allocate and validate space for the signal handler
1041 * context. Note that if the stack is in P0 space, the
1042 * call to grow() is a nop, and the useracc() check
1043 * will fail if the process has not already allocated
1044 * the space with a `brk'.
1045 */
1046 if ((psp->ps_flags & SAS_ALTSTACK) && !oonstack &&
1047 (psp->ps_sigonstack & sigmask(sig))) {
1048 scp = (struct sigcontext *)(psp->ps_sigstk.ss_sp +
1049 psp->ps_sigstk.ss_size - rndfsize);
1050 psp->ps_sigstk.ss_flags |= SS_ONSTACK;
1051 } else
1052 scp = (struct sigcontext *)(frame->tf_regs[FRAME_SP] -
1053 rndfsize);
1054 if ((u_long)scp <= USRSTACK - ctob(p->p_vmspace->vm_ssize))
1055 (void)grow(p, (u_long)scp);
1056 #ifdef DEBUG
1057 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
1058 printf("sendsig(%d): sig %d ssp %lx usp %lx\n", p->p_pid,
1059 sig, &oonstack, scp);
1060 #endif
1061 if (useracc((caddr_t)scp, fsize, B_WRITE) == 0) {
1062 #ifdef DEBUG
1063 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
1064 printf("sendsig(%d): useracc failed on sig %d\n",
1065 p->p_pid, sig);
1066 #endif
1067 /*
1068 * Process has trashed its stack; give it an illegal
1069 * instruction to halt it in its tracks.
1070 */
1071 SIGACTION(p, SIGILL) = SIG_DFL;
1072 sig = sigmask(SIGILL);
1073 p->p_sigignore &= ~sig;
1074 p->p_sigcatch &= ~sig;
1075 p->p_sigmask &= ~sig;
1076 psignal(p, SIGILL);
1077 return;
1078 }
1079
1080 /*
1081 * Build the signal context to be used by sigreturn.
1082 */
1083 ksc.sc_onstack = oonstack;
1084 ksc.sc_mask = mask;
1085 ksc.sc_pc = frame->tf_pc;
1086 ksc.sc_ps = frame->tf_ps;
1087
1088 /* copy the registers. */
1089 frametoreg(frame, (struct reg *)ksc.sc_regs);
1090 ksc.sc_regs[R_ZERO] = 0xACEDBADE; /* magic number */
1091
1092 /* save the floating-point state, if necessary, then copy it. */
1093 if (p == fpcurproc) {
1094 pal_wrfen(1);
1095 savefpstate(&p->p_addr->u_pcb.pcb_fp);
1096 pal_wrfen(0);
1097 fpcurproc = NULL;
1098 }
1099 ksc.sc_ownedfp = p->p_md.md_flags & MDP_FPUSED;
1100 bcopy(&p->p_addr->u_pcb.pcb_fp, (struct fpreg *)ksc.sc_fpregs,
1101 sizeof(struct fpreg));
1102 ksc.sc_fp_control = 0; /* XXX ? */
1103 bzero(ksc.sc_reserved, sizeof ksc.sc_reserved); /* XXX */
1104 bzero(ksc.sc_xxx, sizeof ksc.sc_xxx); /* XXX */
1105
1106
1107 #ifdef COMPAT_OSF1
1108 /*
1109 * XXX Create an OSF/1-style sigcontext and associated goo.
1110 */
1111 #endif
1112
1113 /*
1114 * copy the frame out to userland.
1115 */
1116 (void) copyout((caddr_t)&ksc, (caddr_t)scp, fsize);
1117 #ifdef DEBUG
1118 if (sigdebug & SDB_FOLLOW)
1119 printf("sendsig(%d): sig %d scp %lx code %lx\n", p->p_pid, sig,
1120 scp, code);
1121 #endif
1122
1123 /*
1124 * Set up the registers to return to sigcode.
1125 */
1126 frame->tf_pc = (u_int64_t)PS_STRINGS - (esigcode - sigcode);
1127 frame->tf_regs[FRAME_SP] = (u_int64_t)scp;
1128 frame->tf_a0 = sig;
1129 frame->tf_a1 = code;
1130 frame->tf_a2 = (u_int64_t)scp;
1131 frame->tf_regs[FRAME_T12] = (u_int64_t)catcher; /* t12 is pv */
1132
1133 #ifdef DEBUG
1134 if (sigdebug & SDB_FOLLOW)
1135 printf("sendsig(%d): pc %lx, catcher %lx\n", p->p_pid,
1136 frame->tf_pc, frame->tf_regs[FRAME_A3]);
1137 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
1138 printf("sendsig(%d): sig %d returns\n",
1139 p->p_pid, sig);
1140 #endif
1141 }
1142
1143 /*
1144 * System call to cleanup state after a signal
1145 * has been taken. Reset signal mask and
1146 * stack state from context left by sendsig (above).
1147 * Return to previous pc and psl as specified by
1148 * context left by sendsig. Check carefully to
1149 * make sure that the user has not modified the
1150 * psl to gain improper priviledges or to cause
1151 * a machine fault.
1152 */
1153 /* ARGSUSED */
1154 int
1155 sys_sigreturn(p, v, retval)
1156 struct proc *p;
1157 void *v;
1158 register_t *retval;
1159 {
1160 struct sys_sigreturn_args /* {
1161 syscallarg(struct sigcontext *) sigcntxp;
1162 } */ *uap = v;
1163 struct sigcontext *scp, ksc;
1164 extern struct proc *fpcurproc;
1165
1166 scp = SCARG(uap, sigcntxp);
1167 #ifdef DEBUG
1168 if (sigdebug & SDB_FOLLOW)
1169 printf("sigreturn: pid %d, scp %lx\n", p->p_pid, scp);
1170 #endif
1171
1172 if (ALIGN(scp) != (u_int64_t)scp)
1173 return (EINVAL);
1174
1175 /*
1176 * Test and fetch the context structure.
1177 * We grab it all at once for speed.
1178 */
1179 if (useracc((caddr_t)scp, sizeof (*scp), B_WRITE) == 0 ||
1180 copyin((caddr_t)scp, (caddr_t)&ksc, sizeof ksc))
1181 return (EINVAL);
1182
1183 if (ksc.sc_regs[R_ZERO] != 0xACEDBADE) /* magic number */
1184 return (EINVAL);
1185 /*
1186 * Restore the user-supplied information
1187 */
1188 if (ksc.sc_onstack)
1189 p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
1190 else
1191 p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
1192 p->p_sigmask = ksc.sc_mask &~ sigcantmask;
1193
1194 p->p_md.md_tf->tf_pc = ksc.sc_pc;
1195 p->p_md.md_tf->tf_ps = (ksc.sc_ps | PSL_USERSET) & ~PSL_USERCLR;
1196
1197 regtoframe((struct reg *)ksc.sc_regs, p->p_md.md_tf);
1198
1199 /* XXX ksc.sc_ownedfp ? */
1200 if (p == fpcurproc)
1201 fpcurproc = NULL;
1202 bcopy((struct fpreg *)ksc.sc_fpregs, &p->p_addr->u_pcb.pcb_fp,
1203 sizeof(struct fpreg));
1204 /* XXX ksc.sc_fp_control ? */
1205
1206 #ifdef DEBUG
1207 if (sigdebug & SDB_FOLLOW)
1208 printf("sigreturn(%d): returns\n", p->p_pid);
1209 #endif
1210 return (EJUSTRETURN);
1211 }
1212
1213 /*
1214 * machine dependent system variables.
1215 */
1216 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
1217 int *name;
1218 u_int namelen;
1219 void *oldp;
1220 size_t *oldlenp;
1221 void *newp;
1222 size_t newlen;
1223 struct proc *p;
1224 {
1225 dev_t consdev;
1226
1227 /* all sysctl names at this level are terminal */
1228 if (namelen != 1)
1229 return (ENOTDIR); /* overloaded */
1230
1231 switch (name[0]) {
1232 case CPU_CONSDEV:
1233 if (cn_tab != NULL)
1234 consdev = cn_tab->cn_dev;
1235 else
1236 consdev = NODEV;
1237 return (sysctl_rdstruct(oldp, oldlenp, newp, &consdev,
1238 sizeof consdev));
1239 default:
1240 return (EOPNOTSUPP);
1241 }
1242 /* NOTREACHED */
1243 }
1244
1245 /*
1246 * Set registers on exec.
1247 */
1248 void
1249 setregs(p, pack, stack, retval)
1250 register struct proc *p;
1251 struct exec_package *pack;
1252 u_long stack;
1253 register_t *retval;
1254 {
1255 struct trapframe *tfp = p->p_md.md_tf;
1256 int i;
1257 extern struct proc *fpcurproc;
1258
1259 #ifdef DEBUG
1260 for (i = 0; i < FRAME_NSAVEREGS; i++)
1261 tfp->tf_regs[i] = 0xbabefacedeadbeef;
1262 tfp->tf_gp = 0xbabefacedeadbeef;
1263 tfp->tf_a0 = 0xbabefacedeadbeef;
1264 tfp->tf_a1 = 0xbabefacedeadbeef;
1265 tfp->tf_a2 = 0xbabefacedeadbeef;
1266 #else
1267 bzero(tfp->tf_regs, FRAME_NSAVEREGS * sizeof tfp->tf_regs[0]);
1268 tfp->tf_gp = 0;
1269 tfp->tf_a0 = 0;
1270 tfp->tf_a1 = 0;
1271 tfp->tf_a2 = 0;
1272 #endif
1273 bzero(&p->p_addr->u_pcb.pcb_fp, sizeof p->p_addr->u_pcb.pcb_fp);
1274 #define FP_RN 2 /* XXX */
1275 p->p_addr->u_pcb.pcb_fp.fpr_cr = (long)FP_RN << 58;
1276 tfp->tf_regs[FRAME_SP] = stack; /* restored to usp in trap return */
1277 tfp->tf_ps = PSL_USERSET;
1278 tfp->tf_pc = pack->ep_entry & ~3;
1279
1280 p->p_md.md_flags & ~MDP_FPUSED;
1281 if (fpcurproc == p)
1282 fpcurproc = NULL;
1283
1284 retval[0] = retval[1] = 0;
1285 }
1286
1287 void
1288 netintr()
1289 {
1290 #ifdef INET
1291 #if NETHER > 0
1292 if (netisr & (1 << NETISR_ARP)) {
1293 netisr &= ~(1 << NETISR_ARP);
1294 arpintr();
1295 }
1296 #endif
1297 if (netisr & (1 << NETISR_IP)) {
1298 netisr &= ~(1 << NETISR_IP);
1299 ipintr();
1300 }
1301 #endif
1302 #ifdef NS
1303 if (netisr & (1 << NETISR_NS)) {
1304 netisr &= ~(1 << NETISR_NS);
1305 nsintr();
1306 }
1307 #endif
1308 #ifdef ISO
1309 if (netisr & (1 << NETISR_ISO)) {
1310 netisr &= ~(1 << NETISR_ISO);
1311 clnlintr();
1312 }
1313 #endif
1314 #ifdef CCITT
1315 if (netisr & (1 << NETISR_CCITT)) {
1316 netisr &= ~(1 << NETISR_CCITT);
1317 ccittintr();
1318 }
1319 #endif
1320 #ifdef PPP
1321 if (netisr & (1 << NETISR_PPP)) {
1322 netisr &= ~(1 << NETISR_CCITT);
1323 pppintr();
1324 }
1325 #endif
1326 }
1327
1328 void
1329 do_sir()
1330 {
1331
1332 if (ssir & SIR_NET) {
1333 siroff(SIR_NET);
1334 cnt.v_soft++;
1335 netintr();
1336 }
1337 if (ssir & SIR_CLOCK) {
1338 siroff(SIR_CLOCK);
1339 cnt.v_soft++;
1340 softclock();
1341 }
1342 }
1343
1344 int
1345 spl0()
1346 {
1347
1348 if (ssir) {
1349 splsoft();
1350 do_sir();
1351 }
1352
1353 return (pal_swpipl(PSL_IPL_0));
1354 }
1355
1356 /*
1357 * The following primitives manipulate the run queues. _whichqs tells which
1358 * of the 32 queues _qs have processes in them. Setrunqueue puts processes
1359 * into queues, Remrq removes them from queues. The running process is on
1360 * no queue, other processes are on a queue related to p->p_priority, divided
1361 * by 4 actually to shrink the 0-127 range of priorities into the 32 available
1362 * queues.
1363 */
1364 /*
1365 * setrunqueue(p)
1366 * proc *p;
1367 *
1368 * Call should be made at splclock(), and p->p_stat should be SRUN.
1369 */
1370
1371 void
1372 setrunqueue(p)
1373 struct proc *p;
1374 {
1375 int bit;
1376
1377 /* firewall: p->p_back must be NULL */
1378 if (p->p_back != NULL)
1379 panic("setrunqueue");
1380
1381 bit = p->p_priority >> 2;
1382 whichqs |= (1 << bit);
1383 p->p_forw = (struct proc *)&qs[bit];
1384 p->p_back = qs[bit].ph_rlink;
1385 p->p_back->p_forw = p;
1386 qs[bit].ph_rlink = p;
1387 }
1388
1389 /*
1390 * Remrq(p)
1391 *
1392 * Call should be made at splclock().
1393 */
1394 void
1395 remrq(p)
1396 struct proc *p;
1397 {
1398 int bit;
1399
1400 bit = p->p_priority >> 2;
1401 if ((whichqs & (1 << bit)) == 0)
1402 panic("remrq");
1403
1404 p->p_back->p_forw = p->p_forw;
1405 p->p_forw->p_back = p->p_back;
1406 p->p_back = NULL; /* for firewall checking. */
1407
1408 if ((struct proc *)&qs[bit] == qs[bit].ph_link)
1409 whichqs &= ~(1 << bit);
1410 }
1411
1412 /*
1413 * Return the best possible estimate of the time in the timeval
1414 * to which tvp points. Unfortunately, we can't read the hardware registers.
1415 * We guarantee that the time will be greater than the value obtained by a
1416 * previous call.
1417 */
1418 void
1419 microtime(tvp)
1420 register struct timeval *tvp;
1421 {
1422 int s = splclock();
1423 static struct timeval lasttime;
1424
1425 *tvp = time;
1426 #ifdef notdef
1427 tvp->tv_usec += clkread();
1428 while (tvp->tv_usec > 1000000) {
1429 tvp->tv_sec++;
1430 tvp->tv_usec -= 1000000;
1431 }
1432 #endif
1433 if (tvp->tv_sec == lasttime.tv_sec &&
1434 tvp->tv_usec <= lasttime.tv_usec &&
1435 (tvp->tv_usec = lasttime.tv_usec + 1) > 1000000) {
1436 tvp->tv_sec++;
1437 tvp->tv_usec -= 1000000;
1438 }
1439 lasttime = *tvp;
1440 splx(s);
1441 }
1442
1443 /*
1444 * Wait "n" microseconds.
1445 */
1446 int
1447 delay(n)
1448 int n;
1449 {
1450 long N = cycles_per_usec * (n);
1451
1452 while (N > 0) /* XXX */
1453 N -= 3; /* XXX */
1454 }
1455
1456 #if defined(COMPAT_OSF1) || 1 /* XXX */
1457 void
1458 cpu_exec_ecoff_setregs(p, pack, stack, retval)
1459 struct proc *p;
1460 struct exec_package *pack;
1461 u_long stack;
1462 register_t *retval;
1463 {
1464 struct ecoff_aouthdr *eap;
1465
1466 setregs(p, pack, stack, retval);
1467
1468 eap = (struct ecoff_aouthdr *)
1469 ((caddr_t)pack->ep_hdr + sizeof(struct ecoff_filehdr));
1470 p->p_md.md_tf->tf_gp = eap->ea_gp_value;
1471 }
1472
1473 /*
1474 * cpu_exec_ecoff_hook():
1475 * cpu-dependent ECOFF format hook for execve().
1476 *
1477 * Do any machine-dependent diddling of the exec package when doing ECOFF.
1478 *
1479 */
1480 int
1481 cpu_exec_ecoff_hook(p, epp, eap)
1482 struct proc *p;
1483 struct exec_package *epp;
1484 struct ecoff_aouthdr *eap;
1485 {
1486 struct ecoff_filehdr *efp = epp->ep_hdr;
1487 extern struct emul emul_netbsd;
1488 #ifdef COMPAT_OSF1
1489 extern struct emul emul_osf1;
1490 #endif
1491
1492 switch (efp->ef_magic) {
1493 #ifdef COMPAT_OSF1
1494 case ECOFF_MAGIC_ALPHA:
1495 epp->ep_emul = &emul_osf1;
1496 break;
1497 #endif
1498
1499 case ECOFF_MAGIC_NETBSD_ALPHA:
1500 epp->ep_emul = &emul_netbsd;
1501 break;
1502
1503 default:
1504 return ENOEXEC;
1505 }
1506 return 0;
1507 }
1508 #endif
1509
1510 vm_offset_t
1511 vtophys(vaddr)
1512 vm_offset_t vaddr;
1513 {
1514 vm_offset_t paddr;
1515
1516 if (vaddr < K0SEG_BEGIN) {
1517 printf("vtophys: invalid vaddr 0x%lx", vaddr);
1518 paddr = vaddr;
1519 } else if (vaddr < K0SEG_END)
1520 paddr = k0segtophys(vaddr);
1521 else
1522 paddr = vatopa(vaddr);
1523
1524 #if 0
1525 printf("vtophys(0x%lx) -> %lx\n", vaddr, paddr);
1526 #endif
1527
1528 return (paddr);
1529 }
1530