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