1 /* src/vm/jit/powerpc/darwin/md-abi.c - PowerPC Darwin ABI
3 Copyright (C) 1996-2005, 2006, 2007, 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
30 #include "vm/jit/powerpc/darwin/md-abi.h"
32 #include "vm/descriptor.hpp"
33 #include "vm/global.h"
35 #include "vm/jit/abi.h"
36 #include "vm/jit/stack.h"
39 /* register descripton arrays *************************************************/
42 /* zero, sp, t0, a0/v0, a0/v1, a2, a3, a4, */
43 REG_RES, REG_RES, REG_TMP, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
45 /* a5, a6, a7, itmp1, itmp2, pv, s0, s1, */
46 REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES, REG_RES, REG_SAV, REG_SAV,
48 /*itmp3, t1, t2, t3, t4, t5, t6, t7, */
49 REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
51 /* s2, s3, s4, s5, s6, s7, s8, s9, */
52 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
57 const char *abi_registers_integer_name[] = {
58 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
59 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
60 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
61 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
64 const int abi_registers_integer_argument[] = {
75 const int abi_registers_integer_saved[] = {
88 const int abi_registers_integer_temporary[] = {
100 int nregdescfloat[] = {
101 /*ftmp3, fa0/v0, fa1, fa2, fa3, fa4, fa5, fa6, */
102 REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
104 /* fa7, fa8, fa9, fa10, fa11, fa12, fs0, fs1, */
105 REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_SAV, REG_SAV,
107 /*ftmp1, ftmp2, ft0, ft1, ft2, ft3, ft4, ft5, */
108 REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
110 /* fs2, fs3, fs4, fs5, fs6, fs7, fs8, fs9 */
111 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
116 const int abi_registers_float_argument[] = {
132 const int abi_registers_float_saved[] = {
145 const int abi_registers_float_temporary[] = {
156 /* md_param_alloc **************************************************************
158 Allocate Arguments to Stackslots according the Calling Conventions
161 md->paramcount: Number of arguments for this method
162 md->paramtypes[].type: Argument types
165 md->params[].inmemory: Argument spilled on stack
166 md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
167 md->memuse: Stackslots needed for argument spilling
168 md->argintreguse: max number of integer arguments used
169 md->argfltreguse: max number of float arguments used
171 *******************************************************************************/
173 void md_param_alloc(methoddesc *md)
181 /* set default values */
185 stacksize = LA_SIZE_IN_POINTERS;
187 /* get params field of methoddesc */
191 for (i = 0; i < md->paramcount; i++, pd++) {
192 switch (md->paramtypes[i].type) {
195 if (iarg < INT_ARG_CNT) {
196 pd->inmemory = false;
198 pd->regoff = abi_registers_integer_argument[iarg];
203 pd->index = stacksize;
204 pd->regoff = stacksize * 8;
210 if (iarg < INT_ARG_CNT - 1) {
211 pd->inmemory = false;
212 pd->index = PACK_REGS(iarg + 1, iarg);
214 PACK_REGS(abi_registers_integer_argument[iarg + 1],
215 abi_registers_integer_argument[iarg]);
220 pd->index = stacksize;
221 pd->regoff = stacksize * 8;
229 if (farg < FLT_ARG_CNT) {
230 pd->inmemory = false;
232 pd->regoff = abi_registers_float_argument[farg];
237 pd->index = stacksize;
238 pd->regoff = stacksize * 8;
246 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return values, this */
247 /* argument register usage has to be regarded, too */
249 if (IS_INT_LNG_TYPE(md->returntype.type)) {
250 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
251 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
254 if (IS_FLT_DBL_TYPE(md->returntype.type))
259 /* fill register and stack usage */
261 md->argintreguse = iarg;
262 md->argfltreguse = farg;
263 md->memuse = stacksize;
267 /* md_param_alloc_native *******************************************************
269 Pre-allocate arguments according the native ABI.
271 *******************************************************************************/
273 void md_param_alloc_native(methoddesc *md)
281 /* set default values */
285 stacksize = LA_SIZE_IN_POINTERS;
287 /* get params field of methoddesc */
291 for (i = 0; i < md->paramcount; i++, pd++) {
292 switch (md->paramtypes[i].type) {
295 if (iarg < INT_ARG_CNT) {
296 pd->inmemory = false;
297 pd->regoff = abi_registers_integer_argument[iarg];
302 pd->regoff = stacksize * 4;
308 if (iarg < INT_ARG_CNT - 1) {
309 pd->inmemory = false;
311 PACK_REGS(abi_registers_integer_argument[iarg + 1],
312 abi_registers_integer_argument[iarg]);
317 pd->regoff = stacksize * 4;
324 if (farg < FLT_ARG_CNT) {
325 pd->inmemory = false;
326 pd->regoff = abi_registers_float_argument[farg];
327 iarg++; /* skip 1 integer argument register */
332 pd->regoff = stacksize * 4;
338 if (farg < FLT_ARG_CNT) {
339 pd->inmemory = false;
340 pd->regoff = abi_registers_float_argument[farg];
341 iarg += 2; /* skip 2 integer argument registers */
346 pd->regoff = stacksize * 4;
354 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return values, this */
355 /* argument register usage has to be regarded, too */
357 if (IS_INT_LNG_TYPE(md->returntype.type)) {
358 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
359 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
362 if (IS_FLT_DBL_TYPE(md->returntype.type))
367 /* fill register and stack usage */
369 md->argintreguse = iarg;
370 md->argfltreguse = farg;
371 md->memuse = stacksize;
375 /* md_return_alloc *************************************************************
377 Precolor the Java Stackelement containing the Return Value, if
378 possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
382 jd: jitdata of the current method
383 stackslot: Java Stackslot to contain the Return Value
386 if precoloring was possible:
387 VAR(stackslot->varnum)->flags = PREALLOC
388 ->regoff = [REG_RESULT|REG_FRESULT]
389 rd->arg[flt|int]reguse set to a value according the register usage
391 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
393 *******************************************************************************/
395 void md_return_alloc(jitdata *jd, stackelement_t* stackslot)
402 /* get required compiler data */
410 /* In Leafmethods Local Vars holding parameters are precolored to
411 their argument register -> so leafmethods with paramcount > 0
412 could already use R3 == a00! */
414 if (!code_is_leafmethod(code) || (md->paramcount == 0)) {
415 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
416 has not to survive method invokations. */
418 if (!(stackslot->flags & SAVEDVAR)) {
420 VAR(stackslot->varnum)->flags = PREALLOC;
422 if (IS_INT_LNG_TYPE(md->returntype.type)) {
423 if (!IS_2_WORD_TYPE(md->returntype.type)) {
424 if (rd->argintreguse < 1)
425 rd->argintreguse = 1;
427 VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
430 if (rd->argintreguse < 2)
431 rd->argintreguse = 2;
433 VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
437 if (rd->argfltreguse < 1)
438 rd->argfltreguse = 1;
440 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
448 * These are local overrides for various environment variables in Emacs.
449 * Please do not remove this and leave it at the end of the file, where
450 * Emacs will automagically detect them.
451 * ---------------------------------------------------------------------
454 * indent-tabs-mode: t