1 /* src/vm/jit/powerpc64/linux/md-abi.c - functions for PowerPC64 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
32 #include "vm/jit/powerpc64/linux/md-abi.h"
34 #include "vm/global.h"
36 #include "vm/jit/abi.h"
37 #include "vm/jit/stack.h"
39 #include "vmcore/descriptor.h"
42 #define CACAO_ALIGN(a) do { if ((a) & 1) (a)++; } while (0)
45 /* register descripton array **************************************************/
48 /* zero, sp, TOC, a0/v0, a1/v1, a2, a3, a4, */
49 REG_RES, REG_RES, REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
51 /* a5, a6, a7, itmp1, itmp2, NO(SYS), pv, s0, */
52 REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES, REG_RES, REG_RES, REG_SAV,
54 /*itmp3, t0, t1, t2, t3, t4, t5, t6, */
55 REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
57 /* s1, s2, s3, s4, s5, s6, s7, s8, */
58 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
63 const char *abi_registers_integer_name[] = {
64 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
65 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
66 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
67 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
70 const s4 abi_registers_integer_argument[] = {
81 const s4 abi_registers_integer_saved[] = {
93 const s4 abi_registers_integer_temporary[] = {
104 s4 nregdescfloat[] = {
105 /*ftmp3, fa0/v0, fa1, fa2, fa3, fa4, fa5, fa6, */
106 REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
108 /* fa7, fa8, fa9, fa10, fa11, fa12, ftmp1, ftmp2, */
109 REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES,
111 /* fs0, fs1, fs2, fs3, fs4, fs5, fs6, fs7 */
112 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
114 /* fs8, fs9, fs10, fs11, fs12, fs13, fs14, fs15 */
115 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
120 const s4 abi_registers_float_argument[] = {
136 const s4 abi_registers_float_saved[] = {
155 const s4 abi_registers_float_temporary[] = {
160 /* md_param_alloc **************************************************************
162 Allocate Arguments to Stackslots according the Calling Conventions
165 md->paramcount: Number of arguments for this method
166 md->paramtypes[].type: Argument types
169 md->params[].inmemory: Argument spilled on stack
170 md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
171 md->memuse: Stackslots needed for argument spilling
172 md->argintreguse: max number of integer arguments used
173 md->argfltreguse: max number of float arguments used
175 *******************************************************************************/
177 void md_param_alloc(methoddesc *md)
184 s4 stacksize, stackcount;
187 /* set default values */
192 stacksize = LA_SIZE_IN_POINTERS;
195 /* get params field of methoddesc */
199 for (i = 0; i < md->paramcount; i++, pd++) {
200 switch (md->paramtypes[i].type) {
204 if (iarg < INT_ARG_CNT) {
205 pd->inmemory = false;
207 pd->regoff = abi_registers_integer_argument[iarg];
212 pd->index = stacksize + stackcount;
213 pd->regoff = (stacksize + stackcount) * 8;
218 if (farg < FLT_ARG_CNT) {
219 pd->inmemory = false;
221 pd->regoff = abi_registers_float_argument[farg];
223 if (arg < INT_ARG_CNT) {
224 iarg++; /* yes, that is true, floating arguments take int register slots away */
229 pd->index = stacksize + stackcount;
230 pd->regoff = (stacksize + stackcount) * 8;
240 /* Since R3, F1 (==A0, A0) are used for passing return values, this */
241 /* argument register usage has to be regarded, too */
242 if (IS_INT_LNG_TYPE(md->returntype.type)) {
246 else if (IS_FLT_DBL_TYPE(md->returntype.type)) {
251 /* fill register and stack usage, parameter areas is at least PA_SIZE_IN_POINTERS */
253 md->argintreguse = iarg;
254 md->argfltreguse = farg;
255 md->memuse = stacksize + (stackcount<PA_SIZE_IN_POINTERS? PA_SIZE_IN_POINTERS: stackcount);
259 /* md_param_alloc_native *******************************************************
261 Pre-allocate arguments according the native ABI.
263 *******************************************************************************/
265 void md_param_alloc_native(methoddesc *md)
267 /* On PowerPC64 we use the same ABI for JIT method calls as for
268 native method calls. */
274 /* md_return_alloc *************************************************************
276 Precolor the Java Stackelement containing the Return Value, if
277 possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
281 jd: jitdata of the current method
282 stackslot: Java Stackslot to contain the Return Value
285 if precoloring was possible:
286 VAR(stackslot->varnum)->flags = PREALLOC
287 VAR(stackslot->varnum)->vv.regoff = [REG_RESULT, REG_FRESULT]
288 rd->arg[flt|int]reguse set to a value according the register usage
290 *******************************************************************************/
292 void md_return_alloc(jitdata *jd, stackelement_t *stackslot)
299 /* get required compiler data */
307 /* In Leafmethods Local Vars holding parameters are precolored to
308 their argument register -> so leafmethods with paramcount > 0
309 could already use R3 == a00! */
311 if (!code_is_leafmethod(code) || (md->paramcount == 0)) {
312 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
313 has not to survive method invokations. */
315 if (!(stackslot->flags & SAVEDVAR)) {
317 VAR(stackslot->varnum)->flags = PREALLOC;
319 if (IS_INT_LNG_TYPE(md->returntype.type)) {
320 if (rd->argintreguse < 1)
321 rd->argintreguse = 1;
323 VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
324 } else { /* float/double */
325 if (rd->argfltreguse < 1)
326 rd->argfltreguse = 1;
328 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
336 * These are local overrides for various environment variables in Emacs.
337 * Please do not remove this and leave it at the end of the file, where
338 * Emacs will automagically detect them.
339 * ---------------------------------------------------------------------
342 * indent-tabs-mode: t