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