machdep.c revision 1.93 1 /* $NetBSD: machdep.c,v 1.93 2003/12/04 19:38:22 atatat 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.93 2003/12/04 19:38:22 atatat 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 #if 0 /* XXX - Not yet... */
455 static int
456 sysctl_machdep_root_device(SYSCTLFN_ARGS)
457 {
458 struct sysctlnode node = *rnode;
459
460 node.sysctl_data = some permutation on root_device;
461 node.sysctl_size = strlen(root_device) + 1;
462 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
463 }
464
465 static int
466 sysctl_machdep_booted_kernel(SYSCTLFN_ARGS)
467 {
468 struct sysctlnode node = *rnode;
469
470 node.sysctl_data = some permutation on booted_kernel;
471 node.sysctl_size = strlen(booted_kernel) + 1;
472 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
473 }
474 #endif
475
476 SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
477 {
478
479 sysctl_createv(SYSCTL_PERMANENT,
480 CTLTYPE_NODE, "machdep", NULL,
481 NULL, 0, NULL, 0,
482 CTL_MACHDEP, CTL_EOL);
483
484 sysctl_createv(SYSCTL_PERMANENT,
485 CTLTYPE_STRUCT, "console_device", NULL,
486 sysctl_consdev, 0, NULL, sizeof(dev_t),
487 CTL_MACHDEP, CPU_CONSDEV, CTL_EOL);
488 #if 0 /* XXX - Not yet... */
489 sysctl_createv(SYSCTL_PERMANENT,
490 CTLTYPE_STRING, "root_device", NULL,
491 sysctl_machdep_root_device, 0, NULL, 0,
492 CTL_MACHDEP, CPU_ROOT_DEVICE, CTL_EOL);
493 sysctl_createv(SYSCTL_PERMANENT,
494 CTLTYPE_STRING, "booted_kernel", NULL,
495 sysctl_machdep_booted_kernel, 0, NULL, 0,
496 CTL_MACHDEP, CPU_BOOTED_KERNEL, CTL_EOL);
497 #endif
498 }
499
500 /* See: sig_machdep.c */
501
502 /*
503 * Do a sync in preparation for a reboot.
504 * XXX - This could probably be common code.
505 * XXX - And now, most of it is in vfs_shutdown()
506 * XXX - Put waittime checks in there too?
507 */
508 int waittime = -1; /* XXX - Who else looks at this? -gwr */
509 static void
510 reboot_sync __P((void))
511 {
512
513 /* Check waittime here to localize its use to this function. */
514 if (waittime >= 0)
515 return;
516 waittime = 0;
517 vfs_shutdown();
518 }
519
520 /*
521 * Common part of the BSD and SunOS reboot system calls.
522 */
523 __dead void
524 cpu_reboot(howto, user_boot_string)
525 int howto;
526 char *user_boot_string;
527 {
528 /* Note: this string MUST be static! */
529 static char bootstr[128];
530 char *p;
531
532 /* If system is cold, just halt. (early panic?) */
533 if (cold)
534 goto haltsys;
535
536 /* Un-blank the screen if appropriate. */
537 cnpollc(1);
538
539 if ((howto & RB_NOSYNC) == 0) {
540 reboot_sync();
541 /*
542 * If we've been adjusting the clock, the todr
543 * will be out of synch; adjust it now.
544 *
545 * XXX - However, if the kernel has been sitting in ddb,
546 * the time will be way off, so don't set the HW clock!
547 * XXX - Should do sanity check against HW clock. -gwr
548 */
549 /* resettodr(); */
550 }
551
552 /* Disable interrupts. */
553 splhigh();
554
555 /* Write out a crash dump if asked. */
556 if (howto & RB_DUMP)
557 dumpsys();
558
559 /* run any shutdown hooks */
560 doshutdownhooks();
561
562 if (howto & RB_HALT) {
563 haltsys:
564 printf("halted.\n");
565 sunmon_halt();
566 }
567
568 /*
569 * Automatic reboot.
570 */
571 if (user_boot_string)
572 strncpy(bootstr, user_boot_string, sizeof(bootstr));
573 else {
574 /*
575 * Build our own boot string with an empty
576 * boot device/file and (maybe) some flags.
577 * The PROM will supply the device/file name.
578 */
579 p = bootstr;
580 *p = '\0';
581 if (howto & (RB_KDB|RB_ASKNAME|RB_SINGLE)) {
582 /* Append the boot flags. */
583 *p++ = ' ';
584 *p++ = '-';
585 if (howto & RB_KDB)
586 *p++ = 'd';
587 if (howto & RB_ASKNAME)
588 *p++ = 'a';
589 if (howto & RB_SINGLE)
590 *p++ = 's';
591 *p = '\0';
592 }
593 }
594 printf("rebooting...\n");
595 sunmon_reboot(bootstr);
596 for (;;) ;
597 /*NOTREACHED*/
598 }
599
600 /*
601 * These variables are needed by /sbin/savecore
602 */
603 u_int32_t dumpmag = 0x8fca0101; /* magic number */
604 int dumpsize = 0; /* pages */
605 long dumplo = 0; /* blocks */
606
607 #define DUMP_EXTRA 1 /* CPU-dependent extra pages */
608
609 /*
610 * This is called by main to set dumplo, dumpsize.
611 * Dumps always skip the first PAGE_SIZE of disk space
612 * in case there might be a disk label stored there.
613 * If there is extra space, put dump at the end to
614 * reduce the chance that swapping trashes it.
615 */
616 void
617 cpu_dumpconf()
618 {
619 const struct bdevsw *bdev;
620 int devblks; /* size of dump device in blocks */
621 int dumpblks; /* size of dump image in blocks */
622 int (*getsize)__P((dev_t));
623
624 if (dumpdev == NODEV)
625 return;
626
627 bdev = bdevsw_lookup(dumpdev);
628 if (bdev == NULL)
629 panic("dumpconf: bad dumpdev=0x%x", dumpdev);
630 getsize = bdev->d_psize;
631 if (getsize == NULL)
632 return;
633 devblks = (*getsize)(dumpdev);
634 if (devblks <= ctod(1))
635 return;
636 devblks &= ~(ctod(1) - 1);
637
638 /*
639 * Note: savecore expects dumpsize to be the
640 * number of pages AFTER the dump header.
641 */
642 dumpsize = physmem; /* pages */
643
644 /* Position dump image near end of space, page aligned. */
645 dumpblks = ctod(physmem + DUMP_EXTRA);
646 dumplo = devblks - dumpblks;
647
648 /* If it does not fit, truncate it by moving dumplo. */
649 /* Note: Must force signed comparison. */
650 if (dumplo < ((long)ctod(1))) {
651 dumplo = ctod(1);
652 dumpsize = dtoc(devblks - dumplo) - DUMP_EXTRA;
653 }
654 }
655
656 /* Note: gdb looks for "dumppcb" in a kernel crash dump. */
657 struct pcb dumppcb;
658
659 /*
660 * Write a crash dump. The format while in swap is:
661 * kcore_seg_t cpu_hdr;
662 * cpu_kcore_hdr_t cpu_data;
663 * padding (PAGE_SIZE-sizeof(kcore_seg_t))
664 * pagemap (2*PAGE_SIZE)
665 * physical memory...
666 */
667 void
668 dumpsys()
669 {
670 const struct bdevsw *dsw;
671 kcore_seg_t *kseg_p;
672 cpu_kcore_hdr_t *chdr_p;
673 struct sun3x_kcore_hdr *sh;
674 phys_ram_seg_t *crs_p;
675 char *vaddr;
676 paddr_t paddr;
677 int psize, todo, seg, segsz;
678 daddr_t blkno;
679 int error = 0;
680
681 if (dumpdev == NODEV)
682 return;
683 dsw = bdevsw_lookup(dumpdev);
684 if (dsw == NULL || dsw->d_psize == NULL)
685 return;
686
687 /*
688 * For dumps during autoconfiguration,
689 * if dump device has already configured...
690 */
691 if (dumpsize == 0)
692 cpu_dumpconf();
693 if (dumplo <= 0) {
694 printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
695 minor(dumpdev));
696 return;
697 }
698 savectx(&dumppcb);
699
700 psize = (*(dsw->d_psize))(dumpdev);
701 if (psize == -1) {
702 printf("dump area unavailable\n");
703 return;
704 }
705
706 printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
707 minor(dumpdev), dumplo);
708
709 /*
710 * Prepare the dump header
711 */
712 blkno = dumplo;
713 todo = dumpsize; /* pages */
714 vaddr = (char *)dumppage;
715 memset(vaddr, 0, PAGE_SIZE);
716
717 /* Set pointers to all three parts. */
718 kseg_p = (kcore_seg_t *)vaddr;
719 chdr_p = (cpu_kcore_hdr_t *)(kseg_p + 1);
720 sh = &chdr_p->un._sun3x;
721
722 /* Fill in kcore_seg_t part. */
723 CORE_SETMAGIC(*kseg_p, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
724 kseg_p->c_size = (ctob(DUMP_EXTRA) - sizeof(*kseg_p));
725
726 /* Fill in cpu_kcore_hdr_t part. */
727 strncpy(chdr_p->name, kernel_arch, sizeof(chdr_p->name));
728 chdr_p->page_size = PAGE_SIZE;
729 chdr_p->kernbase = KERNBASE;
730
731 /* Fill in the sun3x_kcore_hdr part. */
732 pmap_kcore_hdr(sh);
733
734 /* Write out the dump header. */
735 error = (*dsw->d_dump)(dumpdev, blkno, vaddr, PAGE_SIZE);
736 if (error)
737 goto fail;
738 blkno += btodb(PAGE_SIZE);
739
740 /*
741 * Now dump physical memory. Note that physical memory
742 * might NOT be congiguous, so do it by segments.
743 */
744
745 vaddr = (char *)vmmap; /* Borrow /dev/mem VA */
746
747 for (seg = 0; seg < SUN3X_NPHYS_RAM_SEGS; seg++) {
748 crs_p = &sh->ram_segs[seg];
749 paddr = crs_p->start;
750 segsz = crs_p->size;
751
752 while (todo && (segsz > 0)) {
753
754 /* Print pages left after every 16. */
755 if ((todo & 0xf) == 0)
756 printf("\r%4d", todo);
757
758 /* Make a temporary mapping for the page. */
759 pmap_kenter_pa(vmmap, paddr | PMAP_NC, VM_PROT_READ);
760 pmap_update(pmap_kernel());
761 error = (*dsw->d_dump)(dumpdev, blkno, vaddr,
762 PAGE_SIZE);
763 pmap_kremove(vmmap, PAGE_SIZE);
764 pmap_update(pmap_kernel());
765 if (error)
766 goto fail;
767 paddr += PAGE_SIZE;
768 segsz -= PAGE_SIZE;
769 blkno += btodb(PAGE_SIZE);
770 todo--;
771 }
772 }
773 printf("\rdump succeeded\n");
774 return;
775 fail:
776 printf(" dump error=%d\n", error);
777 }
778
779 static void
780 initcpu()
781 {
782 /* XXX: Enable RAM parity/ECC checking? */
783 /* XXX: parityenable(); */
784
785 #ifdef HAVECACHE
786 cache_enable();
787 #endif
788 }
789
790 /* straptrap() in trap.c */
791
792 /* from hp300: badaddr() */
793 /* peek_byte(), peek_word() moved to bus_subr.c */
794
795 /* XXX: parityenable() ? */
796 /* regdump() moved to regdump.c */
797
798 /*
799 * cpu_exec_aout_makecmds():
800 * cpu-dependent a.out format hook for execve().
801 *
802 * Determine if the given exec package refers to something which we
803 * understand and, if so, set up the vmcmds for it.
804 */
805 int
806 cpu_exec_aout_makecmds(p, epp)
807 struct proc *p;
808 struct exec_package *epp;
809 {
810 return ENOEXEC;
811 }
812