2 |
7u83 |
1 |
/*
|
7 |
7u83 |
2 |
* Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
|
|
|
3 |
* All rights reserved.
|
|
|
4 |
*
|
|
|
5 |
* Redistribution and use in source and binary forms, with or without
|
|
|
6 |
* modification, are permitted provided that the following conditions are met:
|
|
|
7 |
*
|
|
|
8 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
9 |
* this list of conditions and the following disclaimer.
|
|
|
10 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
11 |
* this list of conditions and the following disclaimer in the documentation
|
|
|
12 |
* and/or other materials provided with the distribution.
|
|
|
13 |
* 3. Neither the name of The TenDRA Project nor the names of its contributors
|
|
|
14 |
* may be used to endorse or promote products derived from this software
|
|
|
15 |
* without specific, prior written permission.
|
|
|
16 |
*
|
|
|
17 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
|
|
|
18 |
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
19 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
20 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
|
|
|
21 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
22 |
* EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
23 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
24 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
25 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
26 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
27 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
28 |
*
|
|
|
29 |
* $Id$
|
|
|
30 |
*/
|
|
|
31 |
/*
|
2 |
7u83 |
32 |
Crown Copyright (c) 1997
|
7 |
7u83 |
33 |
|
2 |
7u83 |
34 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
35 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
36 |
acting through the Defence Evaluation and Research Agency
|
|
|
37 |
(DERA). It is made available to Recipients with a
|
|
|
38 |
royalty-free licence for its use, reproduction, transfer
|
|
|
39 |
to other parties and amendment for any purpose not excluding
|
|
|
40 |
product development provided that any such use et cetera
|
|
|
41 |
shall be deemed to be acceptance of the following conditions:-
|
7 |
7u83 |
42 |
|
2 |
7u83 |
43 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
44 |
reproduced upon any copies or amended versions of it;
|
7 |
7u83 |
45 |
|
2 |
7u83 |
46 |
(2) Any amended version of it shall be clearly marked to
|
|
|
47 |
show both the nature of and the organisation responsible
|
|
|
48 |
for the relevant amendment or amendments;
|
7 |
7u83 |
49 |
|
2 |
7u83 |
50 |
(3) Its onward transfer from a recipient to another
|
|
|
51 |
party shall be deemed to be that party's acceptance of
|
|
|
52 |
these conditions;
|
7 |
7u83 |
53 |
|
2 |
7u83 |
54 |
(4) DERA gives no warranty or assurance as to its
|
|
|
55 |
quality or suitability for any purpose and DERA accepts
|
|
|
56 |
no liability whatsoever in relation to any use to which
|
|
|
57 |
it may be put.
|
|
|
58 |
*/
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
/* frames.c,v 1.5 1995/09/29 09:45:02 john Exp */
|
|
|
62 |
|
|
|
63 |
#ifndef lint
|
|
|
64 |
static char vcid[] = "frames.c,v 1.5 1995/09/29 09:45:02 john Exp";
|
|
|
65 |
#endif /* lint */
|
|
|
66 |
#include "config.h"
|
|
|
67 |
#include "common_types.h"
|
|
|
68 |
#include "frames.h"
|
|
|
69 |
#include "procrecs.h"
|
|
|
70 |
#include "expmacs.h"
|
|
|
71 |
#include "tags.h"
|
|
|
72 |
#include "bitsmacs.h"
|
|
|
73 |
#include "reg_defs.h"
|
|
|
74 |
#include "fail.h"
|
|
|
75 |
#include "cross.h"
|
|
|
76 |
#include "bool.h"
|
7 |
7u83 |
77 |
extern int bitsin(int32);
|
|
|
78 |
extern exp father(exp);
|
2 |
7u83 |
79 |
|
|
|
80 |
bool Has_fp = FALSE;
|
|
|
81 |
bool Has_tos = FALSE;
|
|
|
82 |
bool No_S = FALSE;
|
|
|
83 |
bool Has_vcallees = FALSE;
|
|
|
84 |
bool Has_no_vcallers = TRUE;
|
|
|
85 |
|
|
|
86 |
int local_reg = 14;
|
|
|
87 |
int callee_size;
|
|
|
88 |
|
|
|
89 |
#define max(x,y) (x>y)?x:y
|
|
|
90 |
|
7 |
7u83 |
91 |
#define min(x,y) (x>y)?y:x
|
2 |
7u83 |
92 |
|
|
|
93 |
void setframe_flags
|
7 |
7u83 |
94 |
(exp e, bool leaf)
|
2 |
7u83 |
95 |
{
|
|
|
96 |
/* e is proc_tag */
|
7 |
7u83 |
97 |
No_S = (!leaf && (name(e)!= general_proc_tag || !proc_has_nolongj(e))
|
2 |
7u83 |
98 |
&& proc_uses_crt_env(e) && proc_has_lv(e));
|
7 |
7u83 |
99 |
Has_fp = (No_S || proc_has_alloca(e) || name(e) == general_proc_tag);
|
2 |
7u83 |
100 |
Has_tos = (No_S && proc_has_alloca(e));
|
|
|
101 |
Has_vcallees = (name(e) == general_proc_tag && proc_has_vcallees(e));
|
|
|
102 |
Has_no_vcallers = (name(e) == proc_tag || !proc_has_vcallers(e));
|
|
|
103 |
#ifdef Try_No_S
|
|
|
104 |
No_S = TRUE;
|
|
|
105 |
#endif
|
|
|
106 |
#ifdef Try_Has_fp
|
|
|
107 |
Has_fp = !leaf;
|
|
|
108 |
#endif
|
|
|
109 |
#ifdef Try_Has_tos
|
|
|
110 |
Has_tos = TRUE;
|
7 |
7u83 |
111 |
#endif
|
2 |
7u83 |
112 |
}
|
|
|
113 |
|
|
|
114 |
/*
|
7 |
7u83 |
115 |
sets up the size of the frame, and the positions in which to
|
2 |
7u83 |
116 |
save the registers.
|
|
|
117 |
*/
|
|
|
118 |
void setframe_info
|
7 |
7u83 |
119 |
(exp e)
|
2 |
7u83 |
120 |
{
|
7 |
7u83 |
121 |
procrec * pr = & procrecs[no(e)];
|
2 |
7u83 |
122 |
needs * ndpr = & pr->needsproc;
|
|
|
123 |
spacereq *sppr = & pr->spacereqproc;
|
|
|
124 |
long pprops = (ndpr->propsneeds);
|
7 |
7u83 |
125 |
bool leaf = (pprops & anyproccall) == 0;
|
|
|
126 |
int ma = ndpr->maxargs; /* maxargs of proc body in bits */
|
2 |
7u83 |
127 |
int pa = ndpr->numparams;
|
|
|
128 |
long st = sppr->stack; /* space for locals in bits */
|
|
|
129 |
int nofixdump;
|
|
|
130 |
int nofloatdump;
|
|
|
131 |
int save_offset;
|
|
|
132 |
setframe_flags(e, leaf);
|
7 |
7u83 |
133 |
|
|
|
134 |
if (has_c_vararg(e) || !Has_no_vcallers) {
|
2 |
7u83 |
135 |
pa=12*64; /* should be 11 */
|
|
|
136 |
}
|
|
|
137 |
else{
|
|
|
138 |
pa=min(pa,6*64);
|
|
|
139 |
}
|
7 |
7u83 |
140 |
|
2 |
7u83 |
141 |
st = (st + 32) & ~63;
|
7 |
7u83 |
142 |
pa = (pa+32) &~63;
|
2 |
7u83 |
143 |
ma = (ma + 32) & ~63; /* put on 64 bit boundaries */
|
|
|
144 |
pr->max_args = ma;
|
|
|
145 |
save_offset=max(ma-384,0);
|
|
|
146 |
/* locate the register to be saved */
|
|
|
147 |
pr->fixdump = sppr->fixdump<<9;/* 8 */
|
7 |
7u83 |
148 |
if (!leaf) {
|
2 |
7u83 |
149 |
pr->fixdump |= 1 << RA;
|
|
|
150 |
} /* space for return address */
|
7 |
7u83 |
151 |
if (No_S) {
|
2 |
7u83 |
152 |
pr->fixdump |= (Has_fp)?0x7e00:0xfe00;
|
|
|
153 |
}
|
|
|
154 |
pr->floatdump = (sppr->fltdump<<1); /* wrong! */
|
7 |
7u83 |
155 |
nofixdump = bitsin(pr->fixdump);
|
|
|
156 |
nofloatdump = bitsin(pr->floatdump);
|
2 |
7u83 |
157 |
/* no of fixed s-regs to be dumped */
|
7 |
7u83 |
158 |
pr->frame_size=pa+st+save_offset+ (nofixdump+nofloatdump)*64;
|
|
|
159 |
pr->frame_size+= ((has_float(e)!=0 || !optop(e))?64:0);
|
|
|
160 |
/* reserve an extra quadword for float reg <-> general reg
|
2 |
7u83 |
161 |
transfers */
|
7 |
7u83 |
162 |
|
|
|
163 |
if (Has_fp) {
|
2 |
7u83 |
164 |
pr->frame_size +=64; /* extra word for old fp */
|
|
|
165 |
/* pr->callee_size += 128;*/
|
|
|
166 |
}
|
7 |
7u83 |
167 |
|
2 |
7u83 |
168 |
pr->dumpstart=save_offset>>3;
|
|
|
169 |
pr->fldumpstart=pr->dumpstart+8*nofixdump;
|
7 |
7u83 |
170 |
pr->locals_offset = (pr->fldumpstart + 8*(nofloatdump+ (has_float(e)!=0 ||
|
|
|
171 |
!optop(e)))) <<3;
|
|
|
172 |
|
2 |
7u83 |
173 |
pr->paramsdumpstart = pr->locals_offset+st + ((Has_fp)?64:0);
|
|
|
174 |
return;
|
7 |
7u83 |
175 |
}
|
2 |
7u83 |
176 |
|
|
|
177 |
int frame_offset
|
7 |
7u83 |
178 |
(exp id)
|
2 |
7u83 |
179 |
{
|
|
|
180 |
exp p;
|
|
|
181 |
procrec * pr;
|
7 |
7u83 |
182 |
int x = no(id);
|
2 |
7u83 |
183 |
int b = x & 0x3f;
|
7 |
7u83 |
184 |
|
2 |
7u83 |
185 |
Assert(name(id) == ident_tag);
|
7 |
7u83 |
186 |
for (p = father(id); name(p)!=proc_tag && name(p)!=general_proc_tag;
|
2 |
7u83 |
187 |
p = father(p));
|
|
|
188 |
pr = & procrecs[no(p)];
|
7 |
7u83 |
189 |
if ((b == SP) || (b == FP)) {
|
|
|
190 |
return((x - b) >> 4) +
|
|
|
191 |
((pr->locals_offset - pr->frame_size - pr->callee_size) >>3);
|
|
|
192 |
}
|
|
|
193 |
else if (b == local_reg) {
|
|
|
194 |
return((x-b) >>4) + (pr->locals_offset>>3) - (pr->frame_size>>3)
|
2 |
7u83 |
195 |
/*- (pr->callee_size>>3)*/;
|
|
|
196 |
}
|
|
|
197 |
else{
|
|
|
198 |
bool Has_vcallees = (name(p) == general_proc_tag && proc_has_vcallees(p));
|
7 |
7u83 |
199 |
int n = -8 - (no(son(id)) >>3);
|
|
|
200 |
if (isparam(id) && name(son(id))!= formal_callee_tag) {
|
2 |
7u83 |
201 |
return n;
|
|
|
202 |
}
|
7 |
7u83 |
203 |
else if (isparam(id) && name(son(id)) == formal_callee_tag) {
|
|
|
204 |
return((Has_vcallees)?n:((pr->callee_size>>3) - n));
|
|
|
205 |
}
|
2 |
7u83 |
206 |
else{
|
|
|
207 |
failer("Illegal frame offset");
|
|
|
208 |
return 0;
|
|
|
209 |
}
|
|
|
210 |
}
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
|
7 |
7u83 |
214 |
|