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