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