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