1*16442Smckusick #ifndef lint
2*16442Smckusick static char sccsid[] = "@(#)dosig.c 4.3 84/05/05";
3*16442Smckusick #endif
46798Srrh
5*16442Smckusick /* From Lou Salkind: compat/RCS/dosig.c,v 1.2 84/01/31 13:34:17 */
6*16442Smckusick
714309Ssam /*
814309Ssam * Handle signal trapping from version 6 or
914309Ssam * version 7 compatability mode programs.
106798Srrh * Art Wetzel November 1979
116798Srrh */
1214309Ssam
136798Srrh #ifdef TRACE
146798Srrh #include <stdio.h>
156798Srrh #endif
166798Srrh #include <signal.h>
176798Srrh #include "defs.h"
1814309Ssam
19*16442Smckusick int sigtrapped;
206798Srrh unsigned int sigvals[NSIG+1];
2114309Ssam
226798Srrh /* actual catch point for all signals */
sigcatch(signum,faultcode,scp)2314309Ssam sigcatch(signum, faultcode, scp)
2414309Ssam int signum, faultcode;
2514309Ssam struct sigcontext *scp;
266798Srrh {
276798Srrh unsigned short *pcptr;
286798Srrh extern getregs();
296798Srrh if(incompat) {
306798Srrh /* hurry up and get the registers before they are destroyed */
316798Srrh getregs();
326798Srrh } else {
336798Srrh /* we were in native mode simulating a sys call */
346798Srrh /* set it up with the old values */
356798Srrh dosig(signum, pc);
366798Srrh /* go back where we were doing the sys call */
376798Srrh return(0);
386798Srrh }
396798Srrh /* figure out the pc */
4014309Ssam pcptr = (unsigned short *) &scp->sc_pc;
416798Srrh pc = (unsigned short *) *pcptr;
426798Srrh /* get the psl with condition codes */
4314309Ssam psl = 0x83c00000 | (scp->sc_ps & 017);
446798Srrh /* actually do the thing */
4514309Ssam if (sigvals[signum] != (unsigned int)SIG_DFL &&
4614309Ssam (sigvals[signum] & (unsigned int)SIG_IGN) == 0)
476798Srrh dosig(signum, pc);
486798Srrh /* go back to compatability mode and the signal routine there */
4914309Ssam sigsetmask(scp->sc_mask);
506798Srrh incompat++;
516798Srrh compat();
526798Srrh }
5314309Ssam
546798Srrh /* routine to set up pdp11 space for return from a signal */
dosig(signum,from)5514309Ssam dosig(signum, from)
5614309Ssam int signum, from;
5714309Ssam {
586798Srrh unsigned short *sp;
5914309Ssam
606798Srrh #ifdef TRACE
616798Srrh fprintf(stderr,"Caught sig %d from 0%o -> 0%o\n",signum,(pc-1),*(pc-1));
626798Srrh #endif
63*16442Smckusick sigtrapped = 1;
646798Srrh /* where is the stack */
656798Srrh sp = (unsigned short *)regs[6];
666798Srrh /* stack up psw condition codes so rti works */
676798Srrh *(--sp) = psl & 017;
686798Srrh /* stack pc */
696798Srrh *(--sp) = (unsigned short)(int)pc;
706798Srrh /* reset stack pointer */
716798Srrh regs[6] = (unsigned short)(int)sp;
726798Srrh /* reset pc to signal catching routine */
736798Srrh pc = (unsigned short *)sigvals[signum];
74*16442Smckusick /* signal(signum, SIG_DFL); */
756798Srrh }
76