CACAO
md-abi.cpp
Go to the documentation of this file.
1 /* src/vm/jit/sparc64/md-abi.cpp - functions for Sparc ABI
2 
3  Copyright (C) 1996-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 
26 #include "config.h"
27 #include "vm/types.hpp"
28 
30 
31 #include "vm/descriptor.hpp"
32 #include "vm/global.hpp"
33 #include "vm/method.hpp"
34 
35 #include "vm/jit/abi.hpp"
36 #include "vm/jit/code.hpp"
37 #include "vm/jit/stack.hpp"
38 
39 /* temp */
40 #include "mm/memory.hpp"
41 #include <assert.h>
42 
43 
44 /* register descripton array **************************************************/
45 
46 /* callee point-of-view, after SAVE has been called. */
48  /* zero itmp1/g1 itmp2/g2 itmp3/g3 temp/g4 temp/g5 sys/g6 sys/g7 */
50 
51  /* o0 o1 o2 o3 o4 pv/o5 sp/o6 ra/o7 */
53 
54  /* l0 l1 l2 l3 l4 l5 l6 l7 */
56 
57  /* i0 i1 i2 i3 i4 pv/i5 fp/i6 ra/i7 */
59  REG_END
60 };
61 
62 const char *abi_registers_integer_name[] = {
63  "zero", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
64  "o0", "o1", "o2", "o3", "o4", "o5", "sp", "o7",
65  "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
66  "i0", "i1", "i2", "i3", "i4", "i5", "fp", "i7"
67 };
68 
70  8, /* o0 */
71  9, /* o1 */
72  10, /* o2 */
73  11, /* o3 */
74  12, /* o4 */
75 };
76 
78  16, /* l0 */
79  17, /* l1 */
80  18, /* l2 */
81  19, /* l3 */
82  20, /* l4 */
83  21, /* l5 */
84  22, /* l6 */
85  23, /* l7 */
86  24, /* i0 */
87  25, /* i1 */
88  26, /* i2 */
89  27, /* i3 */
90  28, /* i4 */
91 };
92 
93 
94 
98  REG_END
99 };
100 
101 
103  8, /* f16 */
104  9, /* f18 */
105  10, /* f20 */
106  11, /* f22 */
107  12, /* f24 */
108 };
109 
111  4, /* f8 */
112  5, /* f10 */
113  6, /* f12 */
114  7, /* f14 */
115  13, /* f26 */
116  14, /* f28 */
117  15, /* f30 */
118 };
119 
122 };
123 
124 
125 /* md_param_alloc **************************************************************
126 
127  Allocate Arguments to Stackslots according the Calling Conventions
128 
129  --- in
130  md->paramcount: Number of arguments for this method
131  md->paramtypes[].type: Argument types
132 
133  --- out
134  md->params[].inmemory: Argument spilled on stack
135  md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
136  md->memuse: Stackslots needed for argument spilling
137  md->argintreguse: max number of integer arguments used
138  md->argfltreguse: max number of float arguments used
139 
140 *******************************************************************************/
141 
143 {
144  paramdesc *pd;
145  s4 i;
146  s4 reguse;
147  s4 stacksize;
148 
149  /* set default values */
150 
151  reguse = 0;
152  stacksize = 0;
153 
154  /* get params field of methoddesc */
155 
156  pd = md->params;
157 
158  for (i = 0; i < md->paramcount; i++, pd++) {
159  switch (md->paramtypes[i].type) {
160  case TYPE_INT:
161  case TYPE_ADR:
162  case TYPE_LNG:
163  if (i < INT_ARG_CNT) {
164  pd->inmemory = false;
165  pd->index = reguse;
167  reguse++;
168  md->argintreguse = reguse;
169  }
170  else {
171  pd->inmemory = true;
172  pd->index = stacksize;
173  pd->regoff = stacksize * 8;
174  stacksize++;
175  }
176  break;
177 
178  case TYPE_FLT:
179  case TYPE_DBL:
180  if (i < FLT_ARG_CNT) {
181  pd->inmemory = false;
182  pd->index = reguse;
183  pd->regoff = abi_registers_float_argument[reguse];
184  reguse++;
185  md->argfltreguse = reguse;
186  }
187  else {
188  pd->inmemory = true;
189  pd->index = stacksize;
190  pd->regoff = stacksize * 8;
191  stacksize++;
192  }
193  break;
194  }
195  assert(pd->regoff != 26);
196  }
197 
198  /* Since O0 is used for passing return values, this */
199  /* argument register usage has to be regarded, too */
200  if (IS_INT_LNG_TYPE(md->returntype.type)) {
201  if (reguse < 1)
202  md->argintreguse = 1;
203  }
204 
205  /* fill register and stack usage */
206 
207  md->memuse = stacksize;
208 }
209 
210 
211 /* md_param_alloc_native *******************************************************
212  *
213  * Pre-allocate arguments according to the native ABI.
214  *
215  * *******************************************************************************/
216 
218 {
219  paramdesc *pd;
220  s4 i;
221  s4 reguse;
222  s4 stacksize;
223  s4 min_nat_regs;
224 
225  /* Note: regoff will be set relative to a stack base of $sp+16 */
226 
227  /* set default values */
228  reguse = 0;
229  stacksize = 6; /* abi params: allocated, but not used */
230 
231  /* when we are above this, we have to increase the stacksize with every */
232  /* single argument to create the proper argument array */
233  min_nat_regs = MIN(INT_NATARG_CNT, FLT_NATARG_CNT);
234 
235  /* get params field of methoddesc */
236 
237  pd = md->params;
238 
239  for (i = 0; i < md->paramcount; i++, pd++) {
240  switch (md->paramtypes[i].type) {
241  case TYPE_INT:
242  case TYPE_ADR:
243  case TYPE_LNG:
244  if (i < INT_NATARG_CNT) {
245  pd->inmemory = false;
246  pd->regoff = nat_argintregs[reguse];
247  reguse++;
248  md->argintreguse = reguse;
249 
250  } else {
251  pd->inmemory = true;
252  pd->regoff = reguse * 8;
253  reguse++;
254  }
255  break;
256  case TYPE_FLT:
257  case TYPE_DBL:
258  if (i < FLT_NATARG_CNT) {
259  pd->inmemory = false;
260  pd->regoff = reguse;
261  reguse++;
262  md->argfltreguse = reguse;
263  } else {
264  pd->inmemory = true;
265  pd->regoff = reguse * 8;
266  reguse++;
267  }
268 
269  break;
270  }
271 
272  if (i >= min_nat_regs)
273  stacksize++;
274  }
275 
276  /* Since O0 is used for passing return values, this */
277  /* argument register usage has to be regarded, too */
278  if (IS_INT_LNG_TYPE(md->returntype.type)) {
279  if (reguse < 1)
280  md->argintreguse = 1;
281  }
282 
283  /* fill register and stack usage */
284 
285  md->memuse = stacksize;
286 }
287 
288 /* md_return_alloc *************************************************************
289 
290  XXX
291 
292 *******************************************************************************/
293 
295 {
296  /* XXX */
297 }
298 
299 
300 /*
301  * These are local overrides for various environment variables in Emacs.
302  * Please do not remove this and leave it at the end of the file, where
303  * Emacs will automagically detect them.
304  * ---------------------------------------------------------------------
305  * Local variables:
306  * mode: c++
307  * indent-tabs-mode: t
308  * c-basic-offset: 4
309  * tab-width: 4
310  * End:
311  * vim:noexpandtab:sw=4:ts=4:
312  */
const s4 abi_registers_float_argument[]
Definition: md-abi.cpp:107
void md_return_alloc(jitdata *jd, stackelement_t *stackslot)
Definition: md-abi.cpp:250
#define INT_NATARG_CNT
Definition: md-abi.hpp:100
Definition: jit.hpp:126
paramdesc * params
Definition: descriptor.hpp:164
#define REG_OUT3
Definition: md-abi.hpp:66
#define REG_SAV
Definition: jit.hpp:449
#define IS_INT_LNG_TYPE(a)
Definition: global.hpp:130
const s4 abi_registers_integer_argument[]
Definition: md-abi.cpp:64
#define REG_OUT0
Definition: md-abi.hpp:63
s4 nregdescint[]
Definition: md-abi.cpp:41
#define MIN(a, b)
Definition: global.hpp:95
#define REG_END
Definition: jit.hpp:453
#define REG_OUT2
Definition: md-abi.hpp:65
#define REG_RES
Definition: jit.hpp:446
const s4 abi_registers_integer_saved[]
Definition: md-abi.cpp:75
uint32_t index
Definition: descriptor.hpp:152
const s4 abi_registers_float_temporary[]
Definition: md-abi.cpp:129
#define FLT_NATARG_CNT
Definition: md-abi.hpp:101
typedesc paramtypes[1]
Definition: descriptor.hpp:167
#define REG_RET
Definition: jit.hpp:447
#define REG_OUT4
Definition: md-abi.hpp:67
#define INT_ARG_CNT
Definition: md-abi.hpp:76
MIIterator i
typedesc returntype
Definition: descriptor.hpp:166
s4 nat_argintregs[INT_NATARG_CNT]
Definition: codegen.hpp:47
int32_t s4
Definition: types.hpp:45
void md_param_alloc(methoddesc *md)
Definition: md-abi.cpp:153
bool inmemory
Definition: descriptor.hpp:151
const char * abi_registers_integer_name[]
Definition: md-abi.cpp:57
void md_param_alloc_native(methoddesc *md)
Definition: md-abi.cpp:224
#define FLT_ARG_CNT
Definition: md-abi.hpp:83
#define REG_ARG
Definition: jit.hpp:451
#define REG_TMP
Definition: jit.hpp:450
s4 nregdescfloat[]
Definition: md-abi.cpp:98
#define REG_OUT5
Definition: md-abi.hpp:68
uint32_t regoff
Definition: descriptor.hpp:153
#define REG_OUT1
Definition: md-abi.hpp:64