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/descriptor.hpp"
34 #include "vm/global.h"
36 #include "vm/jit/abi.h"
37 #include "vm/jit/stack.h"
40 /* register descripton arrays *************************************************/
43 /* zero, sp, NO(sys), a0/v0, a1/v1, a2, a3, a4, */
44 REG_RES, REG_RES, REG_RES, 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, t0, t1, t2, t3, t4, t5, t6, */
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[] = {
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, ft0, ft1, ft2, ft3, ft4, fs0, fs1, */
105 REG_ARG, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_SAV, REG_SAV,
107 /*ftmp1, ftmp2, ft5, ft6, ft7, ft8, ft9, ft10, */
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,
117 const int abi_registers_float_argument[] = {
128 const int abi_registers_float_saved[] = {
141 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) {
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;
249 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return
250 values, this argument register usage has to be regarded,
253 if (IS_INT_LNG_TYPE(md->returntype.type)) {
254 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
255 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
258 if (IS_FLT_DBL_TYPE(md->returntype.type))
263 /* fill register and stack usage */
265 md->argintreguse = iarg;
266 md->argfltreguse = farg;
267 md->memuse = stacksize;
271 /* md_param_alloc_native *******************************************************
273 Pre-allocate arguments according the native ABI.
275 *******************************************************************************/
277 void md_param_alloc_native(methoddesc *md)
285 /* set default values */
289 stacksize = LA_SIZE_IN_POINTERS;
291 /* get params field of methoddesc */
295 for (i = 0; i < md->paramcount; i++, pd++) {
296 switch (md->paramtypes[i].type) {
299 if (iarg < INT_ARG_CNT) {
300 pd->inmemory = false;
301 pd->regoff = abi_registers_integer_argument[iarg];
306 pd->regoff = stacksize * 4;
312 if (iarg < INT_ARG_CNT - 1) {
314 pd->inmemory = false;
316 PACK_REGS(abi_registers_integer_argument[iarg + 1],
317 abi_registers_integer_argument[iarg]);
323 pd->regoff = stacksize * 4;
330 if (farg < FLT_ARG_CNT) {
331 pd->inmemory = false;
332 pd->regoff = abi_registers_float_argument[farg];
337 pd->regoff = stacksize * 4;
343 if (farg < FLT_ARG_CNT) {
344 pd->inmemory = false;
345 pd->regoff = abi_registers_float_argument[farg];
351 pd->regoff = stacksize * 4;
361 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return
362 values, this argument register usage has to be regarded,
365 if (IS_INT_LNG_TYPE(md->returntype.type)) {
366 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
367 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
370 if (IS_FLT_DBL_TYPE(md->returntype.type))
375 /* fill register and stack usage */
377 md->argintreguse = iarg;
378 md->argfltreguse = farg;
379 md->memuse = stacksize;
383 /* md_return_alloc *************************************************************
385 Precolor the Java Stackelement containing the Return Value, if
386 possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
390 jd: jitdata of the current method
391 stackslot: Java Stackslot to contain the Return Value
394 if precoloring was possible:
395 VAR(stackslot->varnum)->flags = PREALLOC
396 ->regoff = [REG_RESULT|REG_FRESULT]
397 rd->arg[flt|int]reguse set to a value according the register usage
399 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
401 *******************************************************************************/
403 void md_return_alloc(jitdata *jd, stackelement_t *stackslot)
411 /* get required compiler data */
419 /* In Leafmethods Local Vars holding parameters are precolored to
420 their argument register -> so leafmethods with paramcount > 0
421 could already use R3 == a00! */
423 if (!code_is_leafmethod(code) || (md->paramcount == 0)) {
424 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
425 has not to survive method invokations. */
427 if (!(stackslot->flags & SAVEDVAR)) {
428 v = VAR(stackslot->varnum);
431 switch (md->returntype.type) {
434 if (rd->argintreguse < 1)
435 rd->argintreguse = 1;
437 v->vv.regoff = REG_RESULT;
441 if (rd->argintreguse < 2)
442 rd->argintreguse = 2;
444 v->vv.regoff = REG_RESULT_PACKED;
449 if (rd->argfltreguse < 1)
450 rd->argfltreguse = 1;
452 v->vv.regoff = REG_FRESULT;
461 * These are local overrides for various environment variables in Emacs.
462 * Please do not remove this and leave it at the end of the file, where
463 * Emacs will automagically detect them.
464 * ---------------------------------------------------------------------
467 * indent-tabs-mode: t
471 * vim:noexpandtab:sw=4:ts=4: