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