1 /* src/vm/jit/powerpc/darwin/md-abi.c - functions for PowerPC Darwin ABI
3 Copyright (C) 1996-2005, 2006 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 Contact: cacao@cacaojvm.org
27 Authors: Christian Thalinger
29 Changes: Christian Ullrich
31 $Id: md-abi.c 5073 2006-07-04 16:02:19Z twisti $
39 #include "vm/jit/powerpc/darwin/md-abi.h"
41 #include "vm/descriptor.h"
42 #include "vm/global.h"
45 /* register descripton arrays *************************************************/
48 /* zero, sp, t0, a0/v0, a0/v1, a2, a3, a4, */
49 REG_RES, REG_RES, REG_TMP, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
51 /* a5, a6, a7, itmp1, itmp2, pv, s0, s1, */
52 REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES, REG_RES, REG_SAV, REG_SAV,
54 /*itmp3, t1, t2, t3, t4, t5, t6, t7, */
55 REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
57 /* s2, s3, s4, s5, s6, s7, s8, s9, */
58 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
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",
71 s4 nregdescfloat[] = {
72 /*ftmp3, fa0/v0, fa1, fa2, fa3, fa4, fa5, fa6, */
73 REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
75 /* fa7, fa8, fa9, fa10, fa11, fa12, fs0, fs1, */
76 REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_SAV, REG_SAV,
78 /*ftmp1, ftmp2, ft0, ft1, ft2, ft3, ft4, ft5, */
79 REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
81 /* fs2, fs3, fs4, fs5, fs6, fs7, fs8, fs9 */
82 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
88 /* md_param_alloc **************************************************************
90 Allocate Arguments to Stackslots according the Calling Conventions
93 md->paramcount: Number of arguments for this method
94 md->paramtypes[].type: Argument types
97 md->params[].inmemory: Argument spilled on stack
98 md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
99 md->memuse: Stackslots needed for argument spilling
100 md->argintreguse: max number of integer arguments used
101 md->argfltreguse: max number of float arguments used
103 *******************************************************************************/
105 void md_param_alloc(methoddesc *md)
113 /* set default values */
117 stacksize = LA_WORD_SIZE;
119 /* get params field of methoddesc */
123 for (i = 0; i < md->paramcount; i++, pd++) {
124 switch (md->paramtypes[i].type) {
127 if (iarg < INT_ARG_CNT) {
128 pd->inmemory = false;
129 pd->regoff = iarg; /* rd->arg[int|flt]regs index !! */
134 pd->regoff = stacksize;
140 if (iarg < INT_ARG_CNT - 1) {
141 pd->inmemory = false;
142 /* rd->arg[int|flt]regs index !! */
143 pd->regoff = PACK_REGS(iarg + 1, iarg);
148 pd->regoff = stacksize;
155 if (farg < FLT_ARG_CNT) {
156 pd->inmemory = false;
157 pd->regoff = farg; /* rd->arg[int|flt]regs index !! */
158 iarg++; /* skip 1 integer argument register */
163 pd->regoff = stacksize;
169 if (farg < FLT_ARG_CNT) {
170 pd->inmemory = false;
171 pd->regoff = farg; /* rd->arg[int|flt]regs index !! */
172 iarg += 2; /* skip 2 integer argument registers */
177 pd->regoff = stacksize;
185 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return values, this */
186 /* argument register usage has to be regarded, too */
188 if (IS_INT_LNG_TYPE(md->returntype.type)) {
189 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
190 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
193 if (IS_FLT_DBL_TYPE(md->returntype.type))
198 /* fill register and stack usage */
200 md->argintreguse = iarg;
201 md->argfltreguse = farg;
202 md->memuse = stacksize;
206 /* md_return_alloc *************************************************************
208 Precolor the Java Stackelement containing the Return Value, if
209 possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
213 m: Methodinfo of current method
214 return_type: Return Type of the Method (TYPE_INT.. TYPE_ADR)
215 TYPE_VOID is not allowed!
216 stackslot: Java Stackslot to contain the Return Value
219 if precoloring was possible:
220 stackslot->varkind =ARGVAR
223 ->regoff =[REG_RESULT, (REG_RESULT2/REG_RESULT), REG_FRESULT]
224 rd->arg[flt|int]reguse set to a value according the register usage
226 *******************************************************************************/
228 void md_return_alloc(methodinfo *m, registerdata *rd, s4 return_type,
231 /* In Leafmethods Local Vars holding parameters are precolored to
232 their argument register -> so leafmethods with paramcount > 0
233 could already use R3 == a00! */
235 if (!m->isleafmethod || (m->parseddesc->paramcount == 0)) {
236 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
237 has not to survive method invokations. */
239 if (!(stackslot->flags & SAVEDVAR)) {
240 stackslot->varkind = ARGVAR;
241 stackslot->varnum = -1;
242 stackslot->flags = 0;
244 if (IS_INT_LNG_TYPE(return_type)) {
245 if (!IS_2_WORD_TYPE(return_type)) {
246 if (rd->argintreguse < 1)
247 rd->argintreguse = 1;
249 stackslot->regoff = REG_RESULT;
252 if (rd->argintreguse < 2)
253 rd->argintreguse = 2;
255 stackslot->regoff = PACK_REGS(REG_RESULT2, REG_RESULT);
258 } else { /* float/double */
259 if (rd->argfltreguse < 1)
260 rd->argfltreguse = 1;
262 stackslot->regoff = REG_FRESULT;
270 * These are local overrides for various environment variables in Emacs.
271 * Please do not remove this and leave it at the end of the file, where
272 * Emacs will automagically detect them.
273 * ---------------------------------------------------------------------
276 * indent-tabs-mode: t