/* $OpenBSD: machdep.c,v 1.109 2006/06/29 17:53:35 miod Exp $ */ /* $NetBSD: machdep.c,v 1.85 1997/09/12 08:55:02 pk Exp $ */ /* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This software was developed by the Computer Systems Engineering group * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and * contributed to Berkeley. * * All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Lawrence Berkeley Laboratory. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)machdep.c 8.6 (Berkeley) 1/14/94 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef SYSVMSG #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef SUN4M #include "power.h" #if NPOWER > 0 #include #endif #include "scf.h" #include "tctrl.h" #if NTCTRL > 0 #include #endif #endif #include "auxreg.h" #ifdef SUN4 #include #include "led.h" #endif struct vm_map *exec_map = NULL; struct vm_map *phys_map = NULL; /* * Declare these as initialized data so we can patch them. */ #ifdef NBUF int nbuf = NBUF; #else int nbuf = 0; #endif #ifndef BUFCACHEPERCENT #define BUFCACHEPERCENT 5 #endif #ifdef BUFPAGES int bufpages = BUFPAGES; #else int bufpages = 0; #endif int bufcachepercent = BUFCACHEPERCENT; int physmem; /* sysctl settable */ int sparc_led_blink = 0; /* * safepri is a safe priority for sleep to set for a spin-wait * during autoconfiguration or after a panic. */ int safepri = 0; /* * dvmamap is used to manage DVMA memory. Note: this coincides with * the memory range in `phys_map' (which is mostly a place-holder). */ vaddr_t dvma_base, dvma_end; struct extent *dvmamap_extent; caddr_t allocsys(caddr_t); void dumpsys(void); void stackdump(void); /* * Machine-dependent startup code */ void cpu_startup() { unsigned i; caddr_t v; int sz; int base, residual; #ifdef DEBUG extern int pmapdebug; int opmapdebug = pmapdebug; #endif vaddr_t minaddr, maxaddr; vsize_t size; extern struct user *proc0paddr; #ifdef DEBUG pmapdebug = 0; #endif if (CPU_ISSUN4M) { extern int stackgap_random; stackgap_random = STACKGAP_RANDOM_SUN4M; } /* * fix message buffer mapping, note phys addr of msgbuf is 0 */ pmap_map(MSGBUF_VA, 0, MSGBUFSIZE, VM_PROT_READ|VM_PROT_WRITE); initmsgbuf((caddr_t)(MSGBUF_VA + (CPU_ISSUN4 ? 4096 : 0)), MSGBUFSIZE); proc0.p_addr = proc0paddr; /* * Good {morning,afternoon,evening,night}. */ printf(version); /*identifycpu();*/ printf("real mem = %d\n", ctob(physmem)); /* * Find out how much space we need, allocate it, * and then give everything true virtual addresses. */ sz = (int)allocsys((caddr_t)0); if ((v = (caddr_t)uvm_km_alloc(kernel_map, round_page(sz))) == 0) panic("startup: no room for tables"); if (allocsys(v) - v != sz) panic("startup: table size inconsistency"); /* * allocate virtual and physical memory for the buffers. */ size = MAXBSIZE * nbuf; /* # bytes for buffers */ /* allocate VM for buffers... area is not managed by VM system */ if (uvm_map(kernel_map, (vaddr_t *) &buffers, round_page(size), NULL, UVM_UNKNOWN_OFFSET, 0, UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE, UVM_ADV_NORMAL, 0))) panic("cpu_startup: cannot allocate VM for buffers"); minaddr = (vaddr_t) buffers; if ((bufpages / nbuf) >= btoc(MAXBSIZE)) { bufpages = btoc(MAXBSIZE) * nbuf; /* do not overallocate RAM */ } base = bufpages / nbuf; residual = bufpages % nbuf; /* now allocate RAM for buffers */ for (i = 0 ; i < nbuf ; i++) { vaddr_t curbuf; vsize_t curbufsize; struct vm_page *pg; /* * each buffer has MAXBSIZE bytes of VM space allocated. of * that MAXBSIZE space we allocate and map (base+1) pages * for the first "residual" buffers, and then we allocate * "base" pages for the rest. */ curbuf = (vaddr_t) buffers + (i * MAXBSIZE); curbufsize = PAGE_SIZE * ((i < residual) ? (base+1) : base); while (curbufsize) { pg = uvm_pagealloc(NULL, 0, NULL, 0); if (pg == NULL) panic("cpu_startup: " "not enough RAM for buffer cache"); pmap_kenter_pa(curbuf, VM_PAGE_TO_PHYS(pg), VM_PROT_READ|VM_PROT_WRITE); curbuf += PAGE_SIZE; curbufsize -= PAGE_SIZE; } } pmap_update(pmap_kernel()); /* * Allocate a submap for exec arguments. This map effectively * limits the number of processes exec'ing at any time. */ minaddr = vm_map_min(kernel_map); exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr, 16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL); /* * Allocate a map for physio. Others use a submap of the kernel * map, but we want one completely separate, even though it uses * the same pmap. */ dvma_base = CPU_ISSUN4M ? DVMA4M_BASE : DVMA_BASE; dvma_end = CPU_ISSUN4M ? DVMA4M_END : DVMA_END; #if defined(SUN4M) if (CPU_ISSUN4M) { /* * The DVMA space we want partially overrides kernel_map. * Allocate it in kernel_map as well to prevent it from being * used for other things. */ if (uvm_map(kernel_map, &dvma_base, vm_map_max(kernel_map) - dvma_base, NULL, UVM_UNKNOWN_OFFSET, 0, UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE, UVM_ADV_NORMAL, 0))) panic("startup: can not steal dvma map"); } #endif phys_map = uvm_map_create(pmap_kernel(), dvma_base, dvma_end, VM_MAP_INTRSAFE); if (phys_map == NULL) panic("unable to create DVMA map"); /* * Allocate DVMA space and dump into a privately managed * resource map for double mappings which is usable from * interrupt contexts. */ if (uvm_km_valloc_wait(phys_map, (dvma_end-dvma_base)) != dvma_base) panic("unable to allocate from DVMA map"); dvmamap_extent = extent_create("dvmamap", dvma_base, dvma_end, M_DEVBUF, NULL, 0, EX_NOWAIT); if (dvmamap_extent == 0) panic("unable to allocate extent for dvma"); #ifdef DEBUG pmapdebug = opmapdebug; #endif printf("avail mem = %ld\n", ptoa(uvmexp.free)); printf("using %d buffers containing %d bytes of memory\n", nbuf, bufpages * PAGE_SIZE); /* * Set up buffers, so they can be used to read disk labels. */ bufinit(); /* Early interrupt handlers initialization */ intr_init(); } /* * Allocate space for system data structures. We are given * a starting virtual address and we return a final virtual * address; along the way we set each data structure pointer. * * You call allocsys() with 0 to find out how much space we want, * allocate that much and fill it with zeroes, and then call * allocsys() again with the correct base virtual address. */ caddr_t allocsys(v) caddr_t v; { #define valloc(name, type, num) \ v = (caddr_t)(((name) = (type *)v) + (num)) #ifdef SYSVMSG valloc(msgpool, char, msginfo.msgmax); valloc(msgmaps, struct msgmap, msginfo.msgseg); valloc(msghdrs, struct msg, msginfo.msgtql); valloc(msqids, struct msqid_ds, msginfo.msgmni); #endif /* * Determine how many buffers to allocate (enough to * hold 5% of total physical memory, but at least 16). * Allocate 1/2 as many swap buffer headers as file i/o buffers. */ if (bufpages == 0) bufpages = physmem * bufcachepercent / 100; if (nbuf == 0) { nbuf = bufpages; if (nbuf < 16) nbuf = 16; } if (nbuf > 200) nbuf = 200; /* or we run out of PMEGS */ /* Restrict to at most 70% filled kvm */ if (nbuf * MAXBSIZE > (VM_MAX_KERNEL_ADDRESS-VM_MIN_KERNEL_ADDRESS) * 7 / 10) nbuf = (VM_MAX_KERNEL_ADDRESS-VM_MIN_KERNEL_ADDRESS) / MAXBSIZE * 7 / 10; /* More buffer pages than fits into the buffers is senseless. */ if (bufpages > nbuf * MAXBSIZE / PAGE_SIZE) bufpages = nbuf * MAXBSIZE / PAGE_SIZE; valloc(buf, struct buf, nbuf); return (v); } /* * Set up registers on exec. * * XXX this entire mess must be fixed */ /* ARGSUSED */ void setregs(p, pack, stack, retval) struct proc *p; struct exec_package *pack; u_long stack; register_t *retval; { struct trapframe *tf = p->p_md.md_tf; struct fpstate *fs; int psr; /* * Setup the process StackGhost cookie which will be XORed into * the return pointer as register windows are over/underflowed */ p->p_addr->u_pcb.pcb_wcookie = arc4random(); /* The cookie needs to guarantee invalid alignment after the XOR */ switch (p->p_addr->u_pcb.pcb_wcookie % 3) { case 0: /* Two lsb's already both set except if the cookie is 0 */ p->p_addr->u_pcb.pcb_wcookie |= 0x3; break; case 1: /* Set the lsb */ p->p_addr->u_pcb.pcb_wcookie = 1 | (p->p_addr->u_pcb.pcb_wcookie & ~0x3); break; case 2: /* Set the second most lsb */ p->p_addr->u_pcb.pcb_wcookie = 2 | (p->p_addr->u_pcb.pcb_wcookie & ~0x3); break; } /* Don't allow misaligned code by default */ p->p_md.md_flags &= ~MDP_FIXALIGN; /* * The syscall will ``return'' to npc or %g7 or %g2; set them all. * Set the rest of the registers to 0 except for %o6 (stack pointer, * built in exec()) and psr (retain CWP and PSR_S bits). */ psr = tf->tf_psr & (PSR_S | PSR_CWP); if ((fs = p->p_md.md_fpstate) != NULL) { /* * We hold an FPU state. If we own *the* FPU chip state * we must get rid of it, and the only way to do that is * to save it. In any case, get rid of our FPU state. */ if (p == cpuinfo.fpproc) { savefpstate(fs); cpuinfo.fpproc = NULL; } free((void *)fs, M_SUBPROC); p->p_md.md_fpstate = NULL; } bzero((caddr_t)tf, sizeof *tf); tf->tf_psr = psr; tf->tf_npc = pack->ep_entry & ~3; tf->tf_global[1] = (int)PS_STRINGS; tf->tf_global[2] = tf->tf_global[7] = tf->tf_npc; /* XXX exec of init(8) returns via proc_trampoline() */ if (p->p_pid == 1) { tf->tf_pc = tf->tf_npc; tf->tf_npc += 4; } stack -= sizeof(struct rwindow); tf->tf_out[6] = stack; retval[1] = 0; } #ifdef DEBUG int sigdebug = 0; int sigpid = 0; #define SDB_FOLLOW 0x01 #define SDB_KSTACK 0x02 #define SDB_FPSTATE 0x04 #endif struct sigframe { int sf_signo; /* signal number */ siginfo_t *sf_sip; /* points to siginfo_t */ #ifdef COMPAT_SUNOS struct sigcontext *sf_scp; /* points to user addr of sigcontext */ #else int sf_xxx; /* placeholder */ #endif caddr_t sf_addr; /* SunOS compat */ struct sigcontext sf_sc; /* actual sigcontext */ siginfo_t sf_si; }; /* * machine dependent system variables. */ int cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) int *name; u_int namelen; void *oldp; size_t *oldlenp; void *newp; size_t newlen; struct proc *p; { #if (NLED > 0) || (NAUXREG > 0) || (NSCF > 0) int oldval; #endif int ret; extern int v8mul; /* all sysctl names are this level are terminal */ if (namelen != 1) return (ENOTDIR); /* overloaded */ switch (name[0]) { case CPU_LED_BLINK: #if (NLED > 0) || (NAUXREG > 0) || (NSCF > 0) oldval = sparc_led_blink; ret = sysctl_int(oldp, oldlenp, newp, newlen, &sparc_led_blink); /* * If we were false and are now true, call led_blink(). * led_blink() itself will catch the other case. */ if (!oldval && sparc_led_blink > oldval) { #if NAUXREG > 0 led_blink((caddr_t *)0); #endif #if NLED > 0 led_cycle((caddr_t *)led_sc); #endif #if NSCF > 0 scfblink((caddr_t *)0); #endif } return (ret); #else return (EOPNOTSUPP); #endif case CPU_CPUTYPE: return (sysctl_rdint(oldp, oldlenp, newp, cputyp)); case CPU_V8MUL: return (sysctl_rdint(oldp, oldlenp, newp, v8mul)); default: return (EOPNOTSUPP); } /* NOTREACHED */ } /* * Send an interrupt to process. */ void sendsig(catcher, sig, mask, code, type, val) sig_t catcher; int sig, mask; u_long code; int type; union sigval val; { struct proc *p = curproc; struct sigacts *psp = p->p_sigacts; struct sigframe *fp; struct trapframe *tf; int caddr, oonstack, oldsp, newsp; struct sigframe sf; #ifdef COMPAT_SUNOS extern struct emul emul_sunos; #endif tf = p->p_md.md_tf; oldsp = tf->tf_out[6]; oonstack = psp->ps_sigstk.ss_flags & SS_ONSTACK; /* * Compute new user stack addresses, subtract off * one signal frame, and align. */ if ((psp->ps_flags & SAS_ALTSTACK) && !oonstack && (psp->ps_sigonstack & sigmask(sig))) { fp = (struct sigframe *)(psp->ps_sigstk.ss_sp + psp->ps_sigstk.ss_size); psp->ps_sigstk.ss_flags |= SS_ONSTACK; } else fp = (struct sigframe *)oldsp; fp = (struct sigframe *)((int)(fp - 1) & ~7); #ifdef DEBUG if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) printf("sendsig: %s[%d] sig %d newusp %p scp %p\n", p->p_comm, p->p_pid, sig, fp, &fp->sf_sc); #endif /* * Now set up the signal frame. We build it in kernel space * and then copy it out. We probably ought to just build it * directly in user space.... */ sf.sf_signo = sig; sf.sf_sip = NULL; #ifdef COMPAT_SUNOS if (p->p_emul == &emul_sunos) { sf.sf_sip = (void *)code; /* SunOS has "int code" */ sf.sf_scp = &fp->sf_sc; sf.sf_addr = val.sival_ptr; } #endif /* * Build the signal context to be used by sigreturn. */ sf.sf_sc.sc_onstack = oonstack; sf.sf_sc.sc_mask = mask; sf.sf_sc.sc_sp = oldsp; sf.sf_sc.sc_pc = tf->tf_pc; sf.sf_sc.sc_npc = tf->tf_npc; sf.sf_sc.sc_psr = tf->tf_psr; sf.sf_sc.sc_g1 = tf->tf_global[1]; sf.sf_sc.sc_o0 = tf->tf_out[0]; if (psp->ps_siginfo & sigmask(sig)) { sf.sf_sip = &fp->sf_si; initsiginfo(&sf.sf_si, sig, code, type, val); } /* * Put the stack in a consistent state before we whack away * at it. Note that write_user_windows may just dump the * registers into the pcb; we need them in the process's memory. * We also need to make sure that when we start the signal handler, * its %i6 (%fp), which is loaded from the newly allocated stack area, * joins seamlessly with the frame it was in when the signal occurred, * so that the debugger and _longjmp code can back up through it. */ newsp = (int)fp - sizeof(struct rwindow); write_user_windows(); /* XXX do not copyout siginfo if not needed */ if (rwindow_save(p) || copyout((caddr_t)&sf, (caddr_t)fp, sizeof sf) || copyout(&oldsp, &((struct rwindow *)newsp)->rw_in[6], sizeof(register_t)) != 0) { /* * Process has trashed its stack; give it an illegal * instruction to halt it in its tracks. */ #ifdef DEBUG if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) printf("sendsig: window save or copyout error\n"); #endif sigexit(p, SIGILL); /* NOTREACHED */ } #ifdef DEBUG if (sigdebug & SDB_FOLLOW) printf("sendsig: %s[%d] sig %d scp %p\n", p->p_comm, p->p_pid, sig, &fp->sf_sc); #endif /* * Arrange to continue execution at the code copied out in exec(). * It needs the function to call in %g1, and a new stack pointer. */ #ifdef COMPAT_SUNOS if (psp->ps_usertramp & sigmask(sig)) { caddr = (int)catcher; /* user does his own trampolining */ } else #endif { caddr = p->p_sigcode; tf->tf_global[1] = (int)catcher; } tf->tf_pc = caddr; tf->tf_npc = caddr + 4; tf->tf_out[6] = newsp; #ifdef DEBUG if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) printf("sendsig: about to return to catcher\n"); #endif } /* * System call to cleanup state after a signal * has been taken. Reset signal mask and * stack state from context left by sendsig (above), * and return to the given trap frame (if there is one). * Check carefully to make sure that the user has not * modified the state to gain improper privileges or to cause * a machine fault. */ /* ARGSUSED */ int sys_sigreturn(p, v, retval) struct proc *p; void *v; register_t *retval; { struct sys_sigreturn_args /* { syscallarg(struct sigcontext *) sigcntxp; } */ *uap = v; struct sigcontext ksc; struct trapframe *tf; int error; /* First ensure consistent stack state (see sendsig). */ write_user_windows(); if (rwindow_save(p)) sigexit(p, SIGILL); #ifdef DEBUG if (sigdebug & SDB_FOLLOW) printf("sigreturn: %s[%d], sigcntxp %p\n", p->p_comm, p->p_pid, SCARG(uap, sigcntxp)); #endif if ((error = copyin(SCARG(uap, sigcntxp), &ksc, sizeof(ksc))) != 0) return (error); tf = p->p_md.md_tf; /* * Only the icc bits in the psr are used, so it need not be * verified. pc and npc must be multiples of 4. This is all * that is required; if it holds, just do it. */ if (((ksc.sc_pc | ksc.sc_npc) & 3) != 0) return (EINVAL); /* take only psr ICC field */ tf->tf_psr = (tf->tf_psr & ~PSR_ICC) | (ksc.sc_psr & PSR_ICC); tf->tf_pc = ksc.sc_pc; tf->tf_npc = ksc.sc_npc; tf->tf_global[1] = ksc.sc_g1; tf->tf_out[0] = ksc.sc_o0; tf->tf_out[6] = ksc.sc_sp; if (ksc.sc_onstack & 1) p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK; else p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK; p->p_sigmask = ksc.sc_mask & ~sigcantmask; return (EJUSTRETURN); } int waittime = -1; void boot(howto) int howto; { int i; static char str[4]; /* room for "-sd\0" */ /* If system is cold, just halt. */ if (cold) { /* (Unless the user explicitly asked for reboot.) */ if ((howto & RB_USERREQ) == 0) howto |= RB_HALT; goto haltsys; } fb_unblank(); boothowto = howto; if ((howto & RB_NOSYNC) == 0 && waittime < 0) { extern struct proc proc0; /* XXX protect against curproc->p_stats.foo refs in sync() */ if (curproc == NULL) curproc = &proc0; waittime = 0; vfs_shutdown(); /* * If we've been adjusting the clock, the todr * will be out of synch; adjust it now unless * the system was sitting in ddb. */ if ((howto & RB_TIMEBAD) == 0) { resettodr(); } else { printf("WARNING: not updating battery clock\n"); } } (void) splhigh(); /* ??? */ if (howto & RB_DUMP) dumpsys(); haltsys: /* Run any shutdown hooks */ doshutdownhooks(); if ((howto & RB_HALT) || (howto & RB_POWERDOWN)) { #if defined(SUN4M) if (howto & RB_POWERDOWN) { printf("attempting to power down...\n"); #if NTCTRL > 0 tadpole_powerdown(); #endif #if NPOWER > 0 auxio_powerdown(); #endif rominterpret("power-off"); printf("WARNING: powerdown failed!\n"); } #endif /* SUN4M */ printf("halted\n\n"); romhalt(); } printf("rebooting\n\n"); i = 1; if (howto & RB_SINGLE) str[i++] = 's'; if (howto & RB_KDB) str[i++] = 'd'; if (i > 1) { str[0] = '-'; str[i] = 0; } else str[0] = 0; romboot(str); /*NOTREACHED*/ } /* XXX - dumpmag not eplicitly used, savecore may search for it to get here */ u_long dumpmag = 0x8fca0101; /* magic number for savecore */ int dumpsize = 0; /* also for savecore */ long dumplo = 0; void dumpconf() { int nblks, dumpblks; if (dumpdev == NODEV || bdevsw[major(dumpdev)].d_psize == 0) /* No usable dump device */ return; nblks = (*bdevsw[major(dumpdev)].d_psize)(dumpdev); dumpblks = ctod(physmem) + ctod(pmap_dumpsize()); if (dumpblks > (nblks - ctod(1))) /* * dump size is too big for the partition. * Note, we safeguard a click at the front for a * possible disk label. */ return; /* Put the dump at the end of the partition */ dumplo = nblks - dumpblks; /* * savecore(8) expects dumpsize to be the number of pages * of actual core dumped (i.e. excluding the MMU stuff). */ dumpsize = physmem; } #define BYTES_PER_DUMP (32 * 1024) /* must be a multiple of pagesize */ static vaddr_t dumpspace; /* * Allocate the dump i/o buffer area during kernel memory allocation */ caddr_t reserve_dumppages(p) caddr_t p; { dumpspace = (vaddr_t)p; return (p + BYTES_PER_DUMP); } /* * Write a crash dump. */ void dumpsys() { int psize; daddr_t blkno; int (*dump)(dev_t, daddr_t, caddr_t, size_t); int error = 0; struct memarr *mp; int nmem; extern struct memarr pmemarr[]; extern int npmemarr; /* copy registers to memory */ snapshot(cpcb); stackdump(); if (dumpdev == NODEV) return; /* * For dumps during autoconfiguration, * if dump device has already configured... */ if (dumpsize == 0) dumpconf(); if (dumplo <= 0) return; printf("\ndumping to dev(%d,%d), at offset %ld blocks\n", major(dumpdev), minor(dumpdev), dumplo); psize = (*bdevsw[major(dumpdev)].d_psize)(dumpdev); printf("dump "); if (psize == -1) { printf("area unavailable\n"); return; } blkno = dumplo; dump = bdevsw[major(dumpdev)].d_dump; printf("mmu "); error = pmap_dumpmmu(dump, blkno); blkno += ctod(pmap_dumpsize()); printf("memory "); for (mp = pmemarr, nmem = npmemarr; --nmem >= 0 && error == 0; mp++) { unsigned i = 0, n; unsigned maddr = mp->addr; /* XXX - what's so special about PA 0 that we can't dump it? */ if (maddr == 0) { /* Skip first page at physical address 0 */ maddr += NBPG; i += NBPG; blkno += btodb(NBPG); } printf("@0x%x:", maddr); for (; i < mp->len; i += n) { n = mp->len - i; if (n > BYTES_PER_DUMP) n = BYTES_PER_DUMP; /* print out which MBs we are dumping */ if (i % (1024*1024) <= NBPG) printf("%d ", i / (1024*1024)); (void) pmap_map(dumpspace, maddr, maddr + n, VM_PROT_READ); error = (*dump)(dumpdev, blkno, (caddr_t)dumpspace, (int)n); pmap_remove(pmap_kernel(), dumpspace, dumpspace + n); if (error) break; maddr += n; blkno += btodb(n); } } switch (error) { case ENXIO: printf("device bad\n"); break; case EFAULT: printf("device not ready\n"); break; case EINVAL: printf("area improper\n"); break; case EIO: printf("i/o error\n"); break; case 0: printf("succeeded\n"); break; default: printf("error %d\n", error); break; } } /* * get the fp and dump the stack as best we can. don't leave the * current stack page */ void stackdump() { struct frame *fp = getfp(), *sfp; sfp = fp; printf("Frame pointer is at %p\n", fp); printf("Call traceback:\n"); while (fp && ((u_long)fp >> PGSHIFT) == ((u_long)sfp >> PGSHIFT)) { printf(" pc = 0x%x args = (0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x) fp = %p\n", fp->fr_pc, fp->fr_arg[0], fp->fr_arg[1], fp->fr_arg[2], fp->fr_arg[3], fp->fr_arg[4], fp->fr_arg[5], fp->fr_arg[6], fp->fr_fp); fp = fp->fr_fp; } } /* * Map an I/O device given physical address and size in bytes, e.g., * * mydev = (struct mydev *)mapdev(myioaddr, 0, * 0, sizeof(struct mydev)); * * See also machine/autoconf.h. * * XXXART - verify types (too tired now). */ void * mapdev(phys, virt, offset, size) struct rom_reg *phys; int offset, virt, size; { vaddr_t va; paddr_t pa, base; void *ret; static vaddr_t iobase; unsigned int pmtype; if (iobase == NULL) iobase = IODEV_BASE; base = (paddr_t)phys->rr_paddr + offset; if (virt != 0) { va = trunc_page(virt); size = round_page(virt + size) - va; } else { size = round_page(base + size) - trunc_page(base); va = iobase; iobase += size; if (iobase > IODEV_END) /* unlikely */ panic("mapiodev"); } if (size == 0) panic("mapdev: zero size"); ret = (void *)(va | (base & PGOFSET)); /* note: preserve page offset */ pa = trunc_page(base); pmtype = PMAP_IOENC(phys->rr_iospace); do { pmap_kenter_pa(va, pa | pmtype | PMAP_NC, VM_PROT_READ | VM_PROT_WRITE); va += PAGE_SIZE; pa += PAGE_SIZE; } while ((size -= PAGE_SIZE) > 0); pmap_update(pmap_kernel()); return (ret); } #ifdef COMPAT_SUNOS int cpu_exec_aout_makecmds(p, epp) struct proc *p; struct exec_package *epp; { int error = ENOEXEC; extern int sunos_exec_aout_makecmds(struct proc *, struct exec_package *); if ((error = sunos_exec_aout_makecmds(p, epp)) == 0) return 0; return error; } #endif #ifdef SUN4 void oldmon_w_trace(va) u_long va; { u_long stop; struct frame *fp; if (curproc) printf("curproc = %p, pid %d\n", curproc, curproc->p_pid); else printf("no curproc\n"); printf("uvm: swtch %d, trap %d, sys %d, intr %d, soft %d, faults %d\n", uvmexp.swtch, uvmexp.traps, uvmexp.syscalls, uvmexp.intrs, uvmexp.softs, uvmexp.faults); write_user_windows(); printf("\nstack trace with sp = 0x%lx\n", va); stop = round_page(va); printf("stop at 0x%lx\n", stop); fp = (struct frame *) va; while (round_page((u_long) fp) == stop) { printf(" 0x%x(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x) fp %p\n", fp->fr_pc, fp->fr_arg[0], fp->fr_arg[1], fp->fr_arg[2], fp->fr_arg[3], fp->fr_arg[4], fp->fr_arg[5], fp->fr_arg[6], fp->fr_fp); fp = fp->fr_fp; if (fp == NULL) break; } printf("end of stack trace\n"); } void oldmon_w_cmd(va, ar) u_long va; char *ar; { switch (*ar) { case '\0': switch (va) { case 0: panic("g0 panic"); case 4: printf("w: case 4\n"); break; default: printf("w: unknown case %ld\n", va); break; } break; case 't': oldmon_w_trace(va); break; default: printf("w: arg not allowed\n"); } } int ldcontrolb(addr) caddr_t addr; { struct pcb *xpcb; extern struct user *proc0paddr; u_long saveonfault; int res; int s; s = splhigh(); if (curproc == NULL) xpcb = (struct pcb *)proc0paddr; else xpcb = &curproc->p_addr->u_pcb; saveonfault = (u_long)xpcb->pcb_onfault; res = xldcontrolb(addr, xpcb); xpcb->pcb_onfault = (caddr_t)saveonfault; splx(s); return (res); } #endif /* SUN4 */