2 |
7u83 |
1 |
/*
|
6 |
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
|
|
|
33 |
|
|
|
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:-
|
|
|
42 |
|
|
|
43 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
44 |
reproduced upon any copies or amended versions of it;
|
|
|
45 |
|
|
|
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;
|
|
|
49 |
|
|
|
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;
|
|
|
53 |
|
|
|
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 |
/**********************************************************************
|
|
|
62 |
$Author: release $
|
|
|
63 |
$Date: 1998/01/17 15:56:05 $
|
|
|
64 |
$Revision: 1.1.1.1 $
|
|
|
65 |
$Log: frames.c,v $
|
|
|
66 |
* Revision 1.1.1.1 1998/01/17 15:56:05 release
|
|
|
67 |
* First version to be checked into rolling release.
|
|
|
68 |
*
|
|
|
69 |
* Revision 1.6 1995/09/26 09:05:02 currie
|
|
|
70 |
* Has_no_vcallers condition wrong
|
|
|
71 |
*
|
|
|
72 |
* Revision 1.4 1995/09/12 10:59:21 currie
|
|
|
73 |
* gcc pedanttry
|
|
|
74 |
*
|
|
|
75 |
* Revision 1.3 1995/06/28 12:15:22 currie
|
|
|
76 |
* New make_stack_limit etc
|
|
|
77 |
*
|
|
|
78 |
* Revision 1.2 1995/05/05 08:12:52 currie
|
|
|
79 |
* initial_value + signtures
|
|
|
80 |
*
|
|
|
81 |
* Revision 1.1 1995/04/13 09:08:06 currie
|
|
|
82 |
* Initial revision
|
|
|
83 |
*
|
|
|
84 |
***********************************************************************/
|
|
|
85 |
|
|
|
86 |
#include "config.h"
|
|
|
87 |
#include "common_types.h"
|
|
|
88 |
#include "procrectypes.h"
|
|
|
89 |
#include "expmacs.h"
|
|
|
90 |
#include "tags.h"
|
|
|
91 |
#include "bitsmacs.h"
|
|
|
92 |
#include "basicread.h"
|
|
|
93 |
#include "frames.h"
|
|
|
94 |
#include "new_code.h"
|
|
|
95 |
|
6 |
7u83 |
96 |
extern exp father(exp);
|
2 |
7u83 |
97 |
extern procrec * procrecs;
|
|
|
98 |
|
|
|
99 |
bool Has_fp = 0;
|
|
|
100 |
|
|
|
101 |
bool Has_tos = 0;
|
|
|
102 |
|
|
|
103 |
bool No_S = 0;
|
|
|
104 |
|
|
|
105 |
bool Has_vcallees = 0;
|
|
|
106 |
bool Has_no_vcallers = 0;
|
|
|
107 |
|
|
|
108 |
int local_reg = 23;
|
|
|
109 |
|
|
|
110 |
long callee_size;
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
void setframe_flags
|
6 |
7u83 |
114 |
(exp e, bool leaf)
|
2 |
7u83 |
115 |
{
|
|
|
116 |
/* e is proc_tag */
|
|
|
117 |
|
|
|
118 |
No_S = (!leaf && (name(e)!=general_proc_tag || !proc_has_nolongj(e))
|
|
|
119 |
&& proc_uses_crt_env(e)
|
6 |
7u83 |
120 |
&& proc_has_lv(e));
|
2 |
7u83 |
121 |
Has_fp = (No_S || proc_has_alloca(e) || name(e) == general_proc_tag);
|
|
|
122 |
|
|
|
123 |
Has_tos = (No_S && proc_has_alloca(e));
|
6 |
7u83 |
124 |
Has_vcallees = (name(e) ==general_proc_tag && proc_has_vcallees(e));
|
2 |
7u83 |
125 |
Has_no_vcallers = (name(e) == proc_tag || !proc_has_vcallers(e));
|
|
|
126 |
|
|
|
127 |
#ifdef Try_No_S
|
|
|
128 |
No_S = 1;
|
|
|
129 |
#endif
|
|
|
130 |
#ifdef Try_Has_fp
|
|
|
131 |
Has_fp = !leaf;
|
|
|
132 |
#endif
|
|
|
133 |
#ifdef Try_Has_tos
|
|
|
134 |
Has_tos = 1;
|
|
|
135 |
#endif
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
void setframe_info
|
6 |
7u83 |
139 |
(exp e)
|
2 |
7u83 |
140 |
{
|
|
|
141 |
procrec * pr = & procrecs[no(e)];
|
|
|
142 |
needs * ndpr = & pr->needsproc;
|
|
|
143 |
spacereq *sppr = & pr->spacereqproc;
|
|
|
144 |
long pprops = (ndpr->propsneeds);
|
|
|
145 |
bool leaf = (pprops & anyproccall) == 0;
|
|
|
146 |
long ma = ndpr->maxargs; /* maxargs of proc body in bits */
|
|
|
147 |
long st = sppr->stack; /* space for locals in bits */
|
|
|
148 |
int nofixdump;
|
|
|
149 |
|
|
|
150 |
setframe_flags(e, leaf);
|
|
|
151 |
|
|
|
152 |
if (!leaf && ma <128) ma = 128; /* required by printf etc!!?? */
|
|
|
153 |
st = (st + 32) & ~63;
|
|
|
154 |
ma = (ma + 32) & ~63; /* put on 64 bit boundaries */
|
|
|
155 |
|
|
|
156 |
pr->max_args = ma;
|
|
|
157 |
|
|
|
158 |
pr->fixdump = (No_S)?0x40ff0000 :((sppr->fixdump) << 16);
|
6 |
7u83 |
159 |
if (!leaf) {
|
2 |
7u83 |
160 |
pr->fixdump |= 1 << 31;
|
|
|
161 |
} /* space for link */
|
|
|
162 |
|
|
|
163 |
if (Has_fp) {
|
|
|
164 |
pr->fixdump &= ~(1<<30);
|
|
|
165 |
/* frame pointer will be preserved by call or prelude ?!*/
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
pr->floatdump = (No_S)?0xffc00000 :((sppr->fltdump) << 20);
|
|
|
169 |
|
6 |
7u83 |
170 |
nofixdump = bitsin(pr->fixdump);
|
2 |
7u83 |
171 |
/* no of fixed s-regs to be dumped */
|
|
|
172 |
ma += (nofixdump + bitsin(pr->floatdump))*32;
|
|
|
173 |
ma = (ma + 32) & ~63;
|
|
|
174 |
/* include space for dumped s-regs */
|
|
|
175 |
|
|
|
176 |
pr->locals_offset = ma; /* the offset to first local in bits from
|
|
|
177 |
$sp */
|
|
|
178 |
pr->frame_size = ma + st; /* the frame size for this proc in bits */
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
st = pr->frame_size >> 3;
|
|
|
182 |
ma = ma >> 3;
|
|
|
183 |
pr->dumpstart = ma; /* the byte displacement from $sp to dump
|
|
|
184 |
fixed s-regs */
|
|
|
185 |
pr->fldumpstart = ma - 4 * nofixdump;
|
|
|
186 |
/* the byte displacement from $sp to dump float s-regs... */
|
|
|
187 |
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
long frame_offset
|
6 |
7u83 |
191 |
(exp id)
|
2 |
7u83 |
192 |
{
|
|
|
193 |
exp p;
|
|
|
194 |
procrec * pr;
|
6 |
7u83 |
195 |
int x = no(id);
|
2 |
7u83 |
196 |
int b = x & 0x3f;
|
|
|
197 |
int lo; int fs; int cs;
|
|
|
198 |
|
|
|
199 |
Assert(name(id) == ident_tag);
|
6 |
7u83 |
200 |
for (p = father(id);(name(p)!=proc_tag && name(p)!=
|
2 |
7u83 |
201 |
general_proc_tag); p = father(p));
|
|
|
202 |
pr = & procrecs[no(p)];
|
|
|
203 |
|
|
|
204 |
lo = pr->locals_offset>>3;
|
|
|
205 |
fs = pr->frame_size>>3;
|
|
|
206 |
cs = pr->callee_size>>3;
|
|
|
207 |
|
|
|
208 |
|
|
|
209 |
if (b==29 || b == 30) {
|
6 |
7u83 |
210 |
return(((x - b) >> 4) +lo - (fs+cs));
|
2 |
7u83 |
211 |
}
|
|
|
212 |
else
|
|
|
213 |
if (b==local_reg) {
|
6 |
7u83 |
214 |
return(((x - b) >> 4) +lo -fs);
|
2 |
7u83 |
215 |
}
|
|
|
216 |
else {
|
|
|
217 |
/* may not be allocated yet */
|
|
|
218 |
|
6 |
7u83 |
219 |
bool Has_vcallees = (name(p) ==general_proc_tag &&
|
2 |
7u83 |
220 |
proc_has_vcallees(p));
|
6 |
7u83 |
221 |
int n = no(son(id)) >>3;
|
2 |
7u83 |
222 |
if (isparam(id) && name(son(id))!=formal_callee_tag) {
|
|
|
223 |
return n;
|
|
|
224 |
}
|
|
|
225 |
else
|
6 |
7u83 |
226 |
if (isparam(id) && name(son(id)) ==formal_callee_tag) {
|
|
|
227 |
return ((Has_vcallees)? n:(cs-n));
|
2 |
7u83 |
228 |
}
|
|
|
229 |
else { failer("Wrong env_offset"); return 0; }
|
|
|
230 |
}
|
|
|
231 |
}
|