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