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