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/global.h"
31 #include "vm/jit/jit.h"
32 #include "vm/jit/stack.h"
34 #include "vm/jit/s390/md-abi.h"
36 #include "vmcore/descriptor.h"
41 /* register descripton array **************************************************/
44 /*itmp3, itmp1, a0, a1, a2, a3, a4, s0, */
45 REG_RES, REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_SAV,
46 /* s1, s2, s3, s4, s5, pv, ra/itmp2, sp */
47 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_RES, REG_RES, REG_RES,
51 const char *abi_registers_integer_name[] = {
52 "r0", "r1", "r2", "r3",
53 "r4", "r5", "r6", "r7",
54 "r8", "r9", "r10", "r11",
55 "r12", "r13", "r14", "r15"
58 const s4 abi_registers_integer_argument[] = {
66 const s4 abi_registers_integer_saved[] = {
75 const s4 abi_registers_integer_temporary[] = {
79 s4 nregdescfloat[] = {
80 REG_ARG, REG_TMP, REG_ARG, REG_TMP, REG_RES, REG_TMP, REG_RES, REG_TMP,
81 REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
85 const s4 abi_registers_float_argument[] = {
90 const s4 abi_registers_float_saved[] = {
94 const s4 abi_registers_float_temporary[] = {
109 /* md_param_alloc_intern *******************************************************
111 Allocates parameters to registers or stackslots for both native and java
115 slot: size in bytes of a stack slot
116 slots1w: number of stack slots used by a 1 word type parameter
117 slots2w: number of stack slots used by a 2 word type parameter
118 stackoff: offset on stack frame where to start placing arguments
120 *******************************************************************************/
122 static void md_param_alloc_intern(methoddesc *md, s4 slot, s4 slots1w, s4 slots2w, s4 stackoff)
130 /* set default values */
136 /* get params field of methoddesc */
140 for (i = 0; i < md->paramcount; i++, pd++) {
141 switch (md->paramtypes[i].type) {
144 if (iarg < INT_ARG_CNT) {
145 pd->inmemory = false;
146 pd->regoff = abi_registers_integer_argument[iarg];
152 pd->regoff = (stacksize * slot) + stackoff;
153 pd->index = stacksize;
154 stacksize += slots1w;
159 if (iarg < INT_ARG_CNT - 1) {
161 pd->inmemory = false;
163 PACK_REGS(abi_registers_integer_argument[iarg + 1],
164 abi_registers_integer_argument[iarg]);
165 pd->index = PACK_REGS(iarg + 1, iarg);
169 /* _ALIGN(stacksize); */
171 pd->regoff = (stacksize * slot) + stackoff;
172 pd->index = stacksize;
174 stacksize += slots2w;
179 if (farg < FLT_ARG_CNT) {
180 pd->inmemory = false;
181 pd->regoff = abi_registers_float_argument[farg];
187 pd->regoff = (stacksize * slot) + stackoff;
188 pd->index = stacksize;
189 stacksize += slots1w;
194 if (farg < FLT_ARG_CNT) {
195 pd->inmemory = false;
196 pd->regoff = abi_registers_float_argument[farg];
201 /* _ALIGN(stacksize); */
203 pd->regoff = (stacksize * slot) + stackoff;
204 pd->index = stacksize;
205 stacksize += slots2w;
214 /* Since A0+A1/FA0 are used for passing return
215 values, this argument register usage has to be regarded,
218 if (IS_INT_LNG_TYPE(md->returntype.type)) {
219 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
220 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
223 if (IS_FLT_DBL_TYPE(md->returntype.type))
228 /* fill register and stack usage */
230 md->argintreguse = iarg;
231 md->argfltreguse = farg;
232 md->memuse = stacksize;
235 void md_param_alloc(methoddesc *md)
237 md_param_alloc_intern(md, 8, 1, 1, 0);
240 void md_param_alloc_native(methoddesc *md)
242 md_param_alloc_intern(md, 4, 1, 2, 96);
246 /* md_return_alloc *************************************************************
248 Precolor the Java Stackelement containing the Return Value. Only
249 for float/ double types straight forward possible, since INT_LNG
250 types use "reserved" registers Float/Double values use a00 as
254 jd: jitdata of the current method
255 stackslot: Java Stackslot to contain the Return Value
258 if precoloring was possible:
259 VAR(stackslot->varnum)->flags = PREALLOC
260 ->vv.regoff = [REG_RESULT|REG_FRESULT]
261 rd->arg[flt|int]reguse set to a value according the register usage
263 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
265 *******************************************************************************/
267 void md_return_alloc(jitdata *jd, stackelement_t* stackslot)
274 /* get required compiler data */
282 /* In Leafmethods Local Vars holding parameters are precolored to
283 their argument register -> so leafmethods with paramcount > 0
284 could already use R3 == a00! */
286 if (!code_is_leafmethod(code) || (md->paramcount == 0)) {
287 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
288 has not to survive method invokations. */
290 if (!(stackslot->flags & SAVEDVAR)) {
291 VAR(stackslot->varnum)->flags = PREALLOC;
293 if (IS_INT_LNG_TYPE(md->returntype.type)) {
294 if (!IS_2_WORD_TYPE(md->returntype.type)) {
295 if (rd->argintreguse < 1)
296 rd->argintreguse = 1;
298 VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
301 if (rd->argintreguse < 2)
302 rd->argintreguse = 2;
304 VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
307 else { /* float/double */
308 if (rd->argfltreguse < 1)
309 rd->argfltreguse = 1;
311 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
319 * These are local overrides for various environment variables in Emacs.
320 * Please do not remove this and leave it at the end of the file, where
321 * Emacs will automagically detect them.
322 * ---------------------------------------------------------------------
325 * indent-tabs-mode: t