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