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