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/descriptor.h"
32 #include "vm/global.h"
34 #include "vm/jit/abi.h"
35 #include "vm/jit/jit.hpp" /* for REG_* (maybe can be removed) */
36 #include "vm/jit/stack.h"
39 /* register descripton array **************************************************/
42 REG_RET, REG_ARG, REG_ARG, REG_TMP, REG_RES, REG_SAV, REG_ARG, REG_ARG,
43 REG_ARG, REG_ARG, REG_RES, REG_RES, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
47 const char *abi_registers_integer_name[] = {
48 "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
49 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
52 const s4 abi_registers_integer_argument[] = {
61 const s4 abi_registers_integer_saved[] = {
69 const s4 abi_registers_integer_temporary[] = {
74 /* float registers *************************************************************
76 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7,
77 (fa0) (fa1) (fa2) (fa3) (fa4) (fa5) (fa6) (fa7)
79 xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15
80 (ftmp1) (ftmp2) (ftmp3) (ft0) (ft1) (ft2) (ft3) (ft4)
82 *******************************************************************************/
84 s4 nregdescfloat[] = {
85 REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
86 REG_RES, REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
91 const s4 abi_registers_float_argument[] = {
102 const s4 abi_registers_float_saved[] = {
106 const s4 abi_registers_float_temporary[] = {
115 /* md_param_alloc **************************************************************
119 *******************************************************************************/
121 void md_param_alloc(methoddesc *md)
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) {
144 if (iarg < INT_ARG_CNT) {
145 pd->inmemory = false;
147 pd->regoff = abi_registers_integer_argument[iarg];
152 pd->index = stacksize;
153 pd->regoff = stacksize * 8;
160 if (farg < FLT_ARG_CNT) {
161 pd->inmemory = false;
163 pd->regoff = abi_registers_float_argument[farg];
168 pd->index = stacksize;
169 pd->regoff = stacksize * 8;
176 /* Since XMM0 (==A0) is used for passing return values, this
177 argument register usage has to be regarded, too. */
179 if (IS_FLT_DBL_TYPE(md->returntype.type))
183 /* fill register and stack usage */
185 md->argintreguse = iarg;
186 md->argfltreguse = farg;
187 md->memuse = stacksize;
191 /* md_param_alloc_native *******************************************************
193 Pre-allocate arguments according the native ABI.
195 *******************************************************************************/
197 void md_param_alloc_native(methoddesc *md)
199 /* On x86_64 we use the same ABI for JIT method calls as for
200 native method calls. */
206 /* md_return_alloc *************************************************************
208 Precolor the Java Stackelement containing the Return Value. Only
209 for float/ double types straight forward possible, since INT_LNG
210 types use "reserved" registers Float/Double values use a00 as
214 jd: jitdata of the current method
215 stackslot: Java Stackslot to contain the Return Value
218 if precoloring was possible:
219 VAR(stackslot->varnum)->flags = PREALLOC
220 ->vv.regoff = [REG_RESULT|REG_FRESULT]
221 rd->arg[flt|int]reguse set to a value according the register usage
223 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
225 *******************************************************************************/
227 void md_return_alloc(jitdata *jd, stackelement_t *stackslot)
234 /* get required compiler data */
242 /* precoloring only straightforward possible with flt/dbl types
243 For Address/Integer/Long REG_RESULT == rax == REG_ITMP1 and so
244 could be destroyed if the return value Stack Slot "lives too
247 if (IS_FLT_DBL_TYPE(md->returntype.type)) {
248 /* In Leafmethods Local Vars holding parameters are precolored
249 to their argument register -> so leafmethods with
250 paramcount > 0 could already use a00! */
252 if (!code_is_leafmethod(code) || (md->paramcount == 0)) {
253 /* Only precolor the stackslot, if it is not a SAVEDVAR
254 <-> has not to survive method invokations */
256 if (!(stackslot->flags & SAVEDVAR)) {
258 VAR(stackslot->varnum)->flags = PREALLOC;
261 if (rd->argfltreguse < 1)
262 rd->argfltreguse = 1;
264 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
272 * These are local overrides for various environment variables in Emacs.
273 * Please do not remove this and leave it at the end of the file, where
274 * Emacs will automagically detect them.
275 * ---------------------------------------------------------------------
278 * indent-tabs-mode: t