1 /* src/vm/jit/powerpc64/linux/md-abi.c - functions for PowerPC64 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
34 #include "vm/jit/powerpc64/linux/md-abi.h"
36 #include "vm/global.h"
38 #include "vm/jit/abi.h"
40 #include "vmcore/descriptor.h"
43 #define CACAO_ALIGN(a) do { if ((a) & 1) (a)++; } while (0)
46 /* register descripton array **************************************************/
49 /* zero, sp, TOC, a0/v0, a1/v1, a2, a3, a4, */
50 REG_RES, REG_RES, REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
52 /* a5, a6, a7, itmp1, itmp2, NO(SYS), pv, s0, */
53 REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES, REG_RES, REG_RES, REG_SAV,
55 /*itmp3, t0, t1, t2, t3, t4, t5, t6, */
56 REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
58 /* s1, s2, s3, s4, s5, s6, s7, s8, */
59 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
64 const char *abi_registers_integer_name[] = {
65 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
66 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
67 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
68 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
71 const s4 abi_registers_integer_argument[] = {
82 const s4 abi_registers_integer_saved[] = {
94 const s4 abi_registers_integer_temporary[] = {
105 s4 nregdescfloat[] = {
106 /*ftmp3, fa0/v0, fa1, fa2, fa3, fa4, fa5, fa6, */
107 REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
109 /* fa7, fa8, fa9, fa10, fa11, fa12, ftmp1, ftmp2, */
110 REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES,
112 /* fs0, fs1, fs2, fs3, fs4, fs5, fs6, fs7 */
113 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
115 /* fs8, fs9, fs10, fs11, fs12, fs13, fs14, fs15 */
116 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
121 const s4 abi_registers_float_argument[] = {
137 const s4 abi_registers_float_saved[] = {
156 const s4 abi_registers_float_temporary[] = {
161 /* md_param_alloc **************************************************************
163 Allocate Arguments to Stackslots according the Calling Conventions
166 md->paramcount: Number of arguments for this method
167 md->paramtypes[].type: Argument types
170 md->params[].inmemory: Argument spilled on stack
171 md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
172 md->memuse: Stackslots needed for argument spilling
173 md->argintreguse: max number of integer arguments used
174 md->argfltreguse: max number of float arguments used
176 *******************************************************************************/
178 void md_param_alloc(methoddesc *md)
185 s4 stacksize, stackcount;
188 /* set default values */
193 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) {
205 if (iarg < INT_ARG_CNT) {
206 pd->inmemory = false;
208 pd->regoff = abi_registers_integer_argument[iarg];
213 pd->index = stacksize + stackcount;
214 pd->regoff = (stacksize + stackcount) * 8;
219 if (farg < FLT_ARG_CNT) {
220 pd->inmemory = false;
222 pd->regoff = abi_registers_float_argument[farg];
224 if (arg < INT_ARG_CNT) {
225 iarg++; /* yes, that is true, floating arguments take int register slots away */
230 pd->index = stacksize + stackcount;
231 pd->regoff = (stacksize + stackcount) * 8;
241 /* Since R3, F1 (==A0, A0) are used for passing return values, this */
242 /* argument register usage has to be regarded, too */
243 if (IS_INT_LNG_TYPE(md->returntype.type)) {
247 else if (IS_FLT_DBL_TYPE(md->returntype.type)) {
252 /* fill register and stack usage, parameter areas is at least PA_SIZE_IN_POINTERS */
254 md->argintreguse = iarg;
255 md->argfltreguse = farg;
256 md->memuse = stacksize + (stackcount<PA_SIZE_IN_POINTERS? PA_SIZE_IN_POINTERS: stackcount);
260 /* md_param_alloc_native *******************************************************
262 Pre-allocate arguments according the native ABI.
264 *******************************************************************************/
266 void md_param_alloc_native(methoddesc *md)
268 /* On PowerPC64 we use the same ABI for JIT method calls as for
269 native method calls. */
275 /* md_return_alloc *************************************************************
277 Precolor the Java Stackelement containing the Return Value, if
278 possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
282 jd: jitdata of the current method
283 stackslot: Java Stackslot to contain the Return Value
286 if precoloring was possible:
287 VAR(stackslot->varnum)->flags = PREALLOC
288 VAR(stackslot->varnum)->vv.regoff = [REG_RESULT, REG_FRESULT]
289 rd->arg[flt|int]reguse set to a value according the register usage
291 *******************************************************************************/
293 void md_return_alloc(jitdata *jd, stackptr stackslot)
300 /* get required compiler data */
308 /* In Leafmethods Local Vars holding parameters are precolored to
309 their argument register -> so leafmethods with paramcount > 0
310 could already use R3 == a00! */
312 if (!jd->isleafmethod || (md->paramcount == 0)) {
313 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
314 has not to survive method invokations. */
316 if (!(stackslot->flags & SAVEDVAR)) {
318 VAR(stackslot->varnum)->flags = PREALLOC;
320 if (IS_INT_LNG_TYPE(md->returntype.type)) {
321 if (rd->argintreguse < 1)
322 rd->argintreguse = 1;
324 VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
325 } else { /* float/double */
326 if (rd->argfltreguse < 1)
327 rd->argfltreguse = 1;
329 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
337 * These are local overrides for various environment variables in Emacs.
338 * Please do not remove this and leave it at the end of the file, where
339 * Emacs will automagically detect them.
340 * ---------------------------------------------------------------------
343 * indent-tabs-mode: t