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
31 #include "vm/jit/arm/md-abi.h"
33 #include "vm/global.h"
35 #include "vm/jit/abi.h"
37 #include "vmcore/descriptor.h"
40 /* register descripton array **************************************************/
43 REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
44 REG_SAV, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES,
48 const char *abi_registers_integer_name[] = {
49 "a1", "a2", "a3", "a4", "v1", "v2", "v3", "v4",
50 "v5", "t3", "t1", "t2", "ip", "sp", "lr", "pc",
53 const s4 abi_registers_integer_argument[] = {
61 const s4 abi_registers_integer_saved[] = {
69 const s4 abi_registers_integer_temporary[] = {
74 #if defined(ENABLE_SOFTFLOAT)
75 s4 nregdescfloat[] = {
76 REG_RES, REG_RES, REG_RES, REG_RES,
77 REG_RES, REG_RES, REG_RES, REG_RES,
81 /* TODO: FPA register usage conventions */
82 s4 nregdescfloat[] = {
83 REG_TMP, REG_TMP, REG_TMP, REG_TMP,
84 REG_TMP, REG_TMP, REG_RES, REG_RES,
87 #endif /* defined(ENABLE_SOFTFLOAT) */
89 const s4 abi_registers_float_argument[] = {
93 const s4 abi_registers_float_saved[] = {
97 const s4 abi_registers_float_temporary[] = {
98 #if defined(ENABLE_SOFTFLOAT)
111 /* md_param_alloc **************************************************************
113 Allocate Arguments to Stackslots according the Calling Conventions
116 md->paramcount: Number of arguments for this method
117 md->paramtypes[].type: Argument types
120 md->params[].inmemory: Argument spilled on stack
121 md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
122 md->memuse: Stackslots needed for argument spilling
123 md->argintreguse: max number of integer arguments used
124 md->argfltreguse: max number of float arguments used
126 *******************************************************************************/
128 void md_param_alloc(methoddesc *md)
135 /* set default values */
140 /* get params field of methoddesc */
144 for (i = 0; i < md->paramcount; i++, pd++) {
145 switch (md->paramtypes[i].type) {
149 if (reguse < INT_ARG_CNT) {
150 pd->inmemory = false;
152 pd->regoff = abi_registers_integer_argument[reguse];
157 pd->index = stacksize;
158 pd->regoff = stacksize * 8;
165 /* interally we use the EABI */
169 if (reguse < INT_ARG_CNT) {
170 pd->inmemory = false;
171 #if defined(__ARMEL__)
172 pd->index = PACK_REGS(reguse, reguse + 1);
174 PACK_REGS(abi_registers_integer_argument[reguse],
175 abi_registers_integer_argument[reguse + 1]);
177 pd->index = PACK_REGS(reguse + 1, reguse);
179 PACK_REGS(abi_registers_integer_argument[reguse + 1],
180 abi_registers_integer_argument[reguse]);
186 /*ALIGN_2(stacksize);*/
189 pd->index = stacksize;
190 pd->regoff = stacksize * 8;
198 /* Since R0/R1 (==A0/A1) are used for passing return values, this
199 argument register usage has to be regarded, too. */
201 if (md->returntype.type != TYPE_VOID) {
202 if (!IS_2_WORD_TYPE(md->returntype.type)) {
212 /* fill register and stack usage */
214 md->argintreguse = reguse;
215 md->argfltreguse = 0;
216 md->memuse = stacksize;
220 /* md_param_alloc_native *******************************************************
222 Pre-allocate arguments according the native ABI.
224 *******************************************************************************/
226 void md_param_alloc_native(methoddesc *md)
233 /* set default values */
238 /* get params field of methoddesc */
242 for (i = 0; i < md->paramcount; i++, pd++) {
243 switch (md->paramtypes[i].type) {
247 if (reguse < INT_ARG_CNT) {
248 pd->inmemory = false;
250 pd->regoff = abi_registers_integer_argument[reguse];
256 pd->regoff = stacksize * 4;
263 if (reguse < (INT_ARG_CNT - 1)) {
264 #if defined(__ARM_EABI__)
267 pd->inmemory = false;
268 #if defined(__ARMEL__)
271 PACK_REGS(abi_registers_integer_argument[reguse],
272 abi_registers_integer_argument[reguse + 1]);
276 PACK_REGS(abi_registers_integer_argument[reguse + 1],
277 abi_registers_integer_argument[reguse]);
281 #if !defined(__ARM_EABI__)
282 else if (reguse < INT_ARG_CNT) {
283 pd->inmemory = false;
284 # if defined(__ARMEL__)
287 PACK_REGS(abi_registers_integer_argument[reguse],
288 abi_registers_integer_argument[INT_ARG_CNT]);
292 PACK_REGS(abi_registers_integer_argument[INT_ARG_CNT],
293 abi_registers_integer_argument[reguse]);
300 #if defined(__ARM_EABI__)
305 pd->regoff = stacksize * 4;
306 reguse = INT_ARG_CNT;
313 /* Since R0/R1 (==A0/A1) are used for passing return values, this
314 argument register usage has to be regarded, too. */
316 if (md->returntype.type != TYPE_VOID) {
317 if (!IS_2_WORD_TYPE(md->returntype.type)) {
327 /* fill register and stack usage */
329 md->argintreguse = reguse;
330 md->argfltreguse = 0;
331 md->memuse = stacksize;
335 /* md_return_alloc *************************************************************
337 Precolor the Java Stackelement containing the Return Value, if possible.
340 m: Methodinfo of current method
341 return_type: Return Type of the Method (TYPE_INT.. TYPE_ADR)
342 TYPE_VOID is not allowed!
343 stackslot: Java Stackslot to contain the Return Value
346 if precoloring was possible:
347 VAR(stackslot->varnum)->flags = PREALLOC
348 VAR(stackslot->varnum)->vv.regoff = [REG_RESULT, (REG_RESULT2/REG_RESULT), REG_FRESULT]
349 rd->arg[flt|int]reguse set to a value according the register usage
351 *******************************************************************************/
353 void md_return_alloc(jitdata *jd, stackptr stackslot)
359 /* get required compiler data */
366 /* In Leafmethods Local Vars holding parameters are precolored to
367 their argument register -> so leafmethods with paramcount > 0
368 could already use R0 == a00! */
370 if (!jd->isleafmethod || (md->paramcount == 0)) {
371 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
372 has not to survive method invokations. */
374 if (!(stackslot->flags & SAVEDVAR)) {
375 #if !defined(ENABLE_SOFTFLOAT)
376 /* Stackelements containing float or double values
377 (TYPE_FLT | TYPE_DBL) cannot be precolored, because we
378 use integer register to pass return values. (floats:
379 R0, doubles: R0/R1) */
381 if (!IS_FLT_DBL_TYPE(md->returntype.type)) {
384 VAR(stackslot->varnum)->flags = PREALLOC;
386 if (!IS_2_WORD_TYPE(md->returntype.type)) {
387 if (rd->argintreguse < 1)
388 rd->argintreguse = 1;
390 VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
393 if (rd->argintreguse < 2)
394 rd->argintreguse = 2;
396 VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
399 #if !defined(ENABLE_SOFTFLOAT)
408 * These are local overrides for various environment variables in Emacs.
409 * Please do not remove this and leave it at the end of the file, where
410 * Emacs will automagically detect them.
411 * ---------------------------------------------------------------------
414 * indent-tabs-mode: t