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