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/global.h"
34 #include "vm/jit/abi.h"
35 #include "vm/jit/stack.h"
37 #include "vmcore/descriptor.h"
40 /* register descripton arrays *************************************************/
43 /* zero, sp, t0, a0/v0, a0/v1, a2, a3, a4, */
44 REG_RES, REG_RES, REG_TMP, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
46 /* a5, a6, a7, itmp1, itmp2, pv, s0, s1, */
47 REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES, REG_RES, REG_SAV, REG_SAV,
49 /*itmp3, t1, t2, t3, t4, t5, t6, t7, */
50 REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
52 /* s2, s3, s4, s5, s6, s7, s8, s9, */
53 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
58 const char *abi_registers_integer_name[] = {
59 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
60 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
61 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
62 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
65 const int abi_registers_integer_argument[] = {
76 const int abi_registers_integer_saved[] = {
89 const int abi_registers_integer_temporary[] = {
101 int nregdescfloat[] = {
102 /*ftmp3, fa0/v0, fa1, fa2, fa3, fa4, fa5, fa6, */
103 REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
105 /* fa7, fa8, fa9, fa10, fa11, fa12, fs0, fs1, */
106 REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_SAV, REG_SAV,
108 /*ftmp1, ftmp2, ft0, ft1, ft2, ft3, ft4, ft5, */
109 REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
111 /* fs2, fs3, fs4, fs5, fs6, fs7, fs8, fs9 */
112 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
117 const int abi_registers_float_argument[] = {
133 const int abi_registers_float_saved[] = {
146 const int abi_registers_float_temporary[] = {
157 /* md_param_alloc **************************************************************
159 Allocate Arguments to Stackslots according the Calling Conventions
162 md->paramcount: Number of arguments for this method
163 md->paramtypes[].type: Argument types
166 md->params[].inmemory: Argument spilled on stack
167 md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
168 md->memuse: Stackslots needed for argument spilling
169 md->argintreguse: max number of integer arguments used
170 md->argfltreguse: max number of float arguments used
172 *******************************************************************************/
174 void md_param_alloc(methoddesc *md)
182 /* set default values */
186 stacksize = LA_SIZE_IN_POINTERS;
188 /* get params field of methoddesc */
192 for (i = 0; i < md->paramcount; i++, pd++) {
193 switch (md->paramtypes[i].type) {
196 if (iarg < INT_ARG_CNT) {
197 pd->inmemory = false;
199 pd->regoff = abi_registers_integer_argument[iarg];
204 pd->index = stacksize;
205 pd->regoff = stacksize * 8;
211 if (iarg < INT_ARG_CNT - 1) {
212 pd->inmemory = false;
213 pd->index = PACK_REGS(iarg + 1, iarg);
215 PACK_REGS(abi_registers_integer_argument[iarg + 1],
216 abi_registers_integer_argument[iarg]);
221 pd->index = stacksize;
222 pd->regoff = stacksize * 8;
230 if (farg < FLT_ARG_CNT) {
231 pd->inmemory = false;
233 pd->regoff = abi_registers_float_argument[farg];
238 pd->index = stacksize;
239 pd->regoff = stacksize * 8;
247 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return values, this */
248 /* argument register usage has to be regarded, too */
250 if (IS_INT_LNG_TYPE(md->returntype.type)) {
251 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
252 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
255 if (IS_FLT_DBL_TYPE(md->returntype.type))
260 /* fill register and stack usage */
262 md->argintreguse = iarg;
263 md->argfltreguse = farg;
264 md->memuse = stacksize;
268 /* md_param_alloc_native *******************************************************
270 Pre-allocate arguments according the native ABI.
272 *******************************************************************************/
274 void md_param_alloc_native(methoddesc *md)
282 /* set default values */
286 stacksize = LA_SIZE_IN_POINTERS;
288 /* get params field of methoddesc */
292 for (i = 0; i < md->paramcount; i++, pd++) {
293 switch (md->paramtypes[i].type) {
296 if (iarg < INT_ARG_CNT) {
297 pd->inmemory = false;
298 pd->regoff = abi_registers_integer_argument[iarg];
303 pd->regoff = stacksize * 4;
309 if (iarg < INT_ARG_CNT - 1) {
310 pd->inmemory = false;
312 PACK_REGS(abi_registers_integer_argument[iarg + 1],
313 abi_registers_integer_argument[iarg]);
318 pd->regoff = stacksize * 4;
325 if (farg < FLT_ARG_CNT) {
326 pd->inmemory = false;
327 pd->regoff = abi_registers_float_argument[farg];
328 iarg++; /* skip 1 integer argument register */
333 pd->regoff = stacksize * 4;
339 if (farg < FLT_ARG_CNT) {
340 pd->inmemory = false;
341 pd->regoff = abi_registers_float_argument[farg];
342 iarg += 2; /* skip 2 integer argument registers */
347 pd->regoff = stacksize * 4;
355 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return values, this */
356 /* argument register usage has to be regarded, too */
358 if (IS_INT_LNG_TYPE(md->returntype.type)) {
359 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
360 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
363 if (IS_FLT_DBL_TYPE(md->returntype.type))
368 /* fill register and stack usage */
370 md->argintreguse = iarg;
371 md->argfltreguse = farg;
372 md->memuse = stacksize;
376 /* md_return_alloc *************************************************************
378 Precolor the Java Stackelement containing the Return Value, if
379 possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
383 jd: jitdata of the current method
384 stackslot: Java Stackslot to contain the Return Value
387 if precoloring was possible:
388 VAR(stackslot->varnum)->flags = PREALLOC
389 ->regoff = [REG_RESULT|REG_FRESULT]
390 rd->arg[flt|int]reguse set to a value according the register usage
392 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
394 *******************************************************************************/
396 void md_return_alloc(jitdata *jd, stackelement_t* stackslot)
403 /* get required compiler data */
411 /* In Leafmethods Local Vars holding parameters are precolored to
412 their argument register -> so leafmethods with paramcount > 0
413 could already use R3 == a00! */
415 if (!code_is_leafmethod(code) || (md->paramcount == 0)) {
416 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
417 has not to survive method invokations. */
419 if (!(stackslot->flags & SAVEDVAR)) {
421 VAR(stackslot->varnum)->flags = PREALLOC;
423 if (IS_INT_LNG_TYPE(md->returntype.type)) {
424 if (!IS_2_WORD_TYPE(md->returntype.type)) {
425 if (rd->argintreguse < 1)
426 rd->argintreguse = 1;
428 VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
431 if (rd->argintreguse < 2)
432 rd->argintreguse = 2;
434 VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
438 if (rd->argfltreguse < 1)
439 rd->argfltreguse = 1;
441 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
449 * These are local overrides for various environment variables in Emacs.
450 * Please do not remove this and leave it at the end of the file, where
451 * Emacs will automagically detect them.
452 * ---------------------------------------------------------------------
455 * indent-tabs-mode: t