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