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