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