1 /* src/vm/jit/powerpc/linux/md-abi.c - functions for PowerPC Linux 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
31 #include "vm/jit/powerpc/linux/md-abi.h"
33 #include "vm/global.h"
35 #include "vm/jit/abi.h"
36 #include "vm/jit/stack.h"
38 #include "vmcore/descriptor.h"
41 /* register descripton arrays *************************************************/
44 /* zero, sp, NO(sys), a0/v0, a1/v1, a2, a3, a4, */
45 REG_RES, REG_RES, REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
47 /* a5, a6, a7, itmp1, itmp2, pv, s0, s1, */
48 REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES, REG_RES, REG_SAV, REG_SAV,
50 /*itmp3, t0, t1, t2, t3, t4, t5, t6, */
51 REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
53 /* s2, s3, s4, s5, s6, s7, s8, s9, */
54 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
59 const char *abi_registers_integer_name[] = {
60 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
61 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
62 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
63 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
66 const int abi_registers_integer_argument[] = {
77 const int abi_registers_integer_saved[] = {
90 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, ft0, ft1, ft2, ft3, ft4, fs0, fs1, */
106 REG_ARG, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_SAV, REG_SAV,
108 /*ftmp1, ftmp2, ft5, ft6, ft7, ft8, ft9, ft10, */
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,
118 const int abi_registers_float_argument[] = {
129 const int abi_registers_float_saved[] = {
142 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) {
213 pd->inmemory = false;
214 pd->index = PACK_REGS(iarg + 1, iarg);
216 PACK_REGS(abi_registers_integer_argument[iarg + 1],
217 abi_registers_integer_argument[iarg]);
222 pd->index = stacksize;
223 pd->regoff = stacksize * 8;
231 if (farg < FLT_ARG_CNT) {
232 pd->inmemory = false;
234 pd->regoff = abi_registers_float_argument[farg];
239 pd->index = stacksize;
240 pd->regoff = stacksize * 8;
250 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return
251 values, this argument register usage has to be regarded,
254 if (IS_INT_LNG_TYPE(md->returntype.type)) {
255 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
256 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
259 if (IS_FLT_DBL_TYPE(md->returntype.type))
264 /* fill register and stack usage */
266 md->argintreguse = iarg;
267 md->argfltreguse = farg;
268 md->memuse = stacksize;
272 /* md_param_alloc_native *******************************************************
274 Pre-allocate arguments according the native ABI.
276 *******************************************************************************/
278 void md_param_alloc_native(methoddesc *md)
286 /* set default values */
290 stacksize = LA_SIZE_IN_POINTERS;
292 /* get params field of methoddesc */
296 for (i = 0; i < md->paramcount; i++, pd++) {
297 switch (md->paramtypes[i].type) {
300 if (iarg < INT_ARG_CNT) {
301 pd->inmemory = false;
302 pd->regoff = abi_registers_integer_argument[iarg];
307 pd->regoff = stacksize * 4;
313 if (iarg < INT_ARG_CNT - 1) {
315 pd->inmemory = false;
317 PACK_REGS(abi_registers_integer_argument[iarg + 1],
318 abi_registers_integer_argument[iarg]);
324 pd->regoff = stacksize * 4;
331 if (farg < FLT_ARG_CNT) {
332 pd->inmemory = false;
333 pd->regoff = abi_registers_float_argument[farg];
338 pd->regoff = stacksize * 4;
344 if (farg < FLT_ARG_CNT) {
345 pd->inmemory = false;
346 pd->regoff = abi_registers_float_argument[farg];
352 pd->regoff = stacksize * 4;
362 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return
363 values, this argument register usage has to be regarded,
366 if (IS_INT_LNG_TYPE(md->returntype.type)) {
367 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
368 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
371 if (IS_FLT_DBL_TYPE(md->returntype.type))
376 /* fill register and stack usage */
378 md->argintreguse = iarg;
379 md->argfltreguse = farg;
380 md->memuse = stacksize;
384 /* md_return_alloc *************************************************************
386 Precolor the Java Stackelement containing the Return Value, if
387 possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
391 jd: jitdata of the current method
392 stackslot: Java Stackslot to contain the Return Value
395 if precoloring was possible:
396 VAR(stackslot->varnum)->flags = PREALLOC
397 ->regoff = [REG_RESULT|REG_FRESULT]
398 rd->arg[flt|int]reguse set to a value according the register usage
400 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
402 *******************************************************************************/
404 void md_return_alloc(jitdata *jd, stackelement_t *stackslot)
412 /* get required compiler data */
420 /* In Leafmethods Local Vars holding parameters are precolored to
421 their argument register -> so leafmethods with paramcount > 0
422 could already use R3 == a00! */
424 if (!code_is_leafmethod(code) || (md->paramcount == 0)) {
425 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
426 has not to survive method invokations. */
428 if (!(stackslot->flags & SAVEDVAR)) {
429 v = VAR(stackslot->varnum);
432 switch (md->returntype.type) {
435 if (rd->argintreguse < 1)
436 rd->argintreguse = 1;
438 v->vv.regoff = REG_RESULT;
442 if (rd->argintreguse < 2)
443 rd->argintreguse = 2;
445 v->vv.regoff = REG_RESULT_PACKED;
450 if (rd->argfltreguse < 1)
451 rd->argfltreguse = 1;
453 v->vv.regoff = REG_FRESULT;
462 * These are local overrides for various environment variables in Emacs.
463 * Please do not remove this and leave it at the end of the file, where
464 * Emacs will automagically detect them.
465 * ---------------------------------------------------------------------
468 * indent-tabs-mode: t