1 /* src/vm/jit/powerpc/darwin/md-abi.c - functions for PowerPC Darwin 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 8270 2007-08-08 13:57:12Z twisti $
34 #include "vm/jit/powerpc/darwin/md-abi.h"
36 #include "vm/global.h"
38 #include "vm/jit/abi.h"
40 #include "vmcore/descriptor.h"
43 /* register descripton arrays *************************************************/
46 /* zero, sp, t0, a0/v0, a0/v1, a2, a3, a4, */
47 REG_RES, REG_RES, REG_TMP, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
49 /* a5, a6, a7, itmp1, itmp2, pv, s0, s1, */
50 REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES, REG_RES, REG_SAV, REG_SAV,
52 /*itmp3, t1, t2, t3, t4, t5, t6, t7, */
53 REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
55 /* s2, s3, s4, s5, s6, s7, s8, s9, */
56 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
61 const char *abi_registers_integer_name[] = {
62 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
63 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
64 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
65 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
68 const int abi_registers_integer_argument[] = {
79 const int abi_registers_integer_saved[] = {
92 const int abi_registers_integer_temporary[] = {
104 int 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, fs0, fs1, */
109 REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_SAV, REG_SAV,
111 /*ftmp1, ftmp2, ft0, ft1, ft2, ft3, ft4, ft5, */
112 REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
114 /* fs2, fs3, fs4, fs5, fs6, fs7, fs8, fs9 */
115 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
120 const int abi_registers_float_argument[] = {
136 const int abi_registers_float_saved[] = {
149 const int 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)
185 /* set default values */
189 stacksize = LA_SIZE_IN_POINTERS;
191 /* get params field of methoddesc */
195 for (i = 0; i < md->paramcount; i++, pd++) {
196 switch (md->paramtypes[i].type) {
199 if (iarg < INT_ARG_CNT) {
200 pd->inmemory = false;
202 pd->regoff = abi_registers_integer_argument[iarg];
207 pd->index = stacksize;
208 pd->regoff = stacksize * 8;
214 if (iarg < INT_ARG_CNT - 1) {
215 pd->inmemory = false;
216 pd->index = PACK_REGS(iarg + 1, iarg);
218 PACK_REGS(abi_registers_integer_argument[iarg + 1],
219 abi_registers_integer_argument[iarg]);
224 pd->index = stacksize;
225 pd->regoff = stacksize * 8;
233 if (farg < FLT_ARG_CNT) {
234 pd->inmemory = false;
236 pd->regoff = abi_registers_float_argument[farg];
241 pd->index = stacksize;
242 pd->regoff = stacksize * 8;
250 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return values, this */
251 /* argument register usage has to be regarded, too */
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) {
313 pd->inmemory = false;
315 PACK_REGS(abi_registers_integer_argument[iarg + 1],
316 abi_registers_integer_argument[iarg]);
321 pd->regoff = stacksize * 4;
328 if (farg < FLT_ARG_CNT) {
329 pd->inmemory = false;
330 pd->regoff = abi_registers_float_argument[farg];
331 iarg++; /* skip 1 integer argument register */
336 pd->regoff = stacksize * 4;
342 if (farg < FLT_ARG_CNT) {
343 pd->inmemory = false;
344 pd->regoff = abi_registers_float_argument[farg];
345 iarg += 2; /* skip 2 integer argument registers */
350 pd->regoff = stacksize * 4;
358 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return values, this */
359 /* argument register usage has to be regarded, too */
361 if (IS_INT_LNG_TYPE(md->returntype.type)) {
362 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
363 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
366 if (IS_FLT_DBL_TYPE(md->returntype.type))
371 /* fill register and stack usage */
373 md->argintreguse = iarg;
374 md->argfltreguse = farg;
375 md->memuse = stacksize;
379 /* md_return_alloc *************************************************************
381 Precolor the Java Stackelement containing the Return Value, if
382 possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
386 jd: jitdata of the current method
387 stackslot: Java Stackslot to contain the Return Value
390 if precoloring was possible:
391 VAR(stackslot->varnum)->flags = PREALLOC
392 ->regoff = [REG_RESULT|REG_FRESULT]
393 rd->arg[flt|int]reguse set to a value according the register usage
395 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
397 *******************************************************************************/
399 void md_return_alloc(jitdata *jd, stackptr stackslot)
405 /* get required compiler data */
412 /* In Leafmethods Local Vars holding parameters are precolored to
413 their argument register -> so leafmethods with paramcount > 0
414 could already use R3 == a00! */
416 if (!jd->isleafmethod || (md->paramcount == 0)) {
417 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
418 has not to survive method invokations. */
420 if (!(stackslot->flags & SAVEDVAR)) {
422 VAR(stackslot->varnum)->flags = PREALLOC;
424 if (IS_INT_LNG_TYPE(md->returntype.type)) {
425 if (!IS_2_WORD_TYPE(md->returntype.type)) {
426 if (rd->argintreguse < 1)
427 rd->argintreguse = 1;
429 VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
432 if (rd->argintreguse < 2)
433 rd->argintreguse = 2;
435 VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
439 if (rd->argfltreguse < 1)
440 rd->argfltreguse = 1;
442 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
450 * These are local overrides for various environment variables in Emacs.
451 * Please do not remove this and leave it at the end of the file, where
452 * Emacs will automagically detect them.
453 * ---------------------------------------------------------------------
456 * indent-tabs-mode: t