machdep.c revision 1.43 1 /* $NetBSD: machdep.c,v 1.43 1999/03/26 23:41:37 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 "opt_bufcache.h"
45 #include "opt_ddb.h"
46 #include "opt_sysv.h"
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/kernel.h>
51 #include <sys/map.h>
52 #include <sys/proc.h>
53 #include <sys/buf.h>
54 #include <sys/reboot.h>
55 #include <sys/conf.h>
56 #include <sys/file.h>
57 #include <sys/clist.h>
58 #include <sys/callout.h>
59 #include <sys/device.h>
60 #include <sys/malloc.h>
61 #include <sys/mbuf.h>
62 #include <sys/msgbuf.h>
63 #include <sys/ioctl.h>
64 #include <sys/tty.h>
65 #include <sys/mount.h>
66 #include <sys/user.h>
67 #include <sys/exec.h>
68 #include <sys/core.h>
69 #include <sys/kcore.h>
70 #include <sys/vnode.h>
71 #include <sys/syscallargs.h>
72 #ifdef SYSVMSG
73 #include <sys/msg.h>
74 #endif
75 #ifdef SYSVSEM
76 #include <sys/sem.h>
77 #endif
78 #ifdef SYSVSHM
79 #include <sys/shm.h>
80 #endif
81 #ifdef KGDB
82 #include <sys/kgdb.h>
83 #endif
84
85 #include <vm/vm.h>
86 #include <vm/vm_map.h>
87 #include <vm/vm_kern.h>
88 #include <vm/vm_page.h>
89
90 #include <uvm/uvm_extern.h>
91
92 #include <sys/sysctl.h>
93
94 #include <dev/cons.h>
95
96 #include <machine/cpu.h>
97 #include <machine/dvma.h>
98 #include <machine/idprom.h>
99 #include <machine/kcore.h>
100 #include <machine/reg.h>
101 #include <machine/psl.h>
102 #include <machine/pte.h>
103
104 #if defined(DDB)
105 #include <machine/db_machdep.h>
106 #include <ddb/db_sym.h>
107 #include <ddb/db_extern.h>
108 #endif
109
110 #include <sun3/sun3/machdep.h>
111
112 /* Defined in locore.s */
113 extern char kernel_text[];
114 /* Defined by the linker */
115 extern char etext[];
116
117 vm_map_t exec_map = NULL;
118 vm_map_t mb_map = NULL;
119 vm_map_t phys_map = NULL;
120
121 int physmem;
122 int fputype;
123 caddr_t msgbufaddr;
124
125 /* Virtual page frame for /dev/mem (see mem.c) */
126 vm_offset_t vmmap;
127
128 /*
129 * safepri is a safe priority for sleep to set for a spin-wait
130 * during autoconfiguration or after a panic.
131 */
132 int safepri = PSL_LOWIPL;
133
134 /*
135 * Declare these as initialized data so we can patch them.
136 */
137 int nswbuf = 0;
138 #ifdef NBUF
139 int nbuf = NBUF;
140 #else
141 int nbuf = 0;
142 #endif
143 #ifdef BUFPAGES
144 int bufpages = BUFPAGES;
145 #else
146 int bufpages = 0;
147 #endif
148
149 u_char cpu_machine_id = 0;
150 char *cpu_string = NULL;
151 int cpu_has_vme = 0;
152 int has_iocache = 0;
153
154 static void identifycpu __P((void));
155 static void initcpu __P((void));
156
157 /*
158 * Console initialization: called early on from main,
159 * before vm init or cpu_startup. This system is able
160 * to use the console for output immediately (via PROM)
161 * but can not use it for input until after this point.
162 */
163 void
164 consinit()
165 {
166
167 /*
168 * Switch from the PROM console (output only)
169 * to our own console driver.
170 */
171 cninit();
172
173 #ifdef DDB
174 db_machine_init();
175 {
176 extern int end[];
177 extern char *esym;
178
179 /* symsize, symstart, symend */
180 ddb_init(end[0], end + 1, (int*)esym);
181 }
182 #endif DDB
183
184 /*
185 * Now that the console can do input as well as
186 * output, consider stopping for a debugger.
187 */
188 if (boothowto & RB_KDB) {
189 #ifdef KGDB
190 /* XXX - Ask on console for kgdb_dev? */
191 /* Note: this will just return if kgdb_dev==NODEV */
192 kgdb_connect(1);
193 #else /* KGDB */
194 /* Either DDB or no debugger (just PROM). */
195 Debugger();
196 #endif /* KGDB */
197 }
198 }
199
200 /*
201 * allocsys() - Private routine used by cpu_startup() below.
202 *
203 * Allocate space for system data structures. We are given
204 * a starting virtual address and we return a final virtual
205 * address; along the way we set each data structure pointer.
206 *
207 * We call allocsys() with 0 to find out how much space we want,
208 * allocate that much and fill it with zeroes, and then call
209 * allocsys() again with the correct base virtual address.
210 */
211 #define valloc(name, type, num) \
212 v = (caddr_t)(((name) = (type *)v) + (num))
213 static caddr_t allocsys __P((caddr_t));
214 static caddr_t
215 allocsys(v)
216 register caddr_t v;
217 {
218
219 #ifdef REAL_CLISTS
220 valloc(cfree, struct cblock, nclist);
221 #endif
222 valloc(callout, struct callout, ncallout);
223 #ifdef SYSVSHM
224 valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
225 #endif
226 #ifdef SYSVSEM
227 valloc(sema, struct semid_ds, seminfo.semmni);
228 valloc(sem, struct sem, seminfo.semmns);
229 /* This is pretty disgusting! */
230 valloc(semu, int, (seminfo.semmnu * seminfo.semusz) / sizeof(int));
231 #endif
232 #ifdef SYSVMSG
233 valloc(msgpool, char, msginfo.msgmax);
234 valloc(msgmaps, struct msgmap, msginfo.msgseg);
235 valloc(msghdrs, struct msg, msginfo.msgtql);
236 valloc(msqids, struct msqid_ds, msginfo.msgmni);
237 #endif
238
239 /*
240 * Determine how many buffers to allocate. We allocate
241 * the BSD standard of use 10% of memory for the first 2 Meg,
242 * 5% of remaining. Insure a minimum of 16 buffers.
243 * Allocate 1/2 as many swap buffer headers as file i/o buffers.
244 */
245 if (bufpages == 0) {
246 /* We always have more than 2MB of memory. */
247 bufpages = ((btoc(2 * 1024 * 1024) + physmem) /
248 (20 * CLSIZE));
249 }
250 if (nbuf == 0) {
251 nbuf = bufpages;
252 if (nbuf < 16)
253 nbuf = 16;
254 }
255 if (nswbuf == 0) {
256 nswbuf = (nbuf / 2) &~ 1; /* force even */
257 if (nswbuf > 256)
258 nswbuf = 256; /* sanity */
259 }
260 valloc(buf, struct buf, nbuf);
261 return v;
262 }
263 #undef valloc
264
265 /*
266 * cpu_startup: allocate memory for variable-sized tables,
267 * initialize cpu, and do autoconfiguration.
268 *
269 * This is called early in init_main.c:main(), after the
270 * kernel memory allocator is ready for use, but before
271 * the creation of processes 1,2, and mountroot, etc.
272 */
273 void
274 cpu_startup()
275 {
276 caddr_t v;
277 int sz, i;
278 vm_size_t size;
279 int base, residual;
280 vm_offset_t minaddr, maxaddr;
281
282 /*
283 * Initialize message buffer (for kernel printf).
284 * This is put in physical page zero so it will
285 * always be in the same place after a reboot.
286 * Its mapping was prepared in pmap_bootstrap().
287 * Also, offset some to avoid PROM scribbles.
288 */
289 v = (caddr_t) KERNBASE;
290 msgbufaddr = (caddr_t)(v + MSGBUFOFF);
291 initmsgbuf(msgbufaddr, MSGBUFSIZE);
292
293 /*
294 * Good {morning,afternoon,evening,night}.
295 */
296 printf(version);
297 identifycpu();
298 initfpu(); /* also prints FPU type */
299
300 size = ptoa(physmem);
301 printf("real mem = %ldK (0x%lx)\n", (size >> 10), size);
302
303 /*
304 * Find out how much space we need, allocate it,
305 * and then give everything true virtual addresses.
306 */
307 sz = (int)allocsys((caddr_t)0);
308 if ((v = (caddr_t)uvm_km_alloc(kernel_map, round_page(sz))) == 0)
309 panic("startup: no room for tables");
310 if (allocsys(v) - v != sz)
311 panic("startup: table size inconsistency");
312
313 /*
314 * Now allocate buffers proper. They are different than the above
315 * in that they usually occupy more virtual memory than physical.
316 */
317 size = MAXBSIZE * nbuf;
318 if (uvm_map(kernel_map, (vm_offset_t *) &buffers, round_page(size),
319 NULL, UVM_UNKNOWN_OFFSET,
320 UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
321 UVM_ADV_NORMAL, 0)) != KERN_SUCCESS)
322 panic("startup: cannot allocate VM for buffers");
323 minaddr = (vm_offset_t)buffers;
324 if ((bufpages / nbuf) >= btoc(MAXBSIZE)) {
325 /* don't want to alloc more physical mem than needed */
326 bufpages = btoc(MAXBSIZE) * nbuf;
327 }
328 base = bufpages / nbuf;
329 residual = bufpages % nbuf;
330 for (i = 0; i < nbuf; i++) {
331 vm_size_t curbufsize;
332 vm_offset_t curbuf;
333 struct vm_page *pg;
334
335 /*
336 * Each buffer has MAXBSIZE bytes of VM space allocated. Of
337 * that MAXBSIZE space, we allocate and map (base+1) pages
338 * for the first "residual" buffers, and then we allocate
339 * "base" pages for the rest.
340 */
341 curbuf = (vm_offset_t) buffers + (i * MAXBSIZE);
342 curbufsize = CLBYTES * ((i < residual) ? (base+1) : base);
343
344 while (curbufsize) {
345 pg = uvm_pagealloc(NULL, 0, NULL);
346 if (pg == NULL)
347 panic("cpu_startup: not enough memory for "
348 "buffer cache");
349 #if defined(PMAP_NEW)
350 pmap_kenter_pgs(curbuf, &pg, 1);
351 #else
352 pmap_enter(kernel_map->pmap, curbuf,
353 VM_PAGE_TO_PHYS(pg), VM_PROT_READ|VM_PROT_WRITE,
354 TRUE, VM_PROT_READ|VM_PROT_WRITE);
355 #endif
356 curbuf += PAGE_SIZE;
357 curbufsize -= PAGE_SIZE;
358 }
359 }
360
361 /*
362 * Allocate a submap for exec arguments. This map effectively
363 * limits the number of processes exec'ing at any time.
364 */
365 exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
366 16*NCARGS, TRUE, FALSE, NULL);
367
368 /*
369 * We don't use a submap for physio, and use a separate map
370 * for DVMA allocations. Our vmapbuf just maps pages into
371 * the kernel map (any kernel mapping is OK) and then the
372 * device drivers clone the kernel mappings into DVMA space.
373 */
374
375 /*
376 * Finally, allocate mbuf cluster submap.
377 */
378 mb_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
379 VM_MBUF_SIZE, FALSE, FALSE, NULL);
380
381 /*
382 * Initialize callouts
383 */
384 callfree = callout;
385 for (i = 1; i < ncallout; i++)
386 callout[i-1].c_next = &callout[i];
387 callout[i-1].c_next = NULL;
388
389 size = ptoa(uvmexp.free);
390 printf("avail mem = %ldK (0x%lx)\n", (size >> 10), size);
391 printf("using %d buffers containing %d bytes of memory\n",
392 nbuf, bufpages * CLBYTES);
393
394 /*
395 * Tell the VM system that writing to kernel text isn't allowed.
396 * If we don't, we might end up COW'ing the text segment!
397 */
398 if (uvm_map_protect(kernel_map, (vm_offset_t) kernel_text,
399 m68k_trunc_page((vm_offset_t) etext),
400 UVM_PROT_READ|UVM_PROT_EXEC, TRUE) != KERN_SUCCESS)
401 panic("can't protect kernel text");
402
403 /*
404 * Allocate a virtual page (for use by /dev/mem)
405 * This page is handed to pmap_enter() therefore
406 * it has to be in the normal kernel VA range.
407 */
408 vmmap = uvm_km_valloc_wait(kernel_map, NBPG);
409
410 /*
411 * Create the DVMA maps.
412 */
413 dvma_init();
414
415 /*
416 * Set up CPU-specific registers, cache, etc.
417 */
418 initcpu();
419
420 /*
421 * Set up buffers, so they can be used to read disk labels.
422 */
423 bufinit();
424
425 /*
426 * Configure the system.
427 */
428 configure();
429 }
430
431 /*
432 * Set registers on exec.
433 */
434 void
435 setregs(p, pack, stack)
436 struct proc *p;
437 struct exec_package *pack;
438 u_long stack;
439 {
440 struct trapframe *tf = (struct trapframe *)p->p_md.md_regs;
441
442 tf->tf_sr = PSL_USERSET;
443 tf->tf_pc = pack->ep_entry & ~1;
444 tf->tf_regs[D0] = 0;
445 tf->tf_regs[D1] = 0;
446 tf->tf_regs[D2] = 0;
447 tf->tf_regs[D3] = 0;
448 tf->tf_regs[D4] = 0;
449 tf->tf_regs[D5] = 0;
450 tf->tf_regs[D6] = 0;
451 tf->tf_regs[D7] = 0;
452 tf->tf_regs[A0] = 0;
453 tf->tf_regs[A1] = 0;
454 tf->tf_regs[A2] = (int)PS_STRINGS;
455 tf->tf_regs[A3] = 0;
456 tf->tf_regs[A4] = 0;
457 tf->tf_regs[A5] = 0;
458 tf->tf_regs[A6] = 0;
459 tf->tf_regs[SP] = stack;
460
461 /* restore a null state frame */
462 p->p_addr->u_pcb.pcb_fpregs.fpf_null = 0;
463 if (fputype)
464 m68881_restore(&p->p_addr->u_pcb.pcb_fpregs);
465
466 p->p_md.md_flags = 0;
467 }
468
469 /*
470 * Info for CTL_HW
471 */
472 char machine[16] = MACHINE; /* from <machine/param.h> */
473 char cpu_model[120];
474
475 /*
476 * XXX - Should empirically estimate the divisor...
477 * Note that the value of delay_divisor is roughly
478 * 2048 / cpuclock (where cpuclock is in MHz).
479 */
480 int delay_divisor = 62; /* assume the fastest (33 MHz) */
481
482 void
483 identifycpu()
484 {
485 u_char machtype;
486
487 machtype = identity_prom.idp_machtype;
488 if ((machtype & IDM_ARCH_MASK) != IDM_ARCH_SUN3X) {
489 printf("Bad IDPROM arch!\n");
490 sunmon_abort();
491 }
492
493 cpu_machine_id = machtype;
494 switch (cpu_machine_id) {
495
496 case SUN3X_MACH_80:
497 cpu_string = "80"; /* Hydra */
498 delay_divisor = 102; /* 20 MHz */
499 cpu_has_vme = FALSE;
500 break;
501
502 case SUN3X_MACH_470:
503 cpu_string = "470"; /* Pegasus */
504 delay_divisor = 62; /* 33 MHz */
505 cpu_has_vme = TRUE;
506 break;
507
508 default:
509 printf("unknown sun3x model\n");
510 sunmon_abort();
511 }
512
513 /* Other stuff? (VAC, mc6888x version, etc.) */
514 sprintf(cpu_model, "Sun-3X (3/%s)", cpu_string);
515
516 printf("Model: %s\n", cpu_model);
517 }
518
519 /*
520 * machine dependent system variables.
521 */
522 int
523 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
524 int *name;
525 u_int namelen;
526 void *oldp;
527 size_t *oldlenp;
528 void *newp;
529 size_t newlen;
530 struct proc *p;
531 {
532 int error;
533 dev_t consdev;
534
535 /* all sysctl names at this level are terminal */
536 if (namelen != 1)
537 return (ENOTDIR); /* overloaded */
538
539 switch (name[0]) {
540 case CPU_CONSDEV:
541 if (cn_tab != NULL)
542 consdev = cn_tab->cn_dev;
543 else
544 consdev = NODEV;
545 error = sysctl_rdstruct(oldp, oldlenp, newp,
546 &consdev, sizeof consdev);
547 break;
548
549 #if 0 /* XXX - Not yet... */
550 case CPU_ROOT_DEVICE:
551 error = sysctl_rdstring(oldp, oldlenp, newp, root_device);
552 break;
553
554 case CPU_BOOTED_KERNEL:
555 error = sysctl_rdstring(oldp, oldlenp, newp, booted_kernel);
556 break;
557 #endif
558
559 default:
560 error = EOPNOTSUPP;
561 }
562 return (error);
563 }
564
565 /* See: sig_machdep.c */
566
567 /*
568 * Do a sync in preparation for a reboot.
569 * XXX - This could probably be common code.
570 * XXX - And now, most of it is in vfs_shutdown()
571 * XXX - Put waittime checks in there too?
572 */
573 int waittime = -1; /* XXX - Who else looks at this? -gwr */
574 static void
575 reboot_sync __P((void))
576 {
577
578 /* Check waittime here to localize its use to this function. */
579 if (waittime >= 0)
580 return;
581 waittime = 0;
582 vfs_shutdown();
583 }
584
585 /*
586 * Common part of the BSD and SunOS reboot system calls.
587 */
588 __dead void
589 cpu_reboot(howto, user_boot_string)
590 int howto;
591 char *user_boot_string;
592 {
593 /* Note: this string MUST be static! */
594 static char bootstr[128];
595 char *p;
596
597 /* If system is cold, just halt. (early panic?) */
598 if (cold)
599 goto haltsys;
600
601 /* Un-blank the screen if appropriate. */
602 cnpollc(1);
603
604 if ((howto & RB_NOSYNC) == 0) {
605 reboot_sync();
606 /*
607 * If we've been adjusting the clock, the todr
608 * will be out of synch; adjust it now.
609 *
610 * XXX - However, if the kernel has been sitting in ddb,
611 * the time will be way off, so don't set the HW clock!
612 * XXX - Should do sanity check against HW clock. -gwr
613 */
614 /* resettodr(); */
615 }
616
617 /* Disable interrupts. */
618 splhigh();
619
620 /* Write out a crash dump if asked. */
621 if (howto & RB_DUMP)
622 dumpsys();
623
624 /* run any shutdown hooks */
625 doshutdownhooks();
626
627 if (howto & RB_HALT) {
628 haltsys:
629 printf("Kernel halted.\n");
630 #if 0
631 /*
632 * This calls the PROM monitor "exit_to_mon" function
633 * which appears to have problems... SunOS uses the
634 * "abort" function when you halt (bug work-around?)
635 * so we might as well do the same.
636 */
637 sunmon_halt(); /* provokes PROM monitor bug */
638 #else
639 sunmon_abort();
640 #endif
641 }
642
643 /*
644 * Automatic reboot.
645 */
646 if (user_boot_string)
647 strncpy(bootstr, user_boot_string, sizeof(bootstr));
648 else {
649 /*
650 * Build our own boot string with an empty
651 * boot device/file and (maybe) some flags.
652 * The PROM will supply the device/file name.
653 */
654 p = bootstr;
655 *p = '\0';
656 if (howto & (RB_KDB|RB_ASKNAME|RB_SINGLE)) {
657 /* Append the boot flags. */
658 *p++ = ' ';
659 *p++ = '-';
660 if (howto & RB_KDB)
661 *p++ = 'd';
662 if (howto & RB_ASKNAME)
663 *p++ = 'a';
664 if (howto & RB_SINGLE)
665 *p++ = 's';
666 *p = '\0';
667 }
668 }
669 printf("Kernel rebooting...\n");
670 sunmon_reboot(bootstr);
671 for (;;) ;
672 /*NOTREACHED*/
673 }
674
675 /*
676 * These variables are needed by /sbin/savecore
677 */
678 u_long dumpmag = 0x8fca0101; /* magic number */
679 int dumpsize = 0; /* pages */
680 long dumplo = 0; /* blocks */
681
682 /*
683 * This is called by main to set dumplo, dumpsize.
684 * Dumps always skip the first CLBYTES of disk space
685 * in case there might be a disk label stored there.
686 * If there is extra space, put dump at the end to
687 * reduce the chance that swapping trashes it.
688 */
689 void
690 cpu_dumpconf()
691 {
692 int nblks; /* size of dump area */
693 int maj;
694 int (*getsize)__P((dev_t));
695
696 /* Validate space in page zero for the kcore header. */
697 if (MSGBUFOFF < (sizeof(kcore_seg_t) + sizeof(cpu_kcore_hdr_t)))
698 panic("cpu_dumpconf: MSGBUFOFF too small");
699
700 if (dumpdev == NODEV)
701 return;
702
703 maj = major(dumpdev);
704 if (maj < 0 || maj >= nblkdev)
705 panic("dumpconf: bad dumpdev=0x%x", dumpdev);
706 getsize = bdevsw[maj].d_psize;
707 if (getsize == NULL)
708 return;
709 nblks = (*getsize)(dumpdev);
710 if (nblks <= ctod(1))
711 return;
712
713 /* Position dump image near end of space, page aligned. */
714 dumpsize = physmem; /* pages */
715 dumplo = nblks - ctod(dumpsize);
716 dumplo &= ~(ctod(1)-1);
717
718 /* If it does not fit, truncate it by moving dumplo. */
719 /* Note: Must force signed comparison. */
720 if (dumplo < ((long)ctod(1))) {
721 dumplo = ctod(1);
722 dumpsize = dtoc(nblks - dumplo);
723 }
724 }
725
726 /* Note: gdb looks for "dumppcb" in a kernel crash dump. */
727 struct pcb dumppcb;
728
729 /*
730 * Write a crash dump. The format while in swap is:
731 * kcore_seg_t cpu_hdr;
732 * cpu_kcore_hdr_t cpu_data;
733 * padding (NBPG-sizeof(kcore_seg_t))
734 * pagemap (2*NBPG)
735 * physical memory...
736 */
737 void
738 dumpsys()
739 {
740 struct bdevsw *dsw;
741 kcore_seg_t *kseg_p;
742 cpu_kcore_hdr_t *chdr_p;
743 struct sun3x_kcore_hdr *sh;
744 phys_ram_seg_t *crs_p;
745 char *vaddr;
746 vm_offset_t paddr;
747 int psize, todo, seg, segsz;
748 daddr_t blkno;
749 int error = 0;
750
751 msgbufenabled = 0;
752 if (dumpdev == NODEV)
753 return;
754
755 /*
756 * For dumps during autoconfiguration,
757 * if dump device has already configured...
758 */
759 if (dumpsize == 0)
760 cpu_dumpconf();
761 if (dumplo <= 0) {
762 printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
763 minor(dumpdev));
764 return;
765 }
766 savectx(&dumppcb);
767
768 dsw = &bdevsw[major(dumpdev)];
769 psize = (*(dsw->d_psize))(dumpdev);
770 if (psize == -1) {
771 printf("dump area unavailable\n");
772 return;
773 }
774
775 printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
776 minor(dumpdev), dumplo);
777
778 /*
779 * We put the dump header is in physical page zero,
780 * so there is no extra work here to write it out.
781 * All we do is initialize the header.
782 */
783
784 /* Set pointers to all three parts. */
785 kseg_p = (kcore_seg_t *)KERNBASE;
786 chdr_p = (cpu_kcore_hdr_t *) (kseg_p + 1);
787 sh = &chdr_p->un._sun3x;
788
789 /* Fill in kcore_seg_t part. */
790 CORE_SETMAGIC(*kseg_p, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
791 kseg_p->c_size = sizeof(*chdr_p);
792
793 /* Fill in cpu_kcore_hdr_t part. */
794 /* Can NOT use machine[] as the name! */
795 strncpy(chdr_p->name, "sun3x", sizeof(chdr_p->name));
796 chdr_p->page_size = NBPG;
797 chdr_p->kernbase = KERNBASE;
798
799 /* Fill in the sun3x_kcore_hdr part. */
800 pmap_kcore_hdr(sh);
801
802 /*
803 * Now dump physical memory. Note that physical memory
804 * might NOT be congiguous, so do it by segments.
805 */
806
807 blkno = dumplo;
808 todo = dumpsize; /* pages */
809 vaddr = (char*)vmmap; /* Borrow /dev/mem VA */
810
811 for (seg = 0; seg < SUN3X_NPHYS_RAM_SEGS; seg++) {
812 crs_p = &sh->ram_segs[seg];
813 paddr = crs_p->start;
814 segsz = crs_p->size;
815 /*
816 * Our header lives in the first little bit of
817 * physical memory (not written separately), so
818 * we have to adjust the first ram segment size
819 * and start address to reflect the stolen RAM.
820 * (Nothing interesing in that RAM anyway 8^).
821 */
822 if (seg == 0) {
823 int adj = sizeof(*kseg_p) + sizeof(*chdr_p);
824 crs_p->start += adj;
825 crs_p->size -= adj;
826 }
827
828 while (todo && (segsz > 0)) {
829
830 /* Print pages left after every 16. */
831 if ((todo & 0xf) == 0)
832 printf("\r%4d", todo);
833
834 /* Make a temporary mapping for the page. */
835 pmap_enter(pmap_kernel(), vmmap, paddr | PMAP_NC,
836 VM_PROT_READ, FALSE, 0);
837 error = (*dsw->d_dump)(dumpdev, blkno, vaddr, NBPG);
838 pmap_remove(pmap_kernel(), vmmap, vmmap + NBPG);
839 if (error)
840 goto fail;
841 paddr += NBPG;
842 segsz -= NBPG;
843 blkno += btodb(NBPG);
844 todo--;
845 }
846 }
847 printf("\rdump succeeded\n");
848 return;
849 fail:
850 printf(" dump error=%d\n", error);
851 }
852
853 static void
854 initcpu()
855 {
856 /* XXX: Enable RAM parity/ECC checking? */
857 /* XXX: parityenable(); */
858
859 #ifdef HAVECACHE
860 cache_enable();
861 #endif
862 }
863
864 /* straptrap() in trap.c */
865
866 /* from hp300: badaddr() */
867 /* peek_byte(), peek_word() moved to bus_subr.c */
868
869 /* XXX: parityenable() ? */
870 /* regdump() moved to regdump.c */
871
872 /*
873 * cpu_exec_aout_makecmds():
874 * cpu-dependent a.out format hook for execve().
875 *
876 * Determine if the given exec package refers to something which we
877 * understand and, if so, set up the vmcmds for it.
878 */
879 int
880 cpu_exec_aout_makecmds(p, epp)
881 struct proc *p;
882 struct exec_package *epp;
883 {
884 return ENOEXEC;
885 }
886