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