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
32 #include "vm/jit/powerpc/darwin/md-abi.h"
34 #include "vm/global.h"
36 #include "vm/jit/abi.h"
38 #include "vmcore/descriptor.h"
41 /* register descripton arrays *************************************************/
44 /* zero, sp, t0, a0/v0, a0/v1, a2, a3, a4, */
45 REG_RES, REG_RES, REG_TMP, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
47 /* a5, a6, a7, itmp1, itmp2, pv, s0, s1, */
48 REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES, REG_RES, REG_SAV, REG_SAV,
50 /*itmp3, t1, t2, t3, t4, t5, t6, t7, */
51 REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
53 /* s2, s3, s4, s5, s6, s7, s8, s9, */
54 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
59 const char *abi_registers_integer_name[] = {
60 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
61 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
62 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
63 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
66 const int abi_registers_integer_argument[] = {
77 const int abi_registers_integer_saved[] = {
90 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, fa8, fa9, fa10, fa11, fa12, fs0, fs1, */
107 REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_SAV, REG_SAV,
109 /*ftmp1, ftmp2, ft0, ft1, ft2, ft3, ft4, ft5, */
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,
118 const int abi_registers_float_argument[] = {
134 const int abi_registers_float_saved[] = {
147 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) {
213 pd->inmemory = false;
214 pd->index = PACK_REGS(iarg + 1, iarg);
216 PACK_REGS(abi_registers_integer_argument[iarg + 1],
217 abi_registers_integer_argument[iarg]);
222 pd->index = stacksize;
223 pd->regoff = stacksize * 8;
231 if (farg < FLT_ARG_CNT) {
232 pd->inmemory = false;
234 pd->regoff = abi_registers_float_argument[farg];
239 pd->index = stacksize;
240 pd->regoff = stacksize * 8;
248 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return values, this */
249 /* argument register usage has to be regarded, too */
251 if (IS_INT_LNG_TYPE(md->returntype.type)) {
252 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
253 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
256 if (IS_FLT_DBL_TYPE(md->returntype.type))
261 /* fill register and stack usage */
263 md->argintreguse = iarg;
264 md->argfltreguse = farg;
265 md->memuse = stacksize;
269 /* md_param_alloc_native *******************************************************
271 Pre-allocate arguments according the native ABI.
273 *******************************************************************************/
275 void md_param_alloc_native(methoddesc *md)
283 /* set default values */
287 stacksize = LA_SIZE_IN_POINTERS;
289 /* get params field of methoddesc */
293 for (i = 0; i < md->paramcount; i++, pd++) {
294 switch (md->paramtypes[i].type) {
297 if (iarg < INT_ARG_CNT) {
298 pd->inmemory = false;
299 pd->regoff = abi_registers_integer_argument[iarg];
304 pd->regoff = stacksize * 4;
310 if (iarg < INT_ARG_CNT - 1) {
311 pd->inmemory = false;
313 PACK_REGS(abi_registers_integer_argument[iarg + 1],
314 abi_registers_integer_argument[iarg]);
319 pd->regoff = stacksize * 4;
326 if (farg < FLT_ARG_CNT) {
327 pd->inmemory = false;
328 pd->regoff = abi_registers_float_argument[farg];
329 iarg++; /* skip 1 integer argument register */
334 pd->regoff = stacksize * 4;
340 if (farg < FLT_ARG_CNT) {
341 pd->inmemory = false;
342 pd->regoff = abi_registers_float_argument[farg];
343 iarg += 2; /* skip 2 integer argument registers */
348 pd->regoff = stacksize * 4;
356 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return values, this */
357 /* argument register usage has to be regarded, too */
359 if (IS_INT_LNG_TYPE(md->returntype.type)) {
360 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
361 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
364 if (IS_FLT_DBL_TYPE(md->returntype.type))
369 /* fill register and stack usage */
371 md->argintreguse = iarg;
372 md->argfltreguse = farg;
373 md->memuse = stacksize;
377 /* md_return_alloc *************************************************************
379 Precolor the Java Stackelement containing the Return Value, if
380 possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
384 jd: jitdata of the current method
385 stackslot: Java Stackslot to contain the Return Value
388 if precoloring was possible:
389 VAR(stackslot->varnum)->flags = PREALLOC
390 ->regoff = [REG_RESULT|REG_FRESULT]
391 rd->arg[flt|int]reguse set to a value according the register usage
393 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
395 *******************************************************************************/
397 void md_return_alloc(jitdata *jd, stackptr stackslot)
403 /* get required compiler data */
410 /* In Leafmethods Local Vars holding parameters are precolored to
411 their argument register -> so leafmethods with paramcount > 0
412 could already use R3 == a00! */
414 if (!jd->isleafmethod || (md->paramcount == 0)) {
415 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
416 has not to survive method invokations. */
418 if (!(stackslot->flags & SAVEDVAR)) {
420 VAR(stackslot->varnum)->flags = PREALLOC;
422 if (IS_INT_LNG_TYPE(md->returntype.type)) {
423 if (!IS_2_WORD_TYPE(md->returntype.type)) {
424 if (rd->argintreguse < 1)
425 rd->argintreguse = 1;
427 VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
430 if (rd->argintreguse < 2)
431 rd->argintreguse = 2;
433 VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
437 if (rd->argfltreguse < 1)
438 rd->argfltreguse = 1;
440 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
448 * These are local overrides for various environment variables in Emacs.
449 * Please do not remove this and leave it at the end of the file, where
450 * Emacs will automagically detect them.
451 * ---------------------------------------------------------------------
454 * indent-tabs-mode: t