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 4357 2006-01-22 23:33:38Z twisti $
39 #include "vm/jit/powerpc/darwin/md-abi.h"
41 #include "vm/descriptor.h"
42 #include "vm/global.h"
45 /* register descripton array **************************************************/
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 s4 nregdescfloat[] = {
65 /*ftmp3, fa0/v0, fa1, fa2, fa3, fa4, fa5, fa6, */
66 REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
68 /* fa7, fa8, fa9, fa10, fa11, fa12, fs0, fs1, */
69 REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_SAV, REG_SAV,
71 /*ftmp1, ftmp2, ft0, ft1, ft2, ft3, ft4, ft5, */
72 REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
74 /* fs2, fs3, fs4, fs5, fs6, fs7, fs8, fs9 */
75 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
81 /* md_param_alloc **************************************************************
83 Allocate Arguments to Stackslots according the Calling Conventions
86 md->paramcount: Number of arguments for this method
87 md->paramtypes[].type: Argument types
90 md->params[].inmemory: Argument spilled on stack
91 md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
92 md->memuse: Stackslots needed for argument spilling
93 md->argintreguse: max number of integer arguments used
94 md->argfltreguse: max number of float arguments used
96 *******************************************************************************/
98 void md_param_alloc(methoddesc *md)
106 /* set default values */
110 stacksize = LA_WORD_SIZE;
112 /* get params field of methoddesc */
116 for (i = 0; i < md->paramcount; i++, pd++) {
117 switch (md->paramtypes[i].type) {
120 if (iarg < INT_ARG_CNT) {
121 pd->inmemory = false;
122 pd->regoff = iarg; /* rd->arg[int|flt]regs index !! */
126 pd->regoff = stacksize;
131 if (iarg < INT_ARG_CNT - 1) {
132 pd->inmemory = false;
133 /* rd->arg[int|flt]regs index !! */
134 pd->regoff = PACK_REGS(iarg + 1, iarg);
138 pd->regoff = stacksize;
144 if (farg < FLT_ARG_CNT) {
145 pd->inmemory = false;
146 pd->regoff = farg; /* rd->arg[int|flt]regs index !! */
147 iarg++; /* skip 1 integer argument register */
151 pd->regoff = stacksize;
156 if (farg < FLT_ARG_CNT) {
157 pd->inmemory = false;
158 pd->regoff = farg; /* rd->arg[int|flt]regs index !! */
159 iarg += 2; /* skip 2 integer argument registers */
163 pd->regoff = stacksize;
171 /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return values, this */
172 /* argument register usage has to be regarded, too */
173 if (IS_INT_LNG_TYPE(md->returntype.type)) {
174 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
175 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
177 if (IS_FLT_DBL_TYPE(md->returntype.type))
182 /* fill register and stack usage */
183 md->argintreguse = iarg;
184 md->argfltreguse = farg;
185 md->memuse = stacksize;
189 /* md_return_alloc *************************************************************
191 Precolor the Java Stackelement containing the Return Value, if
192 possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
196 m: Methodinfo of current method
197 return_type: Return Type of the Method (TYPE_INT.. TYPE_ADR)
198 TYPE_VOID is not allowed!
199 stackslot: Java Stackslot to contain the Return Value
202 if precoloring was possible:
203 stackslot->varkind =ARGVAR
206 ->regoff =[REG_RESULT, (REG_RESULT2/REG_RESULT), REG_FRESULT]
207 rd->arg[flt|int]reguse set to a value according the register usage
209 *******************************************************************************/
211 void md_return_alloc(methodinfo *m, registerdata *rd, s4 return_type,
214 /* In Leafmethods Local Vars holding parameters are precolored to their */
215 /* argument register -> so leafmethods with paramcount > 0 could already */
218 if (!m->isleafmethod || (m->paramcount == 0)) {
219 /* Only precolor the stackslot, if it is not a SAVEDVAR <-> has not */
220 /* to survive method invokations */
222 if (!(stackslot->flags & SAVEDVAR)) {
223 stackslot->varkind = ARGVAR;
224 stackslot->varnum = -1;
225 stackslot->flags = 0;
227 if (IS_INT_LNG_TYPE(return_type)) {
228 if (!IS_2_WORD_TYPE(return_type)) {
229 if (rd->argintreguse < 1)
230 rd->argintreguse = 1;
232 stackslot->regoff = REG_RESULT;
235 if (rd->argintreguse < 2)
236 rd->argintreguse = 2;
238 stackslot->regoff = PACK_REGS(REG_RESULT2, REG_RESULT);
241 } else { /* float/double */
242 if (rd->argfltreguse < 1)
243 rd->argfltreguse = 1;
245 stackslot->regoff = REG_FRESULT;
253 * These are local overrides for various environment variables in Emacs.
254 * Please do not remove this and leave it at the end of the file, where
255 * Emacs will automagically detect them.
256 * ---------------------------------------------------------------------
259 * indent-tabs-mode: t