* configure.ac [ENABLE_STATICVM] (AC_CHECK_LIB(dl)): Only perform the
[cacao.git] / src / vm / jit / arm / md-abi.c
1 /* src/vm/jit/arm/md-abi.c - functions for arm 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: Michael Starzinger
28
29    Changes: Christian Thalinger
30
31    $Id: md-abi.c 6548 2006-10-01 22:18:38Z edwin $
32
33 */
34
35
36 #include "config.h"
37 #include "vm/types.h"
38
39 #include "vm/jit/arm/md-abi.h"
40
41 #include "vm/descriptor.h"
42 #include "vm/global.h"
43 #include "vm/jit/abi.h"
44
45
46 /* register descripton array **************************************************/
47
48 s4 nregdescint[] = {
49         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
50         REG_SAV, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES,
51         REG_END
52 };
53
54 #if defined(ENABLE_SOFTFLOAT)
55 s4 nregdescfloat[] = {
56         REG_RES, REG_RES, REG_RES, REG_RES,
57         REG_RES, REG_RES, REG_RES, REG_RES,
58         REG_END
59 };
60 #else
61 /* TODO: FPA register usage conventions */
62 s4 nregdescfloat[] = {
63         REG_TMP, REG_TMP, REG_TMP, REG_TMP,
64         REG_TMP, REG_TMP, REG_RES, REG_RES,
65         REG_END
66 };
67 #endif /* defined(ENABLE_SOFTFLOAT) */
68
69
70 /* md_param_alloc **************************************************************
71
72    Allocate Arguments to Stackslots according the Calling Conventions
73
74    --- in:
75    md->paramcount:           Number of arguments for this method
76    md->paramtypes[].type:    Argument types
77
78    --- out:
79    md->params[].inmemory:    Argument spilled on stack
80    md->params[].regoff:      Stack offset or rd->arg[int|flt]regs index
81    md->memuse:               Stackslots needed for argument spilling
82    md->argintreguse:         max number of integer arguments used
83    md->argfltreguse:         max number of float arguments used
84
85 *******************************************************************************/
86
87 void md_param_alloc(methoddesc *md)
88 {
89         paramdesc *pd;
90         s4         i;
91         s4         reguse;
92         s4         stacksize;
93
94         /* set default values */
95         reguse = 0;
96         stacksize = 0;
97
98         /* get params field of methoddesc */
99         pd = md->params;
100
101         for (i = 0; i < md->paramcount; i++, pd++) {
102                 switch (md->paramtypes[i].type) {
103                 case TYPE_INT:
104                 case TYPE_ADR:
105                 case TYPE_FLT:
106                         if (reguse < INT_ARG_CNT) {
107                                 pd->inmemory = false;
108                                 pd->regoff = reguse;
109                                 reguse++;
110                         }
111                         else {
112                                 pd->inmemory = true;
113                                 pd->regoff = stacksize;
114                                 stacksize++;
115                         }
116                         break;
117
118                 case TYPE_LNG:
119                 case TYPE_DBL:
120                         if (reguse+1 < INT_ARG_CNT) {
121                                 pd->inmemory = false;
122 #if defined(__ARMEL__)
123                                 pd->regoff = PACK_REGS(reguse, reguse+1);
124 #else
125                                 pd->regoff = PACK_REGS(reguse+1, reguse);
126 #endif
127                                 reguse += 2;
128                         }
129                         else if (reguse < INT_ARG_CNT) {
130                                 pd->inmemory = false;
131 #if defined(__ARMEL__)
132                                 pd->regoff = PACK_REGS(reguse, INT_ARG_CNT);
133 #else
134                                 pd->regoff = PACK_REGS(INT_ARG_CNT, reguse);
135 #endif
136                                 reguse++;
137                                 stacksize++;
138                         }
139                         else {
140                                 pd->inmemory = true;
141                                 pd->regoff = stacksize;
142                                 stacksize += 2;
143                         }
144                         break;
145                 }
146         }
147
148         /* Since R0/R1 (==A0/A1) are used for passing return values, this
149            argument register usage has to be regarded, too. */
150
151         if (md->returntype.type != TYPE_VOID) {
152                 if (!IS_2_WORD_TYPE(md->returntype.type)) {
153                         if (reguse < 1)
154                                 reguse = 1;
155                 }
156                 else {
157                         if (reguse < 2)
158                                 reguse = 2;
159                 }
160         }
161
162         /* fill register and stack usage */
163
164         md->argintreguse = reguse;
165         md->argfltreguse = 0;
166         md->memuse       = stacksize;
167 }
168
169
170 /* md_return_alloc *************************************************************
171
172    Precolor the Java Stackelement containing the Return Value, if possible.
173
174    --- in
175    m:                       Methodinfo of current method
176    return_type:             Return Type of the Method (TYPE_INT.. TYPE_ADR)
177                             TYPE_VOID is not allowed!
178    stackslot:               Java Stackslot to contain the Return Value
179
180    --- out
181    if precoloring was possible:
182    VAR(stackslot->varnum)->flags = PREALLOC
183    VAR(stackslot->varnum)->vv.regoff = [REG_RESULT, (REG_RESULT2/REG_RESULT), REG_FRESULT]
184    rd->arg[flt|int]reguse   set to a value according the register usage
185
186 *******************************************************************************/
187
188 void md_return_alloc(jitdata *jd, stackptr stackslot)
189 {
190         methodinfo   *m;
191         registerdata *rd;
192         methoddesc   *md;
193
194         /* get required compiler data */
195
196         m  = jd->m;
197         rd = jd->rd;
198
199         md = m->parseddesc;
200
201         /* In Leafmethods Local Vars holding parameters are precolored to
202            their argument register -> so leafmethods with paramcount > 0
203            could already use R0 == a00! */
204
205         if (!jd->isleafmethod || (md->paramcount == 0)) {
206                 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
207                    has not to survive method invokations. */
208
209                 if (!(stackslot->flags & SAVEDVAR)) {
210 #if !defined(ENABLE_SOFTFLOAT)
211                         /* Stackelements containing float or double values
212                            (TYPE_FLT | TYPE_DBL) cannot be precolored, because we
213                            use integer register to pass return values. (floats:
214                            R0, doubles: R0/R1) */
215
216                         if (!IS_FLT_DBL_TYPE(md->returntype.type)) {
217 #endif
218
219                                 VAR(stackslot->varnum)->flags = PREALLOC;
220
221                                 if (!IS_2_WORD_TYPE(md->returntype.type)) {
222                                         if (rd->argintreguse < 1)
223                                                 rd->argintreguse = 1;
224
225                                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
226                                 }
227                                 else {
228                                         if (rd->argintreguse < 2)
229                                                 rd->argintreguse = 2;
230
231                                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
232                                 }
233
234 #if !defined(ENABLE_SOFTFLOAT)
235                         }
236 #endif
237                 }
238         }
239 }
240
241
242 /*
243  * These are local overrides for various environment variables in Emacs.
244  * Please do not remove this and leave it at the end of the file, where
245  * Emacs will automagically detect them.
246  * ---------------------------------------------------------------------
247  * Local variables:
248  * mode: c
249  * indent-tabs-mode: t
250  * c-basic-offset: 4
251  * tab-width: 4
252  * End:
253  */