Merged revisions 7797-7917 via svnmerge from
[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 7839 2007-04-29 22:46:56Z 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         2  /* 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                                 iarg++;
146                         }
147                         else {
148                                 pd->inmemory  = true;
149                                 pd->regoff    = stacksize;
150                                 stacksize++;
151                         }
152                         break;
153
154                 case TYPE_LNG:
155                         if (iarg < INT_ARG_CNT - 1) {
156                                 /* _ALIGN(iarg); */
157                                 pd->inmemory  = false;
158                                 pd->regoff    = 
159                                         PACK_REGS(abi_registers_integer_argument[iarg + 1], 
160                                                           abi_registers_integer_argument[iarg]); 
161                                 iarg += 2;
162                         }
163                         else {
164                                 /* _ALIGN(stacksize); */
165                                 pd->inmemory  = true;
166                                 pd->regoff    = stacksize;
167                                 iarg          = INT_ARG_CNT;
168                                 stacksize    += 2;
169                         }
170                         break;
171
172                 case TYPE_FLT:
173                         if (farg < FLT_ARG_CNT) {
174                                 pd->inmemory  = false;
175                                 pd->regoff    = abi_registers_float_argument[farg]; 
176                                 farg++;
177                         }
178                         else {
179                                 pd->inmemory  = true;
180                                 pd->regoff    = stacksize;
181                                 stacksize++;
182                         }
183                         break;
184
185                 case TYPE_DBL:
186                         if (farg < FLT_ARG_CNT) {
187                                 pd->inmemory  = false;
188                                 pd->regoff    = abi_registers_float_argument[farg]; 
189                                 farg++;
190                         }
191                         else {
192                                 /* _ALIGN(stacksize); */
193                                 pd->inmemory  = true;
194                                 pd->regoff    = stacksize;
195                                 stacksize    += 2;
196                         }
197                         break;
198
199                 default:
200                         assert(0);
201                 }
202         }
203
204         /* Since A0+A1/FA0 are used for passing return
205            values, this argument register usage has to be regarded,
206            too. */
207
208         if (IS_INT_LNG_TYPE(md->returntype.type)) {
209                 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
210                         iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
211         }
212         else {
213                 if (IS_FLT_DBL_TYPE(md->returntype.type))
214                         if (farg < 1)
215                                 farg = 1;
216         }
217
218         /* fill register and stack usage */
219
220         md->argintreguse = iarg;
221         md->argfltreguse = farg;
222         md->memuse = stacksize;
223 }
224
225 void md_param_alloc_native(methoddesc *md)
226 {
227         /* On PowerPC we use the same ABI for JIT method calls as for
228          *        native method calls. */
229
230         md_param_alloc(md);
231 }
232
233
234 /* md_return_alloc *************************************************************
235
236    Precolor the Java Stackelement containing the Return Value. Only
237    for float/ double types straight forward possible, since INT_LNG
238    types use "reserved" registers Float/Double values use a00 as
239    return register.
240
241    --- in
242    jd:                      jitdata of the current method
243    stackslot:               Java Stackslot to contain the Return Value
244
245    --- out
246    if precoloring was possible:
247    VAR(stackslot->varnum)->flags     = PREALLOC
248                                      ->vv.regoff = [REG_RESULT|REG_FRESULT]
249    rd->arg[flt|int]reguse   set to a value according the register usage
250
251    NOTE: Do not pass a LOCALVAR in stackslot->varnum.
252
253 *******************************************************************************/
254
255 void md_return_alloc(jitdata *jd, stackptr stackslot)
256 {
257         methodinfo   *m;
258         registerdata *rd;
259         methoddesc   *md;
260
261         /* get required compiler data */
262
263         m  = jd->m;
264         rd = jd->rd;
265
266         md = m->parseddesc;
267
268         /* In Leafmethods Local Vars holding parameters are precolored to
269            their argument register -> so leafmethods with paramcount > 0
270            could already use R3 == a00! */
271
272         if (!jd->isleafmethod || (md->paramcount == 0)) {
273                 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
274                    has not to survive method invokations. */
275
276                 if (!(stackslot->flags & SAVEDVAR)) {
277                         VAR(stackslot->varnum)->flags = PREALLOC;
278
279                         if (IS_INT_LNG_TYPE(md->returntype.type)) {
280                                 if (!IS_2_WORD_TYPE(md->returntype.type)) {
281                                         if (rd->argintreguse < 1)
282                                                 rd->argintreguse = 1;
283
284                                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
285                                 }
286                                 else {
287                                         if (rd->argintreguse < 2)
288                                                 rd->argintreguse = 2;
289
290                                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
291                                 }
292                         }
293                         else { /* float/double */
294                                 if (rd->argfltreguse < 1)
295                                         rd->argfltreguse = 1;
296
297                                 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
298                         }
299                 }
300         }
301 }
302
303
304 /*
305  * These are local overrides for various environment variables in Emacs.
306  * Please do not remove this and leave it at the end of the file, where
307  * Emacs will automagically detect them.
308  * ---------------------------------------------------------------------
309  * Local variables:
310  * mode: c
311  * indent-tabs-mode: t
312  * c-basic-offset: 4
313  * tab-width: 4
314  * End:
315  */