1 /* src/vm/jit/sparc64/md-abi.c - functions for Sparc ABI
3 Copyright (C) 1996-2005, 2006, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 #include "vm/jit/sparc64/md-abi.h"
31 #include "vm/descriptor.hpp"
32 #include "vm/global.h"
34 #include "vm/jit/abi.h"
35 #include "vm/jit/stack.h"
38 #include "mm/memory.hpp"
42 /* helper macros for allocation methods ***************************************/
43 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
45 /* register descripton array **************************************************/
47 /* callee point-of-view, after SAVE has been called. */
49 /* zero itmp1/g1 itmp2/g2 itmp3/g3 temp/g4 temp/g5 sys/g6 sys/g7 */
50 REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES,
52 /* o0 o1 o2 o3 o4 pv/o5 sp/o6 ra/o7 */
53 REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES, REG_RES,
55 /* l0 l1 l2 l3 l4 l5 l6 l7 */
56 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
58 /* i0 i1 i2 i3 i4 pv/i5 fp/i6 ra/i7 */
59 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_RES, REG_RES, REG_RES,
63 const char *abi_registers_integer_name[] = {
64 "zero", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
65 "o0", "o1", "o2", "o3", "o4", "o5", "sp", "o7",
66 "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
67 "i0", "i1", "i2", "i3", "i4", "i5", "fp", "i7"
70 const s4 abi_registers_integer_argument[] = {
78 const s4 abi_registers_integer_saved[] = {
96 s4 nregdescfloat[] = {
97 REG_RET, REG_RES, REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
98 REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP, REG_TMP,
103 const s4 abi_registers_float_argument[] = {
111 const s4 abi_registers_float_temporary[] = {
121 s4 nat_argintregs[] = {
122 REG_OUT0, REG_OUT1, REG_OUT2, REG_OUT3, REG_OUT4, REG_OUT5
126 /* md_param_alloc **************************************************************
128 Allocate Arguments to Stackslots according the Calling Conventions
131 md->paramcount: Number of arguments for this method
132 md->paramtypes[].type: Argument types
135 md->params[].inmemory: Argument spilled on stack
136 md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
137 md->memuse: Stackslots needed for argument spilling
138 md->argintreguse: max number of integer arguments used
139 md->argfltreguse: max number of float arguments used
141 *******************************************************************************/
143 void md_param_alloc(methoddesc *md)
150 /* set default values */
155 /* get params field of methoddesc */
159 for (i = 0; i < md->paramcount; i++, pd++) {
160 switch (md->paramtypes[i].type) {
164 if (i < INT_ARG_CNT) {
165 pd->inmemory = false;
167 pd->regoff = abi_registers_integer_argument[reguse];
169 md->argintreguse = reguse;
173 pd->index = stacksize;
174 pd->regoff = stacksize * 8;
181 if (i < FLT_ARG_CNT) {
182 pd->inmemory = false;
184 pd->regoff = abi_registers_float_argument[reguse];
186 md->argfltreguse = reguse;
190 pd->index = stacksize;
191 pd->regoff = stacksize * 8;
196 assert(pd->regoff != 26);
199 /* Since O0 is used for passing return values, this */
200 /* argument register usage has to be regarded, too */
201 if (IS_INT_LNG_TYPE(md->returntype.type)) {
203 md->argintreguse = 1;
206 /* fill register and stack usage */
208 md->memuse = stacksize;
212 /* md_param_alloc_native *******************************************************
214 * Pre-allocate arguments according to the native ABI.
216 * *******************************************************************************/
218 void md_param_alloc_native(methoddesc *md)
226 /* Note: regoff will be set relative to a stack base of $sp+16 */
228 /* set default values */
230 stacksize = 6; /* abi params: allocated, but not used */
232 /* when we are above this, we have to increase the stacksize with every */
233 /* single argument to create the proper argument array */
234 min_nat_regs = MIN(INT_NATARG_CNT, FLT_NATARG_CNT);
236 /* get params field of methoddesc */
240 for (i = 0; i < md->paramcount; i++, pd++) {
241 switch (md->paramtypes[i].type) {
245 if (i < INT_NATARG_CNT) {
246 pd->inmemory = false;
247 pd->regoff = nat_argintregs[reguse];
249 md->argintreguse = reguse;
253 pd->regoff = reguse * 8;
259 if (i < FLT_NATARG_CNT) {
260 pd->inmemory = false;
263 md->argfltreguse = reguse;
266 pd->regoff = reguse * 8;
273 if (i >= min_nat_regs)
277 /* Since O0 is used for passing return values, this */
278 /* argument register usage has to be regarded, too */
279 if (IS_INT_LNG_TYPE(md->returntype.type)) {
281 md->argintreguse = 1;
284 /* fill register and stack usage */
286 md->memuse = stacksize;
289 /* md_return_alloc *************************************************************
293 *******************************************************************************/
295 void md_return_alloc(jitdata *jd, stackelement_t* stackslot)
302 * These are local overrides for various environment variables in Emacs.
303 * Please do not remove this and leave it at the end of the file, where
304 * Emacs will automagically detect them.
305 * ---------------------------------------------------------------------
308 * indent-tabs-mode: t