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 7932 2007-05-22 07:00:57Z michi $
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",
55 const s4 abi_registers_integer_argument[] = {
63 const s4 abi_registers_integer_saved[] = {
71 const s4 abi_registers_integer_temporary[] = {
76 #if defined(ENABLE_SOFTFLOAT)
77 s4 nregdescfloat[] = {
78 REG_RES, REG_RES, REG_RES, REG_RES,
79 REG_RES, REG_RES, REG_RES, REG_RES,
83 /* TODO: FPA register usage conventions */
84 s4 nregdescfloat[] = {
85 REG_TMP, REG_TMP, REG_TMP, REG_TMP,
86 REG_TMP, REG_TMP, REG_RES, REG_RES,
89 #endif /* defined(ENABLE_SOFTFLOAT) */
91 const s4 abi_registers_float_argument[] = {
95 const s4 abi_registers_float_saved[] = {
99 const s4 abi_registers_float_temporary[] = {
100 #if defined(ENABLE_SOFTFLOAT)
113 /* md_param_alloc **************************************************************
115 Allocate Arguments to Stackslots according the Calling Conventions
118 md->paramcount: Number of arguments for this method
119 md->paramtypes[].type: Argument types
122 md->params[].inmemory: Argument spilled on stack
123 md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
124 md->memuse: Stackslots needed for argument spilling
125 md->argintreguse: max number of integer arguments used
126 md->argfltreguse: max number of float arguments used
128 *******************************************************************************/
130 void md_param_alloc(methoddesc *md)
137 /* set default values */
142 /* get params field of methoddesc */
146 for (i = 0; i < md->paramcount; i++, pd++) {
147 switch (md->paramtypes[i].type) {
151 if (reguse < INT_ARG_CNT) {
152 pd->inmemory = false;
153 pd->regoff = abi_registers_integer_argument[reguse];
158 pd->regoff = stacksize;
165 /* interally we use the EABI */
169 if (reguse < INT_ARG_CNT) {
170 pd->inmemory = false;
171 #if defined(__ARMEL__)
173 PACK_REGS(abi_registers_integer_argument[reguse],
174 abi_registers_integer_argument[reguse + 1]);
177 PACK_REGS(abi_registers_integer_argument[reguse + 1],
178 abi_registers_integer_argument[reguse]);
187 pd->regoff = stacksize;
194 /* Since R0/R1 (==A0/A1) are used for passing return values, this
195 argument register usage has to be regarded, too. */
197 if (md->returntype.type != TYPE_VOID) {
198 if (!IS_2_WORD_TYPE(md->returntype.type)) {
208 /* fill register and stack usage */
210 md->argintreguse = reguse;
211 md->argfltreguse = 0;
212 md->memuse = stacksize;
216 /* md_param_alloc_native *******************************************************
218 Pre-allocate arguments according the native ABI.
220 *******************************************************************************/
222 void md_param_alloc_native(methoddesc *md)
229 /* set default values */
234 /* get params field of methoddesc */
238 for (i = 0; i < md->paramcount; i++, pd++) {
239 switch (md->paramtypes[i].type) {
243 if (reguse < INT_ARG_CNT) {
244 pd->inmemory = false;
245 pd->regoff = abi_registers_integer_argument[reguse];
250 pd->regoff = stacksize;
257 if (reguse < (INT_ARG_CNT - 1)) {
258 #if defined(__ARM_EABI__)
261 pd->inmemory = false;
262 #if defined(__ARMEL__)
264 PACK_REGS(abi_registers_integer_argument[reguse],
265 abi_registers_integer_argument[reguse + 1]);
268 PACK_REGS(abi_registers_integer_argument[reguse + 1],
269 abi_registers_integer_argument[reguse]);
273 #if !defined(__ARM_EABI__)
274 else if (reguse < INT_ARG_CNT) {
275 pd->inmemory = false;
276 # if defined(__ARMEL__)
278 PACK_REGS(abi_registers_integer_argument[reguse],
279 abi_registers_integer_argument[INT_ARG_CNT]);
282 PACK_REGS(abi_registers_integer_argument[INT_ARG_CNT],
283 abi_registers_integer_argument[reguse]);
290 #if defined(__ARM_EABI__)
294 pd->regoff = stacksize;
295 reguse = INT_ARG_CNT;
302 /* Since R0/R1 (==A0/A1) are used for passing return values, this
303 argument register usage has to be regarded, too. */
305 if (md->returntype.type != TYPE_VOID) {
306 if (!IS_2_WORD_TYPE(md->returntype.type)) {
316 /* fill register and stack usage */
318 md->argintreguse = reguse;
319 md->argfltreguse = 0;
320 md->memuse = stacksize;
324 /* md_return_alloc *************************************************************
326 Precolor the Java Stackelement containing the Return Value, if possible.
329 m: Methodinfo of current method
330 return_type: Return Type of the Method (TYPE_INT.. TYPE_ADR)
331 TYPE_VOID is not allowed!
332 stackslot: Java Stackslot to contain the Return Value
335 if precoloring was possible:
336 VAR(stackslot->varnum)->flags = PREALLOC
337 VAR(stackslot->varnum)->vv.regoff = [REG_RESULT, (REG_RESULT2/REG_RESULT), REG_FRESULT]
338 rd->arg[flt|int]reguse set to a value according the register usage
340 *******************************************************************************/
342 void md_return_alloc(jitdata *jd, stackptr stackslot)
348 /* get required compiler data */
355 /* In Leafmethods Local Vars holding parameters are precolored to
356 their argument register -> so leafmethods with paramcount > 0
357 could already use R0 == a00! */
359 if (!jd->isleafmethod || (md->paramcount == 0)) {
360 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
361 has not to survive method invokations. */
363 if (!(stackslot->flags & SAVEDVAR)) {
364 #if !defined(ENABLE_SOFTFLOAT)
365 /* Stackelements containing float or double values
366 (TYPE_FLT | TYPE_DBL) cannot be precolored, because we
367 use integer register to pass return values. (floats:
368 R0, doubles: R0/R1) */
370 if (!IS_FLT_DBL_TYPE(md->returntype.type)) {
373 VAR(stackslot->varnum)->flags = PREALLOC;
375 if (!IS_2_WORD_TYPE(md->returntype.type)) {
376 if (rd->argintreguse < 1)
377 rd->argintreguse = 1;
379 VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
382 if (rd->argintreguse < 2)
383 rd->argintreguse = 2;
385 VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
388 #if !defined(ENABLE_SOFTFLOAT)
397 * These are local overrides for various environment variables in Emacs.
398 * Please do not remove this and leave it at the end of the file, where
399 * Emacs will automagically detect them.
400 * ---------------------------------------------------------------------
403 * indent-tabs-mode: t