* src/vm/jit/s390/emit.c,
[cacao.git] / src / vm / jit / s390 / 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 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    Contact: cacao@cacaojvm.org
26
27    Authors: Christian Thalinger
28
29    Changes:
30
31    $Id: md-abi.c 7581 2007-03-26 07:23:16Z pm $
32
33 */
34
35
36 #include "config.h"
37 #include "vm/types.h"
38
39 #include "vm/jit/s390/md-abi.h"
40
41 #include "vmcore/descriptor.h"
42 #include "vm/global.h"
43 #include "vm/jit/jit.h"
44
45
46 /* register descripton array **************************************************/
47
48 s4 nregdescint[] = {
49         /*   r0,   itmp1,      a0,      a1,      a2,      a3,      a4,      s0, */
50         REG_TMP, REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_SAV,
51         /*   s1,      s2,      s3,      s4,   itmp2,    pv,  ra/itmp3,      sp */
52         REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_RES, REG_RES, REG_RES, REG_RES,
53     REG_END
54 };
55
56 const char *abi_registers_integer_name[] = {
57         "r0", "r1", "r2", "r3",
58         "r4", "r5", "r6", "r7",
59         "r8", "r9", "r10", "r11",
60         "r12", "r13", "r14", "r15"
61 };
62
63 const s4 abi_registers_integer_argument[] = {
64         2, /* r2/a0 */
65         3, /* r3/a1 */
66         4, /* r4/a2 */
67         5, /* r5/a3 */
68         6  /* r6/a4 */
69 };
70
71 const s4 abi_registers_integer_saved[] = {
72         7,  /* r7/s0 */
73         8,  /* r8/s1 */
74         9,  /* r9/s2 */
75         10, /* r10/s3 */
76         11  /* r11/s4 */
77 };
78
79 const s4 abi_registers_integer_temporary[] = {
80         0, /* r0 */
81 };
82
83 s4 nregdescfloat[] = {
84         REG_ARG, REG_TMP, REG_ARG, REG_TMP, REG_RES, REG_TMP, REG_RES, REG_TMP,
85         REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
86     REG_END
87 };
88
89 const s4 abi_registers_float_argument[] = {
90         0, /* f0/fa0 */
91         1  /* f2/fa2 */
92 };
93
94 const s4 abi_registers_float_saved[] = {
95         /* nothing */
96         -1
97 };
98
99 const s4 abi_registers_float_temporary[] = {
100         1,  /* f1/ft0 */
101         3,  /* f3/ft1 */
102         5,  /* f5/ft2 */
103         7,  /* f7/ft3 */
104         8,  /* f8/ft4 */
105         9,  /* f9/ft5 */
106         10, /* f10/ft6 */
107         11, /* f11/ft7 */
108         12, /* f12/ft8 */
109         13, /* f13/ft9 */
110         14, /* f14/ft10 */
111         15  /* f15/ft11 */
112 };
113
114 /* md_param_alloc **************************************************************
115
116    XXX
117
118 *******************************************************************************/
119
120 void md_param_alloc(methoddesc *md)
121 {
122         paramdesc *pd;
123         s4         i;
124         s4         iarg;
125         s4         farg;
126         s4         stacksize;
127
128         /* set default values */
129
130         iarg = 0;
131         farg = 0;
132         stacksize = 0;
133
134         /* get params field of methoddesc */
135
136         pd = md->params;
137
138         for (i = 0; i < md->paramcount; i++, pd++) {
139                 switch (md->paramtypes[i].type) {
140                 case TYPE_INT:
141                 case TYPE_ADR:
142                         if (iarg < INT_ARG_CNT) {
143                                 pd->inmemory  = false;
144 /*                              pd->regoff    = abi_registers_integer_argument[iarg]; */
145                                 pd->regoff    = iarg;
146                                 iarg++;
147                         }
148                         else {
149                                 pd->inmemory  = true;
150                                 pd->regoff    = stacksize;
151                                 stacksize++;
152                         }
153                         break;
154
155                 case TYPE_LNG:
156                         if (iarg < INT_ARG_CNT - 1) {
157                                 /* _ALIGN(iarg); */
158                                 pd->inmemory  = false;
159 /*                              pd->regoff    = */
160 /*                                      PACK_REGS(abi_registers_integer_argument[iarg + 1], */
161 /*                                                        abi_registers_integer_argument[iarg]); */
162                                 pd->regoff    = PACK_REGS(iarg + 1, iarg);
163                                 iarg += 2;
164                         }
165                         else {
166                                 /* _ALIGN(stacksize); */
167                                 pd->inmemory  = true;
168                                 pd->regoff    = stacksize;
169                                 iarg          = INT_ARG_CNT;
170                                 stacksize    += 2;
171                         }
172                         break;
173
174                 case TYPE_FLT:
175                         if (farg < FLT_ARG_CNT) {
176                                 pd->inmemory  = false;
177 /*                              pd->regoff    = abi_registers_float_argument[farg]; */
178                                 pd->regoff    = farg;
179                                 farg++;
180                         }
181                         else {
182                                 pd->inmemory  = true;
183                                 pd->regoff    = stacksize;
184                                 stacksize++;
185                         }
186                         break;
187
188                 case TYPE_DBL:
189                         if (farg < FLT_ARG_CNT) {
190                                 pd->inmemory  = false;
191 /*                              pd->regoff    = abi_registers_integer_argument[farg]; */
192                                 pd->regoff    = farg;
193                                 farg++;
194                         }
195                         else {
196                                 /* _ALIGN(stacksize); */
197                                 pd->inmemory  = true;
198                                 pd->regoff    = stacksize;
199                                 stacksize    += 2;
200                         }
201                         break;
202
203                 default:
204                         assert(0);
205                 }
206         }
207
208         /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return
209            values, this argument register usage has to be regarded,
210            too. */
211
212         if (IS_INT_LNG_TYPE(md->returntype.type)) {
213                 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
214                         iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
215         }
216         else {
217                 if (IS_FLT_DBL_TYPE(md->returntype.type))
218                         if (farg < 1)
219                                 farg = 1;
220         }
221
222         /* fill register and stack usage */
223
224         md->argintreguse = iarg;
225         md->argfltreguse = farg;
226         md->memuse = stacksize;
227 }
228
229 void md_param_alloc_native(methoddesc *md)
230 {
231         /* On PowerPC we use the same ABI for JIT method calls as for
232          *        native method calls. */
233
234         md_param_alloc(md);
235 }
236
237
238 /* md_return_alloc *************************************************************
239
240    Precolor the Java Stackelement containing the Return Value. Only
241    for float/ double types straight forward possible, since INT_LNG
242    types use "reserved" registers Float/Double values use a00 as
243    return register.
244
245    --- in
246    jd:                      jitdata of the current method
247    stackslot:               Java Stackslot to contain the Return Value
248
249    --- out
250    if precoloring was possible:
251    VAR(stackslot->varnum)->flags     = PREALLOC
252                                      ->vv.regoff = [REG_RESULT|REG_FRESULT]
253    rd->arg[flt|int]reguse   set to a value according the register usage
254
255    NOTE: Do not pass a LOCALVAR in stackslot->varnum.
256
257 *******************************************************************************/
258
259 void md_return_alloc(jitdata *jd, stackptr stackslot)
260 {
261         methodinfo   *m;
262         registerdata *rd;
263         methoddesc   *md;
264
265         /* get required compiler data */
266
267         m  = jd->m;
268         rd = jd->rd;
269
270         md = m->parseddesc;
271
272         /* In Leafmethods Local Vars holding parameters are precolored to
273            their argument register -> so leafmethods with paramcount > 0
274            could already use R3 == a00! */
275
276         if (!jd->isleafmethod || (md->paramcount == 0)) {
277                 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
278                    has not to survive method invokations. */
279
280                 if (!(stackslot->flags & SAVEDVAR)) {
281                         VAR(stackslot->varnum)->flags = PREALLOC;
282
283                         if (IS_INT_LNG_TYPE(md->returntype.type)) {
284                                 if (!IS_2_WORD_TYPE(md->returntype.type)) {
285                                         if (rd->argintreguse < 1)
286                                                 rd->argintreguse = 1;
287
288                                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
289                                 }
290                                 else {
291                                         if (rd->argintreguse < 2)
292                                                 rd->argintreguse = 2;
293
294                                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
295                                 }
296                         }
297                         else { /* float/double */
298                                 if (rd->argfltreguse < 1)
299                                         rd->argfltreguse = 1;
300
301                                 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
302                         }
303                 }
304         }
305 }
306
307
308 /*
309  * These are local overrides for various environment variables in Emacs.
310  * Please do not remove this and leave it at the end of the file, where
311  * Emacs will automagically detect them.
312  * ---------------------------------------------------------------------
313  * Local variables:
314  * mode: c
315  * indent-tabs-mode: t
316  * c-basic-offset: 4
317  * tab-width: 4
318  * End:
319  */