* src/vm/method.c (method_descriptor2types): Removed.
[cacao.git] / src / vm / jit / x86_64 / 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 4381 2006-01-28 14:18:06Z twisti $
32
33 */
34
35
36 #include "config.h"
37 #include "vm/types.h"
38
39 #include "vm/jit/x86_64/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     REG_RET, REG_ARG, REG_ARG, REG_TMP, REG_RES, REG_SAV, REG_ARG, REG_ARG,
49     REG_ARG, REG_ARG, REG_RES, REG_RES, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
50     REG_END
51 };
52
53
54 s4 nregdescfloat[] = {
55     REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
56     REG_RES, REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
57     REG_END
58 };
59
60
61 /* md_param_alloc **************************************************************
62
63    XXX
64
65 *******************************************************************************/
66
67 void md_param_alloc(methoddesc *md)
68 {
69         paramdesc *pd;
70         s4         i;
71         s4         iarg;
72         s4         farg;
73         s4         stacksize;
74
75         /* set default values */
76
77         iarg = 0;
78         farg = 0;
79         stacksize = 0;
80
81         /* get params field of methoddesc */
82
83         pd = md->params;
84
85         for (i = 0; i < md->paramcount; i++, pd++) {
86                 switch (md->paramtypes[i].type) {
87                 case TYPE_INT:
88                 case TYPE_ADR:
89                 case TYPE_LNG:
90                         if (iarg < INT_ARG_CNT) {
91                                 pd->inmemory = false;
92                                 pd->regoff = iarg;
93                         } else {
94                                 pd->inmemory = true;
95                                 pd->regoff = stacksize;
96                         }
97                         if (iarg < INT_ARG_CNT)
98                                 iarg++;
99                         else
100                                 stacksize++;
101                         break;
102                 case TYPE_FLT:
103                 case TYPE_DBL:
104                         if (farg < FLT_ARG_CNT) {
105                                 pd->inmemory = false;
106                                 pd->regoff = farg;
107                         } else {
108                                 pd->inmemory = true;
109                                 pd->regoff = stacksize;
110                         }
111                         if (farg < FLT_ARG_CNT)
112                                 farg++;
113                         else
114                                 stacksize++;
115                         break;
116                 }
117         }
118
119         /* fill register and stack usage */
120
121         md->argintreguse = iarg;
122         md->argfltreguse = farg;
123         md->memuse = stacksize;
124 }
125
126
127 /* md_return_alloc *************************************************************
128
129    Precolor the Java Stackelement containing the Return Value. Only
130    for float/ double types straight forward possible, since INT_LNG
131    types use "reserved" registers Float/Double values use a00 as
132    return register.
133
134    --- in
135    m:                       Methodinfo of current method
136    return_type:             Return Type of the Method (TYPE_INT.. TYPE_ADR)
137                                                         TYPE_VOID is not allowed!
138    stackslot:               Java Stackslot to contain the Return Value
139
140    --- out
141    if precoloring was possible:
142    stackslot->varkind       =ARGVAR
143                         ->varnum        =-1
144                         ->flags         =0
145                         ->regoff        =[REG_RESULT, (REG_RESULT2/REG_RESULT), REG_FRESULT]
146    rd->arg[flt|int]reguse   set to a value according the register usage
147
148 *******************************************************************************/
149
150 void md_return_alloc(methodinfo *m, registerdata *rd, s4 return_type,
151                                          stackptr stackslot)
152 {
153         /* precoloring only straightforward possible with flt/dbl types
154            For Address/Integer/Long REG_RESULT == rax == REG_ITMP1 and so
155            could be destroyed if the return value Stack Slot "lives too
156            long" */
157
158         if (IS_FLT_DBL_TYPE(return_type)) {
159                 /* In Leafmethods Local Vars holding parameters are precolored
160                    to their argument register -> so leafmethods with
161                    paramcount > 0 could already use a00! */
162
163                 if (!m->isleafmethod || (m->parseddesc->paramcount == 0)) {
164                         /* Only precolor the stackslot, if it is not a SAVEDVAR
165                            <-> has not to survive method invokations */
166
167                         if (!(stackslot->flags & SAVEDVAR)) {
168                                 stackslot->varkind = ARGVAR;
169                                 stackslot->varnum = -1;
170                                 stackslot->flags = 0;
171
172                             /* float/double */
173                                 if (rd->argfltreguse < 1)
174                                         rd->argfltreguse = 1;
175
176                                 stackslot->regoff = REG_FRESULT;
177                         }
178                 }
179         }
180 }
181
182
183 /*
184  * These are local overrides for various environment variables in Emacs.
185  * Please do not remove this and leave it at the end of the file, where
186  * Emacs will automagically detect them.
187  * ---------------------------------------------------------------------
188  * Local variables:
189  * mode: c
190  * indent-tabs-mode: t
191  * c-basic-offset: 4
192  * tab-width: 4
193  * End:
194  */