2 |
7u83 |
1 |
/*
|
|
|
2 |
Copyright (c) 1993 Open Software Foundation, Inc.
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
All Rights Reserved
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
Permission to use, copy, modify, and distribute this software
|
|
|
9 |
and its documentation for any purpose and without fee is hereby
|
|
|
10 |
granted, provided that the above copyright notice appears in all
|
|
|
11 |
copies and that both the copyright notice and this permission
|
|
|
12 |
notice appear in supporting documentation.
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING
|
|
|
16 |
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
17 |
PARTICULAR PURPOSE.
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
|
|
|
21 |
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
22 |
LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
|
|
|
23 |
NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
24 |
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
25 |
*/
|
|
|
26 |
|
|
|
27 |
/*
|
|
|
28 |
Crown Copyright (c) 1997
|
|
|
29 |
|
|
|
30 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
31 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
32 |
acting through the Defence Evaluation and Research Agency
|
|
|
33 |
(DERA). It is made available to Recipients with a
|
|
|
34 |
royalty-free licence for its use, reproduction, transfer
|
|
|
35 |
to other parties and amendment for any purpose not excluding
|
|
|
36 |
product development provided that any such use et cetera
|
|
|
37 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
38 |
|
|
|
39 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
40 |
reproduced upon any copies or amended versions of it;
|
|
|
41 |
|
|
|
42 |
(2) Any amended version of it shall be clearly marked to
|
|
|
43 |
show both the nature of and the organisation responsible
|
|
|
44 |
for the relevant amendment or amendments;
|
|
|
45 |
|
|
|
46 |
(3) Its onward transfer from a recipient to another
|
|
|
47 |
party shall be deemed to be that party's acceptance of
|
|
|
48 |
these conditions;
|
|
|
49 |
|
|
|
50 |
(4) DERA gives no warranty or assurance as to its
|
|
|
51 |
quality or suitability for any purpose and DERA accepts
|
|
|
52 |
no liability whatsoever in relation to any use to which
|
|
|
53 |
it may be put.
|
|
|
54 |
*/
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
/**********************************************************************
|
|
|
59 |
$Author: release $
|
|
|
60 |
$Date: 1998/02/04 15:48:49 $
|
|
|
61 |
$Revision: 1.2 $
|
|
|
62 |
$Log: guard.c,v $
|
|
|
63 |
* Revision 1.2 1998/02/04 15:48:49 release
|
|
|
64 |
* Added OSF copyright message.
|
|
|
65 |
*
|
|
|
66 |
* Revision 1.1.1.1 1998/01/17 15:55:56 release
|
|
|
67 |
* First version to be checked into rolling release.
|
|
|
68 |
*
|
|
|
69 |
* Revision 1.2 1996/10/04 16:01:15 pwe
|
|
|
70 |
* add banners and mod for PWE ownership
|
|
|
71 |
*
|
|
|
72 |
**********************************************************************/
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
/****************************************************************
|
|
|
76 |
guard.c
|
|
|
77 |
|
|
|
78 |
These routines protect registers from future use. The type
|
|
|
79 |
involved is space which consists of two long ints with bit patterns
|
|
|
80 |
taken to represent usage of temporary fixed and floating
|
|
|
81 |
point registers. These bits are used in the procedure
|
|
|
82 |
getregs which understands a clear bit to mean that the corresponding
|
|
|
83 |
register is free for use.
|
|
|
84 |
The procedures are widely used in make_code which may use
|
|
|
85 |
getreg to choose a register to contain the result of an expression.
|
|
|
86 |
If this expression is the first operand of a binary operation (say) then the register
|
|
|
87 |
is guarded, producing another space which will be used by make_code for the
|
|
|
88 |
second operand.
|
|
|
89 |
|
|
|
90 |
******************************************************************/
|
|
|
91 |
|
|
|
92 |
#include "config.h"
|
|
|
93 |
#include "codegen.h"
|
|
|
94 |
|
|
|
95 |
#include "tempdecs.h" /* for tempdecopt */
|
|
|
96 |
#include "comment.h"
|
|
|
97 |
|
|
|
98 |
#include "guard.h"
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
/*******************************************************************
|
|
|
102 |
The integer parameter to procedures guardreg and guardfreg
|
|
|
103 |
is taken to be a register which needs to be protected. For floating point
|
|
|
104 |
registers a factor of 2 is involved. The corresponding bit in the appropriate field of the
|
|
|
105 |
space i.e fixed or float, is therefore set.
|
|
|
106 |
********************************************************************/
|
|
|
107 |
|
|
|
108 |
space guardreg PROTO_N ((r,sp)) PROTO_T (int r X space sp)
|
|
|
109 |
{
|
|
|
110 |
if (IS_TREG(r))
|
|
|
111 |
{
|
|
|
112 |
sp.fixed |= RMASK(r);
|
|
|
113 |
} /* set bit in the fixed field of sp */
|
|
|
114 |
return sp;
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
space guardfreg PROTO_N ((r,sp)) PROTO_T (int r X space sp)
|
|
|
118 |
{
|
|
|
119 |
if (IS_FLT_TREG(r)) /* r is a floating point t reg */
|
|
|
120 |
{
|
|
|
121 |
sp.flt |= RMASK(r);
|
|
|
122 |
} /* set bit in the flt field of sp */
|
|
|
123 |
return sp;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
/*
|
|
|
128 |
* needreg & needfreg are like guardreg & guardfreg,
|
|
|
129 |
* except it is an error if the reg is alread in use.
|
|
|
130 |
* Used, eg, when claiming regs that will be damaged, as in a call.
|
|
|
131 |
*/
|
|
|
132 |
|
|
|
133 |
space needreg PROTO_N ((r,sp)) PROTO_T (int r X space sp)
|
|
|
134 |
{
|
|
|
135 |
/* tempdec() can allocate t regs if dead over calls, so dont fail */
|
|
|
136 |
if (!(tempdecopt && IS_TREG(r)) && (sp.fixed&RMASK(r))!=0)
|
|
|
137 |
{
|
|
|
138 |
COMMENT1("needreg: %d", r);
|
|
|
139 |
fail("needreg: fixed reg already in use");
|
|
|
140 |
}
|
|
|
141 |
return guardreg(r, sp);
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
space needfreg PROTO_N ((r,sp)) PROTO_T (int r X space sp)
|
|
|
145 |
{
|
|
|
146 |
/* tempdec() can allocate t regs if dead over calls, so dont fail */
|
|
|
147 |
if (!(tempdecopt && IS_FLT_TREG(r)) && (sp.flt&RMASK(r))!=0)
|
|
|
148 |
{
|
|
|
149 |
COMMENT1("needfreg: %d", r);
|
|
|
150 |
fail("needfreg: float reg already in use");
|
|
|
151 |
}
|
|
|
152 |
return guardreg(r, sp);
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
/********************************************************************
|
|
|
157 |
The procedure guard may also protect a register involved in
|
|
|
158 |
addressing depending on the value of the parameter of type where. This is a
|
|
|
159 |
union of a fixpnt reg , a float reg and an instore value. In the latter case the
|
|
|
160 |
register involved in the addressing can be deduced from the base field of the
|
|
|
161 |
instore value. These types are defined in addresstypes.h.
|
|
|
162 |
*********************************************************************/
|
|
|
163 |
|
|
|
164 |
space guard PROTO_N ((w,sp)) PROTO_T (where w X space sp)
|
|
|
165 |
{
|
|
|
166 |
switch (w.answhere.discrim)
|
|
|
167 |
{
|
|
|
168 |
case inreg:
|
|
|
169 |
{
|
|
|
170 |
int r = regalt(w.answhere);
|
|
|
171 |
|
|
|
172 |
if (IS_TREG(r))
|
|
|
173 |
{
|
|
|
174 |
sp.fixed |= RMASK(r);
|
|
|
175 |
} /* guard reg */
|
|
|
176 |
return sp;
|
|
|
177 |
}
|
|
|
178 |
case infreg:
|
|
|
179 |
{
|
|
|
180 |
int r = fregalt(w.answhere).fr;
|
|
|
181 |
|
|
|
182 |
if (IS_FLT_TREG(r))
|
|
|
183 |
{
|
|
|
184 |
sp.flt |= RMASK(r);
|
|
|
185 |
} /* guard freg */
|
|
|
186 |
return sp;
|
|
|
187 |
}
|
|
|
188 |
case notinreg:
|
|
|
189 |
{
|
|
|
190 |
int r = insalt(w.answhere).b.base;
|
|
|
191 |
|
|
|
192 |
if (IS_TREG(r))
|
|
|
193 |
{
|
|
|
194 |
sp.fixed |= RMASK(r);
|
|
|
195 |
}
|
|
|
196 |
/* guard fixed point t reg used as base of address */
|
|
|
197 |
return sp;
|
|
|
198 |
}
|
|
|
199 |
case insomereg:
|
|
|
200 |
case insomefreg:
|
|
|
201 |
{
|
|
|
202 |
fail("guard: Guard ? reg");
|
|
|
203 |
return sp;
|
|
|
204 |
}
|
|
|
205 |
default:
|
|
|
206 |
{
|
|
|
207 |
fail("guard: not in switch");
|
|
|
208 |
return sp;
|
|
|
209 |
}
|
|
|
210 |
}
|
|
|
211 |
}
|