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