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