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