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
35 #include "vm/global.h"
36 #include "vm/jit/jit.h"
37 #include "vm/jit/s390/md-abi.h"
40 #include "vmcore/descriptor.h"
44 /* register descripton array **************************************************/
47 /*itmp3, itmp1, a0, a1, a2, a3, a4, s0, */
48 REG_RES, REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_SAV,
49 /* s1, s2, s3, s4, s5, pv, ra/itmp2, sp */
50 REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, 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[] = {
78 const s4 abi_registers_integer_temporary[] = {
82 s4 nregdescfloat[] = {
83 REG_ARG, REG_TMP, REG_ARG, REG_TMP, REG_RES, REG_TMP, REG_RES, REG_TMP,
84 REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
88 const s4 abi_registers_float_argument[] = {
93 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
121 stackoff: offset on stack frame where to start placing arguments
123 *******************************************************************************/
125 static void md_param_alloc_intern(methoddesc *md, s4 slot, s4 slots1w, s4 slots2w, s4 stackoff)
133 /* set default values */
139 /* get params field of methoddesc */
143 for (i = 0; i < md->paramcount; i++, pd++) {
144 switch (md->paramtypes[i].type) {
147 if (iarg < INT_ARG_CNT) {
148 pd->inmemory = false;
149 pd->regoff = abi_registers_integer_argument[iarg];
155 pd->regoff = (stacksize * slot) + stackoff;
156 pd->index = stacksize;
157 stacksize += slots1w;
162 if (iarg < INT_ARG_CNT - 1) {
164 pd->inmemory = false;
166 PACK_REGS(abi_registers_integer_argument[iarg + 1],
167 abi_registers_integer_argument[iarg]);
168 pd->index = PACK_REGS(iarg + 1, iarg);
172 /* _ALIGN(stacksize); */
174 pd->regoff = (stacksize * slot) + stackoff;
175 pd->index = stacksize;
177 stacksize += slots2w;
182 if (farg < FLT_ARG_CNT) {
183 pd->inmemory = false;
184 pd->regoff = abi_registers_float_argument[farg];
190 pd->regoff = (stacksize * slot) + stackoff;
191 pd->index = stacksize;
192 stacksize += slots1w;
197 if (farg < FLT_ARG_CNT) {
198 pd->inmemory = false;
199 pd->regoff = abi_registers_float_argument[farg];
204 /* _ALIGN(stacksize); */
206 pd->regoff = (stacksize * slot) + stackoff;
207 pd->index = stacksize;
208 stacksize += slots2w;
217 /* Since A0+A1/FA0 are used for passing return
218 values, this argument register usage has to be regarded,
221 if (IS_INT_LNG_TYPE(md->returntype.type)) {
222 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
223 iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
226 if (IS_FLT_DBL_TYPE(md->returntype.type))
231 /* fill register and stack usage */
233 md->argintreguse = iarg;
234 md->argfltreguse = farg;
235 md->memuse = stacksize;
238 void md_param_alloc(methoddesc *md)
240 md_param_alloc_intern(md, 8, 1, 1, 0);
243 void md_param_alloc_native(methoddesc *md)
245 md_param_alloc_intern(md, 4, 1, 2, 96);
249 /* md_return_alloc *************************************************************
251 Precolor the Java Stackelement containing the Return Value. Only
252 for float/ double types straight forward possible, since INT_LNG
253 types use "reserved" registers Float/Double values use a00 as
257 jd: jitdata of the current method
258 stackslot: Java Stackslot to contain the Return Value
261 if precoloring was possible:
262 VAR(stackslot->varnum)->flags = PREALLOC
263 ->vv.regoff = [REG_RESULT|REG_FRESULT]
264 rd->arg[flt|int]reguse set to a value according the register usage
266 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
268 *******************************************************************************/
270 void md_return_alloc(jitdata *jd, stackptr stackslot)
276 /* get required compiler data */
283 /* In Leafmethods Local Vars holding parameters are precolored to
284 their argument register -> so leafmethods with paramcount > 0
285 could already use R3 == a00! */
287 if (!jd->isleafmethod || (md->paramcount == 0)) {
288 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
289 has not to survive method invokations. */
291 if (!(stackslot->flags & SAVEDVAR)) {
292 VAR(stackslot->varnum)->flags = PREALLOC;
294 if (IS_INT_LNG_TYPE(md->returntype.type)) {
295 if (!IS_2_WORD_TYPE(md->returntype.type)) {
296 if (rd->argintreguse < 1)
297 rd->argintreguse = 1;
299 VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
302 if (rd->argintreguse < 2)
303 rd->argintreguse = 2;
305 VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
308 else { /* float/double */
309 if (rd->argfltreguse < 1)
310 rd->argfltreguse = 1;
312 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
320 * These are local overrides for various environment variables in Emacs.
321 * Please do not remove this and leave it at the end of the file, where
322 * Emacs will automagically detect them.
323 * ---------------------------------------------------------------------
326 * indent-tabs-mode: t