machdep.c revision 1.42 1 /* $NetBSD: machdep.c,v 1.42 1999/03/24 05:51:15 mrg 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_ALL, TRUE);
354 #endif
355 curbuf += PAGE_SIZE;
356 curbufsize -= PAGE_SIZE;
357 }
358 }
359
360 /*
361 * Allocate a submap for exec arguments. This map effectively
362 * limits the number of processes exec'ing at any time.
363 */
364 exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
365 16*NCARGS, TRUE, FALSE, NULL);
366
367 /*
368 * We don't use a submap for physio, and use a separate map
369 * for DVMA allocations. Our vmapbuf just maps pages into
370 * the kernel map (any kernel mapping is OK) and then the
371 * device drivers clone the kernel mappings into DVMA space.
372 */
373
374 /*
375 * Finally, allocate mbuf cluster submap.
376 */
377 mb_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
378 VM_MBUF_SIZE, FALSE, FALSE, NULL);
379
380 /*
381 * Initialize callouts
382 */
383 callfree = callout;
384 for (i = 1; i < ncallout; i++)
385 callout[i-1].c_next = &callout[i];
386 callout[i-1].c_next = NULL;
387
388 size = ptoa(uvmexp.free);
389 printf("avail mem = %ldK (0x%lx)\n", (size >> 10), size);
390 printf("using %d buffers containing %d bytes of memory\n",
391 nbuf, bufpages * CLBYTES);
392
393 /*
394 * Tell the VM system that writing to kernel text isn't allowed.
395 * If we don't, we might end up COW'ing the text segment!
396 */
397 if (uvm_map_protect(kernel_map, (vm_offset_t) kernel_text,
398 m68k_trunc_page((vm_offset_t) etext),
399 UVM_PROT_READ|UVM_PROT_EXEC, TRUE) != KERN_SUCCESS)
400 panic("can't protect kernel text");
401
402 /*
403 * Allocate a virtual page (for use by /dev/mem)
404 * This page is handed to pmap_enter() therefore
405 * it has to be in the normal kernel VA range.
406 */
407 vmmap = uvm_km_valloc_wait(kernel_map, NBPG);
408
409 /*
410 * Create the DVMA maps.
411 */
412 dvma_init();
413
414 /*
415 * Set up CPU-specific registers, cache, etc.
416 */
417 initcpu();
418
419 /*
420 * Set up buffers, so they can be used to read disk labels.
421 */
422 bufinit();
423
424 /*
425 * Configure the system.
426 */
427 configure();
428 }
429
430 /*
431 * Set registers on exec.
432 */
433 void
434 setregs(p, pack, stack)
435 struct proc *p;
436 struct exec_package *pack;
437 u_long stack;
438 {
439 struct trapframe *tf = (struct trapframe *)p->p_md.md_regs;
440
441 tf->tf_sr = PSL_USERSET;
442 tf->tf_pc = pack->ep_entry & ~1;
443 tf->tf_regs[D0] = 0;
444 tf->tf_regs[D1] = 0;
445 tf->tf_regs[D2] = 0;
446 tf->tf_regs[D3] = 0;
447 tf->tf_regs[D4] = 0;
448 tf->tf_regs[D5] = 0;
449 tf->tf_regs[D6] = 0;
450 tf->tf_regs[D7] = 0;
451 tf->tf_regs[A0] = 0;
452 tf->tf_regs[A1] = 0;
453 tf->tf_regs[A2] = (int)PS_STRINGS;
454 tf->tf_regs[A3] = 0;
455 tf->tf_regs[A4] = 0;
456 tf->tf_regs[A5] = 0;
457 tf->tf_regs[A6] = 0;
458 tf->tf_regs[SP] = stack;
459
460 /* restore a null state frame */
461 p->p_addr->u_pcb.pcb_fpregs.fpf_null = 0;
462 if (fputype)
463 m68881_restore(&p->p_addr->u_pcb.pcb_fpregs);
464
465 p->p_md.md_flags = 0;
466 }
467
468 /*
469 * Info for CTL_HW
470 */
471 char machine[16] = MACHINE; /* from <machine/param.h> */
472 char cpu_model[120];
473
474 /*
475 * XXX - Should empirically estimate the divisor...
476 * Note that the value of delay_divisor is roughly
477 * 2048 / cpuclock (where cpuclock is in MHz).
478 */
479 int delay_divisor = 62; /* assume the fastest (33 MHz) */
480
481 void
482 identifycpu()
483 {
484 u_char machtype;
485
486 machtype = identity_prom.idp_machtype;
487 if ((machtype & IDM_ARCH_MASK) != IDM_ARCH_SUN3X) {
488 printf("Bad IDPROM arch!\n");
489 sunmon_abort();
490 }
491
492 cpu_machine_id = machtype;
493 switch (cpu_machine_id) {
494
495 case SUN3X_MACH_80:
496 cpu_string = "80"; /* Hydra */
497 delay_divisor = 102; /* 20 MHz */
498 cpu_has_vme = FALSE;
499 break;
500
501 case SUN3X_MACH_470:
502 cpu_string = "470"; /* Pegasus */
503 delay_divisor = 62; /* 33 MHz */
504 cpu_has_vme = TRUE;
505 break;
506
507 default:
508 printf("unknown sun3x model\n");
509 sunmon_abort();
510 }
511
512 /* Other stuff? (VAC, mc6888x version, etc.) */
513 sprintf(cpu_model, "Sun-3X (3/%s)", cpu_string);
514
515 printf("Model: %s\n", cpu_model);
516 }
517
518 /*
519 * machine dependent system variables.
520 */
521 int
522 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
523 int *name;
524 u_int namelen;
525 void *oldp;
526 size_t *oldlenp;
527 void *newp;
528 size_t newlen;
529 struct proc *p;
530 {
531 int error;
532 dev_t consdev;
533
534 /* all sysctl names at this level are terminal */
535 if (namelen != 1)
536 return (ENOTDIR); /* overloaded */
537
538 switch (name[0]) {
539 case CPU_CONSDEV:
540 if (cn_tab != NULL)
541 consdev = cn_tab->cn_dev;
542 else
543 consdev = NODEV;
544 error = sysctl_rdstruct(oldp, oldlenp, newp,
545 &consdev, sizeof consdev);
546 break;
547
548 #if 0 /* XXX - Not yet... */
549 case CPU_ROOT_DEVICE:
550 error = sysctl_rdstring(oldp, oldlenp, newp, root_device);
551 break;
552
553 case CPU_BOOTED_KERNEL:
554 error = sysctl_rdstring(oldp, oldlenp, newp, booted_kernel);
555 break;
556 #endif
557
558 default:
559 error = EOPNOTSUPP;
560 }
561 return (error);
562 }
563
564 /* See: sig_machdep.c */
565
566 /*
567 * Do a sync in preparation for a reboot.
568 * XXX - This could probably be common code.
569 * XXX - And now, most of it is in vfs_shutdown()
570 * XXX - Put waittime checks in there too?
571 */
572 int waittime = -1; /* XXX - Who else looks at this? -gwr */
573 static void
574 reboot_sync __P((void))
575 {
576
577 /* Check waittime here to localize its use to this function. */
578 if (waittime >= 0)
579 return;
580 waittime = 0;
581 vfs_shutdown();
582 }
583
584 /*
585 * Common part of the BSD and SunOS reboot system calls.
586 */
587 __dead void
588 cpu_reboot(howto, user_boot_string)
589 int howto;
590 char *user_boot_string;
591 {
592 /* Note: this string MUST be static! */
593 static char bootstr[128];
594 char *p;
595
596 /* If system is cold, just halt. (early panic?) */
597 if (cold)
598 goto haltsys;
599
600 /* Un-blank the screen if appropriate. */
601 cnpollc(1);
602
603 if ((howto & RB_NOSYNC) == 0) {
604 reboot_sync();
605 /*
606 * If we've been adjusting the clock, the todr
607 * will be out of synch; adjust it now.
608 *
609 * XXX - However, if the kernel has been sitting in ddb,
610 * the time will be way off, so don't set the HW clock!
611 * XXX - Should do sanity check against HW clock. -gwr
612 */
613 /* resettodr(); */
614 }
615
616 /* Disable interrupts. */
617 splhigh();
618
619 /* Write out a crash dump if asked. */
620 if (howto & RB_DUMP)
621 dumpsys();
622
623 /* run any shutdown hooks */
624 doshutdownhooks();
625
626 if (howto & RB_HALT) {
627 haltsys:
628 printf("Kernel halted.\n");
629 #if 0
630 /*
631 * This calls the PROM monitor "exit_to_mon" function
632 * which appears to have problems... SunOS uses the
633 * "abort" function when you halt (bug work-around?)
634 * so we might as well do the same.
635 */
636 sunmon_halt(); /* provokes PROM monitor bug */
637 #else
638 sunmon_abort();
639 #endif
640 }
641
642 /*
643 * Automatic reboot.
644 */
645 if (user_boot_string)
646 strncpy(bootstr, user_boot_string, sizeof(bootstr));
647 else {
648 /*
649 * Build our own boot string with an empty
650 * boot device/file and (maybe) some flags.
651 * The PROM will supply the device/file name.
652 */
653 p = bootstr;
654 *p = '\0';
655 if (howto & (RB_KDB|RB_ASKNAME|RB_SINGLE)) {
656 /* Append the boot flags. */
657 *p++ = ' ';
658 *p++ = '-';
659 if (howto & RB_KDB)
660 *p++ = 'd';
661 if (howto & RB_ASKNAME)
662 *p++ = 'a';
663 if (howto & RB_SINGLE)
664 *p++ = 's';
665 *p = '\0';
666 }
667 }
668 printf("Kernel rebooting...\n");
669 sunmon_reboot(bootstr);
670 for (;;) ;
671 /*NOTREACHED*/
672 }
673
674 /*
675 * These variables are needed by /sbin/savecore
676 */
677 u_long dumpmag = 0x8fca0101; /* magic number */
678 int dumpsize = 0; /* pages */
679 long dumplo = 0; /* blocks */
680
681 /*
682 * This is called by main to set dumplo, dumpsize.
683 * Dumps always skip the first CLBYTES of disk space
684 * in case there might be a disk label stored there.
685 * If there is extra space, put dump at the end to
686 * reduce the chance that swapping trashes it.
687 */
688 void
689 cpu_dumpconf()
690 {
691 int nblks; /* size of dump area */
692 int maj;
693 int (*getsize)__P((dev_t));
694
695 /* Validate space in page zero for the kcore header. */
696 if (MSGBUFOFF < (sizeof(kcore_seg_t) + sizeof(cpu_kcore_hdr_t)))
697 panic("cpu_dumpconf: MSGBUFOFF too small");
698
699 if (dumpdev == NODEV)
700 return;
701
702 maj = major(dumpdev);
703 if (maj < 0 || maj >= nblkdev)
704 panic("dumpconf: bad dumpdev=0x%x", dumpdev);
705 getsize = bdevsw[maj].d_psize;
706 if (getsize == NULL)
707 return;
708 nblks = (*getsize)(dumpdev);
709 if (nblks <= ctod(1))
710 return;
711
712 /* Position dump image near end of space, page aligned. */
713 dumpsize = physmem; /* pages */
714 dumplo = nblks - ctod(dumpsize);
715 dumplo &= ~(ctod(1)-1);
716
717 /* If it does not fit, truncate it by moving dumplo. */
718 /* Note: Must force signed comparison. */
719 if (dumplo < ((long)ctod(1))) {
720 dumplo = ctod(1);
721 dumpsize = dtoc(nblks - dumplo);
722 }
723 }
724
725 /* Note: gdb looks for "dumppcb" in a kernel crash dump. */
726 struct pcb dumppcb;
727
728 /*
729 * Write a crash dump. The format while in swap is:
730 * kcore_seg_t cpu_hdr;
731 * cpu_kcore_hdr_t cpu_data;
732 * padding (NBPG-sizeof(kcore_seg_t))
733 * pagemap (2*NBPG)
734 * physical memory...
735 */
736 void
737 dumpsys()
738 {
739 struct bdevsw *dsw;
740 kcore_seg_t *kseg_p;
741 cpu_kcore_hdr_t *chdr_p;
742 struct sun3x_kcore_hdr *sh;
743 phys_ram_seg_t *crs_p;
744 char *vaddr;
745 vm_offset_t paddr;
746 int psize, todo, seg, segsz;
747 daddr_t blkno;
748 int error = 0;
749
750 msgbufenabled = 0;
751 if (dumpdev == NODEV)
752 return;
753
754 /*
755 * For dumps during autoconfiguration,
756 * if dump device has already configured...
757 */
758 if (dumpsize == 0)
759 cpu_dumpconf();
760 if (dumplo <= 0) {
761 printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
762 minor(dumpdev));
763 return;
764 }
765 savectx(&dumppcb);
766
767 dsw = &bdevsw[major(dumpdev)];
768 psize = (*(dsw->d_psize))(dumpdev);
769 if (psize == -1) {
770 printf("dump area unavailable\n");
771 return;
772 }
773
774 printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
775 minor(dumpdev), dumplo);
776
777 /*
778 * We put the dump header is in physical page zero,
779 * so there is no extra work here to write it out.
780 * All we do is initialize the header.
781 */
782
783 /* Set pointers to all three parts. */
784 kseg_p = (kcore_seg_t *)KERNBASE;
785 chdr_p = (cpu_kcore_hdr_t *) (kseg_p + 1);
786 sh = &chdr_p->un._sun3x;
787
788 /* Fill in kcore_seg_t part. */
789 CORE_SETMAGIC(*kseg_p, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
790 kseg_p->c_size = sizeof(*chdr_p);
791
792 /* Fill in cpu_kcore_hdr_t part. */
793 /* Can NOT use machine[] as the name! */
794 strncpy(chdr_p->name, "sun3x", sizeof(chdr_p->name));
795 chdr_p->page_size = NBPG;
796 chdr_p->kernbase = KERNBASE;
797
798 /* Fill in the sun3x_kcore_hdr part. */
799 pmap_kcore_hdr(sh);
800
801 /*
802 * Now dump physical memory. Note that physical memory
803 * might NOT be congiguous, so do it by segments.
804 */
805
806 blkno = dumplo;
807 todo = dumpsize; /* pages */
808 vaddr = (char*)vmmap; /* Borrow /dev/mem VA */
809
810 for (seg = 0; seg < SUN3X_NPHYS_RAM_SEGS; seg++) {
811 crs_p = &sh->ram_segs[seg];
812 paddr = crs_p->start;
813 segsz = crs_p->size;
814 /*
815 * Our header lives in the first little bit of
816 * physical memory (not written separately), so
817 * we have to adjust the first ram segment size
818 * and start address to reflect the stolen RAM.
819 * (Nothing interesing in that RAM anyway 8^).
820 */
821 if (seg == 0) {
822 int adj = sizeof(*kseg_p) + sizeof(*chdr_p);
823 crs_p->start += adj;
824 crs_p->size -= adj;
825 }
826
827 while (todo && (segsz > 0)) {
828
829 /* Print pages left after every 16. */
830 if ((todo & 0xf) == 0)
831 printf("\r%4d", todo);
832
833 /* Make a temporary mapping for the page. */
834 pmap_enter(pmap_kernel(), vmmap, paddr | PMAP_NC,
835 VM_PROT_READ, FALSE);
836 error = (*dsw->d_dump)(dumpdev, blkno, vaddr, NBPG);
837 pmap_remove(pmap_kernel(), vmmap, vmmap + NBPG);
838 if (error)
839 goto fail;
840 paddr += NBPG;
841 segsz -= NBPG;
842 blkno += btodb(NBPG);
843 todo--;
844 }
845 }
846 printf("\rdump succeeded\n");
847 return;
848 fail:
849 printf(" dump error=%d\n", error);
850 }
851
852 static void
853 initcpu()
854 {
855 /* XXX: Enable RAM parity/ECC checking? */
856 /* XXX: parityenable(); */
857
858 #ifdef HAVECACHE
859 cache_enable();
860 #endif
861 }
862
863 /* straptrap() in trap.c */
864
865 /* from hp300: badaddr() */
866 /* peek_byte(), peek_word() moved to bus_subr.c */
867
868 /* XXX: parityenable() ? */
869 /* regdump() moved to regdump.c */
870
871 /*
872 * cpu_exec_aout_makecmds():
873 * cpu-dependent a.out format hook for execve().
874 *
875 * Determine if the given exec package refers to something which we
876 * understand and, if so, set up the vmcmds for it.
877 */
878 int
879 cpu_exec_aout_makecmds(p, epp)
880 struct proc *p;
881 struct exec_package *epp;
882 {
883 return ENOEXEC;
884 }
885