* jit/codegen-common.h: Enabled dseg_adddata for s390.
[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 7283 2007-02-04 19:41:14Z 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 "vm/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
56 s4 nregdescfloat[] = {
57         REG_ARG, REG_TMP, REG_ARG, REG_TMP, REG_SAV, REG_TMP, REG_SAV, REG_TMP,
58         REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
59     REG_END
60 };
61
62
63 /* md_param_alloc **************************************************************
64
65    XXX
66
67 *******************************************************************************/
68
69 void md_param_alloc(methoddesc *md)
70 {
71         paramdesc *pd;
72         s4         i;
73         s4         iarg;
74         s4         farg;
75         s4         stacksize;
76
77         /* set default values */
78
79         iarg = 0;
80         farg = 0;
81         stacksize = 0;
82
83         /* get params field of methoddesc */
84
85         pd = md->params;
86
87         for (i = 0; i < md->paramcount; i++, pd++) {
88                 switch (md->paramtypes[i].type) {
89                 case TYPE_INT:
90                 case TYPE_ADR:
91                 case TYPE_LNG:
92                         if (iarg < INT_ARG_CNT) {
93                                 pd->inmemory = false;
94                                 pd->regoff   = iarg;
95                         }
96                         else {
97                                 pd->inmemory = true;
98                                 pd->regoff   = stacksize;
99                         }
100                         if (iarg < INT_ARG_CNT)
101                                 iarg++;
102                         else
103                                 stacksize++;
104                         break;
105
106                 case TYPE_FLT:
107                 case TYPE_DBL:
108                         if (farg < FLT_ARG_CNT) {
109                                 pd->inmemory = false;
110                                 pd->regoff   = farg;
111                         }
112                         else {
113                                 pd->inmemory = true;
114                                 pd->regoff   = stacksize;
115                         }
116                         if (farg < FLT_ARG_CNT)
117                                 farg++;
118                         else
119                                 stacksize++;
120                         break;
121                 }
122         }
123
124         /* Since XMM0 (==A0) is used for passing return values, this
125            argument register usage has to be regarded, too. */
126
127         if (IS_FLT_DBL_TYPE(md->returntype.type))
128                 if (farg < 1)
129                         farg = 1;
130
131         /* fill register and stack usage */
132
133         md->argintreguse = iarg;
134         md->argfltreguse = farg;
135         md->memuse       = stacksize;
136 }
137
138
139 /* md_return_alloc *************************************************************
140
141    Precolor the Java Stackelement containing the Return Value. Only
142    for float/ double types straight forward possible, since INT_LNG
143    types use "reserved" registers Float/Double values use a00 as
144    return register.
145
146    --- in
147    jd:                      jitdata of the current method
148    stackslot:               Java Stackslot to contain the Return Value
149
150    --- out
151    if precoloring was possible:
152    VAR(stackslot->varnum)->flags     = PREALLOC
153                                      ->vv.regoff = [REG_RESULT|REG_FRESULT]
154    rd->arg[flt|int]reguse   set to a value according the register usage
155
156    NOTE: Do not pass a LOCALVAR in stackslot->varnum.
157
158 *******************************************************************************/
159
160 void md_return_alloc(jitdata *jd, stackptr stackslot)
161 {
162         methodinfo   *m;
163         registerdata *rd;
164         methoddesc   *md;
165
166         /* get required compiler data */
167
168         m  = jd->m;
169         rd = jd->rd;
170
171         md = m->parseddesc;
172
173         /* precoloring only straightforward possible with flt/dbl types
174            For Address/Integer/Long REG_RESULT == rax == REG_ITMP1 and so
175            could be destroyed if the return value Stack Slot "lives too
176            long" */
177
178         if (IS_FLT_DBL_TYPE(md->returntype.type)) {
179                 /* In Leafmethods Local Vars holding parameters are precolored
180                    to their argument register -> so leafmethods with
181                    paramcount > 0 could already use a00! */
182
183                 if (!jd->isleafmethod || (md->paramcount == 0)) {
184                         /* Only precolor the stackslot, if it is not a SAVEDVAR
185                            <-> has not to survive method invokations */
186
187                         if (!(stackslot->flags & SAVEDVAR)) {
188
189                                 VAR(stackslot->varnum)->flags = PREALLOC;
190
191                             /* float/double */
192                                 if (rd->argfltreguse < 1)
193                                         rd->argfltreguse = 1;
194
195                                 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
196                         }
197                 }
198         }
199 }
200
201
202 /*
203  * These are local overrides for various environment variables in Emacs.
204  * Please do not remove this and leave it at the end of the file, where
205  * Emacs will automagically detect them.
206  * ---------------------------------------------------------------------
207  * Local variables:
208  * mode: c
209  * indent-tabs-mode: t
210  * c-basic-offset: 4
211  * tab-width: 4
212  * End:
213  */