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