machdep.c revision 1.19 1 /* $NetBSD: machdep.c,v 1.19 1997/09/11 23:02:24 mycroft Exp $ */
2
3 /*
4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1982, 1986, 1990, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * from: Utah Hdr: machdep.c 1.74 92/12/20
41 * from: @(#)machdep.c 8.10 (Berkeley) 4/20/94
42 */
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
47 #include <sys/map.h>
48 #include <sys/proc.h>
49 #include <sys/buf.h>
50 #include <sys/reboot.h>
51 #include <sys/conf.h>
52 #include <sys/file.h>
53 #include <sys/clist.h>
54 #include <sys/callout.h>
55 #include <sys/malloc.h>
56 #include <sys/mbuf.h>
57 #include <sys/msgbuf.h>
58 #include <sys/ioctl.h>
59 #include <sys/tty.h>
60 #include <sys/mount.h>
61 #include <sys/user.h>
62 #include <sys/exec.h>
63 #include <sys/core.h>
64 #include <sys/kcore.h>
65 #include <sys/vnode.h>
66 #include <sys/sysctl.h>
67 #include <sys/syscallargs.h>
68 #ifdef SYSVMSG
69 #include <sys/msg.h>
70 #endif
71 #ifdef SYSVSEM
72 #include <sys/sem.h>
73 #endif
74 #ifdef SYSVSHM
75 #include <sys/shm.h>
76 #endif
77 #ifdef KGDB
78 #include <sys/kgdb.h>
79 #endif
80
81 #include <vm/vm.h>
82 #include <vm/vm_map.h>
83 #include <vm/vm_kern.h>
84 #include <vm/vm_page.h>
85
86 #include <dev/cons.h>
87
88 #include <machine/cpu.h>
89 #include <machine/reg.h>
90 #include <machine/psl.h>
91 #include <machine/pte.h>
92 #include <machine/dvma.h>
93 #include <machine/kcore.h>
94 #include <machine/db_machdep.h>
95 #include <machine/idprom.h>
96 #include <machine/machdep.h>
97
98 extern char version[];
99
100 /* Defined in locore.s */
101 extern char kernel_text[];
102 /* Defined by the linker */
103 extern char etext[];
104
105 int physmem;
106 int fputype;
107 int msgbufmapped;
108 struct msgbuf *msgbufp;
109
110 vm_offset_t vmmap;
111
112 /*
113 * safepri is a safe priority for sleep to set for a spin-wait
114 * during autoconfiguration or after a panic.
115 */
116 int safepri = PSL_LOWIPL;
117
118 /*
119 * Declare these as initialized data so we can patch them.
120 */
121 int nswbuf = 0;
122 #ifdef NBUF
123 int nbuf = NBUF;
124 #else
125 int nbuf = 0;
126 #endif
127 #ifdef BUFPAGES
128 int bufpages = BUFPAGES;
129 #else
130 int bufpages = 0;
131 #endif
132
133 unsigned char cpu_machine_id = 0;
134 char *cpu_string = NULL;
135 int cpu_has_vme = 0;
136 int has_iocache = 0;
137
138 static void identifycpu __P((void));
139 static void initcpu __P((void));
140
141 /*
142 * Console initialization: called early on from main,
143 * before vm init or cpu_startup. This system is able
144 * to setup the console much earlier than here (thanks
145 * to some help from the PROM monitor) so all that is
146 * left to do here is the debugger stuff.
147 */
148 void
149 consinit()
150 {
151
152 #ifdef KGDB
153 /* XXX - Ask on console for kgdb_dev? */
154 /* Note: this will just return if kgdb_dev<0 */
155 if (boothowto & RB_KDB)
156 kgdb_connect(1);
157 #endif
158 #ifdef DDB
159 /* Now that we have a console, we can stop in DDB. */
160 db_machine_init();
161 ddb_init();
162 if (boothowto & RB_KDB)
163 Debugger();
164 #endif DDB
165 }
166
167 /*
168 * allocsys() - Private routine used by cpu_startup() below.
169 *
170 * Allocate space for system data structures. We are given
171 * a starting virtual address and we return a final virtual
172 * address; along the way we set each data structure pointer.
173 *
174 * We call allocsys() with 0 to find out how much space we want,
175 * allocate that much and fill it with zeroes, and then call
176 * allocsys() again with the correct base virtual address.
177 */
178 #define valloc(name, type, num) \
179 v = (caddr_t)(((name) = (type *)v) + (num))
180 static caddr_t allocsys __P((caddr_t));
181 static caddr_t
182 allocsys(v)
183 register caddr_t v;
184 {
185
186 #ifdef REAL_CLISTS
187 valloc(cfree, struct cblock, nclist);
188 #endif
189 valloc(callout, struct callout, ncallout);
190 #ifdef SYSVSHM
191 valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
192 #endif
193 #ifdef SYSVSEM
194 valloc(sema, struct semid_ds, seminfo.semmni);
195 valloc(sem, struct sem, seminfo.semmns);
196 /* This is pretty disgusting! */
197 valloc(semu, int, (seminfo.semmnu * seminfo.semusz) / sizeof(int));
198 #endif
199 #ifdef SYSVMSG
200 valloc(msgpool, char, msginfo.msgmax);
201 valloc(msgmaps, struct msgmap, msginfo.msgseg);
202 valloc(msghdrs, struct msg, msginfo.msgtql);
203 valloc(msqids, struct msqid_ds, msginfo.msgmni);
204 #endif
205
206 /*
207 * Determine how many buffers to allocate. We allocate
208 * the BSD standard of use 10% of memory for the first 2 Meg,
209 * 5% of remaining. Insure a minimum of 16 buffers.
210 * Allocate 1/2 as many swap buffer headers as file i/o buffers.
211 */
212 if (bufpages == 0) {
213 /* We always have more than 2MB of memory. */
214 bufpages = ((btoc(2 * 1024 * 1024) + physmem) /
215 (20 * CLSIZE));
216 }
217 if (nbuf == 0) {
218 nbuf = bufpages;
219 if (nbuf < 16)
220 nbuf = 16;
221 }
222 if (nswbuf == 0) {
223 nswbuf = (nbuf / 2) &~ 1; /* force even */
224 if (nswbuf > 256)
225 nswbuf = 256; /* sanity */
226 }
227 valloc(swbuf, struct buf, nswbuf);
228 valloc(buf, struct buf, nbuf);
229 return v;
230 }
231 #undef valloc
232
233 /*
234 * cpu_startup: allocate memory for variable-sized tables,
235 * initialize cpu, and do autoconfiguration.
236 *
237 * This is called early in init_main.c:main(), after the
238 * kernel memory allocator is ready for use, but before
239 * the creation of processes 1,2, and mountroot, etc.
240 */
241 void
242 cpu_startup()
243 {
244 caddr_t v;
245 int sz, i;
246 vm_size_t size;
247 int base, residual;
248 vm_offset_t minaddr, maxaddr;
249
250 /*
251 * Initialize message buffer (for kernel printf).
252 * This is put in physical page zero so it will
253 * always be in the same place after a reboot.
254 * Its mapping was prepared in pmap_bootstrap().
255 * Also, offset some to avoid PROM scribbles.
256 */
257 v = (caddr_t) KERNBASE;
258 msgbufp = (struct msgbuf *)(v + 0x1000);
259 msgbufmapped = 1;
260
261 /*
262 * Good {morning,afternoon,evening,night}.
263 */
264 printf(version);
265 identifycpu();
266 initfpu(); /* also prints FPU type */
267
268 printf("real mem = %d\n", ctob(physmem));
269
270 /*
271 * Find out how much space we need, allocate it,
272 * and then give everything true virtual addresses.
273 */
274 sz = (int)allocsys((caddr_t)0);
275 if ((v = (caddr_t)kmem_alloc(kernel_map, round_page(sz))) == 0)
276 panic("startup: no room for tables");
277 if (allocsys(v) - v != sz)
278 panic("startup: table size inconsistency");
279
280 /*
281 * Now allocate buffers proper. They are different than the above
282 * in that they usually occupy more virtual memory than physical.
283 */
284 size = MAXBSIZE * nbuf;
285 buffer_map = kmem_suballoc(kernel_map, (vm_offset_t *)&buffers,
286 &maxaddr, size, TRUE);
287 minaddr = (vm_offset_t)buffers;
288 if (vm_map_find(buffer_map, vm_object_allocate(size), (vm_offset_t)0,
289 &minaddr, size, FALSE) != KERN_SUCCESS)
290 panic("startup: cannot allocate buffers");
291 if ((bufpages / nbuf) >= btoc(MAXBSIZE)) {
292 /* don't want to alloc more physical mem than needed */
293 bufpages = btoc(MAXBSIZE) * nbuf;
294 }
295 base = bufpages / nbuf;
296 residual = bufpages % nbuf;
297 for (i = 0; i < nbuf; i++) {
298 vm_size_t curbufsize;
299 vm_offset_t curbuf;
300
301 /*
302 * First <residual> buffers get (base+1) physical pages
303 * allocated for them. The rest get (base) physical pages.
304 *
305 * The rest of each buffer occupies virtual space,
306 * but has no physical memory allocated for it.
307 */
308 curbuf = (vm_offset_t)buffers + i * MAXBSIZE;
309 curbufsize = CLBYTES * (i < residual ? base+1 : base);
310 vm_map_pageable(buffer_map, curbuf, curbuf+curbufsize, FALSE);
311 vm_map_simplify(buffer_map, curbuf);
312 }
313
314 /*
315 * Allocate a submap for exec arguments. This map effectively
316 * limits the number of processes exec'ing at any time.
317 */
318 exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
319 16*NCARGS, TRUE);
320
321 /*
322 * We don't use a submap for physio, and use a separate map
323 * for DVMA allocations. Our vmapbuf just maps pages into
324 * the kernel map (any kernel mapping is OK) and then the
325 * device drivers clone the kernel mappings into DVMA space.
326 */
327
328 /*
329 * Finally, allocate mbuf cluster submap.
330 */
331 mb_map = kmem_suballoc(kernel_map, (vm_offset_t *)&mbutl, &maxaddr,
332 VM_MBUF_SIZE, FALSE);
333
334 /*
335 * Initialize callouts
336 */
337 callfree = callout;
338 for (i = 1; i < ncallout; i++)
339 callout[i-1].c_next = &callout[i];
340 callout[i-1].c_next = NULL;
341
342 printf("avail mem = %d\n", (int) ptoa(cnt.v_free_count));
343 printf("using %d buffers containing %d bytes of memory\n",
344 nbuf, bufpages * CLBYTES);
345
346 /*
347 * Tell the VM system that writing to kernel text isn't allowed.
348 * If we don't, we might end up COW'ing the text segment!
349 */
350 if (vm_map_protect(kernel_map, (vm_offset_t) kernel_text,
351 trunc_page((vm_offset_t) etext),
352 VM_PROT_READ|VM_PROT_EXECUTE, TRUE)
353 != KERN_SUCCESS)
354 panic("can't protect kernel text");
355
356 /*
357 * Allocate a virtual page (for use by /dev/mem)
358 * This page is handed to pmap_enter() therefore
359 * it has to be in the normal kernel VA range.
360 */
361 vmmap = kmem_alloc_wait(kernel_map, NBPG);
362
363 /*
364 * Create the DVMA maps.
365 */
366 dvma_init();
367
368 /*
369 * Set up CPU-specific registers, cache, etc.
370 */
371 initcpu();
372
373 /*
374 * Set up buffers, so they can be used to read disk labels.
375 */
376 bufinit();
377
378 /*
379 * Configure the system.
380 */
381 configure();
382 }
383
384 /*
385 * Set registers on exec.
386 * XXX Should clear registers except sp, pc,
387 * but would break init; should be fixed soon.
388 */
389 void
390 setregs(p, pack, stack)
391 register struct proc *p;
392 struct exec_package *pack;
393 u_long stack;
394 {
395 struct trapframe *tf = (struct trapframe *)p->p_md.md_regs;
396
397 tf->tf_pc = pack->ep_entry & ~1;
398 tf->tf_regs[SP] = stack;
399 tf->tf_regs[A2] = (int)PS_STRINGS;
400
401 /* restore a null state frame */
402 p->p_addr->u_pcb.pcb_fpregs.fpf_null = 0;
403 if (fputype)
404 m68881_restore(&p->p_addr->u_pcb.pcb_fpregs);
405
406 p->p_md.md_flags = 0;
407 /* XXX - HPUX sigcode hack would go here... */
408 }
409
410 /*
411 * Info for CTL_HW
412 */
413 char machine[] = MACHINE; /* from <machine/param.h> */
414 char cpu_model[120];
415
416 /*
417 * XXX - Should empirically estimate the divisor...
418 * Note that the value of delay_divisor is roughly
419 * 2048 / cpuclock (where cpuclock is in MHz).
420 */
421 int delay_divisor = 62; /* assume the fastest (33 MHz) */
422
423 void
424 identifycpu()
425 {
426 unsigned char machtype;
427
428 /* Find the IDPROM and copy it to memory. */
429 /* Note: this needs to use peek_byte(). */
430 idprom_init();
431
432 machtype = identity_prom.idp_machtype;
433 if ((machtype & CPU_ARCH_MASK) != SUN3X_ARCH) {
434 printf("not a sun3x?\n");
435 sunmon_abort();
436 }
437
438 cpu_machine_id = machtype & SUN3X_IMPL_MASK;
439 switch (cpu_machine_id) {
440
441 case SUN3X_MACH_80:
442 cpu_string = "80"; /* Hydra */
443 delay_divisor = 102; /* 20 MHz */
444 cpu_has_vme = FALSE;
445 break;
446
447 case SUN3X_MACH_470:
448 cpu_string = "470"; /* Pegasus */
449 delay_divisor = 62; /* 33 MHz */
450 cpu_has_vme = TRUE;
451 break;
452
453 default:
454 printf("unknown sun3x model\n");
455 sunmon_abort();
456 }
457
458 /* Other stuff? (VAC, mc6888x version, etc.) */
459 sprintf(cpu_model, "Sun 3/%s", cpu_string);
460
461 printf("Model: %s (hostid %x)\n", cpu_model, (int) hostid);
462 }
463
464 /*
465 * machine dependent system variables.
466 */
467 int
468 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
469 int *name;
470 u_int namelen;
471 void *oldp;
472 size_t *oldlenp;
473 void *newp;
474 size_t newlen;
475 struct proc *p;
476 {
477 int error;
478 dev_t consdev;
479
480 /* all sysctl names at this level are terminal */
481 if (namelen != 1)
482 return (ENOTDIR); /* overloaded */
483
484 switch (name[0]) {
485 case CPU_CONSDEV:
486 if (cn_tab != NULL)
487 consdev = cn_tab->cn_dev;
488 else
489 consdev = NODEV;
490 error = sysctl_rdstruct(oldp, oldlenp, newp,
491 &consdev, sizeof consdev);
492 break;
493
494 #if 0 /* XXX - Not yet... */
495 case CPU_ROOT_DEVICE:
496 error = sysctl_rdstring(oldp, oldlenp, newp, root_device);
497 break;
498
499 case CPU_BOOTED_KERNEL:
500 error = sysctl_rdstring(oldp, oldlenp, newp, booted_kernel);
501 break;
502 #endif
503
504 default:
505 error = EOPNOTSUPP;
506 }
507 return (error);
508 }
509
510 /* See: sig_machdep.c */
511
512 /*
513 * Do a sync in preparation for a reboot.
514 * XXX - This could probably be common code.
515 * XXX - And now, most of it is in vfs_shutdown()
516 * XXX - Put waittime checks in there too?
517 */
518 int waittime = -1; /* XXX - Who else looks at this? -gwr */
519 static void
520 reboot_sync __P((void))
521 {
522
523 /* Check waittime here to localize its use to this function. */
524 if (waittime >= 0)
525 return;
526 waittime = 0;
527 vfs_shutdown();
528 }
529
530 /*
531 * Common part of the BSD and SunOS reboot system calls.
532 */
533 __dead void
534 cpu_reboot(howto, user_boot_string)
535 int howto;
536 char *user_boot_string;
537 {
538 /* Note: this string MUST be static! */
539 static char bootstr[128];
540 char *p;
541
542 /* If system is cold, just halt. (early panic?) */
543 if (cold)
544 goto haltsys;
545
546 if ((howto & RB_NOSYNC) == 0) {
547 reboot_sync();
548 /*
549 * If we've been adjusting the clock, the todr
550 * will be out of synch; adjust it now.
551 *
552 * XXX - However, if the kernel has been sitting in ddb,
553 * the time will be way off, so don't set the HW clock!
554 * XXX - Should do sanity check against HW clock. -gwr
555 */
556 /* resettodr(); */
557 }
558
559 /* Disable interrupts. */
560 splhigh();
561
562 /* Write out a crash dump if asked. */
563 if (howto & RB_DUMP)
564 dumpsys();
565
566 /* run any shutdown hooks */
567 doshutdownhooks();
568
569 if (howto & RB_HALT) {
570 haltsys:
571 printf("Kernel halted.\n");
572 #if 0
573 /*
574 * This calls the PROM monitor "exit_to_mon" function
575 * which appears to have problems... SunOS uses the
576 * "abort" function when you halt (bug work-around?)
577 * so we might as well do the same.
578 */
579 sunmon_halt(); /* provokes PROM monitor bug */
580 #else
581 sunmon_abort();
582 #endif
583 }
584
585 /*
586 * Automatic reboot.
587 */
588 if (user_boot_string)
589 strncpy(bootstr, user_boot_string, sizeof(bootstr));
590 else {
591 /*
592 * Build our own boot string with an empty
593 * boot device/file and (maybe) some flags.
594 * The PROM will supply the device/file name.
595 */
596 p = bootstr;
597 *p = '\0';
598 if (howto & (RB_KDB|RB_ASKNAME|RB_SINGLE)) {
599 /* Append the boot flags. */
600 *p++ = ' ';
601 *p++ = '-';
602 if (howto & RB_KDB)
603 *p++ = 'd';
604 if (howto & RB_ASKNAME)
605 *p++ = 'a';
606 if (howto & RB_SINGLE)
607 *p++ = 's';
608 *p = '\0';
609 }
610 }
611 printf("Kernel rebooting...\n");
612 sunmon_reboot(bootstr);
613 for (;;) ;
614 /*NOTREACHED*/
615 }
616
617 /*
618 * These variables are needed by /sbin/savecore
619 */
620 u_long dumpmag = 0x8fca0101; /* magic number */
621 int dumpsize = 0; /* pages */
622 long dumplo = 0; /* blocks */
623
624 /*
625 * This is called by main to set dumplo, dumpsize.
626 * Dumps always skip the first CLBYTES of disk space
627 * in case there might be a disk label stored there.
628 * If there is extra space, put dump at the end to
629 * reduce the chance that swapping trashes it.
630 */
631 void
632 cpu_dumpconf()
633 {
634 int nblks; /* size of dump area */
635 int maj;
636 int (*getsize)__P((dev_t));
637
638 if (dumpdev == NODEV)
639 return;
640
641 maj = major(dumpdev);
642 if (maj < 0 || maj >= nblkdev)
643 panic("dumpconf: bad dumpdev=0x%x", dumpdev);
644 getsize = bdevsw[maj].d_psize;
645 if (getsize == NULL)
646 return;
647 nblks = (*getsize)(dumpdev);
648 if (nblks <= ctod(1))
649 return;
650
651 /* Position dump image near end of space, page aligned. */
652 dumpsize = physmem; /* pages */
653 dumplo = nblks - ctod(dumpsize);
654 dumplo &= ~(ctod(1)-1);
655
656 /* If it does not fit, truncate it by moving dumplo. */
657 /* Note: Must force signed comparison. */
658 if (dumplo < ((long)ctod(1))) {
659 dumplo = ctod(1);
660 dumpsize = dtoc(nblks - dumplo);
661 }
662 }
663
664 /* Note: gdb looks for "dumppcb" in a kernel crash dump. */
665 struct pcb dumppcb;
666
667 /*
668 * Write a crash dump. The format while in swap is:
669 * kcore_seg_t cpu_hdr;
670 * cpu_kcore_hdr_t cpu_data;
671 * padding (NBPG-sizeof(kcore_seg_t))
672 * pagemap (2*NBPG)
673 * physical memory...
674 */
675 void
676 dumpsys()
677 {
678 struct bdevsw *dsw;
679 kcore_seg_t *kseg_p;
680 cpu_kcore_hdr_t *chdr_p;
681 struct sun3x_kcore_hdr *sh;
682 phys_ram_seg_t *crs_p;
683 char *vaddr;
684 vm_offset_t paddr;
685 int psize, todo, seg, segsz;
686 daddr_t blkno;
687 int error = 0;
688
689 msgbufmapped = 0;
690 if (dumpdev == NODEV)
691 return;
692
693 /*
694 * For dumps during autoconfiguration,
695 * if dump device has already configured...
696 */
697 if (dumpsize == 0)
698 cpu_dumpconf();
699 if (dumplo <= 0)
700 return;
701 savectx(&dumppcb);
702
703 dsw = &bdevsw[major(dumpdev)];
704 psize = (*(dsw->d_psize))(dumpdev);
705 if (psize == -1) {
706 printf("dump area unavailable\n");
707 return;
708 }
709
710 printf("\ndumping to dev %x, offset %d\n",
711 (int) dumpdev, (int) dumplo);
712
713 /*
714 * We put the dump header is in physical page zero,
715 * so there is no extra work here to write it out.
716 */
717 kseg_p = (kcore_seg_t *)KERNBASE;
718 chdr_p = (cpu_kcore_hdr_t *) (kseg_p + 1);
719 sh = &chdr_p->un._sun3x;
720 CORE_SETMAGIC(*kseg_p, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
721 kseg_p->c_size = sizeof(*chdr_p);
722 pmap_set_kcore_hdr(chdr_p);
723
724 /*
725 * Now dump physical memory. Note that physical memory
726 * might NOT be congiguous, so do it by segments.
727 */
728
729 blkno = dumplo;
730 todo = dumpsize; /* pages */
731 vaddr = (char*)vmmap; /* Borrow /dev/mem VA */
732
733 for (seg = 0; seg < SUN3X_NPHYS_RAM_SEGS; seg++) {
734 crs_p = &sh->ram_segs[seg];
735 paddr = crs_p->start;
736 segsz = crs_p->size;
737 /*
738 * Our header lives in the first little bit of
739 * physical memory (not written separately), so
740 * we have to adjust the first ram segment size
741 * and start address to reflect the stolen RAM.
742 * (Nothing interesing in that RAM anyway 8^).
743 */
744 if (seg == 0) {
745 int adj = sizeof(*kseg_p) + sizeof(*chdr_p);
746 crs_p->start += adj;
747 crs_p->size -= adj;
748 }
749
750 while (todo && (segsz > 0)) {
751
752 /* Print pages left after every 16. */
753 if ((todo & 0xf) == 0)
754 printf("\r%4d", todo);
755
756 /* Make a temporary mapping for the page. */
757 pmap_enter(pmap_kernel(), vmmap, paddr | PMAP_NC,
758 VM_PROT_READ, FALSE);
759 error = (*dsw->d_dump)(dumpdev, blkno, vaddr, NBPG);
760 pmap_remove(pmap_kernel(), vmmap, vmmap + NBPG);
761 if (error)
762 goto fail;
763 paddr += NBPG;
764 segsz -= NBPG;
765 blkno += btodb(NBPG);
766 todo--;
767 }
768 }
769 printf("\rdump succeeded\n");
770 return;
771 fail:
772 printf(" dump error=%d\n", error);
773 }
774
775 static void
776 initcpu()
777 {
778 /* XXX: Enable RAM parity/ECC checking? */
779 /* XXX: parityenable(); */
780
781 #ifdef HAVECACHE
782 cache_enable();
783 #endif
784 }
785
786 /* straptrap() in trap.c */
787
788 /* from hp300: badaddr() */
789 /* peek_byte(), peek_word() moved to bus_subr.c */
790
791 /* XXX: parityenable() ? */
792 /* regdump() moved to regdump.c */
793
794 /*
795 * cpu_exec_aout_makecmds():
796 * cpu-dependent a.out format hook for execve().
797 *
798 * Determine if the given exec package refers to something which we
799 * understand and, if so, set up the vmcmds for it.
800 */
801 int
802 cpu_exec_aout_makecmds(p, epp)
803 struct proc *p;
804 struct exec_package *epp;
805 {
806 int error = ENOEXEC;
807
808 #ifdef COMPAT_SUNOS
809 extern sunos_exec_aout_makecmds
810 __P((struct proc *, struct exec_package *));
811 if ((error = sunos_exec_aout_makecmds(p, epp)) == 0)
812 return 0;
813 #endif
814 return error;
815 }
816