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