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
	/*	Spec Token Definitions for trans386		*/
32
	/*	Needs to be linked with posix library		*/
33
	/*	specific to each platform.			*/
34
	/*							*/
35
	/* **************************************************** */
36
 
37
 
38
Tokdec ~Throw : [NAT] EXP;
39
 
40
Tokdec ansi.stdlib.abort : [] EXP;
41
Tokdec ansi.signal.SIGFPE : [] EXP;
42
Tokdec ansi.signal.SIGSEGV : [] EXP;
43
Tokdec posix.signal.SIG_SETMASK : [] EXP;
44
Tokdec posix.signal.sigaction : [EXP, EXP, EXP] EXP;
45
Tokdec posix.signal.sigemptyset : [EXP] EXP;
46
Tokdec posix.signal.sigset_t : [] SHAPE;
47
Tokdec posix.signal.struct_sigaction : [] SHAPE;
48
Tokdec posix.signal.sigaction.sa_handler : [] EXP;
49
Tokdec posix.signal.sigaction.sa_mask : [] EXP;
50
Tokdec posix.signal.sigaction.sa_flags : [] EXP;
51
Tokdec posix.signal.sigprocmask : [EXP, EXP, EXP] EXP;
52
 
53
 
54
Iddec __trans386_special : proc;	/* special interface to trans386 */
55
 
56
Common __trans386_stack_limit : pointer (locals_alignment)
57
		= make_null_ptr (locals_alignment);
58
 
59
 
60
Common __trans386_errhandler : proc;
61
	/* Initialised by ~Set_signal_handler */
62
	/* called from numerical exception interrupt or from translated code */
63
 
64
Var allsigs : posix.signal.sigset_t;
65
 
66
 
67
Tokdef ~Set_signal_handler = [] EXP
68
	/* must be called before any possible exceptions */
69
 
70
Let ovhandler = Proc bottom (sig : Int)
71
  {
72
    __trans386_special [top](2(Int));	/* fclex to clear interrupt */
73
    posix.signal.sigprocmask [posix.signal.SIG_SETMASK, allsigs,
74
		make_null_ptr (alignment (posix.signal.sigset_t)) ];
75
    (* __trans386_errhandler) [bottom] (+ error_val(overflow)(Int));
76
  }
77
 
78
Let nilaccess_handler = Proc bottom (sig : Int)
79
  {
80
    posix.signal.sigprocmask [posix.signal.SIG_SETMASK, allsigs,
81
		make_null_ptr (alignment (posix.signal.sigset_t)) ];
82
    (* __trans386_errhandler) [bottom] (+ error_val(nil_access)(Int));
83
  }
84
 
85
Let errhandler = Proc bottom (err : Int)
86
{	/* called from numerical or nilaccess exception interrupt,
87
	   or from translated code */
88
  __trans386_special [top](1(Int));	/* finit for known state before ~Throw */
89
  ?{	? (* err == + error_val(overflow)(Int));
90
	~Throw[error_val(overflow)];
91
	ansi.stdlib.abort ;
92
  | ?{	? (* err == + error_val(stack_overflow)(Int));
93
	~Throw[error_val(stack_overflow)];
94
	ansi.stdlib.abort ;
95
    |	~Throw[error_val(nil_access)];
96
	ansi.stdlib.abort ;
97
  } }
98
}
99
 
100
Var sigact : posix.signal.struct_sigaction
101
 
102
{		/* main body of ~Set_signal_handler */
103
  __trans386_errhandler = errhandler;
104
  posix.signal.sigemptyset [allsigs];
105
  posix.signal.sigemptyset [sigact *+. posix.signal.sigaction.sa_mask];
106
  (sigact *+. posix.signal.sigaction.sa_flags) = 0(Int);
107
  (sigact *+. posix.signal.sigaction.sa_handler) = ovhandler;
108
  posix.signal.sigaction [ ansi.signal.SIGFPE, sigact, 
109
		make_null_ptr (alignment (posix.signal.struct_sigaction)) ];
110
  (sigact *+. posix.signal.sigaction.sa_handler) = nilaccess_handler;
111
  posix.signal.sigaction [ ansi.signal.SIGSEGV, sigact, 
112
		make_null_ptr (alignment (posix.signal.struct_sigaction)) ];
113
  env_size (errhandler)
114
};
115
 
116
 
117
Tokdef ~Sync_handler = [] EXP
118
	/* must be called prior to any action that modifies ~Trap handling */
119
{
120
  __trans386_special [top](0(Int));	/* fwait */
121
};
122
 
123
 
124
Keep (~Set_signal_handler, ~Sync_handler, 
125
	__trans386_errhandler, __trans386_stack_limit)