Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
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
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 42... Line 72...
42
#include "bitsmacs.h"
72
#include "bitsmacs.h"
43
#include "reg_defs.h"
73
#include "reg_defs.h"
44
#include "fail.h"
74
#include "fail.h"
45
#include "cross.h"
75
#include "cross.h"
46
#include "bool.h"
76
#include "bool.h"
47
extern int bitsin PROTO_S ((int32));
77
extern int bitsin(int32);
48
extern exp father PROTO_S ((exp));
78
extern exp father(exp);
49
 
79
 
50
bool Has_fp = FALSE;
80
bool Has_fp = FALSE;
51
bool Has_tos = FALSE;
81
bool Has_tos = FALSE;
52
bool No_S = FALSE;
82
bool No_S = FALSE;
53
bool Has_vcallees = FALSE;
83
bool Has_vcallees = FALSE;
Line 56... Line 86...
56
int local_reg = 14;
86
int local_reg = 14;
57
int callee_size;
87
int callee_size;
58
 
88
 
59
#define max(x,y)	(x>y)?x:y
89
#define max(x,y)	(x>y)?x:y
60
 
90
 
61
#define min(x,y)        (x>y)?y:x
91
#define min(x,y)      (x>y)?y:x
62
 
92
 
63
void setframe_flags
93
void setframe_flags
64
    PROTO_N ( ( e,leaf ) )
-
 
65
    PROTO_T ( exp e X bool leaf )
94
(exp e, bool leaf)
66
{
95
{
67
   /* e is proc_tag */
96
   /* e is proc_tag */
68
  No_S = (!leaf && (name(e) != general_proc_tag || !proc_has_nolongj(e))
97
  No_S = (!leaf && (name(e)!= general_proc_tag || !proc_has_nolongj(e))
69
	  && proc_uses_crt_env(e) && proc_has_lv(e));
98
	  && proc_uses_crt_env(e) && proc_has_lv(e));
70
  Has_fp = (No_S || proc_has_alloca(e)|| name(e) == general_proc_tag);
99
  Has_fp = (No_S || proc_has_alloca(e) || name(e) == general_proc_tag);
71
  Has_tos = (No_S && proc_has_alloca(e));
100
  Has_tos = (No_S && proc_has_alloca(e));
72
  Has_vcallees = (name(e) == general_proc_tag && proc_has_vcallees(e));
101
  Has_vcallees = (name(e) == general_proc_tag && proc_has_vcallees(e));
73
  Has_no_vcallers = (name(e) == proc_tag || !proc_has_vcallers(e));
102
  Has_no_vcallers = (name(e) == proc_tag || !proc_has_vcallers(e));
74
#ifdef Try_No_S
103
#ifdef Try_No_S
75
  No_S = TRUE;
104
  No_S = TRUE;
Line 77... Line 106...
77
#ifdef Try_Has_fp
106
#ifdef Try_Has_fp
78
  Has_fp = !leaf;
107
  Has_fp = !leaf;
79
#endif
108
#endif
80
#ifdef Try_Has_tos
109
#ifdef Try_Has_tos
81
  Has_tos = TRUE;
110
  Has_tos = TRUE;
82
#endif      
111
#endif
83
}
112
}
84
 
113
 
85
/*
114
/*
86
  sets up the size of the frame, and the positions in which to 
115
  sets up the size of the frame, and the positions in which to
87
  save the registers.
116
  save the registers.
88
*/
117
*/
89
void setframe_info
118
void setframe_info
90
    PROTO_N ( ( e ) )
-
 
91
    PROTO_T ( exp e )
119
(exp e)
92
{
120
{
93
  procrec * pr = & procrecs[no(e)];			 
121
  procrec * pr = & procrecs[no(e)];
94
  needs * ndpr = & pr->needsproc;
122
  needs * ndpr = & pr->needsproc;
95
  spacereq *sppr = & pr->spacereqproc;
123
  spacereq *sppr = & pr->spacereqproc;
96
  long pprops = (ndpr->propsneeds);
124
  long pprops = (ndpr->propsneeds);
97
  bool leaf = (pprops & anyproccall) == 0; 
125
  bool leaf = (pprops & anyproccall) == 0;
98
  int ma = ndpr->maxargs;	/* maxargs of proc body in bits */	
126
  int ma = ndpr->maxargs;	/* maxargs of proc body in bits */
99
  int pa = ndpr->numparams;
127
  int pa = ndpr->numparams;
100
  long st = sppr->stack;	/* space for locals in bits */
128
  long st = sppr->stack;	/* space for locals in bits */
101
  int nofixdump;
129
  int nofixdump;
102
  int nofloatdump;
130
  int nofloatdump;
103
  int save_offset;
131
  int save_offset;
104
  setframe_flags(e, leaf);
132
  setframe_flags(e, leaf);
105
  
133
 
106
  if(has_c_vararg(e) || !Has_no_vcallers){
134
  if (has_c_vararg(e) || !Has_no_vcallers) {
107
    pa=12*64;	/* should be 11 */
135
    pa=12*64;	/* should be 11 */
108
  }
136
  }
109
  else{
137
  else{
110
    pa=min(pa,6*64);
138
    pa=min(pa,6*64);
111
  }
139
  }
112
  
140
 
113
  st = (st + 32) & ~63;
141
  st = (st + 32) & ~63;
114
  pa = (pa+32)&~63;
142
  pa = (pa+32) &~63;
115
  ma = (ma + 32) & ~63;	/* put on 64 bit boundaries */
143
  ma = (ma + 32) & ~63;	/* put on 64 bit boundaries */
116
  pr->max_args = ma;
144
  pr->max_args = ma;
117
  save_offset=max(ma-384,0);
145
  save_offset=max(ma-384,0);
118
  /* locate the register to be saved */
146
  /* locate the register to be saved */
119
  pr->fixdump = sppr->fixdump<<9;/* 8 */
147
  pr->fixdump = sppr->fixdump<<9;/* 8 */
120
  if (!leaf ) {
148
  if (!leaf) {
121
    pr->fixdump |= 1 << RA;
149
    pr->fixdump |= 1 << RA;
122
  }	/* space for return address */
150
  }	/* space for return address */
123
  if(No_S) {
151
  if (No_S) {
124
    pr->fixdump |= (Has_fp)?0x7e00:0xfe00;
152
    pr->fixdump |= (Has_fp)?0x7e00:0xfe00;
125
  }
153
  }
126
  pr->floatdump = (sppr->fltdump<<1);	/* wrong! */
154
  pr->floatdump = (sppr->fltdump<<1);	/* wrong! */
127
  nofixdump = bitsin (pr->fixdump);
155
  nofixdump = bitsin(pr->fixdump);
128
  nofloatdump = bitsin (pr->floatdump);
156
  nofloatdump = bitsin(pr->floatdump);
129
  /* no of fixed s-regs to be dumped */
157
  /* no of fixed s-regs to be dumped */
130
  pr->frame_size=pa+st+save_offset+(nofixdump+nofloatdump)*64;
158
  pr->frame_size=pa+st+save_offset+ (nofixdump+nofloatdump)*64;
131
  pr->frame_size+=((has_float(e)!=0 || !optop(e))?64:0);
159
  pr->frame_size+= ((has_float(e)!=0 || !optop(e))?64:0);
132
  /* reserve an extra quadword for float reg <-> general reg 
160
  /* reserve an extra quadword for float reg <-> general reg
133
     transfers */
161
     transfers */
134
  
162
 
135
  if (Has_fp) { 
163
  if (Has_fp) {
136
    pr->frame_size +=64; /* extra word for old fp  */
164
    pr->frame_size +=64; /* extra word for old fp  */
137
/*    pr->callee_size += 128;*/
165
/*    pr->callee_size += 128;*/
138
  }
166
  }
139
  
167
 
140
  pr->dumpstart=save_offset>>3;
168
  pr->dumpstart=save_offset>>3;
141
  pr->fldumpstart=pr->dumpstart+8*nofixdump;
169
  pr->fldumpstart=pr->dumpstart+8*nofixdump;
142
  pr->locals_offset = (pr->fldumpstart + 8*(nofloatdump+(has_float(e)!=0 ||
170
  pr->locals_offset = (pr->fldumpstart + 8*(nofloatdump+ (has_float(e)!=0 ||
143
							 !optop(e))))<<3;
171
							 !optop(e)))) <<3;
144
  
172
 
145
  pr->paramsdumpstart = pr->locals_offset+st + ((Has_fp)?64:0);
173
  pr->paramsdumpstart = pr->locals_offset+st + ((Has_fp)?64:0);
146
  return;
174
  return;
147
}	
175
}
148
 
176
 
149
int frame_offset
177
int frame_offset
150
    PROTO_N ( ( id ) )
-
 
151
    PROTO_T ( exp id )
178
(exp id)
152
{
179
{
153
  exp p;
180
  exp p;
154
  procrec * pr;
181
  procrec * pr;
155
  int  x = no (id);
182
  int  x = no(id);
156
  int  b = x & 0x3f;
183
  int  b = x & 0x3f;
157
  
184
 
158
  Assert(name(id) == ident_tag);
185
  Assert(name(id) == ident_tag);
159
  for (p = father(id); name(p)!=proc_tag && name(p)!=general_proc_tag; 
186
  for (p = father(id); name(p)!=proc_tag && name(p)!=general_proc_tag;
160
		       p = father(p));
187
		       p = father(p));
161
  pr = & procrecs[no(p)];
188
  pr = & procrecs[no(p)];
162
  if((b == SP) || (b == FP)){
189
  if ((b == SP) || (b == FP)) {
163
    return ((x - b) >> 4) + 
190
    return((x - b) >> 4) +
164
      ((pr->locals_offset - pr->frame_size - pr->callee_size)>>3);
191
     ((pr->locals_offset - pr->frame_size - pr->callee_size) >>3);
165
  }	
192
  }
166
  else if (b == local_reg){
193
  else if (b == local_reg) {
167
    return ((x-b)>>4) + (pr->locals_offset>>3) - (pr->frame_size>>3) 
194
    return((x-b) >>4) + (pr->locals_offset>>3) - (pr->frame_size>>3)
168
      /*- (pr->callee_size>>3)*/;
195
      /*- (pr->callee_size>>3)*/;
169
  }
196
  }
170
  else{
197
  else{
171
    bool Has_vcallees = (name(p) == general_proc_tag && proc_has_vcallees(p));
198
    bool Has_vcallees = (name(p) == general_proc_tag && proc_has_vcallees(p));
172
    int n = -8 - (no(son(id))>>3);
199
    int n = -8 - (no(son(id)) >>3);
173
    if(isparam(id) && name(son(id)) != formal_callee_tag){
200
    if (isparam(id) && name(son(id))!= formal_callee_tag) {
174
      return n;
201
      return n;
175
    }	
202
    }
176
    else if(isparam(id) && name(son(id)) == formal_callee_tag){
203
    else if (isparam(id) && name(son(id)) == formal_callee_tag) {
177
      return ((Has_vcallees)?n:((pr->callee_size>>3) - n));
204
      return((Has_vcallees)?n:((pr->callee_size>>3) - n));
178
    }
205
    }
179
    else{
206
    else{
180
      failer("Illegal frame offset");
207
      failer("Illegal frame offset");
181
      return 0;
208
      return 0;
182
    }
209
    }
183
  }
210
  }
184
}
211
}
185
 
212
 
186
	
213
 
187
 
214