1 /* src/vm/jit/s390/md-abi.c - s390 Linux ABI
3 Copyright (C) 1996-2005, 2006, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 #include "vm/descriptor.hpp"
29 #include "vm/global.h"
32 #include "vm/jit/jit.hpp"
33 #include "vm/jit/stack.h"
35 #include "vm/jit/s390/md-abi.h"
40 /* register descripton array **************************************************/
43 /*itmp3, itmp1, a0, a1, a2, a3, a4, s0, */
44 REG_RES, REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_SAV,
45 /* s1, s2, s3, s4, s5, pv, ra/itmp2, sp */
46 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_RES, REG_RES, REG_RES,
50 const char *abi_registers_integer_name[] = {
51 "r0", "r1", "r2", "r3",
52 "r4", "r5", "r6", "r7",
53 "r8", "r9", "r10", "r11",
54 "r12", "r13", "r14", "r15"
57 const s4 abi_registers_integer_argument[] = {
65 const s4 abi_registers_integer_saved[] = {
74 const s4 abi_registers_integer_temporary[] = {
78 s4 nregdescfloat[] = {
79 REG_ARG, REG_TMP, REG_ARG, REG_TMP, REG_RES, REG_TMP, REG_RES, REG_TMP,
80 REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
84 const s4 abi_registers_float_argument[] = {
89 const s4 abi_registers_float_saved[] = {
93 const s4 abi_registers_float_temporary[] = {
108 /* md_param_alloc_intern *******************************************************
110 Allocates parameters to registers or stackslots for both native and java
114 slot: size in bytes of a stack slot
115 slots1w: number of stack slots used by a 1 word type parameter
116 slots2w: number of stack slots used by a 2 word type parameter
117 stackoff: offset on stack frame where to start placing arguments
119 *******************************************************************************/
121 static void md_param_alloc_intern(methoddesc *md, s4 slot, s4 slots1w, s4 slots2w, s4 stackoff)
129 /* set default values */
135 /* get params field of methoddesc */
139 for (i = 0; i < md->paramcount; i++, pd++) {
140 switch (md->paramtypes[i].type) {
143 if (iarg < INT_ARG_CNT) {
144 pd->inmemory = false;
145 pd->regoff = abi_registers_integer_argument[iarg];
151 pd->regoff = (stacksize * slot) + stackoff;
152 pd->index = stacksize;
153 stacksize += slots1w;
158 if (iarg < INT_ARG_CNT - 1) {
160 pd->inmemory = false;
162 PACK_REGS(abi_registers_integer_argument[iarg + 1],
163 abi_registers_integer_argument[iarg]);
164 pd->index = PACK_REGS(iarg + 1, iarg);
168 /* _ALIGN(stacksize); */
170 pd->regoff = (stacksize * slot) + stackoff;
171 pd->index = stacksize;
173 stacksize += slots2w;
178 if (farg < FLT_ARG_CNT) {
179 pd->inmemory = false;
180 pd->regoff = abi_registers_float_argument[farg];
186 pd->regoff = (stacksize * slot) + stackoff;
187 pd->index = stacksize;
188 stacksize += slots1w;
193 if (farg < FLT_ARG_CNT) {
194 pd->inmemory = false;
195 pd->regoff = abi_registers_float_argument[farg];
200 /* _ALIGN(stacksize); */
202 pd->regoff = (stacksize * slot) + stackoff;
203 pd->index = stacksize;
204 stacksize += slots2w;
213 /* Since A0+A1/FA0 are used for passing return
214 values, this argument register usage has to be regarded,
217 if (IS_INT_LNG_TYPE(md->returntype.type)) {
218 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
219 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
222 if (IS_FLT_DBL_TYPE(md->returntype.type))
227 /* fill register and stack usage */
229 md->argintreguse = iarg;
230 md->argfltreguse = farg;
231 md->memuse = stacksize;
234 void md_param_alloc(methoddesc *md)
236 md_param_alloc_intern(md, 8, 1, 1, 0);
239 void md_param_alloc_native(methoddesc *md)
241 md_param_alloc_intern(md, 4, 1, 2, 96);
245 /* md_return_alloc *************************************************************
247 Precolor the Java Stackelement containing the Return Value. Only
248 for float/ double types straight forward possible, since INT_LNG
249 types use "reserved" registers Float/Double values use a00 as
253 jd: jitdata of the current method
254 stackslot: Java Stackslot to contain the Return Value
257 if precoloring was possible:
258 VAR(stackslot->varnum)->flags = PREALLOC
259 ->vv.regoff = [REG_RESULT|REG_FRESULT]
260 rd->arg[flt|int]reguse set to a value according the register usage
262 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
264 *******************************************************************************/
266 void md_return_alloc(jitdata *jd, stackelement_t* stackslot)
273 /* get required compiler data */
281 /* In Leafmethods Local Vars holding parameters are precolored to
282 their argument register -> so leafmethods with paramcount > 0
283 could already use R3 == a00! */
285 if (!code_is_leafmethod(code) || (md->paramcount == 0)) {
286 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
287 has not to survive method invokations. */
289 if (!(stackslot->flags & SAVEDVAR)) {
290 VAR(stackslot->varnum)->flags = PREALLOC;
292 if (IS_INT_LNG_TYPE(md->returntype.type)) {
293 if (!IS_2_WORD_TYPE(md->returntype.type)) {
294 if (rd->argintreguse < 1)
295 rd->argintreguse = 1;
297 VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
300 if (rd->argintreguse < 2)
301 rd->argintreguse = 2;
303 VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
306 else { /* float/double */
307 if (rd->argfltreguse < 1)
308 rd->argfltreguse = 1;
310 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
318 * These are local overrides for various environment variables in Emacs.
319 * Please do not remove this and leave it at the end of the file, where
320 * Emacs will automagically detect them.
321 * ---------------------------------------------------------------------
324 * indent-tabs-mode: t