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