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