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