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
 
30
 
31
/*
32
$Log: guard.c,v $
33
 * Revision 1.1.1.1  1998/01/17  15:56:02  release
34
 * First version to be checked into rolling release.
35
 *
36
 * Revision 1.2  1995/12/18  13:11:26  wfs
37
 * Put hppatrans uder cvs control. Major Changes made since last release
38
 * include:
39
 * (i) PIC code generation.
40
 * (ii) Profiling.
41
 * (iii) Dynamic Initialization.
42
 * (iv) Debugging of Exception Handling and Diagnostics.
43
 *
44
 * Revision 5.0  1995/08/25  13:42:58  wfs
45
 * Preperation for August 25 Glue release
46
 *
47
 * Revision 3.4  1995/08/25  09:31:40  wfs
48
 * *** empty log message ***
49
 *
50
 * Revision 3.4  1995/08/25  09:31:40  wfs
51
 * *** empty log message ***
52
 *
53
 * Revision 3.1  95/04/10  16:26:36  16:26:36  wfs (William Simmonds)
54
 * Apr95 tape version.
55
 * 
56
 * Revision 3.0  95/03/30  11:17:16  11:17:16  wfs (William Simmonds)
57
 * Mar95 tape version with CRCR95_178 bug fix.
58
 * 
59
 * Revision 2.0  95/03/15  15:27:04  15:27:04  wfs (William Simmonds)
60
 * spec 3.1 changes implemented, tests outstanding.
61
 * 
62
 * Revision 1.1  95/01/11  13:08:43  13:08:43  wfs (William Simmonds)
63
 * Initial revision
64
 * 
65
*/
66
 
67
 
68
#define  HPPATRANS_CODE
69
/****************************************************************
70
		 guard.c
71
 
72
	These routines protect registers from future use. The type
73
involved is space which consists of two long ints with bit patterns
74
taken to represent usage of temporary fixed and floating
75
point registers. These bits are used in the procedure
76
getregs which understands a clear bit to mean that the corresponding
77
register is free for use.
78
	The procedures are widely used in make_code which may use
79
getreg to choose a register to contain the result of an expression.
80
If this expression is the first operand of a binary operation (say)
81
then the register is guarded, producing another space which will be
82
used by make_code for the second operand.
83
 
84
******************************************************************/
85
 
86
 
87
#include "config.h"
88
#include "regmacs.h"
89
#include "procrec.h"
90
#include "addrtypes.h"
91
#include "tempdecs.h"
92
#include "comment.h"
93
#include "guard.h"
94
 
95
 
96
/*******************************************************************
97
The integer parameter to procedures guardreg and guardfreg
98
is taken to be a register which needs to be protected. For floating point
99
registers a factor of 2 is involved. The corresponding bit in the appropriate field of the
100
space i.e fixed or float, is therefore set.
101
********************************************************************/
102
 
103
space guardreg 
104
    PROTO_N ( ( r, sp ) )
105
    PROTO_T ( int r X space sp )
106
{
107
  if (IS_TREG(r))
108
  {
109
    sp.fixed |= RMASK(r);
110
  }				/* set bit in the fixed field of sp */
111
  return sp;
112
}
113
 
114
space guardfreg 
115
    PROTO_N ( ( r, sp ) )
116
    PROTO_T ( int r X space sp )
117
{
118
  if (IS_FLT_TREG(r))		/* r is a floating point t reg */
119
  {
120
    sp.flt |= RMASK(r);
121
  }				/* set bit in the flt field of sp */
122
  return sp;
123
}
124
 
125
 
126
/*
127
 * needreg & needfreg are like guardreg & guardfreg,
128
 * except it is an error if the reg is alread in use.
129
 * Used, eg, when claiming regs that will be damaged, as in a call.
130
 */
131
 
132
space needreg 
133
    PROTO_N ( ( r, sp ) )
134
    PROTO_T ( int r X space sp )
135
{
136
  /* tempdec() can allocate t regs if dead over calls, so dont fail */
137
#if 0 /* !!!! */
138
  if (!(tempdecopt && IS_TREG(r)) && (sp.fixed & RMASK(r)) != 0)
139
  {
140
    comment1("needreg: %d", r);
141
    fail("needreg: fixed reg already in use");
142
  }
143
#endif
144
  return guardreg(r, sp);
145
}
146
 
147
space needfreg 
148
    PROTO_N ( ( r, sp ) )
149
    PROTO_T ( int r X space sp )
150
{
151
#if 0 /* !!!! */
152
  /* tempdec() can allocate t regs if dead over calls, so dont fail */
153
  if (!(tempdecopt && IS_FLT_TREG(r)) && (sp.flt & RMASK(r)) != 0)
154
  {
155
    comment1("needfreg: %d", r);
156
    fail("needfreg: float reg already in use");
157
  }
158
#endif
159
  return guardreg(r, sp);
160
}
161
 
162
 
163
/********************************************************************
164
The procedure guard may also protect a register involved in
165
addressing depending on the value of the parameter of type where. This is a
166
union of a fixpnt reg , a float reg and an instore value. In the latter case the
167
register involved in the addressing can be deduced from the base field of the
168
instore value. These types are defined in addrtypes.h.
169
*********************************************************************/
170
 
171
space guard 
172
    PROTO_N ( ( w, sp ) )
173
    PROTO_T ( where w X space sp )
174
{
175
  switch (discrim ( w.answhere ) )
176
  {
177
    case inreg:
178
    {
179
      int r = regalt(w.answhere);
180
 
181
      if (IS_TREG(r))
182
      {
183
	sp.fixed |= RMASK(r);
184
      }				/* guard reg */
185
      return sp;
186
    }
187
  case infreg:
188
    {
189
      int r = fregalt(w.answhere).fr;
190
 
191
      if (IS_FLT_TREG(r))
192
      {
193
	sp.flt |= RMASK(r);
194
      }				/* guard freg */
195
      return sp;
196
    }
197
#if USE_BITAD
198
  case bitad:
199
#endif
200
  case notinreg:
201
    {
202
      int r = insalt(w.answhere).b.base;
203
 
204
      if (IS_TREG(r))
205
      {
206
	sp.fixed |= RMASK(r);
207
      }
208
      /* guard fixed point t reg used as base of address */
209
      return sp;
210
    }
211
  case insomereg:
212
  case insomefreg:
213
    {
214
      comment1("guard: BAD discrim %d", discrim ( w.answhere ) );
215
      fail("guard: Guard ? reg");
216
      return sp;
217
    }
218
  default:
219
    {
220
      comment1("guard: BAD discrim %d", discrim ( w.answhere ) );
221
      fail("guard: not in switch");
222
      return sp;
223
    }
224
  }
225
}
226
 
227
 
228