1 /* src/vm/jit/powerpc/linux/md-abi.c - functions for PowerPC Linux ABI
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: md-abi.c 7713 2007-04-15 21:49:48Z twisti $
36 #include "vm/jit/powerpc/linux/md-abi.h"
38 #include "vm/global.h"
40 #include "vm/jit/abi.h"
42 #include "vmcore/descriptor.h"
45 #define _ALIGN(a) do { if ((a) & 1) (a)++; } while (0)
48 /* register descripton arrays *************************************************/
51 /* zero, sp, NO(sys), a0/v0, a1/v1, a2, a3, a4, */
52 REG_RES, REG_RES, REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
54 /* a5, a6, a7, itmp1, itmp2, pv, s0, s1, */
55 REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES, REG_RES, REG_SAV, REG_SAV,
57 /*itmp3, t0, t1, t2, t3, t4, t5, t6, */
58 REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
60 /* s2, s3, s4, s5, s6, s7, s8, s9, */
61 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
66 const char *abi_registers_integer_name[] = {
67 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
68 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
69 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
70 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
73 const s4 abi_registers_integer_argument[] = {
84 const s4 abi_registers_integer_saved[] = {
97 const s4 abi_registers_integer_temporary[] = {
108 s4 nregdescfloat[] = {
109 /*ftmp3, fa0/v0, fa1, fa2, fa3, fa4, fa5, fa6, */
110 REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
112 /* fa7, ft0, ft1, ft2, ft3, ft4, fs0, fs1, */
113 REG_ARG, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_SAV, REG_SAV,
115 /*ftmp1, ftmp2, ft5, ft6, ft7, ft8, ft9, ft10, */
116 REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
118 /* fs2, fs3, fs4, fs5, fs6, fs7, fs8, fs9 */
119 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
125 const s4 abi_registers_float_argument[] = {
136 const s4 abi_registers_float_saved[] = {
149 const s4 abi_registers_float_temporary[] = {
165 /* md_param_alloc **************************************************************
167 Allocate Arguments to Stackslots according the Calling Conventions
170 md->paramcount: Number of arguments for this method
171 md->paramtypes[].type: Argument types
174 md->params[].inmemory: Argument spilled on stack
175 md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
176 md->memuse: Stackslots needed for argument spilling
177 md->argintreguse: max number of integer arguments used
178 md->argfltreguse: max number of float arguments used
180 *******************************************************************************/
182 void md_param_alloc(methoddesc *md)
190 /* set default values */
194 stacksize = LA_SIZE_IN_POINTERS;
196 /* get params field of methoddesc */
200 for (i = 0; i < md->paramcount; i++, pd++) {
201 switch (md->paramtypes[i].type) {
204 if (iarg < INT_ARG_CNT) {
205 pd->inmemory = false;
206 pd->regoff = abi_registers_integer_argument[iarg];
211 pd->regoff = stacksize;
217 if (iarg < INT_ARG_CNT - 1) {
219 pd->inmemory = false;
221 PACK_REGS(abi_registers_integer_argument[iarg + 1],
222 abi_registers_integer_argument[iarg]);
228 pd->regoff = stacksize;
235 if (farg < FLT_ARG_CNT) {
236 pd->inmemory = false;
237 pd->regoff = abi_registers_float_argument[farg];
242 pd->regoff = stacksize;
248 if (farg < FLT_ARG_CNT) {
249 pd->inmemory = false;
250 pd->regoff = abi_registers_float_argument[farg];
256 pd->regoff = stacksize;
266 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return
267 values, this argument register usage has to be regarded,
270 if (IS_INT_LNG_TYPE(md->returntype.type)) {
271 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
272 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
275 if (IS_FLT_DBL_TYPE(md->returntype.type))
280 /* fill register and stack usage */
282 md->argintreguse = iarg;
283 md->argfltreguse = farg;
284 md->memuse = stacksize;
288 /* md_param_alloc_native *******************************************************
290 Pre-allocate arguments according the native ABI.
292 *******************************************************************************/
294 void md_param_alloc_native(methoddesc *md)
296 /* On PowerPC we use the same ABI for JIT method calls as for
297 native method calls. */
303 /* md_return_alloc *************************************************************
305 Precolor the Java Stackelement containing the Return Value, if
306 possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
310 jd: jitdata of the current method
311 stackslot: Java Stackslot to contain the Return Value
314 if precoloring was possible:
315 VAR(stackslot->varnum)->flags = PREALLOC
316 ->regoff = [REG_RESULT|REG_FRESULT]
317 rd->arg[flt|int]reguse set to a value according the register usage
319 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
321 *******************************************************************************/
323 void md_return_alloc(jitdata *jd, stackptr stackslot)
329 /* get required compiler data */
336 /* In Leafmethods Local Vars holding parameters are precolored to
337 their argument register -> so leafmethods with paramcount > 0
338 could already use R3 == a00! */
340 if (!jd->isleafmethod || (md->paramcount == 0)) {
341 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
342 has not to survive method invokations. */
344 if (!(stackslot->flags & SAVEDVAR)) {
345 VAR(stackslot->varnum)->flags = PREALLOC;
347 if (IS_INT_LNG_TYPE(md->returntype.type)) {
348 if (!IS_2_WORD_TYPE(md->returntype.type)) {
349 if (rd->argintreguse < 1)
350 rd->argintreguse = 1;
352 VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
355 if (rd->argintreguse < 2)
356 rd->argintreguse = 2;
358 VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
361 else { /* float/double */
362 if (rd->argfltreguse < 1)
363 rd->argfltreguse = 1;
365 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
373 * These are local overrides for various environment variables in Emacs.
374 * Please do not remove this and leave it at the end of the file, where
375 * Emacs will automagically detect them.
376 * ---------------------------------------------------------------------
379 * indent-tabs-mode: t