Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

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