machdep.c revision 1.21 1 /* $NetBSD: machdep.c,v 1.21 1996/06/12 01:36:01 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': /* askname */
593 boothowto |= RB_ASKNAME;
594 break;
595
596 case 'A': /* DEC's notion of autoboot */
597 boothowto &= ~RB_SINGLE;
598 break;
599
600 #if 0
601 case 'm': /* mini root present in memory */
602 boothowto |= RB_MINIROOT;
603 break;
604 #endif
605 }
606 }
607
608 /*
609 * Figure out the number of cpus in the box, from RPB fields.
610 * Really. We mean it.
611 */
612 for (i = 0; i < hwrpb->rpb_pcs_cnt; i++) {
613 struct pcs *pcsp;
614
615 pcsp = (struct pcs *)((char *)hwrpb + hwrpb->rpb_pcs_off +
616 (i * hwrpb->rpb_pcs_size));
617 if ((pcsp->pcs_flags & PCS_PP) != 0)
618 ncpus++;
619 }
620
621 return (0);
622 }
623
624 void
625 consinit()
626 {
627
628 (*cpu_consinit)(boot_console);
629 pmap_unmap_prom();
630 }
631
632 void
633 cpu_startup()
634 {
635 register unsigned i;
636 register caddr_t v;
637 int base, residual;
638 vm_offset_t minaddr, maxaddr;
639 vm_size_t size;
640 #ifdef DEBUG
641 extern int pmapdebug;
642 int opmapdebug = pmapdebug;
643
644 pmapdebug = 0;
645 #endif
646
647 /*
648 * Good {morning,afternoon,evening,night}.
649 */
650 printf(version);
651 identifycpu();
652 printf("real mem = %d (%d reserved for PROM, %d used by NetBSD)\n",
653 ctob(totalphysmem), ctob(resvmem), ctob(physmem));
654 if (unusedmem)
655 printf("WARNING: unused memory = %d bytes\n", ctob(unusedmem));
656 if (unknownmem)
657 printf("WARNING: %d bytes of memory with unknown purpose\n",
658 ctob(unknownmem));
659
660 /*
661 * Allocate virtual address space for file I/O buffers.
662 * Note they are different than the array of headers, 'buf',
663 * and usually occupy more virtual memory than physical.
664 */
665 size = MAXBSIZE * nbuf;
666 buffer_map = kmem_suballoc(kernel_map, (vm_offset_t *)&buffers,
667 &maxaddr, size, TRUE);
668 minaddr = (vm_offset_t)buffers;
669 if (vm_map_find(buffer_map, vm_object_allocate(size), (vm_offset_t)0,
670 &minaddr, size, FALSE) != KERN_SUCCESS)
671 panic("startup: cannot allocate buffers");
672 base = bufpages / nbuf;
673 residual = bufpages % nbuf;
674 for (i = 0; i < nbuf; i++) {
675 vm_size_t curbufsize;
676 vm_offset_t curbuf;
677
678 /*
679 * First <residual> buffers get (base+1) physical pages
680 * allocated for them. The rest get (base) physical pages.
681 *
682 * The rest of each buffer occupies virtual space,
683 * but has no physical memory allocated for it.
684 */
685 curbuf = (vm_offset_t)buffers + i * MAXBSIZE;
686 curbufsize = CLBYTES * (i < residual ? base+1 : base);
687 vm_map_pageable(buffer_map, curbuf, curbuf+curbufsize, FALSE);
688 vm_map_simplify(buffer_map, curbuf);
689 }
690 /*
691 * Allocate a submap for exec arguments. This map effectively
692 * limits the number of processes exec'ing at any time.
693 */
694 exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
695 16 * NCARGS, TRUE);
696
697 /*
698 * Allocate a submap for physio
699 */
700 phys_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
701 VM_PHYS_SIZE, TRUE);
702
703 /*
704 * Finally, allocate mbuf pool. Since mclrefcnt is an off-size
705 * we use the more space efficient malloc in place of kmem_alloc.
706 */
707 mclrefcnt = (char *)malloc(NMBCLUSTERS+CLBYTES/MCLBYTES,
708 M_MBUF, M_NOWAIT);
709 bzero(mclrefcnt, NMBCLUSTERS+CLBYTES/MCLBYTES);
710 mb_map = kmem_suballoc(kernel_map, (vm_offset_t *)&mbutl, &maxaddr,
711 VM_MBUF_SIZE, FALSE);
712 /*
713 * Initialize callouts
714 */
715 callfree = callout;
716 for (i = 1; i < ncallout; i++)
717 callout[i-1].c_next = &callout[i];
718 callout[i-1].c_next = NULL;
719
720 #ifdef DEBUG
721 pmapdebug = opmapdebug;
722 #endif
723 printf("avail mem = %ld\n", (long)ptoa(cnt.v_free_count));
724 printf("using %ld buffers containing %ld bytes of memory\n",
725 (long)nbuf, (long)(bufpages * CLBYTES));
726
727 /*
728 * Set up buffers, so they can be used to read disk labels.
729 */
730 bufinit();
731
732 /*
733 * Configure the system.
734 */
735 configure();
736 }
737
738 identifycpu()
739 {
740
741 /*
742 * print out CPU identification information.
743 */
744 printf("%s, %dMHz\n", cpu_model,
745 hwrpb->rpb_cc_freq / 1000000); /* XXX true for 21164? */
746 printf("%d byte page size, %d processor%s.\n",
747 hwrpb->rpb_page_size, ncpus, ncpus == 1 ? "" : "s");
748 #if 0
749 /* this isn't defined for any systems that we run on? */
750 printf("serial number 0x%lx 0x%lx\n",
751 ((long *)hwrpb->rpb_ssn)[0], ((long *)hwrpb->rpb_ssn)[1]);
752
753 /* and these aren't particularly useful! */
754 printf("variation: 0x%lx, revision 0x%lx\n",
755 hwrpb->rpb_variation, *(long *)hwrpb->rpb_revision);
756 #endif
757 }
758
759 int waittime = -1;
760 struct pcb dumppcb;
761
762 void
763 boot(howto)
764 int howto;
765 {
766 extern int cold;
767
768 /* If system is cold, just halt. */
769 if (cold) {
770 howto |= RB_HALT;
771 goto haltsys;
772 }
773
774 boothowto = howto;
775 if ((howto & RB_NOSYNC) == 0 && waittime < 0) {
776 waittime = 0;
777 vfs_shutdown();
778 /*
779 * If we've been adjusting the clock, the todr
780 * will be out of synch; adjust it now.
781 */
782 resettodr();
783 }
784
785 /* Disable interrupts. */
786 splhigh();
787
788 /* If rebooting and a dump is requested do it. */
789 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) {
790 savectx(&dumppcb, 0);
791 dumpsys();
792 }
793
794 haltsys:
795
796 /* run any shutdown hooks */
797 doshutdownhooks();
798
799 #ifdef BOOTKEY
800 printf("hit any key to %s...\n", howto & RB_HALT ? "halt" : "reboot");
801 cngetc();
802 printf("\n");
803 #endif
804
805 /* Finally, halt/reboot the system. */
806 printf("%s\n\n", howto & RB_HALT ? "halted." : "rebooting...");
807 prom_halt(howto & RB_HALT);
808 /*NOTREACHED*/
809 }
810
811 /*
812 * These variables are needed by /sbin/savecore
813 */
814 u_long dumpmag = 0x8fca0101; /* magic number */
815 int dumpsize = 0; /* pages */
816 long dumplo = 0; /* blocks */
817
818 /*
819 * This is called by configure to set dumplo and dumpsize.
820 * Dumps always skip the first CLBYTES of disk space
821 * in case there might be a disk label stored there.
822 * If there is extra space, put dump at the end to
823 * reduce the chance that swapping trashes it.
824 */
825 void
826 dumpconf()
827 {
828 int nblks; /* size of dump area */
829 int maj;
830
831 if (dumpdev == NODEV)
832 return;
833 maj = major(dumpdev);
834 if (maj < 0 || maj >= nblkdev)
835 panic("dumpconf: bad dumpdev=0x%x", dumpdev);
836 if (bdevsw[maj].d_psize == NULL)
837 return;
838 nblks = (*bdevsw[maj].d_psize)(dumpdev);
839 if (nblks <= ctod(1))
840 return;
841
842 /* XXX XXX XXX STARTING MEMORY LOCATION */
843 dumpsize = physmem;
844
845 /* Always skip the first CLBYTES, in case there is a label there. */
846 if (dumplo < ctod(1))
847 dumplo = ctod(1);
848
849 /* Put dump at end of partition, and make it fit. */
850 if (dumpsize > dtoc(nblks - dumplo))
851 dumpsize = dtoc(nblks - dumplo);
852 if (dumplo < nblks - ctod(dumpsize))
853 dumplo = nblks - ctod(dumpsize);
854 }
855
856 /*
857 * Doadump comes here after turning off memory management and
858 * getting on the dump stack, either when called above, or by
859 * the auto-restart code.
860 */
861 void
862 dumpsys()
863 {
864
865 msgbufmapped = 0;
866 if (dumpdev == NODEV)
867 return;
868 if (dumpsize == 0) {
869 dumpconf();
870 if (dumpsize == 0)
871 return;
872 }
873 printf("\ndumping to dev %x, offset %d\n", dumpdev, dumplo);
874
875 printf("dump ");
876 switch ((*bdevsw[major(dumpdev)].d_dump)(dumpdev)) {
877
878 case ENXIO:
879 printf("device bad\n");
880 break;
881
882 case EFAULT:
883 printf("device not ready\n");
884 break;
885
886 case EINVAL:
887 printf("area improper\n");
888 break;
889
890 case EIO:
891 printf("i/o error\n");
892 break;
893
894 case EINTR:
895 printf("aborted from console\n");
896 break;
897
898 default:
899 printf("succeeded\n");
900 break;
901 }
902 printf("\n\n");
903 delay(1000);
904 }
905
906 void
907 frametoreg(framep, regp)
908 struct trapframe *framep;
909 struct reg *regp;
910 {
911
912 regp->r_regs[R_V0] = framep->tf_regs[FRAME_V0];
913 regp->r_regs[R_T0] = framep->tf_regs[FRAME_T0];
914 regp->r_regs[R_T1] = framep->tf_regs[FRAME_T1];
915 regp->r_regs[R_T2] = framep->tf_regs[FRAME_T2];
916 regp->r_regs[R_T3] = framep->tf_regs[FRAME_T3];
917 regp->r_regs[R_T4] = framep->tf_regs[FRAME_T4];
918 regp->r_regs[R_T5] = framep->tf_regs[FRAME_T5];
919 regp->r_regs[R_T6] = framep->tf_regs[FRAME_T6];
920 regp->r_regs[R_T7] = framep->tf_regs[FRAME_T7];
921 regp->r_regs[R_S0] = framep->tf_regs[FRAME_S0];
922 regp->r_regs[R_S1] = framep->tf_regs[FRAME_S1];
923 regp->r_regs[R_S2] = framep->tf_regs[FRAME_S2];
924 regp->r_regs[R_S3] = framep->tf_regs[FRAME_S3];
925 regp->r_regs[R_S4] = framep->tf_regs[FRAME_S4];
926 regp->r_regs[R_S5] = framep->tf_regs[FRAME_S5];
927 regp->r_regs[R_S6] = framep->tf_regs[FRAME_S6];
928 regp->r_regs[R_A0] = framep->tf_a0;
929 regp->r_regs[R_A1] = framep->tf_a1;
930 regp->r_regs[R_A2] = framep->tf_a2;
931 regp->r_regs[R_A3] = framep->tf_regs[FRAME_A3];
932 regp->r_regs[R_A4] = framep->tf_regs[FRAME_A4];
933 regp->r_regs[R_A5] = framep->tf_regs[FRAME_A5];
934 regp->r_regs[R_T8] = framep->tf_regs[FRAME_T8];
935 regp->r_regs[R_T9] = framep->tf_regs[FRAME_T9];
936 regp->r_regs[R_T10] = framep->tf_regs[FRAME_T10];
937 regp->r_regs[R_T11] = framep->tf_regs[FRAME_T11];
938 regp->r_regs[R_RA] = framep->tf_regs[FRAME_RA];
939 regp->r_regs[R_T12] = framep->tf_regs[FRAME_T12];
940 regp->r_regs[R_AT] = framep->tf_regs[FRAME_AT];
941 regp->r_regs[R_GP] = framep->tf_gp;
942 regp->r_regs[R_SP] = framep->tf_regs[FRAME_SP];
943 regp->r_regs[R_ZERO] = 0;
944 }
945
946 void
947 regtoframe(regp, framep)
948 struct reg *regp;
949 struct trapframe *framep;
950 {
951
952 framep->tf_regs[FRAME_V0] = regp->r_regs[R_V0];
953 framep->tf_regs[FRAME_T0] = regp->r_regs[R_T0];
954 framep->tf_regs[FRAME_T1] = regp->r_regs[R_T1];
955 framep->tf_regs[FRAME_T2] = regp->r_regs[R_T2];
956 framep->tf_regs[FRAME_T3] = regp->r_regs[R_T3];
957 framep->tf_regs[FRAME_T4] = regp->r_regs[R_T4];
958 framep->tf_regs[FRAME_T5] = regp->r_regs[R_T5];
959 framep->tf_regs[FRAME_T6] = regp->r_regs[R_T6];
960 framep->tf_regs[FRAME_T7] = regp->r_regs[R_T7];
961 framep->tf_regs[FRAME_S0] = regp->r_regs[R_S0];
962 framep->tf_regs[FRAME_S1] = regp->r_regs[R_S1];
963 framep->tf_regs[FRAME_S2] = regp->r_regs[R_S2];
964 framep->tf_regs[FRAME_S3] = regp->r_regs[R_S3];
965 framep->tf_regs[FRAME_S4] = regp->r_regs[R_S4];
966 framep->tf_regs[FRAME_S5] = regp->r_regs[R_S5];
967 framep->tf_regs[FRAME_S6] = regp->r_regs[R_S6];
968 framep->tf_a0 = regp->r_regs[R_A0];
969 framep->tf_a1 = regp->r_regs[R_A1];
970 framep->tf_a2 = regp->r_regs[R_A2];
971 framep->tf_regs[FRAME_A3] = regp->r_regs[R_A3];
972 framep->tf_regs[FRAME_A4] = regp->r_regs[R_A4];
973 framep->tf_regs[FRAME_A5] = regp->r_regs[R_A5];
974 framep->tf_regs[FRAME_T8] = regp->r_regs[R_T8];
975 framep->tf_regs[FRAME_T9] = regp->r_regs[R_T9];
976 framep->tf_regs[FRAME_T10] = regp->r_regs[R_T10];
977 framep->tf_regs[FRAME_T11] = regp->r_regs[R_T11];
978 framep->tf_regs[FRAME_RA] = regp->r_regs[R_RA];
979 framep->tf_regs[FRAME_T12] = regp->r_regs[R_T12];
980 framep->tf_regs[FRAME_AT] = regp->r_regs[R_AT];
981 framep->tf_gp = regp->r_regs[R_GP];
982 framep->tf_regs[FRAME_SP] = regp->r_regs[R_SP];
983 /* ??? = regp->r_regs[R_ZERO]; */
984 }
985
986 void
987 printregs(regp)
988 struct reg *regp;
989 {
990 int i;
991
992 for (i = 0; i < 32; i++)
993 printf("R%d:\t0x%016lx%s", i, regp->r_regs[i],
994 i & 1 ? "\n" : "\t");
995 }
996
997 void
998 regdump(framep)
999 struct trapframe *framep;
1000 {
1001 struct reg reg;
1002
1003 frametoreg(framep, ®);
1004 printf("REGISTERS:\n");
1005 printregs(®);
1006 }
1007
1008 #ifdef DEBUG
1009 int sigdebug = 0;
1010 int sigpid = 0;
1011 #define SDB_FOLLOW 0x01
1012 #define SDB_KSTACK 0x02
1013 #endif
1014
1015 /*
1016 * Send an interrupt to process.
1017 */
1018 void
1019 sendsig(catcher, sig, mask, code)
1020 sig_t catcher;
1021 int sig, mask;
1022 u_long code;
1023 {
1024 struct proc *p = curproc;
1025 struct sigcontext *scp, ksc;
1026 struct trapframe *frame;
1027 struct sigacts *psp = p->p_sigacts;
1028 int oonstack, fsize, rndfsize;
1029 extern char sigcode[], esigcode[];
1030 extern struct proc *fpcurproc;
1031
1032 frame = p->p_md.md_tf;
1033 oonstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
1034 fsize = sizeof ksc;
1035 rndfsize = ((fsize + 15) / 16) * 16;
1036 /*
1037 * Allocate and validate space for the signal handler
1038 * context. Note that if the stack is in P0 space, the
1039 * call to grow() is a nop, and the useracc() check
1040 * will fail if the process has not already allocated
1041 * the space with a `brk'.
1042 */
1043 if ((psp->ps_flags & SAS_ALTSTACK) && !oonstack &&
1044 (psp->ps_sigonstack & sigmask(sig))) {
1045 scp = (struct sigcontext *)(psp->ps_sigstk.ss_sp +
1046 psp->ps_sigstk.ss_size - rndfsize);
1047 psp->ps_sigstk.ss_flags |= SS_ONSTACK;
1048 } else
1049 scp = (struct sigcontext *)(frame->tf_regs[FRAME_SP] -
1050 rndfsize);
1051 if ((u_long)scp <= USRSTACK - ctob(p->p_vmspace->vm_ssize))
1052 (void)grow(p, (u_long)scp);
1053 #ifdef DEBUG
1054 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
1055 printf("sendsig(%d): sig %d ssp %lx usp %lx\n", p->p_pid,
1056 sig, &oonstack, scp);
1057 #endif
1058 if (useracc((caddr_t)scp, fsize, B_WRITE) == 0) {
1059 #ifdef DEBUG
1060 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
1061 printf("sendsig(%d): useracc failed on sig %d\n",
1062 p->p_pid, sig);
1063 #endif
1064 /*
1065 * Process has trashed its stack; give it an illegal
1066 * instruction to halt it in its tracks.
1067 */
1068 SIGACTION(p, SIGILL) = SIG_DFL;
1069 sig = sigmask(SIGILL);
1070 p->p_sigignore &= ~sig;
1071 p->p_sigcatch &= ~sig;
1072 p->p_sigmask &= ~sig;
1073 psignal(p, SIGILL);
1074 return;
1075 }
1076
1077 /*
1078 * Build the signal context to be used by sigreturn.
1079 */
1080 ksc.sc_onstack = oonstack;
1081 ksc.sc_mask = mask;
1082 ksc.sc_pc = frame->tf_pc;
1083 ksc.sc_ps = frame->tf_ps;
1084
1085 /* copy the registers. */
1086 frametoreg(frame, (struct reg *)ksc.sc_regs);
1087 ksc.sc_regs[R_ZERO] = 0xACEDBADE; /* magic number */
1088
1089 /* save the floating-point state, if necessary, then copy it. */
1090 if (p == fpcurproc) {
1091 pal_wrfen(1);
1092 savefpstate(&p->p_addr->u_pcb.pcb_fp);
1093 pal_wrfen(0);
1094 fpcurproc = NULL;
1095 }
1096 ksc.sc_ownedfp = p->p_md.md_flags & MDP_FPUSED;
1097 bcopy(&p->p_addr->u_pcb.pcb_fp, (struct fpreg *)ksc.sc_fpregs,
1098 sizeof(struct fpreg));
1099 ksc.sc_fp_control = 0; /* XXX ? */
1100 bzero(ksc.sc_reserved, sizeof ksc.sc_reserved); /* XXX */
1101 bzero(ksc.sc_xxx, sizeof ksc.sc_xxx); /* XXX */
1102
1103
1104 #ifdef COMPAT_OSF1
1105 /*
1106 * XXX Create an OSF/1-style sigcontext and associated goo.
1107 */
1108 #endif
1109
1110 /*
1111 * copy the frame out to userland.
1112 */
1113 (void) copyout((caddr_t)&ksc, (caddr_t)scp, fsize);
1114 #ifdef DEBUG
1115 if (sigdebug & SDB_FOLLOW)
1116 printf("sendsig(%d): sig %d scp %lx code %lx\n", p->p_pid, sig,
1117 scp, code);
1118 #endif
1119
1120 /*
1121 * Set up the registers to return to sigcode.
1122 */
1123 frame->tf_pc = (u_int64_t)PS_STRINGS - (esigcode - sigcode);
1124 frame->tf_regs[FRAME_SP] = (u_int64_t)scp;
1125 frame->tf_a0 = sig;
1126 frame->tf_a1 = code;
1127 frame->tf_a2 = (u_int64_t)scp;
1128 frame->tf_regs[FRAME_T12] = (u_int64_t)catcher; /* t12 is pv */
1129
1130 #ifdef DEBUG
1131 if (sigdebug & SDB_FOLLOW)
1132 printf("sendsig(%d): pc %lx, catcher %lx\n", p->p_pid,
1133 frame->tf_pc, frame->tf_regs[FRAME_A3]);
1134 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
1135 printf("sendsig(%d): sig %d returns\n",
1136 p->p_pid, sig);
1137 #endif
1138 }
1139
1140 /*
1141 * System call to cleanup state after a signal
1142 * has been taken. Reset signal mask and
1143 * stack state from context left by sendsig (above).
1144 * Return to previous pc and psl as specified by
1145 * context left by sendsig. Check carefully to
1146 * make sure that the user has not modified the
1147 * psl to gain improper priviledges or to cause
1148 * a machine fault.
1149 */
1150 /* ARGSUSED */
1151 int
1152 sys_sigreturn(p, v, retval)
1153 struct proc *p;
1154 void *v;
1155 register_t *retval;
1156 {
1157 struct sys_sigreturn_args /* {
1158 syscallarg(struct sigcontext *) sigcntxp;
1159 } */ *uap = v;
1160 struct sigcontext *scp, ksc;
1161 extern struct proc *fpcurproc;
1162
1163 scp = SCARG(uap, sigcntxp);
1164 #ifdef DEBUG
1165 if (sigdebug & SDB_FOLLOW)
1166 printf("sigreturn: pid %d, scp %lx\n", p->p_pid, scp);
1167 #endif
1168
1169 if (ALIGN(scp) != (u_int64_t)scp)
1170 return (EINVAL);
1171
1172 /*
1173 * Test and fetch the context structure.
1174 * We grab it all at once for speed.
1175 */
1176 if (useracc((caddr_t)scp, sizeof (*scp), B_WRITE) == 0 ||
1177 copyin((caddr_t)scp, (caddr_t)&ksc, sizeof ksc))
1178 return (EINVAL);
1179
1180 if (ksc.sc_regs[R_ZERO] != 0xACEDBADE) /* magic number */
1181 return (EINVAL);
1182 /*
1183 * Restore the user-supplied information
1184 */
1185 if (ksc.sc_onstack)
1186 p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
1187 else
1188 p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
1189 p->p_sigmask = ksc.sc_mask &~ sigcantmask;
1190
1191 p->p_md.md_tf->tf_pc = ksc.sc_pc;
1192 p->p_md.md_tf->tf_ps = (ksc.sc_ps | PSL_USERSET) & ~PSL_USERCLR;
1193
1194 regtoframe((struct reg *)ksc.sc_regs, p->p_md.md_tf);
1195
1196 /* XXX ksc.sc_ownedfp ? */
1197 if (p == fpcurproc)
1198 fpcurproc = NULL;
1199 bcopy((struct fpreg *)ksc.sc_fpregs, &p->p_addr->u_pcb.pcb_fp,
1200 sizeof(struct fpreg));
1201 /* XXX ksc.sc_fp_control ? */
1202
1203 #ifdef DEBUG
1204 if (sigdebug & SDB_FOLLOW)
1205 printf("sigreturn(%d): returns\n", p->p_pid);
1206 #endif
1207 return (EJUSTRETURN);
1208 }
1209
1210 /*
1211 * machine dependent system variables.
1212 */
1213 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
1214 int *name;
1215 u_int namelen;
1216 void *oldp;
1217 size_t *oldlenp;
1218 void *newp;
1219 size_t newlen;
1220 struct proc *p;
1221 {
1222 dev_t consdev;
1223
1224 /* all sysctl names at this level are terminal */
1225 if (namelen != 1)
1226 return (ENOTDIR); /* overloaded */
1227
1228 switch (name[0]) {
1229 case CPU_CONSDEV:
1230 if (cn_tab != NULL)
1231 consdev = cn_tab->cn_dev;
1232 else
1233 consdev = NODEV;
1234 return (sysctl_rdstruct(oldp, oldlenp, newp, &consdev,
1235 sizeof consdev));
1236 default:
1237 return (EOPNOTSUPP);
1238 }
1239 /* NOTREACHED */
1240 }
1241
1242 /*
1243 * Set registers on exec.
1244 */
1245 void
1246 setregs(p, pack, stack, retval)
1247 register struct proc *p;
1248 struct exec_package *pack;
1249 u_long stack;
1250 register_t *retval;
1251 {
1252 struct trapframe *tfp = p->p_md.md_tf;
1253 int i;
1254 extern struct proc *fpcurproc;
1255
1256 #ifdef DEBUG
1257 for (i = 0; i < FRAME_NSAVEREGS; i++)
1258 tfp->tf_regs[i] = 0xbabefacedeadbeef;
1259 tfp->tf_gp = 0xbabefacedeadbeef;
1260 tfp->tf_a0 = 0xbabefacedeadbeef;
1261 tfp->tf_a1 = 0xbabefacedeadbeef;
1262 tfp->tf_a2 = 0xbabefacedeadbeef;
1263 #else
1264 bzero(tfp->tf_regs, FRAME_NSAVEREGS * sizeof tfp->tf_regs[0]);
1265 tfp->tf_gp = 0;
1266 tfp->tf_a0 = 0;
1267 tfp->tf_a1 = 0;
1268 tfp->tf_a2 = 0;
1269 #endif
1270 bzero(&p->p_addr->u_pcb.pcb_fp, sizeof p->p_addr->u_pcb.pcb_fp);
1271 #define FP_RN 2 /* XXX */
1272 p->p_addr->u_pcb.pcb_fp.fpr_cr = (long)FP_RN << 58;
1273 tfp->tf_regs[FRAME_SP] = stack; /* restored to usp in trap return */
1274 tfp->tf_ps = PSL_USERSET;
1275 tfp->tf_pc = pack->ep_entry & ~3;
1276
1277 p->p_md.md_flags & ~MDP_FPUSED;
1278 if (fpcurproc == p)
1279 fpcurproc = NULL;
1280
1281 retval[0] = retval[1] = 0;
1282 }
1283
1284 void
1285 netintr()
1286 {
1287 #ifdef INET
1288 #if NETHER > 0
1289 if (netisr & (1 << NETISR_ARP)) {
1290 netisr &= ~(1 << NETISR_ARP);
1291 arpintr();
1292 }
1293 #endif
1294 if (netisr & (1 << NETISR_IP)) {
1295 netisr &= ~(1 << NETISR_IP);
1296 ipintr();
1297 }
1298 #endif
1299 #ifdef NS
1300 if (netisr & (1 << NETISR_NS)) {
1301 netisr &= ~(1 << NETISR_NS);
1302 nsintr();
1303 }
1304 #endif
1305 #ifdef ISO
1306 if (netisr & (1 << NETISR_ISO)) {
1307 netisr &= ~(1 << NETISR_ISO);
1308 clnlintr();
1309 }
1310 #endif
1311 #ifdef CCITT
1312 if (netisr & (1 << NETISR_CCITT)) {
1313 netisr &= ~(1 << NETISR_CCITT);
1314 ccittintr();
1315 }
1316 #endif
1317 #ifdef PPP
1318 if (netisr & (1 << NETISR_PPP)) {
1319 netisr &= ~(1 << NETISR_PPP);
1320 pppintr();
1321 }
1322 #endif
1323 }
1324
1325 void
1326 do_sir()
1327 {
1328
1329 if (ssir & SIR_NET) {
1330 siroff(SIR_NET);
1331 cnt.v_soft++;
1332 netintr();
1333 }
1334 if (ssir & SIR_CLOCK) {
1335 siroff(SIR_CLOCK);
1336 cnt.v_soft++;
1337 softclock();
1338 }
1339 }
1340
1341 int
1342 spl0()
1343 {
1344
1345 if (ssir) {
1346 splsoft();
1347 do_sir();
1348 }
1349
1350 return (pal_swpipl(PSL_IPL_0));
1351 }
1352
1353 /*
1354 * The following primitives manipulate the run queues. _whichqs tells which
1355 * of the 32 queues _qs have processes in them. Setrunqueue puts processes
1356 * into queues, Remrq removes them from queues. The running process is on
1357 * no queue, other processes are on a queue related to p->p_priority, divided
1358 * by 4 actually to shrink the 0-127 range of priorities into the 32 available
1359 * queues.
1360 */
1361 /*
1362 * setrunqueue(p)
1363 * proc *p;
1364 *
1365 * Call should be made at splclock(), and p->p_stat should be SRUN.
1366 */
1367
1368 void
1369 setrunqueue(p)
1370 struct proc *p;
1371 {
1372 int bit;
1373
1374 /* firewall: p->p_back must be NULL */
1375 if (p->p_back != NULL)
1376 panic("setrunqueue");
1377
1378 bit = p->p_priority >> 2;
1379 whichqs |= (1 << bit);
1380 p->p_forw = (struct proc *)&qs[bit];
1381 p->p_back = qs[bit].ph_rlink;
1382 p->p_back->p_forw = p;
1383 qs[bit].ph_rlink = p;
1384 }
1385
1386 /*
1387 * Remrq(p)
1388 *
1389 * Call should be made at splclock().
1390 */
1391 void
1392 remrq(p)
1393 struct proc *p;
1394 {
1395 int bit;
1396
1397 bit = p->p_priority >> 2;
1398 if ((whichqs & (1 << bit)) == 0)
1399 panic("remrq");
1400
1401 p->p_back->p_forw = p->p_forw;
1402 p->p_forw->p_back = p->p_back;
1403 p->p_back = NULL; /* for firewall checking. */
1404
1405 if ((struct proc *)&qs[bit] == qs[bit].ph_link)
1406 whichqs &= ~(1 << bit);
1407 }
1408
1409 /*
1410 * Return the best possible estimate of the time in the timeval
1411 * to which tvp points. Unfortunately, we can't read the hardware registers.
1412 * We guarantee that the time will be greater than the value obtained by a
1413 * previous call.
1414 */
1415 void
1416 microtime(tvp)
1417 register struct timeval *tvp;
1418 {
1419 int s = splclock();
1420 static struct timeval lasttime;
1421
1422 *tvp = time;
1423 #ifdef notdef
1424 tvp->tv_usec += clkread();
1425 while (tvp->tv_usec > 1000000) {
1426 tvp->tv_sec++;
1427 tvp->tv_usec -= 1000000;
1428 }
1429 #endif
1430 if (tvp->tv_sec == lasttime.tv_sec &&
1431 tvp->tv_usec <= lasttime.tv_usec &&
1432 (tvp->tv_usec = lasttime.tv_usec + 1) > 1000000) {
1433 tvp->tv_sec++;
1434 tvp->tv_usec -= 1000000;
1435 }
1436 lasttime = *tvp;
1437 splx(s);
1438 }
1439
1440 /*
1441 * Wait "n" microseconds.
1442 */
1443 int
1444 delay(n)
1445 int n;
1446 {
1447 long N = cycles_per_usec * (n);
1448
1449 while (N > 0) /* XXX */
1450 N -= 3; /* XXX */
1451 }
1452
1453 #if defined(COMPAT_OSF1) || 1 /* XXX */
1454 void
1455 cpu_exec_ecoff_setregs(p, epp, stack, retval)
1456 struct proc *p;
1457 struct exec_package *epp;
1458 u_long stack;
1459 register_t *retval;
1460 {
1461 struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr;
1462
1463 setregs(p, epp, stack, retval);
1464 p->p_md.md_tf->tf_gp = execp->a.gp_value;
1465 }
1466
1467 /*
1468 * cpu_exec_ecoff_hook():
1469 * cpu-dependent ECOFF format hook for execve().
1470 *
1471 * Do any machine-dependent diddling of the exec package when doing ECOFF.
1472 *
1473 */
1474 int
1475 cpu_exec_ecoff_hook(p, epp)
1476 struct proc *p;
1477 struct exec_package *epp;
1478 {
1479 struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr;
1480 extern struct emul emul_netbsd;
1481 #ifdef COMPAT_OSF1
1482 extern struct emul emul_osf1;
1483 #endif
1484
1485 switch (execp->f.f_magic) {
1486 #ifdef COMPAT_OSF1
1487 case ECOFF_MAGIC_ALPHA:
1488 epp->ep_emul = &emul_osf1;
1489 break;
1490 #endif
1491
1492 case ECOFF_MAGIC_NETBSD_ALPHA:
1493 epp->ep_emul = &emul_netbsd;
1494 break;
1495
1496 default:
1497 return ENOEXEC;
1498 }
1499 return 0;
1500 }
1501 #endif
1502
1503 vm_offset_t
1504 vtophys(vaddr)
1505 vm_offset_t vaddr;
1506 {
1507 vm_offset_t paddr;
1508
1509 if (vaddr < K0SEG_BEGIN) {
1510 printf("vtophys: invalid vaddr 0x%lx", vaddr);
1511 paddr = vaddr;
1512 } else if (vaddr < K0SEG_END)
1513 paddr = k0segtophys(vaddr);
1514 else
1515 paddr = vatopa(vaddr);
1516
1517 #if 0
1518 printf("vtophys(0x%lx) -> %lx\n", vaddr, paddr);
1519 #endif
1520
1521 return (paddr);
1522 }
1523