xref: /csrg-svn/old/games.vax/compat/dosig.c (revision 14309)
1*14309Ssam static char sccsid[] = "@(#)dosig.c	4.2  83/07/31";
26798Srrh 
3*14309Ssam /*
4*14309Ssam  * Handle signal trapping from version 6 or
5*14309Ssam  * version 7 compatability mode programs.
66798Srrh  *	Art Wetzel	November 1979
76798Srrh  */
8*14309Ssam 
96798Srrh #ifdef TRACE
106798Srrh #include <stdio.h>
116798Srrh #endif
126798Srrh #include <signal.h>
136798Srrh #include "defs.h"
14*14309Ssam 
156798Srrh unsigned int  sigvals[NSIG+1];
16*14309Ssam 
176798Srrh /* actual catch point for all signals */
18*14309Ssam sigcatch(signum, faultcode, scp)
19*14309Ssam 	int signum, faultcode;
20*14309Ssam 	struct sigcontext *scp;
216798Srrh {
226798Srrh 	unsigned short *pcptr;
236798Srrh 	extern getregs();
246798Srrh 	if(incompat) {
256798Srrh 		/* hurry up and get the registers before they are destroyed */
266798Srrh 		getregs();
276798Srrh 	} else {
286798Srrh 		/* we were in native mode simulating a sys call */
296798Srrh 		/* set it up with the old values */
306798Srrh 		dosig(signum, pc);
316798Srrh 		/* go back where we were doing the sys call */
326798Srrh 		return(0);
336798Srrh 	}
346798Srrh 	/* figure out the pc */
35*14309Ssam 	pcptr = (unsigned short *) &scp->sc_pc;
366798Srrh 	pc = (unsigned short *) *pcptr;
376798Srrh 	/* get the psl with condition codes */
38*14309Ssam 	psl = 0x83c00000 | (scp->sc_ps & 017);
396798Srrh 	/* actually do the thing */
40*14309Ssam 	if (sigvals[signum] != (unsigned int)SIG_DFL &&
41*14309Ssam 	    (sigvals[signum] & (unsigned int)SIG_IGN) == 0)
426798Srrh 		dosig(signum, pc);
436798Srrh 	/* go back to compatability mode and the signal routine there */
44*14309Ssam 	sigsetmask(scp->sc_mask);
456798Srrh 	incompat++;
466798Srrh 	compat();
476798Srrh }
48*14309Ssam 
496798Srrh /* routine to set up pdp11 space for return from a signal */
50*14309Ssam dosig(signum, from)
51*14309Ssam 	int signum, from;
52*14309Ssam {
536798Srrh 	unsigned short *sp;
54*14309Ssam 
556798Srrh #ifdef TRACE
566798Srrh 	fprintf(stderr,"Caught sig %d from 0%o -> 0%o\n",signum,(pc-1),*(pc-1));
576798Srrh #endif
586798Srrh 	/* where is the stack */
596798Srrh 	sp = (unsigned short *)regs[6];
606798Srrh 	/* stack up psw condition codes so rti works */
616798Srrh 	*(--sp) = psl & 017;
626798Srrh 	/* stack pc */
636798Srrh 	*(--sp) = (unsigned short)(int)pc;
646798Srrh 	/* reset stack pointer */
656798Srrh 	regs[6] = (unsigned short)(int)sp;
666798Srrh 	/* reset pc to signal catching routine */
676798Srrh 	pc = (unsigned short *)sigvals[signum];
68*14309Ssam 	signal(signum, SIG_DFL);
696798Srrh }
70