Subversion Repositories tendra.SVN

Rev

Rev 6 | 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 module gives the MIPS specific error handling, using C signals
32
   where possible. Particular language implementations must provide
33
   definitions of the tokens Throw and Convert_stndard_error as well as
34
   ensuring that SET_SIGNAL_HANDLER is called before any possible
35
   exceptions. MAKE_STACK_LIMIT[n] makes a limit of the stack.
36
*/
37
 
38
Iddec signal:proc;
39
Iddec exit:proc;
40
Iddec __mipshandler:proc;
41
 
42
Tokdec Throw:[EXP]EXP;
43
	/* This token must be defined to throw the language specific error
44
	value
45
	*/
46
Tokdec Convert_standard_error: [NAT]EXP;
47
	/* This token must be defined to convert TDF ERROR_CODEs to their
48
	   language specific error values */
49
 
50
Var __TDFstacklim:pointer(alignment(Char));
51
	/* will contain the stack limit set up by set_stack_limit */
52
 
53
Tokdec SIGFPE:[]SIGNED_NAT;
54
Tokdec SIGBUS:[]SIGNED_NAT;
55
Tokdec SIGSEGV:[]SIGNED_NAT;
56
Tokdec SIGUSR1:[]SIGNED_NAT;
57
	/* Standard C signal numbers - SIGUSR1 is used for stack overflow
58
	*/
59
 
60
 
61
Proc __TDFhandler = top( sig:Int, code:Int)
62
{
63
/* This procedure may either be called via __mipshandler or else as a
64
   result of an explicit error test in the user program. It's action is to
65
   throw the language specific error coding. 
66
   NB. there always must be enough space to run it on the stack - the offset
67
   of this space can be found by env_size(__TDFhandler)
68
*/
69
 
70
   Labelled {
71
	Case * sig (SIGFPE -> overf, SIGBUS -> nilref1, SIGSEGV -> nilref2,	
72
			SIGUSR1 -> stackov)
73
	| :overf: 
74
		signal[top](SIGFPE(Int), __mipshandler);
75
		Throw[Convert_standard_error[error_val(overflow)]]
76
	| :nilref1:
77
		signal[top](SIGBUS(Int), __mipshandler); 
78
		Throw[Convert_standard_error[error_val(nil_access)]]
79
	| :nilref2:
80
		signal[top](SIGSEGV(Int), __mipshandler); 
81
		Throw[Convert_standard_error[error_val(nil_access)]]
82
	| :stackov:
83
		signal[top](SIGUSR1(Int), __mipshandler); 
84
		Throw[Convert_standard_error[error_val(stack_overflow)]]
85
	/* other C signals can be treated similarly */
86
   };
87
   exit[bottom](* sig)
88
};
89
 
90
 
91
 
92
 
93
Tokdef MAKE_STACK_LIMIT = [s:EXP]EXP
94
	/* sets the stack limit to be s bytes on top of current stack */
95
	make_stack_limit(current_env,
96
	         env_size(__TDFhandler) .+. s, 
97
		offset_zero(alloca_alignment));
98
 
99
 
100
Tokdef SET_SIGNAL_HANDLER = [] EXP 
101
{
102
/* This token must be called before any possible exceptions */
103
	signal[top](SIGFPE(Int), __mipshandler);
104
	signal[top](SIGBUS(Int), __mipshandler);
105
	signal[top](SIGSEGV(Int), __mipshandler);
106
	signal[top](SIGUSR1(Int), __mipshandler);
107
};
108
 
109
Keep(__TDFhandler, SET_SIGNAL_HANDLER, __TDFstacklim, MAKE_STACK_LIMIT  )