machdep.c revision 1.16 1 /* $NetBSD: machdep.c,v 1.16 1997/05/14 16:45:22 gwr 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 valloc(swapmap, struct map, nswapmap = maxproc * 2);
191 #ifdef SYSVSHM
192 valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
193 #endif
194 #ifdef SYSVSEM
195 valloc(sema, struct semid_ds, seminfo.semmni);
196 valloc(sem, struct sem, seminfo.semmns);
197 /* This is pretty disgusting! */
198 valloc(semu, int, (seminfo.semmnu * seminfo.semusz) / sizeof(int));
199 #endif
200 #ifdef SYSVMSG
201 valloc(msgpool, char, msginfo.msgmax);
202 valloc(msgmaps, struct msgmap, msginfo.msgseg);
203 valloc(msghdrs, struct msg, msginfo.msgtql);
204 valloc(msqids, struct msqid_ds, msginfo.msgmni);
205 #endif
206
207 /*
208 * Determine how many buffers to allocate. We allocate
209 * the BSD standard of use 10% of memory for the first 2 Meg,
210 * 5% of remaining. Insure a minimum of 16 buffers.
211 * Allocate 1/2 as many swap buffer headers as file i/o buffers.
212 */
213 if (bufpages == 0) {
214 /* We always have more than 2MB of memory. */
215 bufpages = ((btoc(2 * 1024 * 1024) + physmem) /
216 (20 * CLSIZE));
217 }
218 if (nbuf == 0) {
219 nbuf = bufpages;
220 if (nbuf < 16)
221 nbuf = 16;
222 }
223 if (nswbuf == 0) {
224 nswbuf = (nbuf / 2) &~ 1; /* force even */
225 if (nswbuf > 256)
226 nswbuf = 256; /* sanity */
227 }
228 valloc(swbuf, struct buf, nswbuf);
229 valloc(buf, struct buf, nbuf);
230 return v;
231 }
232 #undef valloc
233
234 /*
235 * cpu_startup: allocate memory for variable-sized tables,
236 * initialize cpu, and do autoconfiguration.
237 *
238 * This is called early in init_main.c:main(), after the
239 * kernel memory allocator is ready for use, but before
240 * the creation of processes 1,2, and mountroot, etc.
241 */
242 void
243 cpu_startup()
244 {
245 caddr_t v;
246 int sz, i;
247 vm_size_t size;
248 int base, residual;
249 vm_offset_t minaddr, maxaddr;
250
251 /*
252 * Initialize message buffer (for kernel printf).
253 * This is put in physical page zero so it will
254 * always be in the same place after a reboot.
255 * Its mapping was prepared in pmap_bootstrap().
256 * Also, offset some to avoid PROM scribbles.
257 */
258 v = (caddr_t) KERNBASE;
259 msgbufp = (struct msgbuf *)(v + 0x1000);
260 msgbufmapped = 1;
261
262 /*
263 * Good {morning,afternoon,evening,night}.
264 */
265 printf(version);
266 identifycpu();
267 initfpu(); /* also prints FPU type */
268
269 printf("real mem = %d\n", ctob(physmem));
270
271 /*
272 * Find out how much space we need, allocate it,
273 * and then give everything true virtual addresses.
274 */
275 sz = (int)allocsys((caddr_t)0);
276 if ((v = (caddr_t)kmem_alloc(kernel_map, round_page(sz))) == 0)
277 panic("startup: no room for tables");
278 if (allocsys(v) - v != sz)
279 panic("startup: table size inconsistency");
280
281 /*
282 * Now allocate buffers proper. They are different than the above
283 * in that they usually occupy more virtual memory than physical.
284 */
285 size = MAXBSIZE * nbuf;
286 buffer_map = kmem_suballoc(kernel_map, (vm_offset_t *)&buffers,
287 &maxaddr, size, TRUE);
288 minaddr = (vm_offset_t)buffers;
289 if (vm_map_find(buffer_map, vm_object_allocate(size), (vm_offset_t)0,
290 &minaddr, size, FALSE) != KERN_SUCCESS)
291 panic("startup: cannot allocate buffers");
292 if ((bufpages / nbuf) >= btoc(MAXBSIZE)) {
293 /* don't want to alloc more physical mem than needed */
294 bufpages = btoc(MAXBSIZE) * nbuf;
295 }
296 base = bufpages / nbuf;
297 residual = bufpages % nbuf;
298 for (i = 0; i < nbuf; i++) {
299 vm_size_t curbufsize;
300 vm_offset_t curbuf;
301
302 /*
303 * First <residual> buffers get (base+1) physical pages
304 * allocated for them. The rest get (base) physical pages.
305 *
306 * The rest of each buffer occupies virtual space,
307 * but has no physical memory allocated for it.
308 */
309 curbuf = (vm_offset_t)buffers + i * MAXBSIZE;
310 curbufsize = CLBYTES * (i < residual ? base+1 : base);
311 vm_map_pageable(buffer_map, curbuf, curbuf+curbufsize, FALSE);
312 vm_map_simplify(buffer_map, curbuf);
313 }
314
315 /*
316 * Allocate a submap for exec arguments. This map effectively
317 * limits the number of processes exec'ing at any time.
318 */
319 exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
320 16*NCARGS, TRUE);
321
322 /*
323 * We don't use a submap for physio, and use a separate map
324 * for DVMA allocations. Our vmapbuf just maps pages into
325 * the kernel map (any kernel mapping is OK) and then the
326 * device drivers clone the kernel mappings into DVMA space.
327 */
328
329 /*
330 * Finally, allocate mbuf cluster submap.
331 */
332 mb_map = kmem_suballoc(kernel_map, (vm_offset_t *)&mbutl, &maxaddr,
333 VM_MBUF_SIZE, FALSE);
334
335 /*
336 * Initialize callouts
337 */
338 callfree = callout;
339 for (i = 1; i < ncallout; i++)
340 callout[i-1].c_next = &callout[i];
341 callout[i-1].c_next = NULL;
342
343 printf("avail mem = %d\n", (int) ptoa(cnt.v_free_count));
344 printf("using %d buffers containing %d bytes of memory\n",
345 nbuf, bufpages * CLBYTES);
346
347 /*
348 * Tell the VM system that writing to kernel text isn't allowed.
349 * If we don't, we might end up COW'ing the text segment!
350 */
351 if (vm_map_protect(kernel_map, (vm_offset_t) kernel_text,
352 trunc_page((vm_offset_t) etext),
353 VM_PROT_READ|VM_PROT_EXECUTE, TRUE)
354 != KERN_SUCCESS)
355 panic("can't protect kernel text");
356
357 /*
358 * Allocate a virtual page (for use by /dev/mem)
359 * This page is handed to pmap_enter() therefore
360 * it has to be in the normal kernel VA range.
361 */
362 vmmap = kmem_alloc_wait(kernel_map, NBPG);
363
364 /*
365 * Create the DVMA maps.
366 */
367 dvma_init();
368
369 /*
370 * Set up CPU-specific registers, cache, etc.
371 */
372 initcpu();
373
374 /*
375 * Set up buffers, so they can be used to read disk labels.
376 */
377 bufinit();
378
379 /*
380 * Configure the system.
381 */
382 configure();
383 }
384
385 /*
386 * Set registers on exec.
387 * XXX Should clear registers except sp, pc,
388 * but would break init; should be fixed soon.
389 */
390 void
391 setregs(p, pack, stack, retval)
392 register struct proc *p;
393 struct exec_package *pack;
394 u_long stack;
395 register_t *retval;
396 {
397 struct trapframe *tf = (struct trapframe *)p->p_md.md_regs;
398
399 tf->tf_pc = pack->ep_entry & ~1;
400 tf->tf_regs[SP] = stack;
401 tf->tf_regs[A2] = (int)PS_STRINGS;
402
403 /* restore a null state frame */
404 p->p_addr->u_pcb.pcb_fpregs.fpf_null = 0;
405 if (fputype) {
406 m68881_restore(&p->p_addr->u_pcb.pcb_fpregs);
407 }
408 p->p_md.md_flags = 0;
409 /* XXX - HPUX sigcode hack would go here... */
410 }
411
412 /*
413 * Info for CTL_HW
414 */
415 char machine[] = "sun3x"; /* cpu "architecture" */
416 char cpu_model[120];
417
418 /*
419 * XXX - Should empirically estimate the divisor...
420 * Note that the value of delay_divisor is roughly
421 * 2048 / cpuclock (where cpuclock is in MHz).
422 */
423 int delay_divisor = 62; /* assume the fastest (33 MHz) */
424
425 void
426 identifycpu()
427 {
428 unsigned char machtype;
429
430 /* Find the IDPROM and copy it to memory. */
431 /* Note: this needs to use peek_byte(). */
432 idprom_init();
433
434 machtype = identity_prom.idp_machtype;
435 if ((machtype & CPU_ARCH_MASK) != SUN3X_ARCH) {
436 printf("not a sun3x?\n");
437 sunmon_abort();
438 }
439
440 cpu_machine_id = machtype & SUN3X_IMPL_MASK;
441 switch (cpu_machine_id) {
442
443 case SUN3X_MACH_80:
444 cpu_string = "80"; /* Hydra */
445 delay_divisor = 102; /* 20 MHz */
446 cpu_has_vme = FALSE;
447 break;
448
449 case SUN3X_MACH_470:
450 cpu_string = "470"; /* Pegasus */
451 delay_divisor = 62; /* 33 MHz */
452 cpu_has_vme = TRUE;
453 break;
454
455 default:
456 printf("unknown sun3x model\n");
457 sunmon_abort();
458 }
459
460 /* Other stuff? (VAC, mc6888x version, etc.) */
461 sprintf(cpu_model, "Sun 3/%s", cpu_string);
462
463 printf("Model: %s (hostid %x)\n", cpu_model, (int) hostid);
464 }
465
466 /*
467 * machine dependent system variables.
468 */
469 int
470 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
471 int *name;
472 u_int namelen;
473 void *oldp;
474 size_t *oldlenp;
475 void *newp;
476 size_t newlen;
477 struct proc *p;
478 {
479 int error;
480 dev_t consdev;
481
482 /* all sysctl names at this level are terminal */
483 if (namelen != 1)
484 return (ENOTDIR); /* overloaded */
485
486 switch (name[0]) {
487 case CPU_CONSDEV:
488 if (cn_tab != NULL)
489 consdev = cn_tab->cn_dev;
490 else
491 consdev = NODEV;
492 error = sysctl_rdstruct(oldp, oldlenp, newp,
493 &consdev, sizeof consdev);
494 break;
495
496 #if 0 /* XXX - Not yet... */
497 case CPU_ROOT_DEVICE:
498 error = sysctl_rdstring(oldp, oldlenp, newp, root_device);
499 break;
500
501 case CPU_BOOTED_KERNEL:
502 error = sysctl_rdstring(oldp, oldlenp, newp, booted_kernel);
503 break;
504 #endif
505
506 default:
507 error = EOPNOTSUPP;
508 }
509 return (error);
510 }
511
512 /* See: sig_machdep.c */
513
514 /*
515 * Do a sync in preparation for a reboot.
516 * XXX - This could probably be common code.
517 * XXX - And now, most of it is in vfs_shutdown()
518 * XXX - Put waittime checks in there too?
519 */
520 int waittime = -1; /* XXX - Who else looks at this? -gwr */
521 static void
522 reboot_sync __P((void))
523 {
524
525 /* Check waittime here to localize its use to this function. */
526 if (waittime >= 0)
527 return;
528 waittime = 0;
529 vfs_shutdown();
530 }
531
532 /*
533 * Common part of the BSD and SunOS reboot system calls.
534 */
535 __dead void
536 cpu_reboot(howto, user_boot_string)
537 int howto;
538 char *user_boot_string;
539 {
540 /* Note: this string MUST be static! */
541 static char bootstr[128];
542 char *p;
543
544 /* If system is cold, just halt. (early panic?) */
545 if (cold)
546 goto haltsys;
547
548 if ((howto & RB_NOSYNC) == 0) {
549 reboot_sync();
550 /*
551 * If we've been adjusting the clock, the todr
552 * will be out of synch; adjust it now.
553 *
554 * XXX - However, if the kernel has been sitting in ddb,
555 * the time will be way off, so don't set the HW clock!
556 * XXX - Should do sanity check against HW clock. -gwr
557 */
558 /* resettodr(); */
559 }
560
561 /* Disable interrupts. */
562 splhigh();
563
564 /* Write out a crash dump if asked. */
565 if (howto & RB_DUMP)
566 dumpsys();
567
568 /* run any shutdown hooks */
569 doshutdownhooks();
570
571 if (howto & RB_HALT) {
572 haltsys:
573 printf("Kernel halted.\n");
574 #if 0
575 /*
576 * This calls the PROM monitor "exit_to_mon" function
577 * which appears to have problems... SunOS uses the
578 * "abort" function when you halt (bug work-around?)
579 * so we might as well do the same.
580 */
581 sunmon_halt(); /* provokes PROM monitor bug */
582 #else
583 sunmon_abort();
584 #endif
585 }
586
587 /*
588 * Automatic reboot.
589 */
590 if (user_boot_string)
591 strncpy(bootstr, user_boot_string, sizeof(bootstr));
592 else {
593 /*
594 * Build our own boot string with an empty
595 * boot device/file and (maybe) some flags.
596 * The PROM will supply the device/file name.
597 */
598 p = bootstr;
599 *p = '\0';
600 if (howto & (RB_KDB|RB_ASKNAME|RB_SINGLE)) {
601 /* Append the boot flags. */
602 *p++ = ' ';
603 *p++ = '-';
604 if (howto & RB_KDB)
605 *p++ = 'd';
606 if (howto & RB_ASKNAME)
607 *p++ = 'a';
608 if (howto & RB_SINGLE)
609 *p++ = 's';
610 *p = '\0';
611 }
612 }
613 printf("Kernel rebooting...\n");
614 sunmon_reboot(bootstr);
615 for (;;) ;
616 /*NOTREACHED*/
617 }
618
619 /*
620 * These variables are needed by /sbin/savecore
621 */
622 u_long dumpmag = 0x8fca0101; /* magic number */
623 int dumpsize = 0; /* pages */
624 long dumplo = 0; /* blocks */
625
626 /*
627 * This is called by main to set dumplo, dumpsize.
628 * Dumps always skip the first CLBYTES of disk space
629 * in case there might be a disk label stored there.
630 * If there is extra space, put dump at the end to
631 * reduce the chance that swapping trashes it.
632 */
633 void
634 cpu_dumpconf()
635 {
636 int nblks; /* size of dump area */
637 int maj;
638 int (*getsize)__P((dev_t));
639
640 if (dumpdev == NODEV)
641 return;
642
643 maj = major(dumpdev);
644 if (maj < 0 || maj >= nblkdev)
645 panic("dumpconf: bad dumpdev=0x%x", dumpdev);
646 getsize = bdevsw[maj].d_psize;
647 if (getsize == NULL)
648 return;
649 nblks = (*getsize)(dumpdev);
650 if (nblks <= ctod(1))
651 return;
652
653 /* Position dump image near end of space, page aligned. */
654 dumpsize = physmem; /* pages */
655 dumplo = nblks - ctod(dumpsize);
656 dumplo &= ~(ctod(1)-1);
657
658 /* If it does not fit, truncate it by moving dumplo. */
659 /* Note: Must force signed comparison. */
660 if (dumplo < ((long)ctod(1))) {
661 dumplo = ctod(1);
662 dumpsize = dtoc(nblks - dumplo);
663 }
664 }
665
666 /* Note: gdb looks for "dumppcb" in a kernel crash dump. */
667 struct pcb dumppcb;
668
669 /*
670 * Write a crash dump. The format while in swap is:
671 * kcore_seg_t cpu_hdr;
672 * cpu_kcore_hdr_t cpu_data;
673 * padding (NBPG-sizeof(kcore_seg_t))
674 * pagemap (2*NBPG)
675 * physical memory...
676 */
677 void
678 dumpsys()
679 {
680 struct bdevsw *dsw;
681 kcore_seg_t *kseg_p;
682 cpu_kcore_hdr_t *chdr_p;
683 struct sun3x_kcore_hdr *sh;
684 phys_ram_seg_t *crs_p;
685 char *vaddr;
686 vm_offset_t paddr;
687 int psize, todo, seg, segsz;
688 daddr_t blkno;
689 int error = 0;
690
691 msgbufmapped = 0;
692 if (dumpdev == NODEV)
693 return;
694
695 /*
696 * For dumps during autoconfiguration,
697 * if dump device has already configured...
698 */
699 if (dumpsize == 0)
700 cpu_dumpconf();
701 if (dumplo <= 0)
702 return;
703 savectx(&dumppcb);
704
705 dsw = &bdevsw[major(dumpdev)];
706 psize = (*(dsw->d_psize))(dumpdev);
707 if (psize == -1) {
708 printf("dump area unavailable\n");
709 return;
710 }
711
712 printf("\ndumping to dev %x, offset %d\n",
713 (int) dumpdev, (int) dumplo);
714
715 /*
716 * We put the dump header is in physical page zero,
717 * so there is no extra work here to write it out.
718 */
719 kseg_p = (kcore_seg_t *)KERNBASE;
720 chdr_p = (cpu_kcore_hdr_t *) (kseg_p + 1);
721 sh = &chdr_p->un._sun3x;
722 CORE_SETMAGIC(*kseg_p, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
723 kseg_p->c_size = sizeof(*chdr_p);
724 pmap_set_kcore_hdr(chdr_p);
725
726 /*
727 * Now dump physical memory. Note that physical memory
728 * might NOT be congiguous, so do it by segments.
729 */
730
731 blkno = dumplo;
732 todo = dumpsize; /* pages */
733 vaddr = (char*)vmmap; /* Borrow /dev/mem VA */
734
735 for (seg = 0; seg < SUN3X_NPHYS_RAM_SEGS; seg++) {
736 crs_p = &sh->ram_segs[seg];
737 paddr = crs_p->start;
738 segsz = crs_p->size;
739 /*
740 * Our header lives in the first little bit of
741 * physical memory (not written separately), so
742 * we have to adjust the first ram segment size
743 * and start address to reflect the stolen RAM.
744 * (Nothing interesing in that RAM anyway 8^).
745 */
746 if (seg == 0) {
747 int adj = sizeof(*kseg_p) + sizeof(*chdr_p);
748 crs_p->start += adj;
749 crs_p->size -= adj;
750 }
751
752 while (todo && (segsz > 0)) {
753
754 /* Print pages left after every 16. */
755 if ((todo & 0xf) == 0)
756 printf("\r%4d", todo);
757
758 /* Make a temporary mapping for the page. */
759 pmap_enter(pmap_kernel(), vmmap, paddr | PMAP_NC,
760 VM_PROT_READ, FALSE);
761 error = (*dsw->d_dump)(dumpdev, blkno, vaddr, NBPG);
762 pmap_remove(pmap_kernel(), vmmap, vmmap + NBPG);
763 if (error)
764 goto fail;
765 paddr += NBPG;
766 segsz -= NBPG;
767 blkno += btodb(NBPG);
768 todo--;
769 }
770 }
771 printf("\rdump succeeded\n");
772 return;
773 fail:
774 printf(" dump error=%d\n", error);
775 }
776
777 static void
778 initcpu()
779 {
780 /* XXX: Enable RAM parity/ECC checking? */
781 /* XXX: parityenable(); */
782
783 #ifdef HAVECACHE
784 cache_enable();
785 #endif
786 }
787
788 /* straptrap() in trap.c */
789
790 /* from hp300: badaddr() */
791 /* peek_byte(), peek_word() moved to bus_subr.c */
792
793 /* XXX: parityenable() ? */
794 /* regdump() moved to regdump.c */
795
796 /*
797 * cpu_exec_aout_makecmds():
798 * cpu-dependent a.out format hook for execve().
799 *
800 * Determine if the given exec package refers to something which we
801 * understand and, if so, set up the vmcmds for it.
802 */
803 int
804 cpu_exec_aout_makecmds(p, epp)
805 struct proc *p;
806 struct exec_package *epp;
807 {
808 int error = ENOEXEC;
809
810 #ifdef COMPAT_SUNOS
811 extern sunos_exec_aout_makecmds
812 __P((struct proc *, struct exec_package *));
813 if ((error = sunos_exec_aout_makecmds(p, epp)) == 0)
814 return 0;
815 #endif
816 return error;
817 }
818