Subversion Repositories tendra.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
/* This is intended for SGI IRIX 32-bit */
32
 
33
Common __TDFhandler:proc;
34
Common __mipshandler:proc;
35
Common __TDFstacklim:pointer(locals_alignment);
36
 
37
Tokdec ansi.signal.signal: [EXP, EXP]EXP;
38
Tokdec ansi.stdlib.exit: [EXP]EXP;
39
 
40
Tokdef SIGFPE = []SIGNED_NAT 8;
41
Tokdef SIGBUS = []SIGNED_NAT 10;
42
Tokdef SIGSEGV = []SIGNED_NAT 11;
43
Tokdef SIGUSR1 = []SIGNED_NAT 16;
44
	/* signal numbers - SIGUSR1 is used for stack overflow
45
	*/
46
 
47
Tokdec ~Throw:[NAT]EXP;
48
	/* This token must be defined to throw the language specific error
49
	value
50
	*/
51
 
52
Struct longptr(hi:Int, lo:Ptr proc);
53
 
54
Struct sigcontext(sc_onstack:Int, sc_mask:Int, 
55
		  sc_pc:longptr,
56
		  sc_regs:nof(32,longptr),
57
		  sc_fpregs:nof(32,longptr),
58
		  sc_ownedfp:Int,
59
		  sc_fpc_csr:Int, sc_fpc_eir:Int, 
60
		  sc_ssflags:Int,
61
		  sc_mdhi:longptr,
62
                  sc_mdlo:longptr,		  
63
		  sc_cause:longptr, 
64
		  sc_badvaddr:longptr
65
		  );
66
 
67
Tokdef SETREG = [scp:EXP, r:NAT, val:EXP]EXP
68
	{ ((scp *+. .sc_regs) *+. 
69
	     (.lo .+. (Sizeof(longptr) .* (+ r(Int)) ))  ) = val };
70
 
71
 
72
Tokdef CAUSE_BD = []SIGNED_NAT 16r80000000;
73
 
74
 
75
Tokdef ~Set_signal_handler = [] EXP 
76
{
77
/* This token must be called before any possible exceptions */
78
 
79
 Let mh =  Proc top(sig:Int, code:Int, scp:Ptr sigcontext) {
80
  /* This procedure is obeyed at an automatic error trap, using signal.
81
   It's action calls __TDFhandler on top of the user stack by overwriting
82
   the relevant registers of the failing process and simply returning.
83
   Could have written this in C.
84
  */
85
	((* scp *+. .sc_pc) *+. .lo) = * __TDFhandler; 
86
		/* the pc of the failing process */
87
	SETREG[* scp, 4, * sig];
88
		/* the first parameter */
89
	SETREG[* scp, 5, * code];
90
		/* the second parameter */
91
	SETREG[* scp, 25, * __TDFhandler];
92
		/* required for PIC code  */
93
	Let x = *(Int)(* scp *+. (.lo .+. .sc_cause))
94
	{ (* scp *+. (.lo .+. .sc_cause)) = (x And not(CAUSE_BD(Int))) 
95
		/* the exception could have occurred in a delay slot
96
		   - make sure the return does not treat it as one.
97
		*/	
98
	};
99
 
100
	return(make_top)
101
	/* reinstates the failing process ie does a call of __TDFhandler */
102
    }
103
 {
104
    __mipshandler = mh; 
105
    __TDFhandler = Proc top( sig:Int, code:Int)
106
   {
107
   /* This procedure may either be called via __mipshandler or else as a
108
   result of an explicit error test in the user program. It's action is to
109
   throw the language specific error coding. 
110
  */
111
 
112
   Labelled {
113
	Case * sig (SIGFPE -> overf, 
114
		    SIGBUS -> nilref1,
115
		    SIGSEGV -> nilref2,	
116
		    SIGUSR1 -> stackov)
117
	| :overf: 
118
		ansi.signal.signal[SIGFPE(Int), * __mipshandler];
119
		~Throw[error_val(overflow)]
120
	| :nilref1:
121
		ansi.signal.signal[SIGBUS(Int), * __mipshandler]; 
122
		~Throw[error_val(nil_access)]
123
	| :nilref2:
124
		ansi.signal.signal[SIGSEGV(Int), * __mipshandler]; 
125
		~Throw[error_val(nil_access)]
126
	| :stackov:
127
		ansi.signal.signal[SIGUSR1(Int), * __mipshandler]; 
128
		~Throw[error_val(stack_overflow)]
129
	/* other C signals can be treated similarly */
130
   };
131
   ansi.stdlib.exit[* sig];
132
   return(make_top);
133
  };
134
 
135
  ansi.signal.signal[SIGFPE(Int), * __mipshandler];
136
  ansi.signal.signal[SIGBUS(Int), * __mipshandler];
137
  ansi.signal.signal[SIGSEGV(Int), * __mipshandler];
138
  ansi.signal.signal[SIGUSR1(Int), * __mipshandler];
139
  env_size(mh) .+. (Sizeof(Char) .* 1000(Int))
140
 }
141
};
142
 
143
Tokdef ~Sync_handler = [] EXP make_top;
144
 
145
Keep (~Set_signal_handler, __TDFhandler, ~Sync_handler, __TDFstacklim)