Annotation of src/sys/arch/powerpc/powerpc/sig_machdep.c, Revision 1.36
1.36 ! rmind 1: /* $NetBSD: sig_machdep.c,v 1.35 2009/11/21 17:40:29 rmind 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.36 ! rmind 35: __KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.35 2009/11/21 17:40:29 rmind Exp $");
1.2 tsubai 36:
1.8 thorpej 37: #include "opt_ppcarch.h"
1.22 matt 38: #include "opt_altivec.h"
1.1 kleink 39:
40: #include <sys/param.h>
41: #include <sys/mount.h>
42: #include <sys/proc.h>
43: #include <sys/syscallargs.h>
44: #include <sys/systm.h>
1.8 thorpej 45: #include <sys/ucontext.h>
1.1 kleink 46:
1.36 ! rmind 47: #include <uvm/uvm_extern.h>
! 48:
1.22 matt 49: #include <powerpc/fpu.h>
50: #include <powerpc/altivec.h>
1.8 thorpej 51:
1.1 kleink 52: /*
53: * Send a signal to process.
54: */
55: void
1.34 he 56: sendsig_siginfo(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);
1.27 ad 61: struct sigaltstack *ss = &l->l_sigstk;
1.13 matt 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.27 ad 66: int onstack, error;
1.1 kleink 67:
68: /* Do we need to jump onto the signal stack? */
1.13 matt 69: onstack = (ss->ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
70: (sd->sd_sigact.sa_flags & SA_ONSTACK) != 0;
1.1 kleink 71:
1.13 matt 72: /* Find top of stack. */
73: sp = (onstack ? (vaddr_t)ss->ss_sp + ss->ss_size : tf->fixreg[1]);
74: sp &= ~(CALLFRAMELEN-1);
75:
76: /* Allocate space for the ucontext. */
77: sp -= sizeof(ucontext_t);
78: ucp = sp;
79:
80: /* Allocate space for the siginfo. */
81: sp -= sizeof(siginfo_t);
82: sip = sp;
83:
84: sp &= ~(CALLFRAMELEN-1);
1.1 kleink 85:
86: /* Save register context. */
1.13 matt 87: uc.uc_flags = _UC_SIGMASK;
88: uc.uc_sigmask = *mask;
1.30 pooka 89: uc.uc_link = l->l_ctxlink;
1.13 matt 90: memset(&uc.uc_stack, 0, sizeof(uc.uc_stack));
1.27 ad 91: sendsig_reset(l, ksi->ksi_signo);
1.32 ad 92: mutex_exit(p->p_lock);
1.13 matt 93: cpu_getmcontext(l, &uc.uc_mcontext, &uc.uc_flags);
1.1 kleink 94:
95: /*
1.13 matt 96: * Copy the siginfo and ucontext onto the user's stack.
1.1 kleink 97: */
1.29 christos 98: error = (copyout(&ksi->ksi_info, (void *)sip, sizeof(ksi->ksi_info)) != 0 ||
99: copyout(&uc, (void *)ucp, sizeof(uc)) != 0);
1.32 ad 100: mutex_enter(p->p_lock);
1.27 ad 101:
102: if (error) {
1.1 kleink 103: /*
104: * Process has trashed its stack; give it an illegal
1.14 matt 105: * instruction to halt it in its tracks.
1.1 kleink 106: */
1.8 thorpej 107: sigexit(l, SIGILL);
1.1 kleink 108: /* NOTREACHED */
109: }
110:
111: /*
1.7 thorpej 112: * Build context to run handler in. Note the trampoline version
113: * numbers are coordinated with machine-dependent code in libc.
1.1 kleink 114: */
1.13 matt 115: switch (sd->sd_vers) {
116: case 2: /* siginfo sigtramp */
1.14 matt 117: tf->fixreg[1] = (register_t)sp - CALLFRAMELEN;
1.17 matt 118: tf->fixreg[3] = (register_t)ksi->ksi_signo;
1.14 matt 119: tf->fixreg[4] = (register_t)sip;
120: tf->fixreg[5] = (register_t)ucp;
121: /* Preserve ucp across call to signal function */
122: tf->fixreg[30] = (register_t)ucp;
123: tf->lr = (register_t)sd->sd_tramp;
124: tf->srr0 = (register_t)sd->sd_sigact.sa_handler;
1.7 thorpej 125: break;
126:
127: default:
1.14 matt 128: goto nosupport;
1.7 thorpej 129: }
1.1 kleink 130:
131: /* Remember that we're now on the signal stack. */
132: if (onstack)
1.13 matt 133: ss->ss_flags |= SS_ONSTACK;
1.14 matt 134: return;
135:
136: nosupport:
137: /* Don't know what trampoline version; kill it. */
138: printf("sendsig_siginfo(sig %d): bad version %d\n",
1.17 matt 139: ksi->ksi_signo, sd->sd_vers);
1.14 matt 140: sigexit(l, SIGILL);
141: /* NOTREACHED */
1.8 thorpej 142: }
143:
144: void
1.13 matt 145: cpu_getmcontext(struct lwp *l, mcontext_t *mcp, unsigned int *flagp)
1.8 thorpej 146: {
147: const struct trapframe *tf = trapframe(l);
1.10 matt 148: __greg_t *gr = mcp->__gregs;
1.22 matt 149: #if defined(PPC_HAVE_FPU) || defined(ALTIVEC)
1.35 rmind 150: struct pcb *pcb = lwp_getpcb(l);
1.8 thorpej 151: #endif
152:
153: /* Save GPR context. */
1.10 matt 154: (void)memcpy(gr, &tf->fixreg, 32 * sizeof (gr[0])); /* GR0-31 */
155: gr[_REG_CR] = tf->cr;
156: gr[_REG_LR] = tf->lr;
157: gr[_REG_PC] = tf->srr0;
1.22 matt 158: gr[_REG_MSR] = tf->srr1 & PSL_USERSRR1;
1.21 matt 159: #ifdef PPC_HAVE_FPU
160: gr[_REG_MSR] |= pcb->pcb_flags & (PCB_FE0|PCB_FE1);
161: #endif
1.22 matt 162: #ifdef ALTIVEC
163: gr[_REG_MSR] |= pcb->pcb_flags & PCB_ALTIVEC ? PSL_VEC : 0;
164: #endif
1.10 matt 165: gr[_REG_CTR] = tf->ctr;
166: gr[_REG_XER] = tf->xer;
1.11 matt 167: #ifdef PPC_OEA
168: gr[_REG_MQ] = tf->tf_xtra[TF_MQ];
169: #else
170: gr[_REG_MQ] = 0;
171: #endif
1.8 thorpej 172: *flagp |= _UC_CPU;
173:
174: #ifdef PPC_HAVE_FPU
175: /* Save FPR context, if any. */
176: if ((pcb->pcb_flags & PCB_FPU) != 0) {
177: /* If we're the FPU owner, dump its context to the PCB first. */
178: if (pcb->pcb_fpcpu)
1.23 matt 179: save_fpu_lwp(l, FPU_SAVE);
180: (void)memcpy(mcp->__fpregs.__fpu_regs, pcb->pcb_fpu.fpreg,
1.8 thorpej 181: sizeof (mcp->__fpregs.__fpu_regs));
182: mcp->__fpregs.__fpu_fpscr =
183: ((int *)&pcb->pcb_fpu.fpscr)[_QUAD_LOWWORD];
184: mcp->__fpregs.__fpu_valid = 1;
185: *flagp |= _UC_FPU;
186: } else
187: #endif
1.13 matt 188: memset(&mcp->__fpregs, 0, sizeof(mcp->__fpregs));
1.8 thorpej 189:
1.22 matt 190: #ifdef ALTIVEC
191: /* Save AltiVec context, if any. */
192: if ((pcb->pcb_flags & PCB_ALTIVEC) != 0) {
193: /*
194: * If we're the AltiVec owner, dump its context
195: * to the PCB first.
196: */
197: if (pcb->pcb_veccpu)
1.23 matt 198: save_vec_lwp(l, ALTIVEC_SAVE);
1.22 matt 199: (void)memcpy(mcp->__vrf.__vrs, pcb->pcb_vr.vreg,
200: sizeof (mcp->__vrf.__vrs));
201: mcp->__vrf.__vscr = pcb->pcb_vr.vscr;
202: mcp->__vrf.__vrsave = pcb->pcb_vr.vrsave;
203: *flagp |= _UC_POWERPC_VEC;
204: } else
205: #endif
206: memset(&mcp->__vrf, 0, sizeof (mcp->__vrf));
1.8 thorpej 207: }
208:
209: int
1.13 matt 210: cpu_setmcontext(struct lwp *l, const mcontext_t *mcp, unsigned int flags)
1.8 thorpej 211: {
212: struct trapframe *tf = trapframe(l);
1.26 he 213: const __greg_t *gr = mcp->__gregs;
1.8 thorpej 214: #ifdef PPC_HAVE_FPU
1.35 rmind 215: struct pcb *pcb = lwp_getpcb(l);
1.8 thorpej 216: #endif
217:
218: /* Restore GPR context, if any. */
219: if (flags & _UC_CPU) {
1.21 matt 220: #ifdef PPC_HAVE_FPU
221: /*
222: * Always save the FP exception mode in the PCB.
223: */
224: pcb->pcb_flags &= ~(PCB_FE0|PCB_FE1);
225: pcb->pcb_flags |= gr[_REG_MSR] & (PCB_FE0|PCB_FE1);
226: #endif
227:
1.10 matt 228: (void)memcpy(&tf->fixreg, gr, 32 * sizeof (gr[0]));
229: tf->cr = gr[_REG_CR];
230: tf->lr = gr[_REG_LR];
231: tf->srr0 = gr[_REG_PC];
1.26 he 232: /*
233: * Accept all user-settable bits without complaint;
234: * userland should not need to know the machine-specific
235: * MSR value.
236: */
237: tf->srr1 = (gr[_REG_MSR] & PSL_USERMOD) | PSL_USERSET;
1.10 matt 238: tf->ctr = gr[_REG_CTR];
239: tf->xer = gr[_REG_XER];
1.11 matt 240: #ifdef PPC_OEA
241: tf->tf_xtra[TF_MQ] = gr[_REG_MQ];
242: #endif
1.8 thorpej 243: }
244:
1.22 matt 245: #ifdef PPC_HAVE_FPU /* Restore FPR context, if any. */
1.8 thorpej 246: if ((flags & _UC_FPU) && mcp->__fpregs.__fpu_valid != 0) {
1.23 matt 247: /* we don't need to save the state, just drop it */
248: save_fpu_lwp(l, FPU_DISCARD);
249: (void)memcpy(&pcb->pcb_fpu.fpreg, &mcp->__fpregs.__fpu_regs,
250: sizeof (pcb->pcb_fpu.fpreg));
1.20 matt 251: ((int *)&pcb->pcb_fpu.fpscr)[_QUAD_LOWWORD] =
252: mcp->__fpregs.__fpu_fpscr;
1.8 thorpej 253: }
254: #endif
255:
1.22 matt 256: #ifdef ALTIVEC
257: /* Restore AltiVec context, if any. */
258: if (flags & _UC_POWERPC_VEC) {
1.23 matt 259: /* we don't need to save the state, just drop it */
260: save_vec_lwp(l, ALTIVEC_DISCARD);
1.22 matt 261: (void)memcpy(pcb->pcb_vr.vreg, &mcp->__vrf.__vrs,
262: sizeof (pcb->pcb_vr.vreg));
263: pcb->pcb_vr.vscr = mcp->__vrf.__vscr;
264: pcb->pcb_vr.vrsave = mcp->__vrf.__vrsave;
265: }
266: #endif
267:
1.8 thorpej 268: return (0);
1.1 kleink 269: }
CVSweb <webmaster@jp.NetBSD.org>