[BACK]Return to sig_machdep.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / arch / powerpc / powerpc

Annotation of src/sys/arch/powerpc/powerpc/sig_machdep.c, Revision 1.17

1.17    ! matt        1: /*     $NetBSD: sig_machdep.c,v 1.16 2003/09/26 18:00:47 matt Exp $    */
1.1       kleink      2:
                      3: /*
                      4:  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
                      5:  * Copyright (C) 1995, 1996 TooLs GmbH.
                      6:  * All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. All advertising materials mentioning features or use of this software
                     17:  *    must display the following acknowledgement:
                     18:  *     This product includes software developed by TooLs GmbH.
                     19:  * 4. The name of TooLs GmbH may not be used to endorse or promote products
                     20:  *    derived from this software without specific prior written permission.
                     21:  *
                     22:  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
                     23:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     24:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     25:  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
                     26:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
                     27:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
                     28:  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                     29:  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
                     30:  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
                     31:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     32:  */
1.12      lukem      33:
                     34: #include <sys/cdefs.h>
1.17    ! matt       35: __KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.16 2003/09/26 18:00:47 matt Exp $");
1.2       tsubai     36:
                     37: #include "opt_compat_netbsd.h"
1.8       thorpej    38: #include "opt_ppcarch.h"
1.1       kleink     39:
                     40: #include <sys/param.h>
                     41: #include <sys/mount.h>
                     42: #include <sys/proc.h>
1.8       thorpej    43: #include <sys/sa.h>
                     44: #include <sys/savar.h>
1.1       kleink     45: #include <sys/syscallargs.h>
                     46: #include <sys/systm.h>
1.8       thorpej    47: #include <sys/ucontext.h>
1.1       kleink     48: #include <sys/user.h>
                     49:
1.8       thorpej    50: #include <machine/fpu.h>
                     51:
1.1       kleink     52: /*
                     53:  * Send a signal to process.
                     54:  */
                     55: void
1.15      christos   56: sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
1.1       kleink     57: {
1.13      matt       58:        struct lwp * const l = curlwp;
                     59:        struct proc * const p = l->l_proc;
                     60:        struct trapframe * const tf = trapframe(l);
                     61:        struct sigaltstack *ss = &p->p_sigctx.ps_sigstk;
                     62:        const struct sigact_sigdesc *sd =
                     63:            &p->p_sigacts->sa_sigdesc[ksi->ksi_signo];
                     64:        ucontext_t uc;
                     65:        vaddr_t sp, sip, ucp;
1.1       kleink     66:        int onstack;
                     67:
1.14      matt       68:        if (sd->sd_vers < 2) {
1.13      matt       69: #ifdef COMPAT_16
                     70:                sendsig_sigcontext(ksi->ksi_signo, mask, ksi->ksi_trap);
                     71:                return;
1.14      matt       72: #else
                     73:                goto nosupport;
                     74: #endif
1.13      matt       75:        }
1.1       kleink     76:
                     77:        /* Do we need to jump onto the signal stack? */
1.13      matt       78:        onstack = (ss->ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
                     79:            (sd->sd_sigact.sa_flags & SA_ONSTACK) != 0;
1.1       kleink     80:
1.13      matt       81:        /* Find top of stack.  */
                     82:        sp = (onstack ? (vaddr_t)ss->ss_sp + ss->ss_size : tf->fixreg[1]);
                     83:        sp &= ~(CALLFRAMELEN-1);
                     84:
                     85:        /* Allocate space for the ucontext.  */
                     86:        sp -= sizeof(ucontext_t);
                     87:        ucp = sp;
                     88:
                     89:        /* Allocate space for the siginfo.  */
                     90:        sp -= sizeof(siginfo_t);
                     91:        sip = sp;
                     92:
                     93:        sp &= ~(CALLFRAMELEN-1);
1.1       kleink     94:
                     95:        /* Save register context. */
1.13      matt       96:        uc.uc_flags = _UC_SIGMASK;
                     97:        uc.uc_sigmask = *mask;
                     98:        uc.uc_link = NULL;
                     99:        memset(&uc.uc_stack, 0, sizeof(uc.uc_stack));
                    100:        cpu_getmcontext(l, &uc.uc_mcontext, &uc.uc_flags);
1.1       kleink    101:
                    102:        /*
1.13      matt      103:         * Copy the siginfo and ucontext onto the user's stack.
1.1       kleink    104:         */
1.16      matt      105:        if (copyout(ksi, (caddr_t)sip, sizeof(*ksi)) != 0 ||
1.13      matt      106:            copyout(&uc, (caddr_t)ucp, sizeof(uc)) != 0) {
1.1       kleink    107:                /*
                    108:                 * Process has trashed its stack; give it an illegal
1.14      matt      109:                 * instruction to halt it in its tracks.
1.1       kleink    110:                 */
1.8       thorpej   111:                sigexit(l, SIGILL);
1.1       kleink    112:                /* NOTREACHED */
                    113:        }
                    114:
                    115:        /*
1.7       thorpej   116:         * Build context to run handler in.  Note the trampoline version
                    117:         * numbers are coordinated with machine-dependent code in libc.
1.1       kleink    118:         */
1.13      matt      119:        switch (sd->sd_vers) {
                    120:        case 2:         /* siginfo sigtramp */
1.14      matt      121:                tf->fixreg[1]  = (register_t)sp - CALLFRAMELEN;
1.17    ! matt      122:                tf->fixreg[3]  = (register_t)ksi->ksi_signo;
1.14      matt      123:                tf->fixreg[4]  = (register_t)sip;
                    124:                tf->fixreg[5]  = (register_t)ucp;
                    125:                /* Preserve ucp across call to signal function */
                    126:                tf->fixreg[30] = (register_t)ucp;
                    127:                tf->lr         = (register_t)sd->sd_tramp;
                    128:                tf->srr0       = (register_t)sd->sd_sigact.sa_handler;
1.7       thorpej   129:                break;
                    130:
                    131:        default:
1.14      matt      132:                goto nosupport;
1.7       thorpej   133:        }
1.1       kleink    134:
                    135:        /* Remember that we're now on the signal stack. */
                    136:        if (onstack)
1.13      matt      137:                ss->ss_flags |= SS_ONSTACK;
1.14      matt      138:        return;
                    139:
                    140:  nosupport:
                    141:        /* Don't know what trampoline version; kill it. */
                    142:        printf("sendsig_siginfo(sig %d): bad version %d\n",
1.17    ! matt      143:            ksi->ksi_signo, sd->sd_vers);
1.14      matt      144:        sigexit(l, SIGILL);
                    145:        /* NOTREACHED */
1.8       thorpej   146: }
                    147:
                    148: void
1.13      matt      149: cpu_getmcontext(struct lwp *l, mcontext_t *mcp, unsigned int *flagp)
1.8       thorpej   150: {
                    151:        const struct trapframe *tf = trapframe(l);
1.10      matt      152:        __greg_t *gr = mcp->__gregs;
1.8       thorpej   153: #ifdef PPC_HAVE_FPU
                    154:        struct pcb *pcb = &l->l_addr->u_pcb;
                    155: #endif
                    156:
                    157:        /* Save GPR context. */
1.10      matt      158:        (void)memcpy(gr, &tf->fixreg, 32 * sizeof (gr[0])); /* GR0-31 */
                    159:        gr[_REG_CR]  = tf->cr;
                    160:        gr[_REG_LR]  = tf->lr;
                    161:        gr[_REG_PC]  = tf->srr0;
                    162:        gr[_REG_MSR] = tf->srr1;
                    163:        gr[_REG_CTR] = tf->ctr;
                    164:        gr[_REG_XER] = tf->xer;
1.11      matt      165: #ifdef PPC_OEA
                    166:        gr[_REG_MQ]  = tf->tf_xtra[TF_MQ];
                    167: #else
                    168:        gr[_REG_MQ]  = 0;
                    169: #endif
1.8       thorpej   170:        *flagp |= _UC_CPU;
                    171:
                    172: #ifdef PPC_HAVE_FPU
                    173:        /* Save FPR context, if any. */
                    174:        if ((pcb->pcb_flags & PCB_FPU) != 0) {
                    175:                /* If we're the FPU owner, dump its context to the PCB first. */
                    176:                if (pcb->pcb_fpcpu)
                    177:                        save_fpu_lwp(l);
                    178:                (void)memcpy(mcp->__fpregs.__fpu_regs, pcb->pcb_fpu.fpr,
                    179:                    sizeof (mcp->__fpregs.__fpu_regs));
                    180:                mcp->__fpregs.__fpu_fpscr =
                    181:                    ((int *)&pcb->pcb_fpu.fpscr)[_QUAD_LOWWORD];
                    182:                mcp->__fpregs.__fpu_valid = 1;
                    183:                *flagp |= _UC_FPU;
                    184:        } else
                    185: #endif
1.13      matt      186:                memset(&mcp->__fpregs, 0, sizeof(mcp->__fpregs));
1.8       thorpej   187:
                    188:        /* No AltiVec support, for now. */
                    189:        memset(&mcp->__vrf, 0, sizeof (mcp->__vrf));
                    190: }
                    191:
                    192: int
1.13      matt      193: cpu_setmcontext(struct lwp *l, const mcontext_t *mcp, unsigned int flags)
1.8       thorpej   194: {
                    195:        struct trapframe *tf = trapframe(l);
1.10      matt      196:        __greg_t *gr = mcp->__gregs;
1.8       thorpej   197: #ifdef PPC_HAVE_FPU
                    198:        struct pcb *pcb = &l->l_addr->u_pcb;
                    199: #endif
                    200:
                    201:        /* Restore GPR context, if any. */
                    202:        if (flags & _UC_CPU) {
1.10      matt      203:                if ((gr[_REG_MSR] & PSL_USERSTATIC) !=
1.8       thorpej   204:                    (tf->srr1 & PSL_USERSTATIC))
                    205:                        return (EINVAL);
                    206:
1.10      matt      207:                (void)memcpy(&tf->fixreg, gr, 32 * sizeof (gr[0]));
                    208:                tf->cr   = gr[_REG_CR];
                    209:                tf->lr   = gr[_REG_LR];
                    210:                tf->srr0 = gr[_REG_PC];
                    211:                tf->srr1 = gr[_REG_MSR];
                    212:                tf->ctr  = gr[_REG_CTR];
                    213:                tf->xer  = gr[_REG_XER];
1.11      matt      214: #ifdef PPC_OEA
                    215:                tf->tf_xtra[TF_MQ] = gr[_REG_MQ];
                    216: #endif
1.8       thorpej   217:        }
                    218:
                    219: #ifdef PPC_HAVE_FPU
                    220:        /* Restore FPR context, if any. */
                    221:        if ((flags & _UC_FPU) && mcp->__fpregs.__fpu_valid != 0) {
                    222:                /* XXX we don't need to save the state, just to drop it */
                    223:                save_fpu_lwp(l);
                    224:                (void)memcpy(&pcb->pcb_fpu.fpr, &mcp->__fpregs.__fpu_regs,
                    225:                    sizeof (pcb->pcb_fpu.fpr));
                    226:                pcb->pcb_fpu.fpscr = *(double *)&mcp->__fpregs.__fpu_fpscr;
                    227:        }
                    228: #endif
                    229:
                    230:        return (0);
1.1       kleink    231: }

CVSweb <webmaster@jp.NetBSD.org>