1*6790Srrh #
2*6790Srrh static char sccsid[] = "	dosig.c	1.1	82/05/12	";
3*6790Srrh 
4*6790Srrh /*	Handle signal trapping from version 6 or version 7 compatability
5*6790Srrh  *	mode programs.
6*6790Srrh  *	Art Wetzel	November 1979
7*6790Srrh  */
8*6790Srrh #ifdef TRACE
9*6790Srrh #include <stdio.h>
10*6790Srrh #endif
11*6790Srrh #include <signal.h>
12*6790Srrh #include "defs.h"
13*6790Srrh unsigned int  sigvals[NSIG+1];
14*6790Srrh /* actual catch point for all signals */
sigcatch(signum)15*6790Srrh sigcatch(signum) int signum; {
16*6790Srrh 	unsigned short *pcptr;
17*6790Srrh 	extern getregs();
18*6790Srrh 	if(incompat) {
19*6790Srrh 		/* hurry up and get the registers before they are destroyed */
20*6790Srrh 		getregs();
21*6790Srrh 	} else {
22*6790Srrh 		/* we were in native mode simulating a sys call */
23*6790Srrh 		/* set it up with the old values */
24*6790Srrh 		dosig(signum, pc);
25*6790Srrh 		/* go back where we were doing the sys call */
26*6790Srrh 		return(0);
27*6790Srrh 	}
28*6790Srrh 	/* figure out the pc */
29*6790Srrh 	pcptr = (unsigned short *)((char *)&pcptr + 20);
30*6790Srrh 	pc = (unsigned short *) *pcptr;
31*6790Srrh 	/* get the psl with condition codes */
32*6790Srrh 	/* requires UNIX-32V patch to not clear out condition codes */
33*6790Srrh 	psl = 0x83c00000 | (*(pcptr - 6) & 017);
34*6790Srrh 	/* actually do the thing */
35*6790Srrh 	if(sigvals[signum] != (unsigned int)SIG_DFL && (sigvals[signum] & (unsigned int)SIG_IGN) == 0)
36*6790Srrh 		dosig(signum, pc);
37*6790Srrh 	/* go back to compatability mode and the signal routine there */
38*6790Srrh 	incompat++;
39*6790Srrh 	compat();
40*6790Srrh }
41*6790Srrh /* routine to set up pdp11 space for return from a signal */
dosig(signum,from)42*6790Srrh dosig(signum, from) {
43*6790Srrh 	unsigned short *sp;
44*6790Srrh #ifdef TRACE
45*6790Srrh 	fprintf(stderr,"Caught sig %d from 0%o -> 0%o\n",signum,(pc-1),*(pc-1));
46*6790Srrh #endif
47*6790Srrh 	/* where is the stack */
48*6790Srrh 	sp = (unsigned short *)regs[6];
49*6790Srrh 	/* stack up psw condition codes so rti works */
50*6790Srrh 	*(--sp) = psl & 017;
51*6790Srrh 	/* stack pc */
52*6790Srrh 	*(--sp) = (unsigned short)(int)pc;
53*6790Srrh 	/* reset stack pointer */
54*6790Srrh 	regs[6] = (unsigned short)(int)sp;
55*6790Srrh 	/* reset pc to signal catching routine */
56*6790Srrh 	pc = (unsigned short *)sigvals[signum];
57*6790Srrh }
58