machdep.c revision 1.22 1 /* $NetBSD: machdep.c,v 1.22 1997/09/19 13:55:42 leo 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
108 caddr_t msgbufaddr;
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 msgbufaddr = (caddr_t)(v + 0x1000);
259 initmsgbuf(msgbufaddr, m68k_round_page(MSGBUFSIZE));
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 */
387 void
388 setregs(p, pack, stack)
389 register struct proc *p;
390 struct exec_package *pack;
391 u_long stack;
392 {
393 struct trapframe *tf = (struct trapframe *)p->p_md.md_regs;
394
395 tf->tf_sr = PSL_USERSET;
396 tf->tf_pc = pack->ep_entry & ~1;
397 tf->tf_regs[D0] = 0;
398 tf->tf_regs[D1] = 0;
399 tf->tf_regs[D2] = 0;
400 tf->tf_regs[D3] = 0;
401 tf->tf_regs[D4] = 0;
402 tf->tf_regs[D5] = 0;
403 tf->tf_regs[D6] = 0;
404 tf->tf_regs[D7] = 0;
405 tf->tf_regs[A0] = 0;
406 tf->tf_regs[A1] = 0;
407 tf->tf_regs[A2] = (int)PS_STRINGS;
408 tf->tf_regs[A3] = 0;
409 tf->tf_regs[A4] = 0;
410 tf->tf_regs[A5] = 0;
411 tf->tf_regs[A6] = 0;
412 tf->tf_regs[SP] = stack;
413
414 /* restore a null state frame */
415 p->p_addr->u_pcb.pcb_fpregs.fpf_null = 0;
416 if (fputype)
417 m68881_restore(&p->p_addr->u_pcb.pcb_fpregs);
418
419 p->p_md.md_flags = 0;
420 }
421
422 /*
423 * Info for CTL_HW
424 */
425 char machine[] = MACHINE; /* from <machine/param.h> */
426 char cpu_model[120];
427
428 /*
429 * XXX - Should empirically estimate the divisor...
430 * Note that the value of delay_divisor is roughly
431 * 2048 / cpuclock (where cpuclock is in MHz).
432 */
433 int delay_divisor = 62; /* assume the fastest (33 MHz) */
434
435 void
436 identifycpu()
437 {
438 unsigned char machtype;
439
440 /* Find the IDPROM and copy it to memory. */
441 /* Note: this needs to use peek_byte(). */
442 idprom_init();
443
444 machtype = identity_prom.idp_machtype;
445 if ((machtype & CPU_ARCH_MASK) != SUN3X_ARCH) {
446 printf("not a sun3x?\n");
447 sunmon_abort();
448 }
449
450 cpu_machine_id = machtype & SUN3X_IMPL_MASK;
451 switch (cpu_machine_id) {
452
453 case SUN3X_MACH_80:
454 cpu_string = "80"; /* Hydra */
455 delay_divisor = 102; /* 20 MHz */
456 cpu_has_vme = FALSE;
457 break;
458
459 case SUN3X_MACH_470:
460 cpu_string = "470"; /* Pegasus */
461 delay_divisor = 62; /* 33 MHz */
462 cpu_has_vme = TRUE;
463 break;
464
465 default:
466 printf("unknown sun3x model\n");
467 sunmon_abort();
468 }
469
470 /* Other stuff? (VAC, mc6888x version, etc.) */
471 sprintf(cpu_model, "Sun 3/%s", cpu_string);
472
473 printf("Model: %s (hostid %x)\n", cpu_model, (int) hostid);
474 }
475
476 /*
477 * machine dependent system variables.
478 */
479 int
480 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
481 int *name;
482 u_int namelen;
483 void *oldp;
484 size_t *oldlenp;
485 void *newp;
486 size_t newlen;
487 struct proc *p;
488 {
489 int error;
490 dev_t consdev;
491
492 /* all sysctl names at this level are terminal */
493 if (namelen != 1)
494 return (ENOTDIR); /* overloaded */
495
496 switch (name[0]) {
497 case CPU_CONSDEV:
498 if (cn_tab != NULL)
499 consdev = cn_tab->cn_dev;
500 else
501 consdev = NODEV;
502 error = sysctl_rdstruct(oldp, oldlenp, newp,
503 &consdev, sizeof consdev);
504 break;
505
506 #if 0 /* XXX - Not yet... */
507 case CPU_ROOT_DEVICE:
508 error = sysctl_rdstring(oldp, oldlenp, newp, root_device);
509 break;
510
511 case CPU_BOOTED_KERNEL:
512 error = sysctl_rdstring(oldp, oldlenp, newp, booted_kernel);
513 break;
514 #endif
515
516 default:
517 error = EOPNOTSUPP;
518 }
519 return (error);
520 }
521
522 /* See: sig_machdep.c */
523
524 /*
525 * Do a sync in preparation for a reboot.
526 * XXX - This could probably be common code.
527 * XXX - And now, most of it is in vfs_shutdown()
528 * XXX - Put waittime checks in there too?
529 */
530 int waittime = -1; /* XXX - Who else looks at this? -gwr */
531 static void
532 reboot_sync __P((void))
533 {
534
535 /* Check waittime here to localize its use to this function. */
536 if (waittime >= 0)
537 return;
538 waittime = 0;
539 vfs_shutdown();
540 }
541
542 /*
543 * Common part of the BSD and SunOS reboot system calls.
544 */
545 __dead void
546 cpu_reboot(howto, user_boot_string)
547 int howto;
548 char *user_boot_string;
549 {
550 /* Note: this string MUST be static! */
551 static char bootstr[128];
552 char *p;
553
554 /* If system is cold, just halt. (early panic?) */
555 if (cold)
556 goto haltsys;
557
558 if ((howto & RB_NOSYNC) == 0) {
559 reboot_sync();
560 /*
561 * If we've been adjusting the clock, the todr
562 * will be out of synch; adjust it now.
563 *
564 * XXX - However, if the kernel has been sitting in ddb,
565 * the time will be way off, so don't set the HW clock!
566 * XXX - Should do sanity check against HW clock. -gwr
567 */
568 /* resettodr(); */
569 }
570
571 /* Disable interrupts. */
572 splhigh();
573
574 /* Write out a crash dump if asked. */
575 if (howto & RB_DUMP)
576 dumpsys();
577
578 /* run any shutdown hooks */
579 doshutdownhooks();
580
581 if (howto & RB_HALT) {
582 haltsys:
583 printf("Kernel halted.\n");
584 #if 0
585 /*
586 * This calls the PROM monitor "exit_to_mon" function
587 * which appears to have problems... SunOS uses the
588 * "abort" function when you halt (bug work-around?)
589 * so we might as well do the same.
590 */
591 sunmon_halt(); /* provokes PROM monitor bug */
592 #else
593 sunmon_abort();
594 #endif
595 }
596
597 /*
598 * Automatic reboot.
599 */
600 if (user_boot_string)
601 strncpy(bootstr, user_boot_string, sizeof(bootstr));
602 else {
603 /*
604 * Build our own boot string with an empty
605 * boot device/file and (maybe) some flags.
606 * The PROM will supply the device/file name.
607 */
608 p = bootstr;
609 *p = '\0';
610 if (howto & (RB_KDB|RB_ASKNAME|RB_SINGLE)) {
611 /* Append the boot flags. */
612 *p++ = ' ';
613 *p++ = '-';
614 if (howto & RB_KDB)
615 *p++ = 'd';
616 if (howto & RB_ASKNAME)
617 *p++ = 'a';
618 if (howto & RB_SINGLE)
619 *p++ = 's';
620 *p = '\0';
621 }
622 }
623 printf("Kernel rebooting...\n");
624 sunmon_reboot(bootstr);
625 for (;;) ;
626 /*NOTREACHED*/
627 }
628
629 /*
630 * These variables are needed by /sbin/savecore
631 */
632 u_long dumpmag = 0x8fca0101; /* magic number */
633 int dumpsize = 0; /* pages */
634 long dumplo = 0; /* blocks */
635
636 /*
637 * This is called by main to set dumplo, dumpsize.
638 * Dumps always skip the first CLBYTES of disk space
639 * in case there might be a disk label stored there.
640 * If there is extra space, put dump at the end to
641 * reduce the chance that swapping trashes it.
642 */
643 void
644 cpu_dumpconf()
645 {
646 int nblks; /* size of dump area */
647 int maj;
648 int (*getsize)__P((dev_t));
649
650 if (dumpdev == NODEV)
651 return;
652
653 maj = major(dumpdev);
654 if (maj < 0 || maj >= nblkdev)
655 panic("dumpconf: bad dumpdev=0x%x", dumpdev);
656 getsize = bdevsw[maj].d_psize;
657 if (getsize == NULL)
658 return;
659 nblks = (*getsize)(dumpdev);
660 if (nblks <= ctod(1))
661 return;
662
663 /* Position dump image near end of space, page aligned. */
664 dumpsize = physmem; /* pages */
665 dumplo = nblks - ctod(dumpsize);
666 dumplo &= ~(ctod(1)-1);
667
668 /* If it does not fit, truncate it by moving dumplo. */
669 /* Note: Must force signed comparison. */
670 if (dumplo < ((long)ctod(1))) {
671 dumplo = ctod(1);
672 dumpsize = dtoc(nblks - dumplo);
673 }
674 }
675
676 /* Note: gdb looks for "dumppcb" in a kernel crash dump. */
677 struct pcb dumppcb;
678
679 /*
680 * Write a crash dump. The format while in swap is:
681 * kcore_seg_t cpu_hdr;
682 * cpu_kcore_hdr_t cpu_data;
683 * padding (NBPG-sizeof(kcore_seg_t))
684 * pagemap (2*NBPG)
685 * physical memory...
686 */
687 void
688 dumpsys()
689 {
690 struct bdevsw *dsw;
691 kcore_seg_t *kseg_p;
692 cpu_kcore_hdr_t *chdr_p;
693 struct sun3x_kcore_hdr *sh;
694 phys_ram_seg_t *crs_p;
695 char *vaddr;
696 vm_offset_t paddr;
697 int psize, todo, seg, segsz;
698 daddr_t blkno;
699 int error = 0;
700
701 msgbufmapped = 0;
702 if (dumpdev == NODEV)
703 return;
704
705 /*
706 * For dumps during autoconfiguration,
707 * if dump device has already configured...
708 */
709 if (dumpsize == 0)
710 cpu_dumpconf();
711 if (dumplo <= 0)
712 return;
713 savectx(&dumppcb);
714
715 dsw = &bdevsw[major(dumpdev)];
716 psize = (*(dsw->d_psize))(dumpdev);
717 if (psize == -1) {
718 printf("dump area unavailable\n");
719 return;
720 }
721
722 printf("\ndumping to dev %x, offset %d\n",
723 (int) dumpdev, (int) dumplo);
724
725 /*
726 * We put the dump header is in physical page zero,
727 * so there is no extra work here to write it out.
728 */
729 kseg_p = (kcore_seg_t *)KERNBASE;
730 chdr_p = (cpu_kcore_hdr_t *) (kseg_p + 1);
731 sh = &chdr_p->un._sun3x;
732 CORE_SETMAGIC(*kseg_p, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
733 kseg_p->c_size = sizeof(*chdr_p);
734 pmap_set_kcore_hdr(chdr_p);
735
736 /*
737 * Now dump physical memory. Note that physical memory
738 * might NOT be congiguous, so do it by segments.
739 */
740
741 blkno = dumplo;
742 todo = dumpsize; /* pages */
743 vaddr = (char*)vmmap; /* Borrow /dev/mem VA */
744
745 for (seg = 0; seg < SUN3X_NPHYS_RAM_SEGS; seg++) {
746 crs_p = &sh->ram_segs[seg];
747 paddr = crs_p->start;
748 segsz = crs_p->size;
749 /*
750 * Our header lives in the first little bit of
751 * physical memory (not written separately), so
752 * we have to adjust the first ram segment size
753 * and start address to reflect the stolen RAM.
754 * (Nothing interesing in that RAM anyway 8^).
755 */
756 if (seg == 0) {
757 int adj = sizeof(*kseg_p) + sizeof(*chdr_p);
758 crs_p->start += adj;
759 crs_p->size -= adj;
760 }
761
762 while (todo && (segsz > 0)) {
763
764 /* Print pages left after every 16. */
765 if ((todo & 0xf) == 0)
766 printf("\r%4d", todo);
767
768 /* Make a temporary mapping for the page. */
769 pmap_enter(pmap_kernel(), vmmap, paddr | PMAP_NC,
770 VM_PROT_READ, FALSE);
771 error = (*dsw->d_dump)(dumpdev, blkno, vaddr, NBPG);
772 pmap_remove(pmap_kernel(), vmmap, vmmap + NBPG);
773 if (error)
774 goto fail;
775 paddr += NBPG;
776 segsz -= NBPG;
777 blkno += btodb(NBPG);
778 todo--;
779 }
780 }
781 printf("\rdump succeeded\n");
782 return;
783 fail:
784 printf(" dump error=%d\n", error);
785 }
786
787 static void
788 initcpu()
789 {
790 /* XXX: Enable RAM parity/ECC checking? */
791 /* XXX: parityenable(); */
792
793 #ifdef HAVECACHE
794 cache_enable();
795 #endif
796 }
797
798 /* straptrap() in trap.c */
799
800 /* from hp300: badaddr() */
801 /* peek_byte(), peek_word() moved to bus_subr.c */
802
803 /* XXX: parityenable() ? */
804 /* regdump() moved to regdump.c */
805
806 /*
807 * cpu_exec_aout_makecmds():
808 * cpu-dependent a.out format hook for execve().
809 *
810 * Determine if the given exec package refers to something which we
811 * understand and, if so, set up the vmcmds for it.
812 */
813 int
814 cpu_exec_aout_makecmds(p, epp)
815 struct proc *p;
816 struct exec_package *epp;
817 {
818 int error = ENOEXEC;
819
820 #ifdef COMPAT_SUNOS
821 extern sunos_exec_aout_makecmds
822 __P((struct proc *, struct exec_package *));
823 if ((error = sunos_exec_aout_makecmds(p, epp)) == 0)
824 return 0;
825 #endif
826 return error;
827 }
828