1 /* $NetBSD: compat_13_machdep.c,v 1.8 2000/12/22 22:58:55 jdolecek Exp $ */ 2 3 /* 4 * Copyright 1996 The Board of Trustees of The Leland Stanford 5 * Junior University. All Rights Reserved. 6 * 7 * Permission to use, copy, modify, and distribute this 8 * software and its documentation for any purpose and without 9 * fee is hereby granted, provided that the above copyright 10 * notice appear in all copies. Stanford University 11 * makes no representations about the suitability of this 12 * software for any purpose. It is provided "as is" without 13 * express or implied warranty. 14 */ 15 16 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 17 18 __KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.8 2000/12/22 22:58:55 jdolecek Exp $"); 19 20 #include <sys/param.h> 21 #include <sys/systm.h> 22 #include <sys/signalvar.h> 23 #include <sys/kernel.h> 24 #include <sys/proc.h> 25 #include <sys/user.h> 26 #include <sys/mount.h> 27 #include <sys/syscallargs.h> 28 29 #include <mips/regnum.h> 30 31 #ifdef DEBUG 32 extern int sigdebug; 33 /* XXX defined in mips_machdep.c */ 34 #define SDB_FOLLOW 0x01 35 #define SDB_KSTACK 0x02 36 #define SDB_FPSTATE 0x04 37 #endif 38 39 int 40 compat_13_sys_sigreturn(p, v, retval) 41 struct proc *p; 42 void *v; 43 register_t *retval; 44 { 45 struct compat_13_sys_sigreturn_args /* { 46 syscallarg(struct sigcontext13 *) sigcntxp; 47 } */ *uap = v; 48 struct sigcontext13 *scp, ksc; 49 int error; 50 struct frame *f; 51 sigset_t mask; 52 53 /* 54 * The trampoline code hands us the context. 55 * It is unsafe to keep track of it ourselves, in the event that a 56 * program jumps out of a signal handler. 57 */ 58 scp = SCARG(uap, sigcntxp); 59 #ifdef DEBUG 60 if (sigdebug & SDB_FOLLOW) 61 printf("sigreturn13: pid %d, scp %p\n", p->p_pid, scp); 62 #endif 63 if ((error = copyin(scp, &ksc, sizeof(ksc))) != 0) 64 return (error); 65 66 if ((int)ksc.sc_regs[ZERO] != 0xACEDBADE) /* magic number */ 67 return (EINVAL); 68 69 /* Resture the register context. */ 70 f = (struct frame *)p->p_md.md_regs; 71 f->f_regs[PC] = ksc.sc_pc; 72 f->f_regs[MULLO] = ksc.mullo; 73 f->f_regs[MULHI] = ksc.mulhi; 74 memcpy(&f->f_regs[1], &scp->sc_regs[1], 75 sizeof(scp->sc_regs) - sizeof(scp->sc_regs[0])); 76 if (scp->sc_fpused) 77 p->p_addr->u_pcb.pcb_fpregs = *(struct fpreg *)scp->sc_fpregs; 78 79 /* Restore signal stack. */ 80 if (ksc.sc_onstack & SS_ONSTACK) 81 p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK; 82 else 83 p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK; 84 85 /* Restore signal mask. */ 86 native_sigset13_to_sigset(&ksc.sc_mask, &mask); 87 (void) sigprocmask1(p, SIG_SETMASK, &mask, 0); 88 89 return (EJUSTRETURN); 90 } 91