1 /* src/vm/jit/x86_64/md-abi.c - functions for x86_64 Linux ABI
3 Copyright (C) 1996-2005, 2006, 2007, 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
29 #include "vm/jit/x86_64/md-abi.h"
31 #include "vm/global.h"
33 #include "vm/jit/abi.h"
34 #include "vm/jit/jit.h" /* for REG_* (maybe can be removed) */
35 #include "vm/jit/stack.h"
37 #include "vmcore/descriptor.h"
40 /* register descripton array **************************************************/
43 REG_RET, REG_ARG, REG_ARG, REG_TMP, REG_RES, REG_SAV, REG_ARG, REG_ARG,
44 REG_ARG, REG_ARG, REG_RES, REG_RES, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
48 const char *abi_registers_integer_name[] = {
49 "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
50 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
53 const s4 abi_registers_integer_argument[] = {
62 const s4 abi_registers_integer_saved[] = {
70 const s4 abi_registers_integer_temporary[] = {
75 /* float registers *************************************************************
77 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7,
78 (fa0) (fa1) (fa2) (fa3) (fa4) (fa5) (fa6) (fa7)
80 xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15
81 (ftmp1) (ftmp2) (ftmp3) (ft0) (ft1) (ft2) (ft3) (ft4)
83 *******************************************************************************/
85 s4 nregdescfloat[] = {
86 REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
87 REG_RES, REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
92 const s4 abi_registers_float_argument[] = {
103 const s4 abi_registers_float_saved[] = {
107 const s4 abi_registers_float_temporary[] = {
116 /* md_param_alloc **************************************************************
120 *******************************************************************************/
122 void md_param_alloc(methoddesc *md)
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) {
145 if (iarg < INT_ARG_CNT) {
146 pd->inmemory = false;
148 pd->regoff = abi_registers_integer_argument[iarg];
153 pd->index = stacksize;
154 pd->regoff = stacksize * 8;
161 if (farg < FLT_ARG_CNT) {
162 pd->inmemory = false;
164 pd->regoff = abi_registers_float_argument[farg];
169 pd->index = stacksize;
170 pd->regoff = stacksize * 8;
177 /* Since XMM0 (==A0) is used for passing return values, this
178 argument register usage has to be regarded, too. */
180 if (IS_FLT_DBL_TYPE(md->returntype.type))
184 /* fill register and stack usage */
186 md->argintreguse = iarg;
187 md->argfltreguse = farg;
188 md->memuse = stacksize;
192 /* md_param_alloc_native *******************************************************
194 Pre-allocate arguments according the native ABI.
196 *******************************************************************************/
198 void md_param_alloc_native(methoddesc *md)
200 /* On x86_64 we use the same ABI for JIT method calls as for
201 native method calls. */
207 /* md_return_alloc *************************************************************
209 Precolor the Java Stackelement containing the Return Value. Only
210 for float/ double types straight forward possible, since INT_LNG
211 types use "reserved" registers Float/Double values use a00 as
215 jd: jitdata of the current method
216 stackslot: Java Stackslot to contain the Return Value
219 if precoloring was possible:
220 VAR(stackslot->varnum)->flags = PREALLOC
221 ->vv.regoff = [REG_RESULT|REG_FRESULT]
222 rd->arg[flt|int]reguse set to a value according the register usage
224 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
226 *******************************************************************************/
228 void md_return_alloc(jitdata *jd, stackelement_t *stackslot)
235 /* get required compiler data */
243 /* precoloring only straightforward possible with flt/dbl types
244 For Address/Integer/Long REG_RESULT == rax == REG_ITMP1 and so
245 could be destroyed if the return value Stack Slot "lives too
248 if (IS_FLT_DBL_TYPE(md->returntype.type)) {
249 /* In Leafmethods Local Vars holding parameters are precolored
250 to their argument register -> so leafmethods with
251 paramcount > 0 could already use a00! */
253 if (!code_is_leafmethod(code) || (md->paramcount == 0)) {
254 /* Only precolor the stackslot, if it is not a SAVEDVAR
255 <-> has not to survive method invokations */
257 if (!(stackslot->flags & SAVEDVAR)) {
259 VAR(stackslot->varnum)->flags = PREALLOC;
262 if (rd->argfltreguse < 1)
263 rd->argfltreguse = 1;
265 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
273 * These are local overrides for various environment variables in Emacs.
274 * Please do not remove this and leave it at the end of the file, where
275 * Emacs will automagically detect them.
276 * ---------------------------------------------------------------------
279 * indent-tabs-mode: t