* src/mm/cacao-gc/rootset.h (rootset_entry_t) Added. Rootsets can be resized.
[cacao.git] / src / vm / jit / x86_64 / md-abi.c
1 /* src/vm/jit/x86_64/md-abi.c - functions for x86_64 Linux ABI
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    $Id: md-abi.c 7723 2007-04-16 18:03:08Z michi $
26
27 */
28
29
30 #include "config.h"
31 #include "vm/types.h"
32
33 #include "vm/jit/x86_64/md-abi.h"
34
35 #include "vm/global.h"
36
37 #include "vm/jit/abi.h"
38 #include "vm/jit/jit.h" /* for REG_* (maybe can be removed) */
39
40 #include "vmcore/descriptor.h"
41
42
43 /* register descripton array **************************************************/
44
45 s4 nregdescint[] = {
46     REG_RET, REG_ARG, REG_ARG, REG_TMP, REG_RES, REG_SAV, REG_ARG, REG_ARG,
47     REG_ARG, REG_ARG, REG_RES, REG_RES, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
48     REG_END
49 };
50
51 const char *abi_registers_integer_name[] = {
52         "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
53         "r8",  "r9",  "r10", "r11", "r12", "r13", "r14", "r15"
54 };
55
56 const s4 abi_registers_integer_argument[] = {
57         7,  /* a0 */
58         6,  /* a1 */
59         2,  /* a2 */
60         1,  /* a3 */
61         8,  /* a4 */
62         9,  /* a5 */
63 };
64
65 const s4 abi_registers_integer_saved[] = {
66         7,  /* s0 */
67         12, /* s1 */
68         13, /* s2 */
69         14, /* s3 */
70         15, /* s4 */
71 };
72
73 const s4 abi_registers_integer_temporary[] = {
74         3,  /* t0 */
75 };
76
77
78 /* float registers *************************************************************
79
80    xmm0,   xmm1,   xmm2,   xmm3,   xmm4,   xmm5,   xmm6,   xmm7,
81    (fa0)   (fa1)   (fa2)   (fa3)   (fa4)   (fa5)   (fa6)   (fa7)
82
83    xmm8,   xmm9,   xmm10,  xmm11,  xmm12,  xmm13,  xmm14,  xmm15
84    (ftmp1) (ftmp2) (ftmp3) (ft0)   (ft1)   (ft2)   (ft3)   (ft4)
85
86 *******************************************************************************/
87
88 s4 nregdescfloat[] = {
89     REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
90     REG_RES, REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
91     REG_END
92 };
93
94
95 const s4 abi_registers_float_argument[] = {
96         0,  /* fa0 */
97         1,  /* fa1 */
98         2,  /* fa2 */
99         3,  /* fa3 */
100         4,  /* fa4 */
101         5,  /* fa5 */
102         6,  /* fa6 */
103         7,  /* fa7 */
104 };
105
106 const s4 abi_registers_float_saved[] = {
107         -1,
108 };
109
110 const s4 abi_registers_float_temporary[] = {
111         11, /* ft0 */
112         12, /* ft1 */
113         13, /* ft2 */
114         14, /* ft3 */
115         15, /* ft4 */
116 };
117
118
119 /* md_param_alloc **************************************************************
120
121    XXX
122
123 *******************************************************************************/
124
125 void md_param_alloc(methoddesc *md)
126 {
127         paramdesc *pd;
128         s4         i;
129         s4         iarg;
130         s4         farg;
131         s4         stacksize;
132
133         /* set default values */
134
135         iarg      = 0;
136         farg      = 0;
137         stacksize = 0;
138
139         /* get params field of methoddesc */
140
141         pd = md->params;
142
143         for (i = 0; i < md->paramcount; i++, pd++) {
144                 switch (md->paramtypes[i].type) {
145                 case TYPE_INT:
146                 case TYPE_ADR:
147                 case TYPE_LNG:
148                         if (iarg < INT_ARG_CNT) {
149                                 pd->inmemory = false;
150                                 pd->regoff   = abi_registers_integer_argument[iarg];
151                                 iarg++;
152                         }
153                         else {
154                                 pd->inmemory = true;
155                                 pd->regoff   = stacksize;
156                                 stacksize++;
157                         }
158                         break;
159
160                 case TYPE_FLT:
161                 case TYPE_DBL:
162                         if (farg < FLT_ARG_CNT) {
163                                 pd->inmemory = false;
164                                 pd->regoff   = abi_registers_float_argument[farg];
165                                 farg++;
166                         }
167                         else {
168                                 pd->inmemory = true;
169                                 pd->regoff   = stacksize;
170                                 stacksize++;
171                         }
172                         break;
173                 }
174         }
175
176         /* Since XMM0 (==A0) is used for passing return values, this
177            argument register usage has to be regarded, too. */
178
179         if (IS_FLT_DBL_TYPE(md->returntype.type))
180                 if (farg < 1)
181                         farg = 1;
182
183         /* fill register and stack usage */
184
185         md->argintreguse = iarg;
186         md->argfltreguse = farg;
187         md->memuse       = stacksize;
188 }
189
190
191 /* md_param_alloc_native *******************************************************
192
193    Pre-allocate arguments according the native ABI.
194
195 *******************************************************************************/
196
197 void md_param_alloc_native(methoddesc *md)
198 {
199         /* On x86_64 we use the same ABI for JIT method calls as for
200            native method calls. */
201
202         md_param_alloc(md);
203 }
204
205
206 /* md_return_alloc *************************************************************
207
208    Precolor the Java Stackelement containing the Return Value. Only
209    for float/ double types straight forward possible, since INT_LNG
210    types use "reserved" registers Float/Double values use a00 as
211    return register.
212
213    --- in
214    jd:                      jitdata of the current method
215    stackslot:               Java Stackslot to contain the Return Value
216
217    --- out
218    if precoloring was possible:
219    VAR(stackslot->varnum)->flags     = PREALLOC
220                                      ->vv.regoff = [REG_RESULT|REG_FRESULT]
221    rd->arg[flt|int]reguse   set to a value according the register usage
222
223    NOTE: Do not pass a LOCALVAR in stackslot->varnum.
224
225 *******************************************************************************/
226
227 void md_return_alloc(jitdata *jd, stackptr stackslot)
228 {
229         methodinfo   *m;
230         registerdata *rd;
231         methoddesc   *md;
232
233         /* get required compiler data */
234
235         m  = jd->m;
236         rd = jd->rd;
237
238         md = m->parseddesc;
239
240         /* precoloring only straightforward possible with flt/dbl types
241            For Address/Integer/Long REG_RESULT == rax == REG_ITMP1 and so
242            could be destroyed if the return value Stack Slot "lives too
243            long" */
244
245         if (IS_FLT_DBL_TYPE(md->returntype.type)) {
246                 /* In Leafmethods Local Vars holding parameters are precolored
247                    to their argument register -> so leafmethods with
248                    paramcount > 0 could already use a00! */
249
250                 if (!jd->isleafmethod || (md->paramcount == 0)) {
251                         /* Only precolor the stackslot, if it is not a SAVEDVAR
252                            <-> has not to survive method invokations */
253
254                         if (!(stackslot->flags & SAVEDVAR)) {
255
256                                 VAR(stackslot->varnum)->flags = PREALLOC;
257
258                             /* float/double */
259                                 if (rd->argfltreguse < 1)
260                                         rd->argfltreguse = 1;
261
262                                 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
263                         }
264                 }
265         }
266 }
267
268
269 /*
270  * These are local overrides for various environment variables in Emacs.
271  * Please do not remove this and leave it at the end of the file, where
272  * Emacs will automagically detect them.
273  * ---------------------------------------------------------------------
274  * Local variables:
275  * mode: c
276  * indent-tabs-mode: t
277  * c-basic-offset: 4
278  * tab-width: 4
279  * End:
280  */