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
33 #include "vm/jit/powerpc/linux/md-abi.h"
35 #include "vm/global.h"
37 #include "vm/jit/abi.h"
39 #include "vmcore/descriptor.h"
42 /* register descripton arrays *************************************************/
45 /* zero, sp, NO(sys), a0/v0, a1/v1, a2, a3, a4, */
46 REG_RES, REG_RES, REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
48 /* a5, a6, a7, itmp1, itmp2, pv, s0, s1, */
49 REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES, REG_RES, REG_SAV, REG_SAV,
51 /*itmp3, t0, t1, t2, t3, t4, t5, t6, */
52 REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
54 /* s2, s3, s4, s5, s6, s7, s8, s9, */
55 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
60 const char *abi_registers_integer_name[] = {
61 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
62 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
63 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
64 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
67 const int abi_registers_integer_argument[] = {
78 const int abi_registers_integer_saved[] = {
91 const int abi_registers_integer_temporary[] = {
102 int nregdescfloat[] = {
103 /*ftmp3, fa0/v0, fa1, fa2, fa3, fa4, fa5, fa6, */
104 REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
106 /* fa7, ft0, ft1, ft2, ft3, ft4, fs0, fs1, */
107 REG_ARG, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_SAV, REG_SAV,
109 /*ftmp1, ftmp2, ft5, ft6, ft7, ft8, ft9, ft10, */
110 REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
112 /* fs2, fs3, fs4, fs5, fs6, fs7, fs8, fs9 */
113 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
119 const int abi_registers_float_argument[] = {
130 const int abi_registers_float_saved[] = {
143 const int abi_registers_float_temporary[] = {
158 /* md_param_alloc **************************************************************
160 Allocate Arguments to Stackslots according the Calling Conventions
163 md->paramcount: Number of arguments for this method
164 md->paramtypes[].type: Argument types
167 md->params[].inmemory: Argument spilled on stack
168 md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
169 md->memuse: Stackslots needed for argument spilling
170 md->argintreguse: max number of integer arguments used
171 md->argfltreguse: max number of float arguments used
173 *******************************************************************************/
175 void md_param_alloc(methoddesc *md)
183 /* set default values */
187 stacksize = LA_SIZE_IN_POINTERS;
189 /* get params field of methoddesc */
193 for (i = 0; i < md->paramcount; i++, pd++) {
194 switch (md->paramtypes[i].type) {
197 if (iarg < INT_ARG_CNT) {
198 pd->inmemory = false;
200 pd->regoff = abi_registers_integer_argument[iarg];
205 pd->index = stacksize;
206 pd->regoff = stacksize * 8;
212 if (iarg < INT_ARG_CNT - 1) {
214 pd->inmemory = false;
215 pd->index = PACK_REGS(iarg + 1, iarg);
217 PACK_REGS(abi_registers_integer_argument[iarg + 1],
218 abi_registers_integer_argument[iarg]);
223 pd->index = stacksize;
224 pd->regoff = stacksize * 8;
232 if (farg < FLT_ARG_CNT) {
233 pd->inmemory = false;
235 pd->regoff = abi_registers_float_argument[farg];
240 pd->index = stacksize;
241 pd->regoff = stacksize * 8;
251 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return
252 values, this argument register usage has to be regarded,
255 if (IS_INT_LNG_TYPE(md->returntype.type)) {
256 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
257 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
260 if (IS_FLT_DBL_TYPE(md->returntype.type))
265 /* fill register and stack usage */
267 md->argintreguse = iarg;
268 md->argfltreguse = farg;
269 md->memuse = stacksize;
273 /* md_param_alloc_native *******************************************************
275 Pre-allocate arguments according the native ABI.
277 *******************************************************************************/
279 void md_param_alloc_native(methoddesc *md)
287 /* set default values */
291 stacksize = LA_SIZE_IN_POINTERS;
293 /* get params field of methoddesc */
297 for (i = 0; i < md->paramcount; i++, pd++) {
298 switch (md->paramtypes[i].type) {
301 if (iarg < INT_ARG_CNT) {
302 pd->inmemory = false;
303 pd->regoff = abi_registers_integer_argument[iarg];
308 pd->regoff = stacksize * 4;
314 if (iarg < INT_ARG_CNT - 1) {
316 pd->inmemory = false;
318 PACK_REGS(abi_registers_integer_argument[iarg + 1],
319 abi_registers_integer_argument[iarg]);
325 pd->regoff = stacksize * 4;
332 if (farg < FLT_ARG_CNT) {
333 pd->inmemory = false;
334 pd->regoff = abi_registers_float_argument[farg];
339 pd->regoff = stacksize * 4;
345 if (farg < FLT_ARG_CNT) {
346 pd->inmemory = false;
347 pd->regoff = abi_registers_float_argument[farg];
353 pd->regoff = stacksize * 4;
363 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return
364 values, this argument register usage has to be regarded,
367 if (IS_INT_LNG_TYPE(md->returntype.type)) {
368 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
369 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
372 if (IS_FLT_DBL_TYPE(md->returntype.type))
377 /* fill register and stack usage */
379 md->argintreguse = iarg;
380 md->argfltreguse = farg;
381 md->memuse = stacksize;
385 /* md_return_alloc *************************************************************
387 Precolor the Java Stackelement containing the Return Value, if
388 possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
392 jd: jitdata of the current method
393 stackslot: Java Stackslot to contain the Return Value
396 if precoloring was possible:
397 VAR(stackslot->varnum)->flags = PREALLOC
398 ->regoff = [REG_RESULT|REG_FRESULT]
399 rd->arg[flt|int]reguse set to a value according the register usage
401 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
403 *******************************************************************************/
405 void md_return_alloc(jitdata *jd, stackptr stackslot)
411 /* get required compiler data */
418 /* In Leafmethods Local Vars holding parameters are precolored to
419 their argument register -> so leafmethods with paramcount > 0
420 could already use R3 == a00! */
422 if (!jd->isleafmethod || (md->paramcount == 0)) {
423 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
424 has not to survive method invokations. */
426 if (!(stackslot->flags & SAVEDVAR)) {
427 VAR(stackslot->varnum)->flags = PREALLOC;
429 if (IS_INT_LNG_TYPE(md->returntype.type)) {
430 if (!IS_2_WORD_TYPE(md->returntype.type)) {
431 if (rd->argintreguse < 1)
432 rd->argintreguse = 1;
434 VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
437 if (rd->argintreguse < 2)
438 rd->argintreguse = 2;
440 VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
443 else { /* float/double */
444 if (rd->argfltreguse < 1)
445 rd->argfltreguse = 1;
447 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
455 * These are local overrides for various environment variables in Emacs.
456 * Please do not remove this and leave it at the end of the file, where
457 * Emacs will automagically detect them.
458 * ---------------------------------------------------------------------
461 * indent-tabs-mode: t