1 /* src/vm/jit/x86_64/md-abi.c - functions for x86_64 Linux 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
37 #include "vm/jit/s390/md-abi.h"
39 #include "vmcore/descriptor.h"
40 #include "vm/global.h"
41 #include "vm/jit/jit.h"
44 /* register descripton array **************************************************/
47 /* r0, itmp1, a0, a1, a2, a3, a4, s0, */
48 REG_TMP, REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_SAV,
49 /* s1, s2, s3, s4, itmp2, pv, ra/itmp3, sp */
50 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_RES, REG_RES, REG_RES, REG_RES,
54 const char *abi_registers_integer_name[] = {
55 "r0", "r1", "r2", "r3",
56 "r4", "r5", "r6", "r7",
57 "r8", "r9", "r10", "r11",
58 "r12", "r13", "r14", "r15"
61 const s4 abi_registers_integer_argument[] = {
69 const s4 abi_registers_integer_saved[] = {
77 const s4 abi_registers_integer_temporary[] = {
81 s4 nregdescfloat[] = {
82 REG_ARG, REG_TMP, REG_ARG, REG_TMP, REG_SAV, REG_TMP, REG_SAV, REG_TMP,
83 REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
87 const s4 abi_registers_float_argument[] = {
92 const s4 abi_registers_float_saved[] = {
97 const s4 abi_registers_float_temporary[] = {
112 /* md_param_alloc_intern *******************************************************
114 Allocates parameters to registers or stackslots for both native and java
118 slot: size in bytes of a stack slot
119 slots1w: number of stack slots used by a 1 word type parameter
120 slots2w: number of stack slots used by a 2 word type parameter
122 *******************************************************************************/
124 static void md_param_alloc_intern(methoddesc *md, s4 slot, s4 slots1w, s4 slots2w)
132 /* set default values */
138 /* get params field of methoddesc */
142 for (i = 0; i < md->paramcount; i++, pd++) {
143 switch (md->paramtypes[i].type) {
146 if (iarg < INT_ARG_CNT) {
147 pd->inmemory = false;
148 pd->regoff = abi_registers_integer_argument[iarg];
154 pd->regoff = stacksize * slot;
155 pd->index = stacksize;
156 stacksize += slots1w;
161 if (iarg < INT_ARG_CNT - 1) {
163 pd->inmemory = false;
165 PACK_REGS(abi_registers_integer_argument[iarg + 1],
166 abi_registers_integer_argument[iarg]);
167 pd->index = PACK_REGS(iarg + 1, iarg);
171 /* _ALIGN(stacksize); */
173 pd->regoff = stacksize * slot;
174 pd->index = stacksize;
176 stacksize += slots2w;
181 if (farg < FLT_ARG_CNT) {
182 pd->inmemory = false;
183 pd->regoff = abi_registers_float_argument[farg];
189 pd->regoff = stacksize * slot;
190 pd->index = stacksize;
191 stacksize += slots1w;
196 if (farg < FLT_ARG_CNT) {
197 pd->inmemory = false;
198 pd->regoff = abi_registers_float_argument[farg];
203 /* _ALIGN(stacksize); */
205 pd->regoff = stacksize * slot;
206 pd->index = stacksize;
207 stacksize += slots2w;
216 /* Since A0+A1/FA0 are used for passing return
217 values, this argument register usage has to be regarded,
220 if (IS_INT_LNG_TYPE(md->returntype.type)) {
221 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
222 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
225 if (IS_FLT_DBL_TYPE(md->returntype.type))
230 /* fill register and stack usage */
232 md->argintreguse = iarg;
233 md->argfltreguse = farg;
234 md->memuse = stacksize;
237 void md_param_alloc(methoddesc *md)
239 md_param_alloc_intern(md, 8, 1, 1);
242 void md_param_alloc_native(methoddesc *md)
244 md_param_alloc_intern(md, 4, 1, 2);
248 /* md_return_alloc *************************************************************
250 Precolor the Java Stackelement containing the Return Value. Only
251 for float/ double types straight forward possible, since INT_LNG
252 types use "reserved" registers Float/Double values use a00 as
256 jd: jitdata of the current method
257 stackslot: Java Stackslot to contain the Return Value
260 if precoloring was possible:
261 VAR(stackslot->varnum)->flags = PREALLOC
262 ->vv.regoff = [REG_RESULT|REG_FRESULT]
263 rd->arg[flt|int]reguse set to a value according the register usage
265 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
267 *******************************************************************************/
269 void md_return_alloc(jitdata *jd, stackptr stackslot)
275 /* 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 (!jd->isleafmethod || (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