machdep.c revision 1.151 1 /* $NetBSD: machdep.c,v 1.151 1998/10/06 21:10:46 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.151 1998/10/06 21:10:46 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 * Set up the HWPCB so that it's safe to configure secondary
1184 * CPUs.
1185 */
1186 hwrpb_primary_init();
1187
1188 /*
1189 * Configure the system.
1190 */
1191 configure();
1192
1193 /*
1194 * Note that bootstrapping is finished, and set the HWRPB up
1195 * to do restarts.
1196 */
1197 hwrpb_restart_setup();
1198
1199 #if defined(MULTIPROCESSOR)
1200 /*
1201 * Spin up any secondary CPUs.
1202 */
1203 cpu_run_spinup_queue();
1204 Debugger();
1205 #endif /* MULTIPROCESSOR */
1206 }
1207
1208 /*
1209 * Retrieve the platform name from the DSR.
1210 */
1211 const char *
1212 alpha_dsr_sysname()
1213 {
1214 struct dsrdb *dsr;
1215 const char *sysname;
1216
1217 /*
1218 * DSR does not exist on early HWRPB versions.
1219 */
1220 if (hwrpb->rpb_version < HWRPB_DSRDB_MINVERS)
1221 return (NULL);
1222
1223 dsr = (struct dsrdb *)(((caddr_t)hwrpb) + hwrpb->rpb_dsrdb_off);
1224 sysname = (const char *)((caddr_t)dsr + (dsr->dsr_sysname_off +
1225 sizeof(u_int64_t)));
1226 return (sysname);
1227 }
1228
1229 /*
1230 * Lookup the system specified system variation in the provided table,
1231 * returning the model string on match.
1232 */
1233 const char *
1234 alpha_variation_name(variation, avtp)
1235 u_int64_t variation;
1236 const struct alpha_variation_table *avtp;
1237 {
1238 int i;
1239
1240 for (i = 0; avtp[i].avt_model != NULL; i++)
1241 if (avtp[i].avt_variation == variation)
1242 return (avtp[i].avt_model);
1243 return (NULL);
1244 }
1245
1246 /*
1247 * Generate a default platform name based for unknown system variations.
1248 */
1249 const char *
1250 alpha_unknown_sysname()
1251 {
1252 static char s[128]; /* safe size */
1253
1254 sprintf(s, "%s family, unknown model variation 0x%lx",
1255 platform.family, hwrpb->rpb_variation & SV_ST_MASK);
1256 return ((const char *)s);
1257 }
1258
1259 void
1260 identifycpu()
1261 {
1262
1263 /*
1264 * print out CPU identification information.
1265 */
1266 printf("%s, %ldMHz\n", cpu_model,
1267 hwrpb->rpb_cc_freq / 1000000); /* XXX true for 21164? */
1268 printf("%ld byte page size, %d processor%s.\n",
1269 hwrpb->rpb_page_size, ncpus, ncpus == 1 ? "" : "s");
1270 #if 0
1271 /* this isn't defined for any systems that we run on? */
1272 printf("serial number 0x%lx 0x%lx\n",
1273 ((long *)hwrpb->rpb_ssn)[0], ((long *)hwrpb->rpb_ssn)[1]);
1274
1275 /* and these aren't particularly useful! */
1276 printf("variation: 0x%lx, revision 0x%lx\n",
1277 hwrpb->rpb_variation, *(long *)hwrpb->rpb_revision);
1278 #endif
1279 }
1280
1281 int waittime = -1;
1282 struct pcb dumppcb;
1283
1284 void
1285 cpu_reboot(howto, bootstr)
1286 int howto;
1287 char *bootstr;
1288 {
1289 extern int cold;
1290 #if defined(MULTIPROCESSOR)
1291 #if 0 /* XXX See below. */
1292 u_long cpu_id;
1293 #endif
1294 #endif
1295
1296 #if defined(MULTIPROCESSOR)
1297 /* We must be running on the primary CPU. */
1298 if (alpha_pal_whami() != hwrpb->rpb_primary_cpu_id)
1299 panic("cpu_reboot: not on primary CPU!");
1300 #endif
1301
1302 /* If system is cold, just halt. */
1303 if (cold) {
1304 howto |= RB_HALT;
1305 goto haltsys;
1306 }
1307
1308 /* If "always halt" was specified as a boot flag, obey. */
1309 if ((boothowto & RB_HALT) != 0)
1310 howto |= RB_HALT;
1311
1312 boothowto = howto;
1313 if ((howto & RB_NOSYNC) == 0 && waittime < 0) {
1314 waittime = 0;
1315 vfs_shutdown();
1316 /*
1317 * If we've been adjusting the clock, the todr
1318 * will be out of synch; adjust it now.
1319 */
1320 resettodr();
1321 }
1322
1323 /* Disable interrupts. */
1324 splhigh();
1325
1326 /* If rebooting and a dump is requested do it. */
1327 #if 0
1328 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
1329 #else
1330 if (howto & RB_DUMP)
1331 #endif
1332 dumpsys();
1333
1334 haltsys:
1335
1336 /* run any shutdown hooks */
1337 doshutdownhooks();
1338
1339 #if defined(MULTIPROCESSOR)
1340 #if 0 /* XXX doesn't work when called from here?! */
1341 /* Kill off any secondary CPUs. */
1342 for (cpu_id = 0; cpu_id < hwrpb->rpb_pcs_cnt; cpu_id++) {
1343 if (cpu_id == hwrpb->rpb_primary_cpu_id ||
1344 cpus[cpu_id] == NULL)
1345 continue;
1346 cpu_halt_secondary(cpu_id);
1347 }
1348 #endif
1349 #endif
1350
1351 #ifdef BOOTKEY
1352 printf("hit any key to %s...\n", howto & RB_HALT ? "halt" : "reboot");
1353 cnpollc(1); /* for proper keyboard command handling */
1354 cngetc();
1355 cnpollc(0);
1356 printf("\n");
1357 #endif
1358
1359 /* Finally, powerdown/halt/reboot the system. */
1360 if ((howto && RB_POWERDOWN) == RB_POWERDOWN &&
1361 platform.powerdown != NULL) {
1362 (*platform.powerdown)();
1363 printf("WARNING: powerdown failed!\n");
1364 }
1365 printf("%s\n\n", howto & RB_HALT ? "halted." : "rebooting...");
1366 prom_halt(howto & RB_HALT);
1367 /*NOTREACHED*/
1368 }
1369
1370 /*
1371 * These variables are needed by /sbin/savecore
1372 */
1373 u_long dumpmag = 0x8fca0101; /* magic number */
1374 int dumpsize = 0; /* pages */
1375 long dumplo = 0; /* blocks */
1376
1377 /*
1378 * cpu_dumpsize: calculate size of machine-dependent kernel core dump headers.
1379 */
1380 int
1381 cpu_dumpsize()
1382 {
1383 int size;
1384
1385 size = ALIGN(sizeof(kcore_seg_t)) + ALIGN(sizeof(cpu_kcore_hdr_t)) +
1386 ALIGN(mem_cluster_cnt * sizeof(phys_ram_seg_t));
1387 if (roundup(size, dbtob(1)) != dbtob(1))
1388 return -1;
1389
1390 return (1);
1391 }
1392
1393 /*
1394 * cpu_dump_mempagecnt: calculate size of RAM (in pages) to be dumped.
1395 */
1396 u_long
1397 cpu_dump_mempagecnt()
1398 {
1399 u_long i, n;
1400
1401 n = 0;
1402 for (i = 0; i < mem_cluster_cnt; i++)
1403 n += atop(mem_clusters[i].size);
1404 return (n);
1405 }
1406
1407 /*
1408 * cpu_dump: dump machine-dependent kernel core dump headers.
1409 */
1410 int
1411 cpu_dump()
1412 {
1413 int (*dump) __P((dev_t, daddr_t, caddr_t, size_t));
1414 char buf[dbtob(1)];
1415 kcore_seg_t *segp;
1416 cpu_kcore_hdr_t *cpuhdrp;
1417 phys_ram_seg_t *memsegp;
1418 int i;
1419
1420 dump = bdevsw[major(dumpdev)].d_dump;
1421
1422 bzero(buf, sizeof buf);
1423 segp = (kcore_seg_t *)buf;
1424 cpuhdrp = (cpu_kcore_hdr_t *)&buf[ALIGN(sizeof(*segp))];
1425 memsegp = (phys_ram_seg_t *)&buf[ ALIGN(sizeof(*segp)) +
1426 ALIGN(sizeof(*cpuhdrp))];
1427
1428 /*
1429 * Generate a segment header.
1430 */
1431 CORE_SETMAGIC(*segp, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
1432 segp->c_size = dbtob(1) - ALIGN(sizeof(*segp));
1433
1434 /*
1435 * Add the machine-dependent header info.
1436 */
1437 cpuhdrp->lev1map_pa = ALPHA_K0SEG_TO_PHYS((vaddr_t)kernel_lev1map);
1438 cpuhdrp->page_size = PAGE_SIZE;
1439 cpuhdrp->nmemsegs = mem_cluster_cnt;
1440
1441 /*
1442 * Fill in the memory segment descriptors.
1443 */
1444 for (i = 0; i < mem_cluster_cnt; i++) {
1445 memsegp[i].start = mem_clusters[i].start;
1446 memsegp[i].size = mem_clusters[i].size & ~PAGE_MASK;
1447 }
1448
1449 return (dump(dumpdev, dumplo, (caddr_t)buf, dbtob(1)));
1450 }
1451
1452 /*
1453 * This is called by main to set dumplo and dumpsize.
1454 * Dumps always skip the first CLBYTES of disk space
1455 * in case there might be a disk label stored there.
1456 * If there is extra space, put dump at the end to
1457 * reduce the chance that swapping trashes it.
1458 */
1459 void
1460 cpu_dumpconf()
1461 {
1462 int nblks, dumpblks; /* size of dump area */
1463 int maj;
1464
1465 if (dumpdev == NODEV)
1466 goto bad;
1467 maj = major(dumpdev);
1468 if (maj < 0 || maj >= nblkdev)
1469 panic("dumpconf: bad dumpdev=0x%x", dumpdev);
1470 if (bdevsw[maj].d_psize == NULL)
1471 goto bad;
1472 nblks = (*bdevsw[maj].d_psize)(dumpdev);
1473 if (nblks <= ctod(1))
1474 goto bad;
1475
1476 dumpblks = cpu_dumpsize();
1477 if (dumpblks < 0)
1478 goto bad;
1479 dumpblks += ctod(cpu_dump_mempagecnt());
1480
1481 /* If dump won't fit (incl. room for possible label), punt. */
1482 if (dumpblks > (nblks - ctod(1)))
1483 goto bad;
1484
1485 /* Put dump at end of partition */
1486 dumplo = nblks - dumpblks;
1487
1488 /* dumpsize is in page units, and doesn't include headers. */
1489 dumpsize = cpu_dump_mempagecnt();
1490 return;
1491
1492 bad:
1493 dumpsize = 0;
1494 return;
1495 }
1496
1497 /*
1498 * Dump the kernel's image to the swap partition.
1499 */
1500 #define BYTES_PER_DUMP NBPG
1501
1502 void
1503 dumpsys()
1504 {
1505 u_long totalbytesleft, bytes, i, n, memcl;
1506 u_long maddr;
1507 int psize;
1508 daddr_t blkno;
1509 int (*dump) __P((dev_t, daddr_t, caddr_t, size_t));
1510 int error;
1511
1512 /* Save registers. */
1513 savectx(&dumppcb);
1514
1515 msgbufenabled = 0; /* don't record dump msgs in msgbuf */
1516 if (dumpdev == NODEV)
1517 return;
1518
1519 /*
1520 * For dumps during autoconfiguration,
1521 * if dump device has already configured...
1522 */
1523 if (dumpsize == 0)
1524 cpu_dumpconf();
1525 if (dumplo <= 0) {
1526 printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
1527 minor(dumpdev));
1528 return;
1529 }
1530 printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
1531 minor(dumpdev), dumplo);
1532
1533 psize = (*bdevsw[major(dumpdev)].d_psize)(dumpdev);
1534 printf("dump ");
1535 if (psize == -1) {
1536 printf("area unavailable\n");
1537 return;
1538 }
1539
1540 /* XXX should purge all outstanding keystrokes. */
1541
1542 if ((error = cpu_dump()) != 0)
1543 goto err;
1544
1545 totalbytesleft = ptoa(cpu_dump_mempagecnt());
1546 blkno = dumplo + cpu_dumpsize();
1547 dump = bdevsw[major(dumpdev)].d_dump;
1548 error = 0;
1549
1550 for (memcl = 0; memcl < mem_cluster_cnt; memcl++) {
1551 maddr = mem_clusters[memcl].start;
1552 bytes = mem_clusters[memcl].size & ~PAGE_MASK;
1553
1554 for (i = 0; i < bytes; i += n, totalbytesleft -= n) {
1555
1556 /* Print out how many MBs we to go. */
1557 if ((totalbytesleft % (1024*1024)) == 0)
1558 printf("%d ", totalbytesleft / (1024 * 1024));
1559
1560 /* Limit size for next transfer. */
1561 n = bytes - i;
1562 if (n > BYTES_PER_DUMP)
1563 n = BYTES_PER_DUMP;
1564
1565 error = (*dump)(dumpdev, blkno,
1566 (caddr_t)ALPHA_PHYS_TO_K0SEG(maddr), n);
1567 if (error)
1568 goto err;
1569 maddr += n;
1570 blkno += btodb(n); /* XXX? */
1571
1572 /* XXX should look for keystrokes, to cancel. */
1573 }
1574 }
1575
1576 err:
1577 switch (error) {
1578
1579 case ENXIO:
1580 printf("device bad\n");
1581 break;
1582
1583 case EFAULT:
1584 printf("device not ready\n");
1585 break;
1586
1587 case EINVAL:
1588 printf("area improper\n");
1589 break;
1590
1591 case EIO:
1592 printf("i/o error\n");
1593 break;
1594
1595 case EINTR:
1596 printf("aborted from console\n");
1597 break;
1598
1599 case 0:
1600 printf("succeeded\n");
1601 break;
1602
1603 default:
1604 printf("error %d\n", error);
1605 break;
1606 }
1607 printf("\n\n");
1608 delay(1000);
1609 }
1610
1611 void
1612 frametoreg(framep, regp)
1613 struct trapframe *framep;
1614 struct reg *regp;
1615 {
1616
1617 regp->r_regs[R_V0] = framep->tf_regs[FRAME_V0];
1618 regp->r_regs[R_T0] = framep->tf_regs[FRAME_T0];
1619 regp->r_regs[R_T1] = framep->tf_regs[FRAME_T1];
1620 regp->r_regs[R_T2] = framep->tf_regs[FRAME_T2];
1621 regp->r_regs[R_T3] = framep->tf_regs[FRAME_T3];
1622 regp->r_regs[R_T4] = framep->tf_regs[FRAME_T4];
1623 regp->r_regs[R_T5] = framep->tf_regs[FRAME_T5];
1624 regp->r_regs[R_T6] = framep->tf_regs[FRAME_T6];
1625 regp->r_regs[R_T7] = framep->tf_regs[FRAME_T7];
1626 regp->r_regs[R_S0] = framep->tf_regs[FRAME_S0];
1627 regp->r_regs[R_S1] = framep->tf_regs[FRAME_S1];
1628 regp->r_regs[R_S2] = framep->tf_regs[FRAME_S2];
1629 regp->r_regs[R_S3] = framep->tf_regs[FRAME_S3];
1630 regp->r_regs[R_S4] = framep->tf_regs[FRAME_S4];
1631 regp->r_regs[R_S5] = framep->tf_regs[FRAME_S5];
1632 regp->r_regs[R_S6] = framep->tf_regs[FRAME_S6];
1633 regp->r_regs[R_A0] = framep->tf_regs[FRAME_A0];
1634 regp->r_regs[R_A1] = framep->tf_regs[FRAME_A1];
1635 regp->r_regs[R_A2] = framep->tf_regs[FRAME_A2];
1636 regp->r_regs[R_A3] = framep->tf_regs[FRAME_A3];
1637 regp->r_regs[R_A4] = framep->tf_regs[FRAME_A4];
1638 regp->r_regs[R_A5] = framep->tf_regs[FRAME_A5];
1639 regp->r_regs[R_T8] = framep->tf_regs[FRAME_T8];
1640 regp->r_regs[R_T9] = framep->tf_regs[FRAME_T9];
1641 regp->r_regs[R_T10] = framep->tf_regs[FRAME_T10];
1642 regp->r_regs[R_T11] = framep->tf_regs[FRAME_T11];
1643 regp->r_regs[R_RA] = framep->tf_regs[FRAME_RA];
1644 regp->r_regs[R_T12] = framep->tf_regs[FRAME_T12];
1645 regp->r_regs[R_AT] = framep->tf_regs[FRAME_AT];
1646 regp->r_regs[R_GP] = framep->tf_regs[FRAME_GP];
1647 /* regp->r_regs[R_SP] = framep->tf_regs[FRAME_SP]; XXX */
1648 regp->r_regs[R_ZERO] = 0;
1649 }
1650
1651 void
1652 regtoframe(regp, framep)
1653 struct reg *regp;
1654 struct trapframe *framep;
1655 {
1656
1657 framep->tf_regs[FRAME_V0] = regp->r_regs[R_V0];
1658 framep->tf_regs[FRAME_T0] = regp->r_regs[R_T0];
1659 framep->tf_regs[FRAME_T1] = regp->r_regs[R_T1];
1660 framep->tf_regs[FRAME_T2] = regp->r_regs[R_T2];
1661 framep->tf_regs[FRAME_T3] = regp->r_regs[R_T3];
1662 framep->tf_regs[FRAME_T4] = regp->r_regs[R_T4];
1663 framep->tf_regs[FRAME_T5] = regp->r_regs[R_T5];
1664 framep->tf_regs[FRAME_T6] = regp->r_regs[R_T6];
1665 framep->tf_regs[FRAME_T7] = regp->r_regs[R_T7];
1666 framep->tf_regs[FRAME_S0] = regp->r_regs[R_S0];
1667 framep->tf_regs[FRAME_S1] = regp->r_regs[R_S1];
1668 framep->tf_regs[FRAME_S2] = regp->r_regs[R_S2];
1669 framep->tf_regs[FRAME_S3] = regp->r_regs[R_S3];
1670 framep->tf_regs[FRAME_S4] = regp->r_regs[R_S4];
1671 framep->tf_regs[FRAME_S5] = regp->r_regs[R_S5];
1672 framep->tf_regs[FRAME_S6] = regp->r_regs[R_S6];
1673 framep->tf_regs[FRAME_A0] = regp->r_regs[R_A0];
1674 framep->tf_regs[FRAME_A1] = regp->r_regs[R_A1];
1675 framep->tf_regs[FRAME_A2] = regp->r_regs[R_A2];
1676 framep->tf_regs[FRAME_A3] = regp->r_regs[R_A3];
1677 framep->tf_regs[FRAME_A4] = regp->r_regs[R_A4];
1678 framep->tf_regs[FRAME_A5] = regp->r_regs[R_A5];
1679 framep->tf_regs[FRAME_T8] = regp->r_regs[R_T8];
1680 framep->tf_regs[FRAME_T9] = regp->r_regs[R_T9];
1681 framep->tf_regs[FRAME_T10] = regp->r_regs[R_T10];
1682 framep->tf_regs[FRAME_T11] = regp->r_regs[R_T11];
1683 framep->tf_regs[FRAME_RA] = regp->r_regs[R_RA];
1684 framep->tf_regs[FRAME_T12] = regp->r_regs[R_T12];
1685 framep->tf_regs[FRAME_AT] = regp->r_regs[R_AT];
1686 framep->tf_regs[FRAME_GP] = regp->r_regs[R_GP];
1687 /* framep->tf_regs[FRAME_SP] = regp->r_regs[R_SP]; XXX */
1688 /* ??? = regp->r_regs[R_ZERO]; */
1689 }
1690
1691 void
1692 printregs(regp)
1693 struct reg *regp;
1694 {
1695 int i;
1696
1697 for (i = 0; i < 32; i++)
1698 printf("R%d:\t0x%016lx%s", i, regp->r_regs[i],
1699 i & 1 ? "\n" : "\t");
1700 }
1701
1702 void
1703 regdump(framep)
1704 struct trapframe *framep;
1705 {
1706 struct reg reg;
1707
1708 frametoreg(framep, ®);
1709 reg.r_regs[R_SP] = alpha_pal_rdusp();
1710
1711 printf("REGISTERS:\n");
1712 printregs(®);
1713 }
1714
1715 #ifdef DEBUG
1716 int sigdebug = 0;
1717 int sigpid = 0;
1718 #define SDB_FOLLOW 0x01
1719 #define SDB_KSTACK 0x02
1720 #endif
1721
1722 /*
1723 * Send an interrupt to process.
1724 */
1725 void
1726 sendsig(catcher, sig, mask, code)
1727 sig_t catcher;
1728 int sig;
1729 sigset_t *mask;
1730 u_long code;
1731 {
1732 struct proc *p = curproc;
1733 struct sigcontext *scp, ksc;
1734 struct trapframe *frame;
1735 struct sigacts *psp = p->p_sigacts;
1736 int onstack, fsize, rndfsize;
1737 extern struct proc *fpcurproc;
1738
1739 frame = p->p_md.md_tf;
1740
1741 /* Do we need to jump onto the signal stack? */
1742 onstack =
1743 (psp->ps_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
1744 (psp->ps_sigact[sig].sa_flags & SA_ONSTACK) != 0;
1745
1746 /* Allocate space for the signal handler context. */
1747 fsize = sizeof(ksc);
1748 rndfsize = ((fsize + 15) / 16) * 16;
1749
1750 if (onstack)
1751 scp = (struct sigcontext *)((caddr_t)psp->ps_sigstk.ss_sp +
1752 psp->ps_sigstk.ss_size);
1753 else
1754 scp = (struct sigcontext *)(alpha_pal_rdusp());
1755 scp = (struct sigcontext *)((caddr_t)scp - rndfsize);
1756
1757 #ifdef DEBUG
1758 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
1759 printf("sendsig(%d): sig %d ssp %p usp %p\n", p->p_pid,
1760 sig, &onstack, scp);
1761 #endif
1762
1763 /* Build stack frame for signal trampoline. */
1764 ksc.sc_pc = frame->tf_regs[FRAME_PC];
1765 ksc.sc_ps = frame->tf_regs[FRAME_PS];
1766
1767 /* Save register context. */
1768 frametoreg(frame, (struct reg *)ksc.sc_regs);
1769 ksc.sc_regs[R_ZERO] = 0xACEDBADE; /* magic number */
1770 ksc.sc_regs[R_SP] = alpha_pal_rdusp();
1771
1772 /* save the floating-point state, if necessary, then copy it. */
1773 if (p == fpcurproc) {
1774 alpha_pal_wrfen(1);
1775 savefpstate(&p->p_addr->u_pcb.pcb_fp);
1776 alpha_pal_wrfen(0);
1777 fpcurproc = NULL;
1778 }
1779 ksc.sc_ownedfp = p->p_md.md_flags & MDP_FPUSED;
1780 bcopy(&p->p_addr->u_pcb.pcb_fp, (struct fpreg *)ksc.sc_fpregs,
1781 sizeof(struct fpreg));
1782 ksc.sc_fp_control = 0; /* XXX ? */
1783 bzero(ksc.sc_reserved, sizeof ksc.sc_reserved); /* XXX */
1784 bzero(ksc.sc_xxx, sizeof ksc.sc_xxx); /* XXX */
1785
1786 /* Save signal stack. */
1787 ksc.sc_onstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
1788
1789 /* Save signal mask. */
1790 ksc.sc_mask = *mask;
1791
1792 #ifdef COMPAT_13
1793 /*
1794 * XXX We always have to save an old style signal mask because
1795 * XXX we might be delivering a signal to a process which will
1796 * XXX escape from the signal in a non-standard way and invoke
1797 * XXX sigreturn() directly.
1798 */
1799 {
1800 /* Note: it's a long in the stack frame. */
1801 sigset13_t mask13;
1802
1803 native_sigset_to_sigset13(mask, &mask13);
1804 ksc.__sc_mask13 = mask13;
1805 }
1806 #endif
1807
1808 #ifdef COMPAT_OSF1
1809 /*
1810 * XXX Create an OSF/1-style sigcontext and associated goo.
1811 */
1812 #endif
1813
1814 if (copyout(&ksc, (caddr_t)scp, fsize) != 0) {
1815 /*
1816 * Process has trashed its stack; give it an illegal
1817 * instruction to halt it in its tracks.
1818 */
1819 #ifdef DEBUG
1820 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
1821 printf("sendsig(%d): copyout failed on sig %d\n",
1822 p->p_pid, sig);
1823 #endif
1824 sigexit(p, SIGILL);
1825 /* NOTREACHED */
1826 }
1827 #ifdef DEBUG
1828 if (sigdebug & SDB_FOLLOW)
1829 printf("sendsig(%d): sig %d scp %p code %lx\n", p->p_pid, sig,
1830 scp, code);
1831 #endif
1832
1833 /* Set up the registers to return to sigcode. */
1834 frame->tf_regs[FRAME_PC] = (u_int64_t)psp->ps_sigcode;
1835 frame->tf_regs[FRAME_A0] = sig;
1836 frame->tf_regs[FRAME_A1] = code;
1837 frame->tf_regs[FRAME_A2] = (u_int64_t)scp;
1838 frame->tf_regs[FRAME_T12] = (u_int64_t)catcher; /* t12 is pv */
1839 alpha_pal_wrusp((unsigned long)scp);
1840
1841 /* Remember that we're now on the signal stack. */
1842 if (onstack)
1843 psp->ps_sigstk.ss_flags |= SS_ONSTACK;
1844
1845 #ifdef DEBUG
1846 if (sigdebug & SDB_FOLLOW)
1847 printf("sendsig(%d): pc %lx, catcher %lx\n", p->p_pid,
1848 frame->tf_regs[FRAME_PC], frame->tf_regs[FRAME_A3]);
1849 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
1850 printf("sendsig(%d): sig %d returns\n",
1851 p->p_pid, sig);
1852 #endif
1853 }
1854
1855 /*
1856 * System call to cleanup state after a signal
1857 * has been taken. Reset signal mask and
1858 * stack state from context left by sendsig (above).
1859 * Return to previous pc and psl as specified by
1860 * context left by sendsig. Check carefully to
1861 * make sure that the user has not modified the
1862 * psl to gain improper priviledges or to cause
1863 * a machine fault.
1864 */
1865 /* ARGSUSED */
1866 int
1867 sys___sigreturn14(p, v, retval)
1868 struct proc *p;
1869 void *v;
1870 register_t *retval;
1871 {
1872 struct sys___sigreturn14_args /* {
1873 syscallarg(struct sigcontext *) sigcntxp;
1874 } */ *uap = v;
1875 struct sigcontext *scp, ksc;
1876 extern struct proc *fpcurproc;
1877
1878 /*
1879 * The trampoline code hands us the context.
1880 * It is unsafe to keep track of it ourselves, in the event that a
1881 * program jumps out of a signal handler.
1882 */
1883 scp = SCARG(uap, sigcntxp);
1884 #ifdef DEBUG
1885 if (sigdebug & SDB_FOLLOW)
1886 printf("sigreturn: pid %d, scp %p\n", p->p_pid, scp);
1887 #endif
1888 if (ALIGN(scp) != (u_int64_t)scp)
1889 return (EINVAL);
1890
1891 if (copyin((caddr_t)scp, &ksc, sizeof(ksc)) != 0)
1892 return (EFAULT);
1893
1894 if (ksc.sc_regs[R_ZERO] != 0xACEDBADE) /* magic number */
1895 return (EINVAL);
1896
1897 /* Restore register context. */
1898 p->p_md.md_tf->tf_regs[FRAME_PC] = ksc.sc_pc;
1899 p->p_md.md_tf->tf_regs[FRAME_PS] =
1900 (ksc.sc_ps | ALPHA_PSL_USERSET) & ~ALPHA_PSL_USERCLR;
1901
1902 regtoframe((struct reg *)ksc.sc_regs, p->p_md.md_tf);
1903 alpha_pal_wrusp(ksc.sc_regs[R_SP]);
1904
1905 /* XXX ksc.sc_ownedfp ? */
1906 if (p == fpcurproc)
1907 fpcurproc = NULL;
1908 bcopy((struct fpreg *)ksc.sc_fpregs, &p->p_addr->u_pcb.pcb_fp,
1909 sizeof(struct fpreg));
1910 /* XXX ksc.sc_fp_control ? */
1911
1912 /* Restore signal stack. */
1913 if (ksc.sc_onstack & SS_ONSTACK)
1914 p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
1915 else
1916 p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
1917
1918 /* Restore signal mask. */
1919 (void) sigprocmask1(p, SIG_SETMASK, &ksc.sc_mask, 0);
1920
1921 #ifdef DEBUG
1922 if (sigdebug & SDB_FOLLOW)
1923 printf("sigreturn(%d): returns\n", p->p_pid);
1924 #endif
1925 return (EJUSTRETURN);
1926 }
1927
1928 /*
1929 * machine dependent system variables.
1930 */
1931 int
1932 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
1933 int *name;
1934 u_int namelen;
1935 void *oldp;
1936 size_t *oldlenp;
1937 void *newp;
1938 size_t newlen;
1939 struct proc *p;
1940 {
1941 dev_t consdev;
1942
1943 /* all sysctl names at this level are terminal */
1944 if (namelen != 1)
1945 return (ENOTDIR); /* overloaded */
1946
1947 switch (name[0]) {
1948 case CPU_CONSDEV:
1949 if (cn_tab != NULL)
1950 consdev = cn_tab->cn_dev;
1951 else
1952 consdev = NODEV;
1953 return (sysctl_rdstruct(oldp, oldlenp, newp, &consdev,
1954 sizeof consdev));
1955
1956 case CPU_ROOT_DEVICE:
1957 return (sysctl_rdstring(oldp, oldlenp, newp,
1958 root_device->dv_xname));
1959
1960 case CPU_UNALIGNED_PRINT:
1961 return (sysctl_int(oldp, oldlenp, newp, newlen,
1962 &alpha_unaligned_print));
1963
1964 case CPU_UNALIGNED_FIX:
1965 return (sysctl_int(oldp, oldlenp, newp, newlen,
1966 &alpha_unaligned_fix));
1967
1968 case CPU_UNALIGNED_SIGBUS:
1969 return (sysctl_int(oldp, oldlenp, newp, newlen,
1970 &alpha_unaligned_sigbus));
1971
1972 case CPU_BOOTED_KERNEL:
1973 return (sysctl_rdstring(oldp, oldlenp, newp,
1974 bootinfo.booted_kernel));
1975
1976 default:
1977 return (EOPNOTSUPP);
1978 }
1979 /* NOTREACHED */
1980 }
1981
1982 /*
1983 * Set registers on exec.
1984 */
1985 void
1986 setregs(p, pack, stack)
1987 register struct proc *p;
1988 struct exec_package *pack;
1989 u_long stack;
1990 {
1991 struct trapframe *tfp = p->p_md.md_tf;
1992 extern struct proc *fpcurproc;
1993 #ifdef DEBUG
1994 int i;
1995 #endif
1996
1997 #ifdef DEBUG
1998 /*
1999 * Crash and dump, if the user requested it.
2000 */
2001 if (boothowto & RB_DUMP)
2002 panic("crash requested by boot flags");
2003 #endif
2004
2005 #ifdef DEBUG
2006 for (i = 0; i < FRAME_SIZE; i++)
2007 tfp->tf_regs[i] = 0xbabefacedeadbeef;
2008 #else
2009 bzero(tfp->tf_regs, FRAME_SIZE * sizeof tfp->tf_regs[0]);
2010 #endif
2011 bzero(&p->p_addr->u_pcb.pcb_fp, sizeof p->p_addr->u_pcb.pcb_fp);
2012 #define FP_RN 2 /* XXX */
2013 p->p_addr->u_pcb.pcb_fp.fpr_cr = (long)FP_RN << 58;
2014 alpha_pal_wrusp(stack);
2015 tfp->tf_regs[FRAME_PS] = ALPHA_PSL_USERSET;
2016 tfp->tf_regs[FRAME_PC] = pack->ep_entry & ~3;
2017
2018 tfp->tf_regs[FRAME_A0] = stack; /* a0 = sp */
2019 tfp->tf_regs[FRAME_A1] = 0; /* a1 = rtld cleanup */
2020 tfp->tf_regs[FRAME_A2] = 0; /* a2 = rtld object */
2021 tfp->tf_regs[FRAME_A3] = (u_int64_t)PS_STRINGS; /* a3 = ps_strings */
2022 tfp->tf_regs[FRAME_T12] = tfp->tf_regs[FRAME_PC]; /* a.k.a. PV */
2023
2024 p->p_md.md_flags &= ~MDP_FPUSED;
2025 if (fpcurproc == p)
2026 fpcurproc = NULL;
2027 }
2028
2029 void
2030 netintr()
2031 {
2032 int n, s;
2033
2034 s = splhigh();
2035 n = netisr;
2036 netisr = 0;
2037 splx(s);
2038
2039 #define DONETISR(bit, fn) \
2040 do { \
2041 if (n & (1 << (bit))) \
2042 fn; \
2043 } while (0)
2044
2045 #ifdef INET
2046 #if NARP > 0
2047 DONETISR(NETISR_ARP, arpintr());
2048 #endif
2049 DONETISR(NETISR_IP, ipintr());
2050 #endif
2051 #ifdef NETATALK
2052 DONETISR(NETISR_ATALK, atintr());
2053 #endif
2054 #ifdef NS
2055 DONETISR(NETISR_NS, nsintr());
2056 #endif
2057 #ifdef ISO
2058 DONETISR(NETISR_ISO, clnlintr());
2059 #endif
2060 #ifdef CCITT
2061 DONETISR(NETISR_CCITT, ccittintr());
2062 #endif
2063 #ifdef NATM
2064 DONETISR(NETISR_NATM, natmintr());
2065 #endif
2066 #if NPPP > 1
2067 DONETISR(NETISR_PPP, pppintr());
2068 #endif
2069
2070 #undef DONETISR
2071 }
2072
2073 void
2074 do_sir()
2075 {
2076 u_int64_t n;
2077
2078 do {
2079 (void)splhigh();
2080 n = ssir;
2081 ssir = 0;
2082 splsoft(); /* don't recurse through spl0() */
2083
2084 #if defined(UVM)
2085 #define COUNT_SOFT uvmexp.softs++
2086 #else
2087 #define COUNT_SOFT cnt.v_soft++
2088 #endif
2089
2090 #define DO_SIR(bit, fn) \
2091 do { \
2092 if (n & (bit)) { \
2093 COUNT_SOFT; \
2094 fn; \
2095 } \
2096 } while (0)
2097
2098 DO_SIR(SIR_NET, netintr());
2099 DO_SIR(SIR_CLOCK, softclock());
2100 #if NCOM > 0
2101 DO_SIR(SIR_SERIAL, comsoft());
2102 #endif
2103
2104 #undef COUNT_SOFT
2105 #undef DO_SIR
2106 } while (ssir != 0);
2107 }
2108
2109 int
2110 spl0()
2111 {
2112
2113 if (ssir)
2114 do_sir(); /* it lowers the IPL itself */
2115
2116 return (alpha_pal_swpipl(ALPHA_PSL_IPL_0));
2117 }
2118
2119 /*
2120 * The following primitives manipulate the run queues. _whichqs tells which
2121 * of the 32 queues _qs have processes in them. Setrunqueue puts processes
2122 * into queues, Remrunqueue removes them from queues. The running process is
2123 * on no queue, other processes are on a queue related to p->p_priority,
2124 * divided by 4 actually to shrink the 0-127 range of priorities into the 32
2125 * available queues.
2126 */
2127 /*
2128 * setrunqueue(p)
2129 * proc *p;
2130 *
2131 * Call should be made at splclock(), and p->p_stat should be SRUN.
2132 */
2133
2134 void
2135 setrunqueue(p)
2136 struct proc *p;
2137 {
2138 int bit;
2139
2140 /* firewall: p->p_back must be NULL */
2141 if (p->p_back != NULL)
2142 panic("setrunqueue");
2143
2144 bit = p->p_priority >> 2;
2145 whichqs |= (1 << bit);
2146 p->p_forw = (struct proc *)&qs[bit];
2147 p->p_back = qs[bit].ph_rlink;
2148 p->p_back->p_forw = p;
2149 qs[bit].ph_rlink = p;
2150 }
2151
2152 /*
2153 * remrunqueue(p)
2154 *
2155 * Call should be made at splclock().
2156 */
2157 void
2158 remrunqueue(p)
2159 struct proc *p;
2160 {
2161 int bit;
2162
2163 bit = p->p_priority >> 2;
2164 if ((whichqs & (1 << bit)) == 0)
2165 panic("remrunqueue");
2166
2167 p->p_back->p_forw = p->p_forw;
2168 p->p_forw->p_back = p->p_back;
2169 p->p_back = NULL; /* for firewall checking. */
2170
2171 if ((struct proc *)&qs[bit] == qs[bit].ph_link)
2172 whichqs &= ~(1 << bit);
2173 }
2174
2175 /*
2176 * Return the best possible estimate of the time in the timeval
2177 * to which tvp points. Unfortunately, we can't read the hardware registers.
2178 * We guarantee that the time will be greater than the value obtained by a
2179 * previous call.
2180 */
2181 void
2182 microtime(tvp)
2183 register struct timeval *tvp;
2184 {
2185 int s = splclock();
2186 static struct timeval lasttime;
2187
2188 *tvp = time;
2189 #ifdef notdef
2190 tvp->tv_usec += clkread();
2191 while (tvp->tv_usec > 1000000) {
2192 tvp->tv_sec++;
2193 tvp->tv_usec -= 1000000;
2194 }
2195 #endif
2196 if (tvp->tv_sec == lasttime.tv_sec &&
2197 tvp->tv_usec <= lasttime.tv_usec &&
2198 (tvp->tv_usec = lasttime.tv_usec + 1) > 1000000) {
2199 tvp->tv_sec++;
2200 tvp->tv_usec -= 1000000;
2201 }
2202 lasttime = *tvp;
2203 splx(s);
2204 }
2205
2206 /*
2207 * Wait "n" microseconds.
2208 */
2209 void
2210 delay(n)
2211 unsigned long n;
2212 {
2213 long N = cycles_per_usec * (n);
2214
2215 while (N > 0) /* XXX */
2216 N -= 3; /* XXX */
2217 }
2218
2219 #if defined(COMPAT_OSF1) || 1 /* XXX */
2220 void cpu_exec_ecoff_setregs __P((struct proc *, struct exec_package *,
2221 u_long));
2222
2223 void
2224 cpu_exec_ecoff_setregs(p, epp, stack)
2225 struct proc *p;
2226 struct exec_package *epp;
2227 u_long stack;
2228 {
2229 struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr;
2230
2231 setregs(p, epp, stack);
2232 p->p_md.md_tf->tf_regs[FRAME_GP] = execp->a.gp_value;
2233 }
2234
2235 /*
2236 * cpu_exec_ecoff_hook():
2237 * cpu-dependent ECOFF format hook for execve().
2238 *
2239 * Do any machine-dependent diddling of the exec package when doing ECOFF.
2240 *
2241 */
2242 int
2243 cpu_exec_ecoff_hook(p, epp)
2244 struct proc *p;
2245 struct exec_package *epp;
2246 {
2247 struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr;
2248 extern struct emul emul_netbsd;
2249 #ifdef COMPAT_OSF1
2250 extern struct emul emul_osf1;
2251 #endif
2252
2253 switch (execp->f.f_magic) {
2254 #ifdef COMPAT_OSF1
2255 case ECOFF_MAGIC_ALPHA:
2256 epp->ep_emul = &emul_osf1;
2257 break;
2258 #endif
2259
2260 case ECOFF_MAGIC_NETBSD_ALPHA:
2261 epp->ep_emul = &emul_netbsd;
2262 break;
2263
2264 default:
2265 return ENOEXEC;
2266 }
2267 return 0;
2268 }
2269 #endif
2270
2271 int
2272 alpha_pa_access(pa)
2273 u_long pa;
2274 {
2275 int i;
2276
2277 for (i = 0; i < mem_cluster_cnt; i++) {
2278 if (pa < mem_clusters[i].start)
2279 continue;
2280 if ((pa - mem_clusters[i].start) >=
2281 (mem_clusters[i].size & ~PAGE_MASK))
2282 continue;
2283 return (mem_clusters[i].size & PAGE_MASK); /* prot */
2284 }
2285 return (PROT_NONE);
2286 }
2287
2288 /* XXX XXX BEGIN XXX XXX */
2289 paddr_t alpha_XXX_dmamap_or; /* XXX */
2290 /* XXX */
2291 paddr_t /* XXX */
2292 alpha_XXX_dmamap(v) /* XXX */
2293 vaddr_t v; /* XXX */
2294 { /* XXX */
2295 /* XXX */
2296 return (vtophys(v) | alpha_XXX_dmamap_or); /* XXX */
2297 } /* XXX */
2298 /* XXX XXX END XXX XXX */
2299
2300 struct mchkinfo *
2301 cpu_mchkinfo()
2302 {
2303 if (mchkinfo_all_cpus == NULL)
2304 return &startup_info;
2305 return mchkinfo_all_cpus + alpha_pal_whami();
2306 }
2307