machdep.c revision 1.112 1 /* $NetBSD: machdep.c,v 1.112 1998/02/24 07:38:01 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center and by Chris G. Demetriou.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
42 * All rights reserved.
43 *
44 * Author: Chris G. Demetriou
45 *
46 * Permission to use, copy, modify and distribute this software and
47 * its documentation is hereby granted, provided that both the copyright
48 * notice and this permission notice appear in all copies of the
49 * software, derivative works or modified versions, and any portions
50 * thereof, and that both notices appear in supporting documentation.
51 *
52 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
53 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
54 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
55 *
56 * Carnegie Mellon requests users of this software to return to
57 *
58 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
59 * School of Computer Science
60 * Carnegie Mellon University
61 * Pittsburgh PA 15213-3890
62 *
63 * any improvements or extensions that they make and grant Carnegie the
64 * rights to redistribute these changes.
65 */
66
67 #include "opt_uvm.h"
68
69 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
70
71 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.112 1998/02/24 07:38:01 thorpej Exp $");
72
73 #include <sys/param.h>
74 #include <sys/systm.h>
75 #include <sys/signalvar.h>
76 #include <sys/kernel.h>
77 #include <sys/map.h>
78 #include <sys/proc.h>
79 #include <sys/buf.h>
80 #include <sys/reboot.h>
81 #include <sys/device.h>
82 #include <sys/file.h>
83 #ifdef REAL_CLISTS
84 #include <sys/clist.h>
85 #endif
86 #include <sys/callout.h>
87 #include <sys/malloc.h>
88 #include <sys/mbuf.h>
89 #include <sys/mman.h>
90 #include <sys/msgbuf.h>
91 #include <sys/ioctl.h>
92 #include <sys/tty.h>
93 #include <sys/user.h>
94 #include <sys/exec.h>
95 #include <sys/exec_ecoff.h>
96 #include <vm/vm.h>
97 #include <sys/sysctl.h>
98 #include <sys/core.h>
99 #include <sys/kcore.h>
100 #include <machine/kcore.h>
101 #ifdef SYSVMSG
102 #include <sys/msg.h>
103 #endif
104 #ifdef SYSVSEM
105 #include <sys/sem.h>
106 #endif
107 #ifdef SYSVSHM
108 #include <sys/shm.h>
109 #endif
110
111 #include <sys/mount.h>
112 #include <sys/syscallargs.h>
113
114 #include <vm/vm_kern.h>
115
116 #if defined(UVM)
117 #include <uvm/uvm_extern.h>
118 #endif
119
120 #include <dev/cons.h>
121
122 #include <machine/autoconf.h>
123 #include <machine/cpu.h>
124 #include <machine/reg.h>
125 #include <machine/rpb.h>
126 #include <machine/prom.h>
127 #include <machine/conf.h>
128
129 #include <net/netisr.h>
130 #include <net/if.h>
131
132 #ifdef INET
133 #include <netinet/in.h>
134 #include <netinet/ip_var.h>
135 #include "arp.h"
136 #if NARP > 0
137 #include <netinet/if_inarp.h>
138 #endif
139 #endif
140 #ifdef NS
141 #include <netns/ns_var.h>
142 #endif
143 #ifdef ISO
144 #include <netiso/iso.h>
145 #include <netiso/clnp.h>
146 #endif
147 #ifdef CCITT
148 #include <netccitt/x25.h>
149 #include <netccitt/pk.h>
150 #include <netccitt/pk_extern.h>
151 #endif
152 #ifdef NATM
153 #include <netnatm/natm.h>
154 #endif
155 #ifdef NETATALK
156 #include <netatalk/at_extern.h>
157 #endif
158 #include "ppp.h"
159 #if NPPP > 0
160 #include <net/ppp_defs.h>
161 #include <net/if_ppp.h>
162 #endif
163
164 #ifdef DDB
165 #include <machine/db_machdep.h>
166 #include <ddb/db_access.h>
167 #include <ddb/db_sym.h>
168 #include <ddb/db_extern.h>
169 #include <ddb/db_interface.h>
170 #endif
171
172 #if defined(UVM)
173 vm_map_t exec_map = NULL;
174 vm_map_t mb_map = NULL;
175 vm_map_t phys_map = NULL;
176 #else
177 vm_map_t buffer_map;
178 #endif
179
180 /*
181 * Declare these as initialized data so we can patch them.
182 */
183 int nswbuf = 0;
184 #ifdef NBUF
185 int nbuf = NBUF;
186 #else
187 int nbuf = 0;
188 #endif
189 #ifdef BUFPAGES
190 int bufpages = BUFPAGES;
191 #else
192 int bufpages = 0;
193 #endif
194 caddr_t msgbufaddr;
195
196 int maxmem; /* max memory per process */
197
198 int totalphysmem; /* total amount of physical memory in system */
199 int physmem; /* physical memory used by NetBSD + some rsvd */
200 int resvmem; /* amount of memory reserved for PROM */
201 int unusedmem; /* amount of memory for OS that we don't use */
202 int unknownmem; /* amount of memory with an unknown use */
203
204 int cputype; /* system type, from the RPB */
205
206 /*
207 * XXX We need an address to which we can assign things so that they
208 * won't be optimized away because we didn't use the value.
209 */
210 u_int32_t no_optimize;
211
212 /* the following is used externally (sysctl_hw) */
213 char machine[] = MACHINE; /* from <machine/param.h> */
214 char machine_arch[] = MACHINE_ARCH; /* from <machine/param.h> */
215 char cpu_model[128];
216
217 struct user *proc0paddr;
218
219 /* Number of machine cycles per microsecond */
220 u_int64_t cycles_per_usec;
221
222 /* number of cpus in the box. really! */
223 int ncpus;
224
225 struct bootinfo_kernel bootinfo;
226
227 struct platform platform;
228
229 u_int32_t vm_mbuf_size = _VM_MBUF_SIZE;
230 u_int32_t vm_kmem_size = _VM_KMEM_SIZE;
231 u_int32_t vm_phys_size = _VM_PHYS_SIZE;
232
233 #ifdef DDB
234 /* start and end of kernel symbol table */
235 void *ksym_start, *ksym_end;
236 #endif
237
238 /* for cpu_sysctl() */
239 int alpha_unaligned_print = 1; /* warn about unaligned accesses */
240 int alpha_unaligned_fix = 1; /* fix up unaligned accesses */
241 int alpha_unaligned_sigbus = 0; /* don't SIGBUS on fixed-up accesses */
242
243 /*
244 * XXX This should be dynamically sized, but we have the chicken-egg problem!
245 * XXX it should also be larger than it is, because not all of the mddt
246 * XXX clusters end up being used for VM.
247 */
248 phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX]; /* low size bits overloaded */
249 int mem_cluster_cnt;
250
251 caddr_t allocsys __P((caddr_t));
252 int cpu_dump __P((void));
253 int cpu_dumpsize __P((void));
254 u_long cpu_dump_mempagecnt __P((void));
255 void dumpsys __P((void));
256 void identifycpu __P((void));
257 void netintr __P((void));
258 void printregs __P((struct reg *));
259
260 void
261 alpha_init(pfn, ptb, bim, bip, biv)
262 u_long pfn; /* first free PFN number */
263 u_long ptb; /* PFN of current level 1 page table */
264 u_long bim; /* bootinfo magic */
265 u_long bip; /* bootinfo pointer */
266 u_long biv; /* bootinfo version */
267 {
268 extern char kernel_text[], _end[];
269 struct mddt *mddtp;
270 struct mddt_cluster *memc;
271 int i, mddtweird;
272 struct vm_physseg *vps;
273 vm_offset_t kernstart, kernend;
274 vm_offset_t kernstartpfn, kernendpfn, pfn0, pfn1;
275 vm_size_t size;
276 char *p;
277 caddr_t v;
278 char *bootinfo_msg;
279
280 /* NO OUTPUT ALLOWED UNTIL FURTHER NOTICE */
281
282 /*
283 * Turn off interrupts (not mchecks) and floating point.
284 * Make sure the instruction and data streams are consistent.
285 */
286 (void)alpha_pal_swpipl(ALPHA_PSL_IPL_HIGH);
287 alpha_pal_wrfen(0);
288 ALPHA_TBIA();
289 alpha_pal_imb();
290
291 /*
292 * Get critical system information (if possible, from the
293 * information provided by the boot program).
294 */
295 bootinfo_msg = NULL;
296 if (bim == BOOTINFO_MAGIC) {
297 if (biv == 0) { /* backward compat */
298 biv = *(u_long *)bip;
299 bip += 8;
300 }
301 switch (biv) {
302 case 1: {
303 struct bootinfo_v1 *v1p = (struct bootinfo_v1 *)bip;
304
305 bootinfo.ssym = v1p->ssym;
306 bootinfo.esym = v1p->esym;
307 /* hwrpb may not be provided by boot block in v1 */
308 if (v1p->hwrpb != NULL) {
309 bootinfo.hwrpb_phys =
310 ((struct rpb *)v1p->hwrpb)->rpb_phys;
311 bootinfo.hwrpb_size = v1p->hwrpbsize;
312 } else {
313 bootinfo.hwrpb_phys =
314 ((struct rpb *)HWRPB_ADDR)->rpb_phys;
315 bootinfo.hwrpb_size =
316 ((struct rpb *)HWRPB_ADDR)->rpb_size;
317 }
318 bcopy(v1p->boot_flags, bootinfo.boot_flags,
319 min(sizeof v1p->boot_flags,
320 sizeof bootinfo.boot_flags));
321 bcopy(v1p->booted_kernel, bootinfo.booted_kernel,
322 min(sizeof v1p->booted_kernel,
323 sizeof bootinfo.booted_kernel));
324 /* booted dev not provided in bootinfo */
325 init_prom_interface((struct rpb *)
326 ALPHA_PHYS_TO_K0SEG(bootinfo.hwrpb_phys));
327 prom_getenv(PROM_E_BOOTED_DEV, bootinfo.booted_dev,
328 sizeof bootinfo.booted_dev);
329 break;
330 }
331 default:
332 bootinfo_msg = "unknown bootinfo version";
333 goto nobootinfo;
334 }
335 } else {
336 bootinfo_msg = "boot program did not pass bootinfo";
337 nobootinfo:
338 bootinfo.ssym = (u_long)_end;
339 bootinfo.esym = (u_long)_end;
340 bootinfo.hwrpb_phys = ((struct rpb *)HWRPB_ADDR)->rpb_phys;
341 bootinfo.hwrpb_size = ((struct rpb *)HWRPB_ADDR)->rpb_size;
342 init_prom_interface((struct rpb *)HWRPB_ADDR);
343 prom_getenv(PROM_E_BOOTED_OSFLAGS, bootinfo.boot_flags,
344 sizeof bootinfo.boot_flags);
345 prom_getenv(PROM_E_BOOTED_FILE, bootinfo.booted_kernel,
346 sizeof bootinfo.booted_kernel);
347 prom_getenv(PROM_E_BOOTED_DEV, bootinfo.booted_dev,
348 sizeof bootinfo.booted_dev);
349 }
350
351 /*
352 * Initialize the kernel's mapping of the RPB. It's needed for
353 * lots of things.
354 */
355 hwrpb = (struct rpb *)ALPHA_PHYS_TO_K0SEG(bootinfo.hwrpb_phys);
356
357 /*
358 * Remember how many cycles there are per microsecond,
359 * so that we can use delay(). Round up, for safety.
360 */
361 cycles_per_usec = (hwrpb->rpb_cc_freq + 999999) / 1000000;
362
363 /*
364 * Initalize the (temporary) bootstrap console interface, so
365 * we can use printf until the VM system starts being setup.
366 * The real console is initialized before then.
367 */
368 init_bootstrap_console();
369
370 /* OUTPUT NOW ALLOWED */
371
372 /* delayed from above */
373 if (bootinfo_msg)
374 printf("WARNING: %s (0x%lx, 0x%lx, 0x%lx)\n",
375 bootinfo_msg, bim, bip, biv);
376
377 /*
378 * Point interrupt/exception vectors to our own.
379 */
380 alpha_pal_wrent(XentInt, ALPHA_KENTRY_INT);
381 alpha_pal_wrent(XentArith, ALPHA_KENTRY_ARITH);
382 alpha_pal_wrent(XentMM, ALPHA_KENTRY_MM);
383 alpha_pal_wrent(XentIF, ALPHA_KENTRY_IF);
384 alpha_pal_wrent(XentUna, ALPHA_KENTRY_UNA);
385 alpha_pal_wrent(XentSys, ALPHA_KENTRY_SYS);
386
387 /*
388 * Clear pending machine checks and error reports, and enable
389 * system- and processor-correctable error reporting.
390 */
391 alpha_pal_wrmces(alpha_pal_rdmces() &
392 ~(ALPHA_MCES_DSC|ALPHA_MCES_DPC));
393
394 /*
395 * Find out what hardware we're on, and do basic initialization.
396 */
397 cputype = hwrpb->rpb_type;
398 if (cputype >= ncpuinit) {
399 platform_not_supported();
400 /* NOTREACHED */
401 }
402 (*cpuinit[cputype].init)();
403 strcpy(cpu_model, platform.model);
404
405 /*
406 * Initalize the real console, so the the bootstrap console is
407 * no longer necessary.
408 */
409 #ifdef _PMAP_MAY_USE_PROM_CONSOLE
410 if (!pmap_uses_prom_console())
411 #endif
412 (*platform.cons_init)();
413
414 #ifdef DIAGNOSTIC
415 /* Paranoid sanity checking */
416
417 /* We should always be running on the the primary. */
418 assert(hwrpb->rpb_primary_cpu_id == alpha_pal_whami());
419
420 /* On single-CPU systypes, the primary should always be CPU 0. */
421 if (cputype != ST_DEC_21000)
422 assert(hwrpb->rpb_primary_cpu_id == 0);
423 #endif
424
425 /* NO MORE FIRMWARE ACCESS ALLOWED */
426 #ifdef _PMAP_MAY_USE_PROM_CONSOLE
427 /*
428 * XXX (unless _PMAP_MAY_USE_PROM_CONSOLE is defined and
429 * XXX pmap_uses_prom_console() evaluates to non-zero.)
430 */
431 #endif
432
433 /*
434 * find out this system's page size
435 */
436 PAGE_SIZE = hwrpb->rpb_page_size;
437 if (PAGE_SIZE != 8192)
438 panic("page size %d != 8192?!", PAGE_SIZE);
439
440 /*
441 * Initialize PAGE_SIZE-dependent variables.
442 */
443 #if defined(UVM)
444 uvm_setpagesize();
445 #else
446 vm_set_page_size();
447 #endif
448
449 /*
450 * Find the beginning and end of the kernel (and leave a
451 * bit of space before the beginning for the bootstrap
452 * stack).
453 */
454 kernstart = trunc_page(kernel_text) - 2 * PAGE_SIZE;
455 #ifdef DDB
456 ksym_start = (void *)bootinfo.ssym;
457 ksym_end = (void *)bootinfo.esym;
458 kernend = (vm_offset_t)round_page(ksym_end);
459 #else
460 kernend = (vm_offset_t)round_page(_end);
461 #endif
462
463 kernstartpfn = atop(ALPHA_K0SEG_TO_PHYS(kernstart));
464 kernendpfn = atop(ALPHA_K0SEG_TO_PHYS(kernend));
465
466 /*
467 * Find out how much memory is available, by looking at
468 * the memory cluster descriptors. This also tries to do
469 * its best to detect things things that have never been seen
470 * before...
471 */
472 mddtp = (struct mddt *)(((caddr_t)hwrpb) + hwrpb->rpb_memdat_off);
473
474 /* MDDT SANITY CHECKING */
475 mddtweird = 0;
476 if (mddtp->mddt_cluster_cnt < 2) {
477 mddtweird = 1;
478 printf("WARNING: weird number of mem clusters: %d\n",
479 mddtp->mddt_cluster_cnt);
480 }
481
482 #if 0
483 printf("Memory cluster count: %d\n", mddtp->mddt_cluster_cnt);
484 #endif
485
486 for (i = 0; i < mddtp->mddt_cluster_cnt; i++) {
487 memc = &mddtp->mddt_clusters[i];
488 #if 0
489 printf("MEMC %d: pfn 0x%lx cnt 0x%lx usage 0x%lx\n", i,
490 memc->mddt_pfn, memc->mddt_pg_cnt, memc->mddt_usage);
491 #endif
492 totalphysmem += memc->mddt_pg_cnt;
493 if (mem_cluster_cnt < VM_PHYSSEG_MAX) { /* XXX */
494 mem_clusters[mem_cluster_cnt].start =
495 ptoa(memc->mddt_pfn);
496 mem_clusters[mem_cluster_cnt].size =
497 ptoa(memc->mddt_pg_cnt);
498 if (memc->mddt_usage & MDDT_mbz ||
499 memc->mddt_usage & MDDT_NONVOLATILE || /* XXX */
500 memc->mddt_usage & MDDT_PALCODE)
501 mem_clusters[mem_cluster_cnt].size |=
502 PROT_READ;
503 else
504 mem_clusters[mem_cluster_cnt].size |=
505 PROT_READ | PROT_WRITE | PROT_EXEC;
506 mem_cluster_cnt++;
507 }
508
509 if (memc->mddt_usage & MDDT_mbz) {
510 mddtweird = 1;
511 printf("WARNING: mem cluster %d has weird "
512 "usage 0x%lx\n", i, memc->mddt_usage);
513 unknownmem += memc->mddt_pg_cnt;
514 continue;
515 }
516 if (memc->mddt_usage & MDDT_NONVOLATILE) {
517 /* XXX should handle these... */
518 printf("WARNING: skipping non-volatile mem "
519 "cluster %d\n", i);
520 unusedmem += memc->mddt_pg_cnt;
521 continue;
522 }
523 if (memc->mddt_usage & MDDT_PALCODE) {
524 resvmem += memc->mddt_pg_cnt;
525 continue;
526 }
527
528 /*
529 * We have a memory cluster available for system
530 * software use. We must determine if this cluster
531 * holds the kernel.
532 */
533 #ifdef _PMAP_MAY_USE_PROM_CONSOLE
534 /*
535 * XXX If the kernel uses the PROM console, we only use the
536 * XXX memory after the kernel in the first system segment,
537 * XXX to avoid clobbering prom mapping, data, etc.
538 */
539 if (!pmap_uses_prom_console() || physmem == 0) {
540 #endif /* _PMAP_MAY_USE_PROM_CONSOLE */
541 physmem += memc->mddt_pg_cnt;
542 pfn0 = memc->mddt_pfn;
543 pfn1 = memc->mddt_pfn + memc->mddt_pg_cnt;
544 if (pfn0 <= kernstartpfn && kernendpfn <= pfn1) {
545 /*
546 * Must compute the location of the kernel
547 * within the segment.
548 */
549 #if 0
550 printf("Cluster %d contains kernel\n", i);
551 #endif
552 #ifdef _PMAP_MAY_USE_PROM_CONSOLE
553 if (!pmap_uses_prom_console()) {
554 #endif /* _PMAP_MAY_USE_PROM_CONSOLE */
555 if (pfn0 < kernstartpfn) {
556 /*
557 * There is a chunk before the kernel.
558 */
559 #if 0
560 printf("Loading chunk before kernel: "
561 "0x%lx / 0x%lx\n", pfn0, kernstartpfn);
562 #endif
563 #if defined(UVM)
564 uvm_page_physload(pfn0, kernstartpfn,
565 pfn0, kernstartpfn);
566 #else
567 vm_page_physload(pfn0, kernstartpfn,
568 pfn0, kernstartpfn);
569 #endif
570 }
571 #ifdef _PMAP_MAY_USE_PROM_CONSOLE
572 }
573 #endif /* _PMAP_MAY_USE_PROM_CONSOLE */
574 if (kernendpfn < pfn1) {
575 /*
576 * There is a chunk after the kernel.
577 */
578 #if 0
579 printf("Loading chunk after kernel: "
580 "0x%lx / 0x%lx\n", kernendpfn, pfn1);
581 #endif
582 #if defined(UVM)
583 uvm_page_physload(kernendpfn, pfn1,
584 kernendpfn, pfn1);
585 #else
586 vm_page_physload(kernendpfn, pfn1,
587 kernendpfn, pfn1);
588 #endif
589 }
590 } else {
591 /*
592 * Just load this cluster as one chunk.
593 */
594 #if 0
595 printf("Loading cluster %d: 0x%lx / 0x%lx\n", i,
596 pfn0, pfn1);
597 #endif
598 #if defined(UVM)
599 uvm_page_physload(pfn0, pfn1, pfn0, pfn1);
600 #else
601 vm_page_physload(pfn0, pfn1, pfn0, pfn1);
602 #endif
603 }
604 #ifdef _PMAP_MAY_USE_PROM_CONSOLE
605 }
606 #endif /* _PMAP_MAY_USE_PROM_CONSOLE */
607 }
608
609 /*
610 * Dump out the MDDT if it looks odd...
611 */
612 if (mddtweird) {
613 printf("\n");
614 printf("complete memory cluster information:\n");
615 for (i = 0; i < mddtp->mddt_cluster_cnt; i++) {
616 printf("mddt %d:\n", i);
617 printf("\tpfn %lx\n",
618 mddtp->mddt_clusters[i].mddt_pfn);
619 printf("\tcnt %lx\n",
620 mddtp->mddt_clusters[i].mddt_pg_cnt);
621 printf("\ttest %lx\n",
622 mddtp->mddt_clusters[i].mddt_pg_test);
623 printf("\tbva %lx\n",
624 mddtp->mddt_clusters[i].mddt_v_bitaddr);
625 printf("\tbpa %lx\n",
626 mddtp->mddt_clusters[i].mddt_p_bitaddr);
627 printf("\tbcksum %lx\n",
628 mddtp->mddt_clusters[i].mddt_bit_cksum);
629 printf("\tusage %lx\n",
630 mddtp->mddt_clusters[i].mddt_usage);
631 }
632 printf("\n");
633 }
634
635 if (totalphysmem == 0)
636 panic("can't happen: system seems to have no memory!");
637
638 #ifdef LIMITMEM
639 /*
640 * XXX Kludge so we can run on machines with memory larger
641 * XXX than 1G until all device drivers are converted to
642 * XXX use bus_dma. (Relies on the fact that vm_physmem
643 * XXX sorted in order of increasing addresses.)
644 */
645 if (vm_physmem[vm_nphysseg - 1].end > atop(LIMITMEM * 1024 * 1024)) {
646
647 printf("******** LIMITING MEMORY TO %dMB **********\n",
648 LIMITMEM);
649
650 do {
651 u_long ovf;
652
653 vps = &vm_physmem[vm_nphysseg - 1];
654
655 if (vps->start >= atop(LIMITMEM * 1024 * 1024)) {
656 /*
657 * If the start is too high, just drop
658 * the whole segment.
659 *
660 * XXX can start != avail_start in this
661 * XXX case? wouldn't that mean that
662 * XXX some memory was stolen above the
663 * XXX limit? What to do?
664 */
665 ovf = vps->end - vps->start;
666 vm_nphysseg--;
667 } else {
668 /*
669 * If the start is OK, calculate how much
670 * to drop and drop it.
671 */
672 ovf = vps->end - atop(LIMITMEM * 1024 * 1024);
673 vps->end -= ovf;
674 vps->avail_end -= ovf;
675 }
676 physmem -= ovf;
677 unusedmem += ovf;
678 } while (vps->end > atop(LIMITMEM * 1024 * 1024));
679 }
680 #endif /* LIMITMEM */
681
682 maxmem = physmem;
683
684 #if 0
685 printf("totalphysmem = %d\n", totalphysmem);
686 printf("physmem = %d\n", physmem);
687 printf("resvmem = %d\n", resvmem);
688 printf("unusedmem = %d\n", unusedmem);
689 printf("unknownmem = %d\n", unknownmem);
690 #endif
691
692 /*
693 * Adjust some parameters if the amount of physmem
694 * available would cause us to croak. This is completely
695 * eyeballed and isn't meant to be the final answer.
696 * vm_phys_size is probably the only one to really worry
697 * about.
698 *
699 * It's for booting a GENERIC kernel on a large memory platform.
700 */
701 if (physmem >= atop(128 * 1024 * 1024)) {
702 vm_mbuf_size <<= 1;
703 vm_kmem_size <<= 3;
704 vm_phys_size <<= 2;
705 }
706
707 /*
708 * Initialize error message buffer (at end of core).
709 */
710 {
711 size_t sz = round_page(MSGBUFSIZE);
712
713 vps = &vm_physmem[vm_nphysseg - 1];
714
715 /* shrink so that it'll fit in the last segment */
716 if ((vps->avail_end - vps->avail_start) < atop(sz))
717 sz = ptoa(vps->avail_end - vps->avail_start);
718
719 vps->end -= atop(sz);
720 vps->avail_end -= atop(sz);
721 msgbufaddr = (caddr_t) ALPHA_PHYS_TO_K0SEG(ptoa(vps->end));
722 initmsgbuf(msgbufaddr, sz);
723
724 /* Remove the last segment if it now has no pages. */
725 if (vps->start == vps->end)
726 vm_nphysseg--;
727
728 /* warn if the message buffer had to be shrunk */
729 if (sz != round_page(MSGBUFSIZE))
730 printf("WARNING: %d bytes not available for msgbuf in last cluster (%d used)\n",
731 round_page(MSGBUFSIZE), sz);
732
733 }
734
735 /*
736 * Init mapping for u page(s) for proc 0
737 */
738 proc0.p_addr = proc0paddr =
739 (struct user *)pmap_steal_memory(UPAGES * PAGE_SIZE, NULL, NULL);
740
741 /*
742 * Allocate space for system data structures. These data structures
743 * are allocated here instead of cpu_startup() because physical
744 * memory is directly addressable. We don't have to map these into
745 * virtual address space.
746 */
747 size = (vm_size_t)allocsys(0);
748 v = (caddr_t)pmap_steal_memory(size, NULL, NULL);
749 if ((allocsys(v) - v) != size)
750 panic("alpha_init: table size inconsistency");
751
752 /*
753 * Initialize the virtual memory system, and set the
754 * page table base register in proc 0's PCB.
755 */
756 #ifndef NEW_PMAP
757 pmap_bootstrap(ALPHA_PHYS_TO_K0SEG(ptb << PGSHIFT));
758 #else
759 pmap_bootstrap(ALPHA_PHYS_TO_K0SEG(ptb << PGSHIFT),
760 hwrpb->rpb_max_asn);
761 #endif
762
763 /*
764 * Initialize the rest of proc 0's PCB, and cache its physical
765 * address.
766 */
767 proc0.p_md.md_pcbpaddr =
768 (struct pcb *)ALPHA_K0SEG_TO_PHYS((vm_offset_t)&proc0paddr->u_pcb);
769
770 /*
771 * Set the kernel sp, reserving space for an (empty) trapframe,
772 * and make proc0's trapframe pointer point to it for sanity.
773 */
774 proc0paddr->u_pcb.pcb_hw.apcb_ksp =
775 (u_int64_t)proc0paddr + USPACE - sizeof(struct trapframe);
776 proc0.p_md.md_tf =
777 (struct trapframe *)proc0paddr->u_pcb.pcb_hw.apcb_ksp;
778
779 #ifdef NEW_PMAP
780 /*
781 * Set up the kernel address space in proc0's hwpcb.
782 */
783 PMAP_ACTIVATE(kernel_pmap, &proc0paddr->u_pcb.pcb_hw, 0);
784 #endif
785
786 /*
787 * Look at arguments passed to us and compute boothowto.
788 */
789
790 boothowto = RB_SINGLE;
791 #ifdef KADB
792 boothowto |= RB_KDB;
793 #endif
794 for (p = bootinfo.boot_flags; p && *p != '\0'; p++) {
795 /*
796 * Note that we'd really like to differentiate case here,
797 * but the Alpha AXP Architecture Reference Manual
798 * says that we shouldn't.
799 */
800 switch (*p) {
801 case 'a': /* autoboot */
802 case 'A':
803 boothowto &= ~RB_SINGLE;
804 break;
805
806 #ifdef DEBUG
807 case 'c': /* crash dump immediately after autoconfig */
808 case 'C':
809 boothowto |= RB_DUMP;
810 break;
811 #endif
812
813 #if defined(KGDB) || defined(DDB)
814 case 'd': /* break into the kernel debugger ASAP */
815 case 'D':
816 boothowto |= RB_KDB;
817 break;
818 #endif
819
820 case 'h': /* always halt, never reboot */
821 case 'H':
822 boothowto |= RB_HALT;
823 break;
824
825 #if 0
826 case 'm': /* mini root present in memory */
827 case 'M':
828 boothowto |= RB_MINIROOT;
829 break;
830 #endif
831
832 case 'n': /* askname */
833 case 'N':
834 boothowto |= RB_ASKNAME;
835 break;
836
837 case 's': /* single-user (default, supported for sanity) */
838 case 'S':
839 boothowto |= RB_SINGLE;
840 break;
841
842 default:
843 printf("Unrecognized boot flag '%c'.\n", *p);
844 break;
845 }
846 }
847
848 /*
849 * Initialize debuggers, and break into them if appropriate.
850 */
851 #ifdef DDB
852 db_machine_init();
853 ddb_init(ksym_start, ksym_end);
854 if (boothowto & RB_KDB)
855 Debugger();
856 #endif
857 #ifdef KGDB
858 if (boothowto & RB_KDB)
859 kgdb_connect(0);
860 #endif
861
862 /*
863 * Figure out the number of cpus in the box, from RPB fields.
864 * Really. We mean it.
865 */
866 for (i = 0; i < hwrpb->rpb_pcs_cnt; i++) {
867 struct pcs *pcsp;
868
869 pcsp = (struct pcs *)((char *)hwrpb + hwrpb->rpb_pcs_off +
870 (i * hwrpb->rpb_pcs_size));
871 if ((pcsp->pcs_flags & PCS_PP) != 0)
872 ncpus++;
873 }
874
875 /*
876 * Figure out our clock frequency, from RPB fields.
877 */
878 hz = hwrpb->rpb_intr_freq >> 12;
879 if (!(60 <= hz && hz <= 10240)) {
880 hz = 1024;
881 #ifdef DIAGNOSTIC
882 printf("WARNING: unbelievable rpb_intr_freq: %ld (%d hz)\n",
883 hwrpb->rpb_intr_freq, hz);
884 #endif
885 }
886
887 }
888
889 /*
890 * Allocate space for system data structures. We are given
891 * a starting virtual address and we return a final virtual
892 * address; along the way we set each data structure pointer.
893 *
894 * We call allocsys() with 0 to find out how much space we want,
895 * allocate that much and fill it with zeroes, and the call
896 * allocsys() again with the correct base virtual address.
897 */
898 caddr_t
899 allocsys(v)
900 caddr_t v;
901 {
902
903 #define valloc(name, type, num) \
904 (name) = (type *)v; v = (caddr_t)ALIGN((name)+(num))
905 #ifdef REAL_CLISTS
906 valloc(cfree, struct cblock, nclist);
907 #endif
908 valloc(callout, struct callout, ncallout);
909 #ifdef SYSVSHM
910 valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
911 #endif
912 #ifdef SYSVSEM
913 valloc(sema, struct semid_ds, seminfo.semmni);
914 valloc(sem, struct sem, seminfo.semmns);
915 /* This is pretty disgusting! */
916 valloc(semu, int, (seminfo.semmnu * seminfo.semusz) / sizeof(int));
917 #endif
918 #ifdef SYSVMSG
919 valloc(msgpool, char, msginfo.msgmax);
920 valloc(msgmaps, struct msgmap, msginfo.msgseg);
921 valloc(msghdrs, struct msg, msginfo.msgtql);
922 valloc(msqids, struct msqid_ds, msginfo.msgmni);
923 #endif
924
925 /*
926 * Determine how many buffers to allocate.
927 * We allocate 10% of memory for buffer space. Insure a
928 * minimum of 16 buffers. We allocate 1/2 as many swap buffer
929 * headers as file i/o buffers.
930 */
931 if (bufpages == 0)
932 bufpages = (physmem * 10) / (CLSIZE * 100);
933 if (nbuf == 0) {
934 nbuf = bufpages;
935 if (nbuf < 16)
936 nbuf = 16;
937 }
938 if (nswbuf == 0) {
939 nswbuf = (nbuf / 2) &~ 1; /* force even */
940 if (nswbuf > 256)
941 nswbuf = 256; /* sanity */
942 }
943 #if !defined(UVM)
944 valloc(swbuf, struct buf, nswbuf);
945 #endif
946 valloc(buf, struct buf, nbuf);
947 return (v);
948 #undef valloc
949 }
950
951 void
952 consinit()
953 {
954
955 /*
956 * Everything related to console initialization is done
957 * in alpha_init().
958 */
959 #if defined(DIAGNOSTIC) && defined(_PMAP_MAY_USE_PROM_CONSOLE)
960 printf("consinit: %susing prom console\n",
961 pmap_uses_prom_console() ? "" : "not ");
962 #endif
963 }
964
965 void
966 cpu_startup()
967 {
968 register unsigned i;
969 int base, residual;
970 vm_offset_t minaddr, maxaddr;
971 vm_size_t size;
972 #if defined(DEBUG)
973 extern int pmapdebug;
974 int opmapdebug = pmapdebug;
975
976 pmapdebug = 0;
977 #endif
978
979 /*
980 * Good {morning,afternoon,evening,night}.
981 */
982 printf(version);
983 identifycpu();
984 printf("real mem = %lu (%lu reserved for PROM, %lu used by NetBSD)\n",
985 ptoa(totalphysmem), ptoa(resvmem), ptoa(physmem));
986 if (unusedmem)
987 printf("WARNING: unused memory = %d bytes\n", ctob(unusedmem));
988 if (unknownmem)
989 printf("WARNING: %d bytes of memory with unknown purpose\n",
990 ctob(unknownmem));
991
992 /*
993 * Allocate virtual address space for file I/O buffers.
994 * Note they are different than the array of headers, 'buf',
995 * and usually occupy more virtual memory than physical.
996 */
997 size = MAXBSIZE * nbuf;
998 #if defined(UVM)
999 if (uvm_map(kernel_map, (vm_offset_t *) &buffers, round_page(size),
1000 NULL, UVM_UNKNOWN_OFFSET,
1001 UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
1002 UVM_ADV_NORMAL, 0)) != KERN_SUCCESS)
1003 panic("startup: cannot allocate VM for buffers");
1004 #else
1005 buffer_map = kmem_suballoc(kernel_map, (vm_offset_t *)&buffers,
1006 &maxaddr, size, TRUE);
1007 minaddr = (vm_offset_t)buffers;
1008 if (vm_map_find(buffer_map, vm_object_allocate(size), (vm_offset_t)0,
1009 &minaddr, size, FALSE) != KERN_SUCCESS)
1010 panic("startup: cannot allocate buffers");
1011 #endif /* UVM */
1012 base = bufpages / nbuf;
1013 residual = bufpages % nbuf;
1014 for (i = 0; i < nbuf; i++) {
1015 #if defined(UVM)
1016 vm_size_t curbufsize;
1017 vm_offset_t curbuf;
1018 struct vm_page *pg;
1019
1020 /*
1021 * Each buffer has MAXBSIZE bytes of VM space allocated. Of
1022 * that MAXBSIZE space, we allocate and map (base+1) pages
1023 * for the first "residual" buffers, and then we allocate
1024 * "base" pages for the rest.
1025 */
1026 curbuf = (vm_offset_t) buffers + (i * MAXBSIZE);
1027 curbufsize = CLBYTES * ((i < residual) ? (base+1) : base);
1028
1029 while (curbufsize) {
1030 pg = uvm_pagealloc(NULL, 0, NULL);
1031 if (pg == NULL)
1032 panic("cpu_startup: not enough memory for "
1033 "buffer cache");
1034 #if defined(PMAP_NEW)
1035 pmap_kenter_pgs(curbuf, &pg, 1);
1036 #else
1037 pmap_enter(kernel_map->pmap, curbuf,
1038 VM_PAGE_TO_PHYS(pg), VM_PROT_ALL, TRUE);
1039 #endif
1040 curbuf += PAGE_SIZE;
1041 curbufsize -= PAGE_SIZE;
1042 }
1043 #else /* ! UVM */
1044 vm_size_t curbufsize;
1045 vm_offset_t curbuf;
1046
1047 /*
1048 * First <residual> buffers get (base+1) physical pages
1049 * allocated for them. The rest get (base) physical pages.
1050 *
1051 * The rest of each buffer occupies virtual space,
1052 * but has no physical memory allocated for it.
1053 */
1054 curbuf = (vm_offset_t)buffers + i * MAXBSIZE;
1055 curbufsize = CLBYTES * (i < residual ? base+1 : base);
1056 vm_map_pageable(buffer_map, curbuf, curbuf+curbufsize, FALSE);
1057 vm_map_simplify(buffer_map, curbuf);
1058 #endif /* UVM */
1059 }
1060 /*
1061 * Allocate a submap for exec arguments. This map effectively
1062 * limits the number of processes exec'ing at any time.
1063 */
1064 #if defined(UVM)
1065 exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
1066 16 * NCARGS, TRUE, FALSE, NULL);
1067 #else
1068 exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
1069 16 * NCARGS, TRUE);
1070 #endif
1071
1072 /*
1073 * Allocate a submap for physio
1074 */
1075 #if defined(UVM)
1076 phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
1077 VM_PHYS_SIZE, TRUE, FALSE, NULL);
1078 #else
1079 phys_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
1080 VM_PHYS_SIZE, TRUE);
1081 #endif
1082
1083 /*
1084 * Finally, allocate mbuf cluster submap.
1085 */
1086 #if defined(UVM)
1087 mb_map = uvm_km_suballoc(kernel_map, (vm_offset_t *)&mbutl, &maxaddr,
1088 VM_MBUF_SIZE, FALSE, FALSE, NULL);
1089 #else
1090 mb_map = kmem_suballoc(kernel_map, (vm_offset_t *)&mbutl, &maxaddr,
1091 VM_MBUF_SIZE, FALSE);
1092 #endif
1093 /*
1094 * Initialize callouts
1095 */
1096 callfree = callout;
1097 for (i = 1; i < ncallout; i++)
1098 callout[i-1].c_next = &callout[i];
1099 callout[i-1].c_next = NULL;
1100
1101 #if defined(DEBUG)
1102 pmapdebug = opmapdebug;
1103 #endif
1104 #if defined(UVM)
1105 printf("avail mem = %ld\n", (long)ptoa(uvmexp.free));
1106 #else
1107 printf("avail mem = %ld\n", (long)ptoa(cnt.v_free_count));
1108 #endif
1109 printf("using %ld buffers containing %ld bytes of memory\n",
1110 (long)nbuf, (long)(bufpages * CLBYTES));
1111
1112 /*
1113 * Set up buffers, so they can be used to read disk labels.
1114 */
1115 bufinit();
1116
1117 /*
1118 * Configure the system.
1119 */
1120 configure();
1121
1122 /*
1123 * Note that bootstrapping is finished, and set the HWRPB up
1124 * to do restarts.
1125 */
1126 hwrpb_restart_setup();
1127 }
1128
1129 /*
1130 * Retrieve the platform name from the DSR.
1131 */
1132 const char *
1133 alpha_dsr_sysname()
1134 {
1135 struct dsrdb *dsr;
1136 const char *sysname;
1137
1138 /*
1139 * DSR does not exist on early HWRPB versions.
1140 */
1141 if (hwrpb->rpb_version < HWRPB_DSRDB_MINVERS)
1142 return (NULL);
1143
1144 dsr = (struct dsrdb *)(((caddr_t)hwrpb) + hwrpb->rpb_dsrdb_off);
1145 sysname = (const char *)((caddr_t)dsr + (dsr->dsr_sysname_off +
1146 sizeof(u_int64_t)));
1147 return (sysname);
1148 }
1149
1150 /*
1151 * Lookup the system specified system variation in the provided table,
1152 * returning the model string on match.
1153 */
1154 const char *
1155 alpha_variation_name(variation, avtp)
1156 u_int64_t variation;
1157 const struct alpha_variation_table *avtp;
1158 {
1159 int i;
1160
1161 for (i = 0; avtp[i].avt_model != NULL; i++)
1162 if (avtp[i].avt_variation == variation)
1163 return (avtp[i].avt_model);
1164 return (NULL);
1165 }
1166
1167 /*
1168 * Generate a default platform name based for unknown system variations.
1169 */
1170 const char *
1171 alpha_unknown_sysname()
1172 {
1173 static char s[128]; /* safe size */
1174
1175 sprintf(s, "%s family, unknown model variation 0x%lx",
1176 platform.family, hwrpb->rpb_variation & SV_ST_MASK);
1177 return ((const char *)s);
1178 }
1179
1180 void
1181 identifycpu()
1182 {
1183
1184 /*
1185 * print out CPU identification information.
1186 */
1187 printf("%s, %ldMHz\n", cpu_model,
1188 hwrpb->rpb_cc_freq / 1000000); /* XXX true for 21164? */
1189 printf("%ld byte page size, %d processor%s.\n",
1190 hwrpb->rpb_page_size, ncpus, ncpus == 1 ? "" : "s");
1191 #if 0
1192 /* this isn't defined for any systems that we run on? */
1193 printf("serial number 0x%lx 0x%lx\n",
1194 ((long *)hwrpb->rpb_ssn)[0], ((long *)hwrpb->rpb_ssn)[1]);
1195
1196 /* and these aren't particularly useful! */
1197 printf("variation: 0x%lx, revision 0x%lx\n",
1198 hwrpb->rpb_variation, *(long *)hwrpb->rpb_revision);
1199 #endif
1200 }
1201
1202 int waittime = -1;
1203 struct pcb dumppcb;
1204
1205 void
1206 cpu_reboot(howto, bootstr)
1207 int howto;
1208 char *bootstr;
1209 {
1210 extern int cold;
1211
1212 /* If system is cold, just halt. */
1213 if (cold) {
1214 howto |= RB_HALT;
1215 goto haltsys;
1216 }
1217
1218 /* If "always halt" was specified as a boot flag, obey. */
1219 if ((boothowto & RB_HALT) != 0)
1220 howto |= RB_HALT;
1221
1222 boothowto = howto;
1223 if ((howto & RB_NOSYNC) == 0 && waittime < 0) {
1224 waittime = 0;
1225 vfs_shutdown();
1226 /*
1227 * If we've been adjusting the clock, the todr
1228 * will be out of synch; adjust it now.
1229 */
1230 resettodr();
1231 }
1232
1233 /* Disable interrupts. */
1234 splhigh();
1235
1236 /* If rebooting and a dump is requested do it. */
1237 #if 0
1238 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
1239 #else
1240 if (howto & RB_DUMP)
1241 #endif
1242 dumpsys();
1243
1244 haltsys:
1245
1246 /* run any shutdown hooks */
1247 doshutdownhooks();
1248
1249 #ifdef BOOTKEY
1250 printf("hit any key to %s...\n", howto & RB_HALT ? "halt" : "reboot");
1251 cngetc();
1252 printf("\n");
1253 #endif
1254
1255 /* Finally, halt/reboot the system. */
1256 printf("%s\n\n", howto & RB_HALT ? "halted." : "rebooting...");
1257 prom_halt(howto & RB_HALT);
1258 /*NOTREACHED*/
1259 }
1260
1261 /*
1262 * These variables are needed by /sbin/savecore
1263 */
1264 u_long dumpmag = 0x8fca0101; /* magic number */
1265 int dumpsize = 0; /* pages */
1266 long dumplo = 0; /* blocks */
1267
1268 /*
1269 * cpu_dumpsize: calculate size of machine-dependent kernel core dump headers.
1270 */
1271 int
1272 cpu_dumpsize()
1273 {
1274 int size;
1275
1276 size = ALIGN(sizeof(kcore_seg_t)) + ALIGN(sizeof(cpu_kcore_hdr_t)) +
1277 ALIGN(mem_cluster_cnt * sizeof(phys_ram_seg_t));
1278 if (roundup(size, dbtob(1)) != dbtob(1))
1279 return -1;
1280
1281 return (1);
1282 }
1283
1284 /*
1285 * cpu_dump_mempagecnt: calculate size of RAM (in pages) to be dumped.
1286 */
1287 u_long
1288 cpu_dump_mempagecnt()
1289 {
1290 u_long i, n;
1291
1292 n = 0;
1293 for (i = 0; i < mem_cluster_cnt; i++)
1294 n += atop(mem_clusters[i].size);
1295 return (n);
1296 }
1297
1298 /*
1299 * cpu_dump: dump machine-dependent kernel core dump headers.
1300 */
1301 int
1302 cpu_dump()
1303 {
1304 int (*dump) __P((dev_t, daddr_t, caddr_t, size_t));
1305 char buf[dbtob(1)];
1306 kcore_seg_t *segp;
1307 cpu_kcore_hdr_t *cpuhdrp;
1308 phys_ram_seg_t *memsegp;
1309 int i;
1310
1311 dump = bdevsw[major(dumpdev)].d_dump;
1312
1313 bzero(buf, sizeof buf);
1314 segp = (kcore_seg_t *)buf;
1315 cpuhdrp = (cpu_kcore_hdr_t *)&buf[ALIGN(sizeof(*segp))];
1316 memsegp = (phys_ram_seg_t *)&buf[ ALIGN(sizeof(*segp)) +
1317 ALIGN(sizeof(*cpuhdrp))];
1318
1319 /*
1320 * Generate a segment header.
1321 */
1322 CORE_SETMAGIC(*segp, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
1323 segp->c_size = dbtob(1) - ALIGN(sizeof(*segp));
1324
1325 /*
1326 * Add the machine-dependent header info.
1327 */
1328 cpuhdrp->lev1map_pa = ALPHA_K0SEG_TO_PHYS((vm_offset_t)Lev1map);
1329 cpuhdrp->page_size = PAGE_SIZE;
1330 cpuhdrp->nmemsegs = mem_cluster_cnt;
1331
1332 /*
1333 * Fill in the memory segment descriptors.
1334 */
1335 for (i = 0; i < mem_cluster_cnt; i++) {
1336 memsegp[i].start = mem_clusters[i].start;
1337 memsegp[i].size = mem_clusters[i].size & ~PAGE_MASK;
1338 }
1339
1340 return (dump(dumpdev, dumplo, (caddr_t)buf, dbtob(1)));
1341 }
1342
1343 /*
1344 * This is called by main to set dumplo and dumpsize.
1345 * Dumps always skip the first CLBYTES of disk space
1346 * in case there might be a disk label stored there.
1347 * If there is extra space, put dump at the end to
1348 * reduce the chance that swapping trashes it.
1349 */
1350 void
1351 cpu_dumpconf()
1352 {
1353 int nblks, dumpblks; /* size of dump area */
1354 int maj;
1355
1356 if (dumpdev == NODEV)
1357 goto bad;
1358 maj = major(dumpdev);
1359 if (maj < 0 || maj >= nblkdev)
1360 panic("dumpconf: bad dumpdev=0x%x", dumpdev);
1361 if (bdevsw[maj].d_psize == NULL)
1362 goto bad;
1363 nblks = (*bdevsw[maj].d_psize)(dumpdev);
1364 if (nblks <= ctod(1))
1365 goto bad;
1366
1367 dumpblks = cpu_dumpsize();
1368 if (dumpblks < 0)
1369 goto bad;
1370 dumpblks += ctod(cpu_dump_mempagecnt());
1371
1372 /* If dump won't fit (incl. room for possible label), punt. */
1373 if (dumpblks > (nblks - ctod(1)))
1374 goto bad;
1375
1376 /* Put dump at end of partition */
1377 dumplo = nblks - dumpblks;
1378
1379 /* dumpsize is in page units, and doesn't include headers. */
1380 dumpsize = cpu_dump_mempagecnt();
1381 return;
1382
1383 bad:
1384 dumpsize = 0;
1385 return;
1386 }
1387
1388 /*
1389 * Dump the kernel's image to the swap partition.
1390 */
1391 #define BYTES_PER_DUMP NBPG
1392
1393 void
1394 dumpsys()
1395 {
1396 u_long totalbytesleft, bytes, i, n, memcl;
1397 u_long maddr;
1398 int psize;
1399 daddr_t blkno;
1400 int (*dump) __P((dev_t, daddr_t, caddr_t, size_t));
1401 int error;
1402
1403 /* Save registers. */
1404 savectx(&dumppcb);
1405
1406 msgbufenabled = 0; /* don't record dump msgs in msgbuf */
1407 if (dumpdev == NODEV)
1408 return;
1409
1410 /*
1411 * For dumps during autoconfiguration,
1412 * if dump device has already configured...
1413 */
1414 if (dumpsize == 0)
1415 cpu_dumpconf();
1416 if (dumplo <= 0) {
1417 printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
1418 minor(dumpdev));
1419 return;
1420 }
1421 printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
1422 minor(dumpdev), dumplo);
1423
1424 psize = (*bdevsw[major(dumpdev)].d_psize)(dumpdev);
1425 printf("dump ");
1426 if (psize == -1) {
1427 printf("area unavailable\n");
1428 return;
1429 }
1430
1431 /* XXX should purge all outstanding keystrokes. */
1432
1433 if ((error = cpu_dump()) != 0)
1434 goto err;
1435
1436 totalbytesleft = ptoa(cpu_dump_mempagecnt());
1437 blkno = dumplo + cpu_dumpsize();
1438 dump = bdevsw[major(dumpdev)].d_dump;
1439 error = 0;
1440
1441 for (memcl = 0; memcl < mem_cluster_cnt; memcl++) {
1442 maddr = mem_clusters[memcl].start;
1443 bytes = mem_clusters[memcl].size & ~PAGE_MASK;
1444
1445 for (i = 0; i < bytes; i += n, totalbytesleft -= n) {
1446
1447 /* Print out how many MBs we to go. */
1448 if ((totalbytesleft % (1024*1024)) == 0)
1449 printf("%d ", totalbytesleft / (1024 * 1024));
1450
1451 /* Limit size for next transfer. */
1452 n = bytes - i;
1453 if (n > BYTES_PER_DUMP)
1454 n = BYTES_PER_DUMP;
1455
1456 error = (*dump)(dumpdev, blkno,
1457 (caddr_t)ALPHA_PHYS_TO_K0SEG(maddr), n);
1458 if (error)
1459 goto err;
1460 maddr += n;
1461 blkno += btodb(n); /* XXX? */
1462
1463 /* XXX should look for keystrokes, to cancel. */
1464 }
1465 }
1466
1467 err:
1468 switch (error) {
1469
1470 case ENXIO:
1471 printf("device bad\n");
1472 break;
1473
1474 case EFAULT:
1475 printf("device not ready\n");
1476 break;
1477
1478 case EINVAL:
1479 printf("area improper\n");
1480 break;
1481
1482 case EIO:
1483 printf("i/o error\n");
1484 break;
1485
1486 case EINTR:
1487 printf("aborted from console\n");
1488 break;
1489
1490 case 0:
1491 printf("succeeded\n");
1492 break;
1493
1494 default:
1495 printf("error %d\n", error);
1496 break;
1497 }
1498 printf("\n\n");
1499 delay(1000);
1500 }
1501
1502 void
1503 frametoreg(framep, regp)
1504 struct trapframe *framep;
1505 struct reg *regp;
1506 {
1507
1508 regp->r_regs[R_V0] = framep->tf_regs[FRAME_V0];
1509 regp->r_regs[R_T0] = framep->tf_regs[FRAME_T0];
1510 regp->r_regs[R_T1] = framep->tf_regs[FRAME_T1];
1511 regp->r_regs[R_T2] = framep->tf_regs[FRAME_T2];
1512 regp->r_regs[R_T3] = framep->tf_regs[FRAME_T3];
1513 regp->r_regs[R_T4] = framep->tf_regs[FRAME_T4];
1514 regp->r_regs[R_T5] = framep->tf_regs[FRAME_T5];
1515 regp->r_regs[R_T6] = framep->tf_regs[FRAME_T6];
1516 regp->r_regs[R_T7] = framep->tf_regs[FRAME_T7];
1517 regp->r_regs[R_S0] = framep->tf_regs[FRAME_S0];
1518 regp->r_regs[R_S1] = framep->tf_regs[FRAME_S1];
1519 regp->r_regs[R_S2] = framep->tf_regs[FRAME_S2];
1520 regp->r_regs[R_S3] = framep->tf_regs[FRAME_S3];
1521 regp->r_regs[R_S4] = framep->tf_regs[FRAME_S4];
1522 regp->r_regs[R_S5] = framep->tf_regs[FRAME_S5];
1523 regp->r_regs[R_S6] = framep->tf_regs[FRAME_S6];
1524 regp->r_regs[R_A0] = framep->tf_regs[FRAME_A0];
1525 regp->r_regs[R_A1] = framep->tf_regs[FRAME_A1];
1526 regp->r_regs[R_A2] = framep->tf_regs[FRAME_A2];
1527 regp->r_regs[R_A3] = framep->tf_regs[FRAME_A3];
1528 regp->r_regs[R_A4] = framep->tf_regs[FRAME_A4];
1529 regp->r_regs[R_A5] = framep->tf_regs[FRAME_A5];
1530 regp->r_regs[R_T8] = framep->tf_regs[FRAME_T8];
1531 regp->r_regs[R_T9] = framep->tf_regs[FRAME_T9];
1532 regp->r_regs[R_T10] = framep->tf_regs[FRAME_T10];
1533 regp->r_regs[R_T11] = framep->tf_regs[FRAME_T11];
1534 regp->r_regs[R_RA] = framep->tf_regs[FRAME_RA];
1535 regp->r_regs[R_T12] = framep->tf_regs[FRAME_T12];
1536 regp->r_regs[R_AT] = framep->tf_regs[FRAME_AT];
1537 regp->r_regs[R_GP] = framep->tf_regs[FRAME_GP];
1538 /* regp->r_regs[R_SP] = framep->tf_regs[FRAME_SP]; XXX */
1539 regp->r_regs[R_ZERO] = 0;
1540 }
1541
1542 void
1543 regtoframe(regp, framep)
1544 struct reg *regp;
1545 struct trapframe *framep;
1546 {
1547
1548 framep->tf_regs[FRAME_V0] = regp->r_regs[R_V0];
1549 framep->tf_regs[FRAME_T0] = regp->r_regs[R_T0];
1550 framep->tf_regs[FRAME_T1] = regp->r_regs[R_T1];
1551 framep->tf_regs[FRAME_T2] = regp->r_regs[R_T2];
1552 framep->tf_regs[FRAME_T3] = regp->r_regs[R_T3];
1553 framep->tf_regs[FRAME_T4] = regp->r_regs[R_T4];
1554 framep->tf_regs[FRAME_T5] = regp->r_regs[R_T5];
1555 framep->tf_regs[FRAME_T6] = regp->r_regs[R_T6];
1556 framep->tf_regs[FRAME_T7] = regp->r_regs[R_T7];
1557 framep->tf_regs[FRAME_S0] = regp->r_regs[R_S0];
1558 framep->tf_regs[FRAME_S1] = regp->r_regs[R_S1];
1559 framep->tf_regs[FRAME_S2] = regp->r_regs[R_S2];
1560 framep->tf_regs[FRAME_S3] = regp->r_regs[R_S3];
1561 framep->tf_regs[FRAME_S4] = regp->r_regs[R_S4];
1562 framep->tf_regs[FRAME_S5] = regp->r_regs[R_S5];
1563 framep->tf_regs[FRAME_S6] = regp->r_regs[R_S6];
1564 framep->tf_regs[FRAME_A0] = regp->r_regs[R_A0];
1565 framep->tf_regs[FRAME_A1] = regp->r_regs[R_A1];
1566 framep->tf_regs[FRAME_A2] = regp->r_regs[R_A2];
1567 framep->tf_regs[FRAME_A3] = regp->r_regs[R_A3];
1568 framep->tf_regs[FRAME_A4] = regp->r_regs[R_A4];
1569 framep->tf_regs[FRAME_A5] = regp->r_regs[R_A5];
1570 framep->tf_regs[FRAME_T8] = regp->r_regs[R_T8];
1571 framep->tf_regs[FRAME_T9] = regp->r_regs[R_T9];
1572 framep->tf_regs[FRAME_T10] = regp->r_regs[R_T10];
1573 framep->tf_regs[FRAME_T11] = regp->r_regs[R_T11];
1574 framep->tf_regs[FRAME_RA] = regp->r_regs[R_RA];
1575 framep->tf_regs[FRAME_T12] = regp->r_regs[R_T12];
1576 framep->tf_regs[FRAME_AT] = regp->r_regs[R_AT];
1577 framep->tf_regs[FRAME_GP] = regp->r_regs[R_GP];
1578 /* framep->tf_regs[FRAME_SP] = regp->r_regs[R_SP]; XXX */
1579 /* ??? = regp->r_regs[R_ZERO]; */
1580 }
1581
1582 void
1583 printregs(regp)
1584 struct reg *regp;
1585 {
1586 int i;
1587
1588 for (i = 0; i < 32; i++)
1589 printf("R%d:\t0x%016lx%s", i, regp->r_regs[i],
1590 i & 1 ? "\n" : "\t");
1591 }
1592
1593 void
1594 regdump(framep)
1595 struct trapframe *framep;
1596 {
1597 struct reg reg;
1598
1599 frametoreg(framep, ®);
1600 reg.r_regs[R_SP] = alpha_pal_rdusp();
1601
1602 printf("REGISTERS:\n");
1603 printregs(®);
1604 }
1605
1606 #ifdef DEBUG
1607 int sigdebug = 0;
1608 int sigpid = 0;
1609 #define SDB_FOLLOW 0x01
1610 #define SDB_KSTACK 0x02
1611 #endif
1612
1613 /*
1614 * Send an interrupt to process.
1615 */
1616 void
1617 sendsig(catcher, sig, mask, code)
1618 sig_t catcher;
1619 int sig, mask;
1620 u_long code;
1621 {
1622 struct proc *p = curproc;
1623 struct sigcontext *scp, ksc;
1624 struct trapframe *frame;
1625 struct sigacts *psp = p->p_sigacts;
1626 int oonstack, fsize, rndfsize;
1627 extern char sigcode[], esigcode[];
1628 extern struct proc *fpcurproc;
1629
1630 frame = p->p_md.md_tf;
1631 oonstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
1632 fsize = sizeof ksc;
1633 rndfsize = ((fsize + 15) / 16) * 16;
1634 /*
1635 * Allocate and validate space for the signal handler
1636 * context. Note that if the stack is in P0 space, the
1637 * call to grow() is a nop, and the useracc() check
1638 * will fail if the process has not already allocated
1639 * the space with a `brk'.
1640 */
1641 if ((psp->ps_flags & SAS_ALTSTACK) && !oonstack &&
1642 (psp->ps_sigonstack & sigmask(sig))) {
1643 scp = (struct sigcontext *)(psp->ps_sigstk.ss_sp +
1644 psp->ps_sigstk.ss_size - rndfsize);
1645 psp->ps_sigstk.ss_flags |= SS_ONSTACK;
1646 } else
1647 scp = (struct sigcontext *)(alpha_pal_rdusp() - rndfsize);
1648 if ((u_long)scp <= USRSTACK - ctob(p->p_vmspace->vm_ssize))
1649 #if defined(UVM)
1650 (void)uvm_grow(p, (u_long)scp);
1651 #else
1652 (void)grow(p, (u_long)scp);
1653 #endif
1654 #ifdef DEBUG
1655 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
1656 printf("sendsig(%d): sig %d ssp %p usp %p\n", p->p_pid,
1657 sig, &oonstack, scp);
1658 #endif
1659 #if defined(UVM)
1660 if (uvm_useracc((caddr_t)scp, fsize, B_WRITE) == 0) {
1661 #else
1662 if (useracc((caddr_t)scp, fsize, B_WRITE) == 0) {
1663 #endif
1664 #ifdef DEBUG
1665 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
1666 printf("sendsig(%d): useracc failed on sig %d\n",
1667 p->p_pid, sig);
1668 #endif
1669 /*
1670 * Process has trashed its stack; give it an illegal
1671 * instruction to halt it in its tracks.
1672 */
1673 SIGACTION(p, SIGILL) = SIG_DFL;
1674 sig = sigmask(SIGILL);
1675 p->p_sigignore &= ~sig;
1676 p->p_sigcatch &= ~sig;
1677 p->p_sigmask &= ~sig;
1678 psignal(p, SIGILL);
1679 return;
1680 }
1681
1682 /*
1683 * Build the signal context to be used by sigreturn.
1684 */
1685 ksc.sc_onstack = oonstack;
1686 ksc.sc_mask = mask;
1687 ksc.sc_pc = frame->tf_regs[FRAME_PC];
1688 ksc.sc_ps = frame->tf_regs[FRAME_PS];
1689
1690 /* copy the registers. */
1691 frametoreg(frame, (struct reg *)ksc.sc_regs);
1692 ksc.sc_regs[R_ZERO] = 0xACEDBADE; /* magic number */
1693 ksc.sc_regs[R_SP] = alpha_pal_rdusp();
1694
1695 /* save the floating-point state, if necessary, then copy it. */
1696 if (p == fpcurproc) {
1697 alpha_pal_wrfen(1);
1698 savefpstate(&p->p_addr->u_pcb.pcb_fp);
1699 alpha_pal_wrfen(0);
1700 fpcurproc = NULL;
1701 }
1702 ksc.sc_ownedfp = p->p_md.md_flags & MDP_FPUSED;
1703 bcopy(&p->p_addr->u_pcb.pcb_fp, (struct fpreg *)ksc.sc_fpregs,
1704 sizeof(struct fpreg));
1705 ksc.sc_fp_control = 0; /* XXX ? */
1706 bzero(ksc.sc_reserved, sizeof ksc.sc_reserved); /* XXX */
1707 bzero(ksc.sc_xxx, sizeof ksc.sc_xxx); /* XXX */
1708
1709
1710 #ifdef COMPAT_OSF1
1711 /*
1712 * XXX Create an OSF/1-style sigcontext and associated goo.
1713 */
1714 #endif
1715
1716 /*
1717 * copy the frame out to userland.
1718 */
1719 (void) copyout((caddr_t)&ksc, (caddr_t)scp, fsize);
1720 #ifdef DEBUG
1721 if (sigdebug & SDB_FOLLOW)
1722 printf("sendsig(%d): sig %d scp %p code %lx\n", p->p_pid, sig,
1723 scp, code);
1724 #endif
1725
1726 /*
1727 * Set up the registers to return to sigcode.
1728 */
1729 frame->tf_regs[FRAME_PC] =
1730 (u_int64_t)PS_STRINGS - (esigcode - sigcode);
1731 frame->tf_regs[FRAME_A0] = sig;
1732 frame->tf_regs[FRAME_A1] = code;
1733 frame->tf_regs[FRAME_A2] = (u_int64_t)scp;
1734 frame->tf_regs[FRAME_T12] = (u_int64_t)catcher; /* t12 is pv */
1735 alpha_pal_wrusp((unsigned long)scp);
1736
1737 #ifdef DEBUG
1738 if (sigdebug & SDB_FOLLOW)
1739 printf("sendsig(%d): pc %lx, catcher %lx\n", p->p_pid,
1740 frame->tf_regs[FRAME_PC], frame->tf_regs[FRAME_A3]);
1741 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
1742 printf("sendsig(%d): sig %d returns\n",
1743 p->p_pid, sig);
1744 #endif
1745 }
1746
1747 /*
1748 * System call to cleanup state after a signal
1749 * has been taken. Reset signal mask and
1750 * stack state from context left by sendsig (above).
1751 * Return to previous pc and psl as specified by
1752 * context left by sendsig. Check carefully to
1753 * make sure that the user has not modified the
1754 * psl to gain improper priviledges or to cause
1755 * a machine fault.
1756 */
1757 /* ARGSUSED */
1758 int
1759 sys_sigreturn(p, v, retval)
1760 struct proc *p;
1761 void *v;
1762 register_t *retval;
1763 {
1764 struct sys_sigreturn_args /* {
1765 syscallarg(struct sigcontext *) sigcntxp;
1766 } */ *uap = v;
1767 struct sigcontext *scp, ksc;
1768 extern struct proc *fpcurproc;
1769
1770 scp = SCARG(uap, sigcntxp);
1771 #ifdef DEBUG
1772 if (sigdebug & SDB_FOLLOW)
1773 printf("sigreturn: pid %d, scp %p\n", p->p_pid, scp);
1774 #endif
1775
1776 if (ALIGN(scp) != (u_int64_t)scp)
1777 return (EINVAL);
1778
1779 /*
1780 * Test and fetch the context structure.
1781 * We grab it all at once for speed.
1782 */
1783 #if defined(UVM)
1784 if (uvm_useracc((caddr_t)scp, sizeof (*scp), B_WRITE) == 0 ||
1785 copyin((caddr_t)scp, (caddr_t)&ksc, sizeof ksc))
1786 return (EINVAL);
1787 #else
1788 if (useracc((caddr_t)scp, sizeof (*scp), B_WRITE) == 0 ||
1789 copyin((caddr_t)scp, (caddr_t)&ksc, sizeof ksc))
1790 return (EINVAL);
1791 #endif
1792
1793 if (ksc.sc_regs[R_ZERO] != 0xACEDBADE) /* magic number */
1794 return (EINVAL);
1795 /*
1796 * Restore the user-supplied information
1797 */
1798 if (ksc.sc_onstack)
1799 p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
1800 else
1801 p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
1802 p->p_sigmask = ksc.sc_mask &~ sigcantmask;
1803
1804 p->p_md.md_tf->tf_regs[FRAME_PC] = ksc.sc_pc;
1805 p->p_md.md_tf->tf_regs[FRAME_PS] =
1806 (ksc.sc_ps | ALPHA_PSL_USERSET) & ~ALPHA_PSL_USERCLR;
1807
1808 regtoframe((struct reg *)ksc.sc_regs, p->p_md.md_tf);
1809 alpha_pal_wrusp(ksc.sc_regs[R_SP]);
1810
1811 /* XXX ksc.sc_ownedfp ? */
1812 if (p == fpcurproc)
1813 fpcurproc = NULL;
1814 bcopy((struct fpreg *)ksc.sc_fpregs, &p->p_addr->u_pcb.pcb_fp,
1815 sizeof(struct fpreg));
1816 /* XXX ksc.sc_fp_control ? */
1817
1818 #ifdef DEBUG
1819 if (sigdebug & SDB_FOLLOW)
1820 printf("sigreturn(%d): returns\n", p->p_pid);
1821 #endif
1822 return (EJUSTRETURN);
1823 }
1824
1825 /*
1826 * machine dependent system variables.
1827 */
1828 int
1829 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
1830 int *name;
1831 u_int namelen;
1832 void *oldp;
1833 size_t *oldlenp;
1834 void *newp;
1835 size_t newlen;
1836 struct proc *p;
1837 {
1838 dev_t consdev;
1839
1840 /* all sysctl names at this level are terminal */
1841 if (namelen != 1)
1842 return (ENOTDIR); /* overloaded */
1843
1844 switch (name[0]) {
1845 case CPU_CONSDEV:
1846 if (cn_tab != NULL)
1847 consdev = cn_tab->cn_dev;
1848 else
1849 consdev = NODEV;
1850 return (sysctl_rdstruct(oldp, oldlenp, newp, &consdev,
1851 sizeof consdev));
1852
1853 case CPU_ROOT_DEVICE:
1854 return (sysctl_rdstring(oldp, oldlenp, newp,
1855 root_device->dv_xname));
1856
1857 case CPU_UNALIGNED_PRINT:
1858 return (sysctl_int(oldp, oldlenp, newp, newlen,
1859 &alpha_unaligned_print));
1860
1861 case CPU_UNALIGNED_FIX:
1862 return (sysctl_int(oldp, oldlenp, newp, newlen,
1863 &alpha_unaligned_fix));
1864
1865 case CPU_UNALIGNED_SIGBUS:
1866 return (sysctl_int(oldp, oldlenp, newp, newlen,
1867 &alpha_unaligned_sigbus));
1868
1869 case CPU_BOOTED_KERNEL:
1870 return (sysctl_rdstring(oldp, oldlenp, newp,
1871 bootinfo.booted_kernel));
1872
1873 default:
1874 return (EOPNOTSUPP);
1875 }
1876 /* NOTREACHED */
1877 }
1878
1879 /*
1880 * Set registers on exec.
1881 */
1882 void
1883 setregs(p, pack, stack)
1884 register struct proc *p;
1885 struct exec_package *pack;
1886 u_long stack;
1887 {
1888 struct trapframe *tfp = p->p_md.md_tf;
1889 extern struct proc *fpcurproc;
1890 #ifdef DEBUG
1891 int i;
1892 #endif
1893
1894 #ifdef DEBUG
1895 /*
1896 * Crash and dump, if the user requested it.
1897 */
1898 if (boothowto & RB_DUMP)
1899 panic("crash requested by boot flags");
1900 #endif
1901
1902 #ifdef DEBUG
1903 for (i = 0; i < FRAME_SIZE; i++)
1904 tfp->tf_regs[i] = 0xbabefacedeadbeef;
1905 #else
1906 bzero(tfp->tf_regs, FRAME_SIZE * sizeof tfp->tf_regs[0]);
1907 #endif
1908 bzero(&p->p_addr->u_pcb.pcb_fp, sizeof p->p_addr->u_pcb.pcb_fp);
1909 #define FP_RN 2 /* XXX */
1910 p->p_addr->u_pcb.pcb_fp.fpr_cr = (long)FP_RN << 58;
1911 alpha_pal_wrusp(stack);
1912 tfp->tf_regs[FRAME_PS] = ALPHA_PSL_USERSET;
1913 tfp->tf_regs[FRAME_PC] = pack->ep_entry & ~3;
1914
1915 tfp->tf_regs[FRAME_A0] = stack; /* a0 = sp */
1916 tfp->tf_regs[FRAME_A1] = 0; /* a1 = rtld cleanup */
1917 tfp->tf_regs[FRAME_A2] = 0; /* a2 = rtld object */
1918 tfp->tf_regs[FRAME_A3] = (u_int64_t)PS_STRINGS; /* a3 = ps_strings */
1919 tfp->tf_regs[FRAME_T12] = tfp->tf_regs[FRAME_PC]; /* a.k.a. PV */
1920
1921 p->p_md.md_flags &= ~MDP_FPUSED;
1922 if (fpcurproc == p)
1923 fpcurproc = NULL;
1924 }
1925
1926 void
1927 netintr()
1928 {
1929 int n, s;
1930
1931 s = splhigh();
1932 n = netisr;
1933 netisr = 0;
1934 splx(s);
1935
1936 #define DONETISR(bit, fn) \
1937 do { \
1938 if (n & (1 << (bit))) \
1939 fn; \
1940 } while (0)
1941
1942 #ifdef INET
1943 #if NARP > 0
1944 DONETISR(NETISR_ARP, arpintr());
1945 #endif
1946 DONETISR(NETISR_IP, ipintr());
1947 #endif
1948 #ifdef NETATALK
1949 DONETISR(NETISR_ATALK, atintr());
1950 #endif
1951 #ifdef NS
1952 DONETISR(NETISR_NS, nsintr());
1953 #endif
1954 #ifdef ISO
1955 DONETISR(NETISR_ISO, clnlintr());
1956 #endif
1957 #ifdef CCITT
1958 DONETISR(NETISR_CCITT, ccittintr());
1959 #endif
1960 #ifdef NATM
1961 DONETISR(NETISR_NATM, natmintr());
1962 #endif
1963 #if NPPP > 1
1964 DONETISR(NETISR_PPP, pppintr());
1965 #endif
1966
1967 #undef DONETISR
1968 }
1969
1970 void
1971 do_sir()
1972 {
1973 u_int64_t n;
1974
1975 do {
1976 (void)splhigh();
1977 n = ssir;
1978 ssir = 0;
1979 splsoft(); /* don't recurse through spl0() */
1980
1981 #if defined(UVM)
1982 #define COUNT_SOFT uvmexp.softs++
1983 #else
1984 #define COUNT_SOFT cnt.v_soft++
1985 #endif
1986
1987 #define DO_SIR(bit, fn) \
1988 do { \
1989 if (n & (bit)) { \
1990 COUNT_SOFT; \
1991 fn; \
1992 } \
1993 } while (0)
1994
1995 DO_SIR(SIR_NET, netintr());
1996 DO_SIR(SIR_CLOCK, softclock());
1997
1998 #undef COUNT_SOFT
1999 #undef DO_SIR
2000 } while (ssir != 0);
2001 }
2002
2003 int
2004 spl0()
2005 {
2006
2007 if (ssir)
2008 do_sir(); /* it lowers the IPL itself */
2009
2010 return (alpha_pal_swpipl(ALPHA_PSL_IPL_0));
2011 }
2012
2013 /*
2014 * The following primitives manipulate the run queues. _whichqs tells which
2015 * of the 32 queues _qs have processes in them. Setrunqueue puts processes
2016 * into queues, Remrunqueue removes them from queues. The running process is
2017 * on no queue, other processes are on a queue related to p->p_priority,
2018 * divided by 4 actually to shrink the 0-127 range of priorities into the 32
2019 * available queues.
2020 */
2021 /*
2022 * setrunqueue(p)
2023 * proc *p;
2024 *
2025 * Call should be made at splclock(), and p->p_stat should be SRUN.
2026 */
2027
2028 void
2029 setrunqueue(p)
2030 struct proc *p;
2031 {
2032 int bit;
2033
2034 /* firewall: p->p_back must be NULL */
2035 if (p->p_back != NULL)
2036 panic("setrunqueue");
2037
2038 bit = p->p_priority >> 2;
2039 whichqs |= (1 << bit);
2040 p->p_forw = (struct proc *)&qs[bit];
2041 p->p_back = qs[bit].ph_rlink;
2042 p->p_back->p_forw = p;
2043 qs[bit].ph_rlink = p;
2044 }
2045
2046 /*
2047 * remrunqueue(p)
2048 *
2049 * Call should be made at splclock().
2050 */
2051 void
2052 remrunqueue(p)
2053 struct proc *p;
2054 {
2055 int bit;
2056
2057 bit = p->p_priority >> 2;
2058 if ((whichqs & (1 << bit)) == 0)
2059 panic("remrunqueue");
2060
2061 p->p_back->p_forw = p->p_forw;
2062 p->p_forw->p_back = p->p_back;
2063 p->p_back = NULL; /* for firewall checking. */
2064
2065 if ((struct proc *)&qs[bit] == qs[bit].ph_link)
2066 whichqs &= ~(1 << bit);
2067 }
2068
2069 /*
2070 * Return the best possible estimate of the time in the timeval
2071 * to which tvp points. Unfortunately, we can't read the hardware registers.
2072 * We guarantee that the time will be greater than the value obtained by a
2073 * previous call.
2074 */
2075 void
2076 microtime(tvp)
2077 register struct timeval *tvp;
2078 {
2079 int s = splclock();
2080 static struct timeval lasttime;
2081
2082 *tvp = time;
2083 #ifdef notdef
2084 tvp->tv_usec += clkread();
2085 while (tvp->tv_usec > 1000000) {
2086 tvp->tv_sec++;
2087 tvp->tv_usec -= 1000000;
2088 }
2089 #endif
2090 if (tvp->tv_sec == lasttime.tv_sec &&
2091 tvp->tv_usec <= lasttime.tv_usec &&
2092 (tvp->tv_usec = lasttime.tv_usec + 1) > 1000000) {
2093 tvp->tv_sec++;
2094 tvp->tv_usec -= 1000000;
2095 }
2096 lasttime = *tvp;
2097 splx(s);
2098 }
2099
2100 /*
2101 * Wait "n" microseconds.
2102 */
2103 void
2104 delay(n)
2105 unsigned long n;
2106 {
2107 long N = cycles_per_usec * (n);
2108
2109 while (N > 0) /* XXX */
2110 N -= 3; /* XXX */
2111 }
2112
2113 #if defined(COMPAT_OSF1) || 1 /* XXX */
2114 void cpu_exec_ecoff_setregs __P((struct proc *, struct exec_package *,
2115 u_long));
2116
2117 void
2118 cpu_exec_ecoff_setregs(p, epp, stack)
2119 struct proc *p;
2120 struct exec_package *epp;
2121 u_long stack;
2122 {
2123 struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr;
2124
2125 setregs(p, epp, stack);
2126 p->p_md.md_tf->tf_regs[FRAME_GP] = execp->a.gp_value;
2127 }
2128
2129 /*
2130 * cpu_exec_ecoff_hook():
2131 * cpu-dependent ECOFF format hook for execve().
2132 *
2133 * Do any machine-dependent diddling of the exec package when doing ECOFF.
2134 *
2135 */
2136 int
2137 cpu_exec_ecoff_hook(p, epp)
2138 struct proc *p;
2139 struct exec_package *epp;
2140 {
2141 struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr;
2142 extern struct emul emul_netbsd;
2143 #ifdef COMPAT_OSF1
2144 extern struct emul emul_osf1;
2145 #endif
2146
2147 switch (execp->f.f_magic) {
2148 #ifdef COMPAT_OSF1
2149 case ECOFF_MAGIC_ALPHA:
2150 epp->ep_emul = &emul_osf1;
2151 break;
2152 #endif
2153
2154 case ECOFF_MAGIC_NETBSD_ALPHA:
2155 epp->ep_emul = &emul_netbsd;
2156 break;
2157
2158 default:
2159 return ENOEXEC;
2160 }
2161 return 0;
2162 }
2163 #endif
2164
2165 int
2166 alpha_pa_access(pa)
2167 u_long pa;
2168 {
2169 int i;
2170
2171 for (i = 0; i < mem_cluster_cnt; i++) {
2172 if (pa < mem_clusters[i].start)
2173 continue;
2174 if ((pa - mem_clusters[i].start) >=
2175 (mem_clusters[i].size & ~PAGE_MASK))
2176 continue;
2177 return (mem_clusters[i].size & PAGE_MASK); /* prot */
2178 }
2179 return (PROT_NONE);
2180 }
2181
2182 /* XXX XXX BEGIN XXX XXX */
2183 vm_offset_t alpha_XXX_dmamap_or; /* XXX */
2184 /* XXX */
2185 vm_offset_t /* XXX */
2186 alpha_XXX_dmamap(v) /* XXX */
2187 vm_offset_t v; /* XXX */
2188 { /* XXX */
2189 /* XXX */
2190 return (vtophys(v) | alpha_XXX_dmamap_or); /* XXX */
2191 } /* XXX */
2192 /* XXX XXX END XXX XXX */
2193