Subversion Repositories tendra.SVN

Rev

Rev 7 | Details | Compare with Previous | 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 Dec ULTRIX */
32
Common __TDFhandler:proc;
33
Common __mipshandler:proc;
34
Common __TDFstacklim:pointer(locals_alignment);
35
 
36
Tokdef SIGFPE = []SIGNED_NAT 8;
37
Tokdef SIGBUS = []SIGNED_NAT 10;
38
Tokdef SIGSEGV = []SIGNED_NAT 11;
39
Tokdef SIGUSR1 = []SIGNED_NAT 30;
40
	/* signal numbers - SIGUSR1 is used for stack overflow
41
	*/
42
 
43
Tokdec ansi.signal.signal: [EXP, EXP]EXP;
44
Tokdec ansi.stdlib.exit: [EXP]EXP;
45
 
46
 
47
 
48
Tokdec ~Throw:[NAT]EXP;
49
	/* This token must be defined to throw the language specific error
50
	value
51
	*/
52
 
53
 
54
Struct sigcontext(sc_onstack:Int, sc_mask:Int, 
55
		  sc_pc:Int,
56
		  sc_regs:nof(32,Int),
57
		  sc_mdlo:Int,
58
                  sc_mdhi:Int,
59
		  sc_ownedfp:Int,
60
		  sc_fpregs:nof(32,Int),
61
		  sc_fpc_csr:Int, sc_fpc_eir:Int, 		  
62
		  sc_cause:Int, 
63
		  sc_badvaddr:Int
64
		  );
65
 
66
Tokdef SETREG = [scp:EXP, r:NAT, val:EXP]EXP
67
	{ ((scp *+. .sc_regs) *+. 
68
	     (Sizeof(Int) .* (+ r(Int)) )  ) = val };
69
 
70
 
71
Tokdef CAUSE_BD = []SIGNED_NAT 16r80000000;
72
 
73
 
74
Tokdef ~Set_signal_handler = [] EXP 
75
{
76
/* This token must be called before any possible exceptions */
77
 Let mh = Proc top(sig:Int, code:Int, scp:Ptr sigcontext) {
78
  /* This procedure is obeyed at an automatic error trap, using signal.
79
   It's action calls __TDFhandler on top of the user stack by overwriting
80
   the relevant registers of the failing process and simply returning.
81
   Could have written this in C.
82
  */
83
	(* scp *+. .sc_pc) = * __TDFhandler; 
84
		/* the pc of the failing process */
85
	SETREG[* scp, 4, * sig];
86
		/* the first parameter */
87
	SETREG[* scp, 5, * code];
88
		/* the second parameter */
89
	SETREG[* scp, 25, * __TDFhandler];
90
		/* required for PIC code  */
91
	Let x = *(Int)(* scp *+. .sc_cause)
92
	{ (* scp *+. .sc_cause) = (x And not(CAUSE_BD(Int))) 
93
		/* the exception could have occurred in a delay slot
94
		   - make sure the return does not treat it as one.
95
		*/	
96
	};
97
 
98
	return(make_top)
99
	/* reinstates the failing process ie does a call of __TDFhandler */
100
    }
101
 {  
102
    __mipshandler = mh;
103
    __TDFhandler = Proc top( sig:Int, code:Int)
104
   {
105
   /* This procedure may either be called via __mipshandler or else as a
106
   result of an explicit error test in the user program. It's action is to
107
   throw the language specific error coding. 
108
  */
109
 
110
   Labelled {
111
	Case * sig (SIGFPE -> overf, 
112
		    SIGBUS -> nilref1,
113
		    SIGSEGV -> nilref2,	
114
		    SIGUSR1 -> stackov)
115
	| :overf: 
116
		ansi.signal.signal[SIGFPE(Int), * __mipshandler];
117
		~Throw[error_val(overflow)]
118
	| :nilref1:
119
		ansi.signal.signal[SIGBUS(Int), * __mipshandler]; 
120
		~Throw[error_val(nil_access)]
121
	| :nilref2:
122
		ansi.signal.signal[SIGSEGV(Int), * __mipshandler]; 
123
		~Throw[error_val(nil_access)]
124
	| :stackov:
125
		ansi.signal.signal[SIGUSR1(Int), * __mipshandler]; 
126
		~Throw[error_val(stack_overflow)]
127
	/* other C signals can be treated similarly */
128
   };
129
   ansi.stdlib.exit[* sig];
130
   return(make_top);
131
  };
132
 
133
  ansi.signal.signal[SIGFPE(Int), * __mipshandler];
134
  ansi.signal.signal[SIGBUS(Int), * __mipshandler];
135
  ansi.signal.signal[SIGSEGV(Int), * __mipshandler];
136
  ansi.signal.signal[SIGUSR1(Int), * __mipshandler];
137
  env_size(mh) .+. (Sizeof(Char) .* 1000(Int))
138
 }
139
};
140
 
141
Tokdef ~Sync_handler = [] EXP make_top;
142
 
143
Keep (~Set_signal_handler, __TDFhandler, ~Sync_handler, __TDFstacklim)