1 /* src/vm/jit/arm/md-abi.c - functions for arm ABI
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
8 This file is part of CACAO.
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.
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.
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
25 $Id: md-abi.c 7356 2007-02-14 11:00:28Z twisti $
33 #include "vm/jit/arm/md-abi.h"
35 #include "vm/global.h"
37 #include "vm/jit/abi.h"
39 #include "vmcore/descriptor.h"
42 /* register descripton array **************************************************/
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,
50 const char *abi_registers_integer_name[] = {
51 "a1", "a2", "a3", "a4", "v1", "v2", "v3", "v4",
52 "v5", "t3", "t1", "t2", "ip", "sp", "lr", "pc",
56 #if defined(ENABLE_SOFTFLOAT)
57 s4 nregdescfloat[] = {
58 REG_RES, REG_RES, REG_RES, REG_RES,
59 REG_RES, REG_RES, REG_RES, REG_RES,
63 /* TODO: FPA register usage conventions */
64 s4 nregdescfloat[] = {
65 REG_TMP, REG_TMP, REG_TMP, REG_TMP,
66 REG_TMP, REG_TMP, REG_RES, REG_RES,
69 #endif /* defined(ENABLE_SOFTFLOAT) */
72 /* md_param_alloc **************************************************************
74 Allocate Arguments to Stackslots according the Calling Conventions
77 md->paramcount: Number of arguments for this method
78 md->paramtypes[].type: Argument types
81 md->params[].inmemory: Argument spilled on stack
82 md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
83 md->memuse: Stackslots needed for argument spilling
84 md->argintreguse: max number of integer arguments used
85 md->argfltreguse: max number of float arguments used
87 *******************************************************************************/
89 void md_param_alloc(methoddesc *md)
96 /* set default values */
100 /* get params field of methoddesc */
103 for (i = 0; i < md->paramcount; i++, pd++) {
104 switch (md->paramtypes[i].type) {
108 if (reguse < INT_ARG_CNT) {
109 pd->inmemory = false;
115 pd->regoff = stacksize;
122 if (reguse+1 < INT_ARG_CNT) {
123 pd->inmemory = false;
124 #if defined(__ARMEL__)
125 pd->regoff = PACK_REGS(reguse, reguse+1);
127 pd->regoff = PACK_REGS(reguse+1, reguse);
131 else if (reguse < INT_ARG_CNT) {
132 pd->inmemory = false;
133 #if defined(__ARMEL__)
134 pd->regoff = PACK_REGS(reguse, INT_ARG_CNT);
136 pd->regoff = PACK_REGS(INT_ARG_CNT, reguse);
143 pd->regoff = stacksize;
150 /* Since R0/R1 (==A0/A1) are used for passing return values, this
151 argument register usage has to be regarded, too. */
153 if (md->returntype.type != TYPE_VOID) {
154 if (!IS_2_WORD_TYPE(md->returntype.type)) {
164 /* fill register and stack usage */
166 md->argintreguse = reguse;
167 md->argfltreguse = 0;
168 md->memuse = stacksize;
172 /* md_param_alloc_native *******************************************************
174 Pre-allocate arguments according the native ABI.
176 *******************************************************************************/
178 #define ALIGN_2(a) do { if ((a) & 0x1) (a)++; } while (0)
180 void md_param_alloc_native(methoddesc *md)
187 /* set default values */
192 /* get params field of methoddesc */
196 for (i = 0; i < md->paramcount; i++, pd++) {
197 switch (md->paramtypes[i].type) {
201 if (reguse < INT_ARG_CNT) {
202 pd->inmemory = false;
208 pd->regoff = stacksize;
215 if (reguse < (INT_ARG_CNT - 1)) {
216 #if defined(__ARM_EABI__)
219 pd->inmemory = false;
220 #if defined(__ARMEL__)
221 pd->regoff = PACK_REGS(reguse, reguse + 1);
223 pd->regoff = PACK_REGS(reguse + 1, reguse);
227 #if !defined(__ARM_EABI__)
228 else if (reguse < INT_ARG_CNT) {
229 pd->inmemory = false;
230 # if defined(__ARMEL__)
231 pd->regoff = PACK_REGS(reguse, INT_ARG_CNT);
233 pd->regoff = PACK_REGS(INT_ARG_CNT, reguse);
240 #if defined(__ARM_EABI__)
244 pd->regoff = stacksize;
245 reguse = INT_ARG_CNT;
252 /* Since R0/R1 (==A0/A1) are used for passing return values, this
253 argument register usage has to be regarded, too. */
255 if (md->returntype.type != TYPE_VOID) {
256 if (!IS_2_WORD_TYPE(md->returntype.type)) {
266 /* fill register and stack usage */
268 md->argintreguse = reguse;
269 md->argfltreguse = 0;
270 md->memuse = stacksize;
274 /* md_return_alloc *************************************************************
276 Precolor the Java Stackelement containing the Return Value, if possible.
279 m: Methodinfo of current method
280 return_type: Return Type of the Method (TYPE_INT.. TYPE_ADR)
281 TYPE_VOID is not allowed!
282 stackslot: Java Stackslot to contain the Return Value
285 if precoloring was possible:
286 VAR(stackslot->varnum)->flags = PREALLOC
287 VAR(stackslot->varnum)->vv.regoff = [REG_RESULT, (REG_RESULT2/REG_RESULT), REG_FRESULT]
288 rd->arg[flt|int]reguse set to a value according the register usage
290 *******************************************************************************/
292 void md_return_alloc(jitdata *jd, stackptr stackslot)
298 /* get required compiler data */
305 /* In Leafmethods Local Vars holding parameters are precolored to
306 their argument register -> so leafmethods with paramcount > 0
307 could already use R0 == a00! */
309 if (!jd->isleafmethod || (md->paramcount == 0)) {
310 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
311 has not to survive method invokations. */
313 if (!(stackslot->flags & SAVEDVAR)) {
314 #if !defined(ENABLE_SOFTFLOAT)
315 /* Stackelements containing float or double values
316 (TYPE_FLT | TYPE_DBL) cannot be precolored, because we
317 use integer register to pass return values. (floats:
318 R0, doubles: R0/R1) */
320 if (!IS_FLT_DBL_TYPE(md->returntype.type)) {
323 VAR(stackslot->varnum)->flags = PREALLOC;
325 if (!IS_2_WORD_TYPE(md->returntype.type)) {
326 if (rd->argintreguse < 1)
327 rd->argintreguse = 1;
329 VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
332 if (rd->argintreguse < 2)
333 rd->argintreguse = 2;
335 VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
338 #if !defined(ENABLE_SOFTFLOAT)
347 * These are local overrides for various environment variables in Emacs.
348 * Please do not remove this and leave it at the end of the file, where
349 * Emacs will automagically detect them.
350 * ---------------------------------------------------------------------
353 * indent-tabs-mode: t