1 /* src/vm/jit/x86_64/md-abi.c - functions for x86_64 Linux ABI
3 Copyright (C) 1996-2005, 2006, 2007 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 $Id: md-abi.c 8123 2007-06-20 23:50:55Z michi $
33 #include "vm/jit/x86_64/md-abi.h"
35 #include "vm/global.h"
37 #include "vm/jit/abi.h"
38 #include "vm/jit/jit.h" /* for REG_* (maybe can be removed) */
40 #include "vmcore/descriptor.h"
43 /* register descripton array **************************************************/
46 REG_RET, REG_ARG, REG_ARG, REG_TMP, REG_RES, REG_SAV, REG_ARG, REG_ARG,
47 REG_ARG, REG_ARG, REG_RES, REG_RES, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
51 const char *abi_registers_integer_name[] = {
52 "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
53 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
56 const s4 abi_registers_integer_argument[] = {
65 const s4 abi_registers_integer_saved[] = {
73 const s4 abi_registers_integer_temporary[] = {
78 /* float registers *************************************************************
80 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7,
81 (fa0) (fa1) (fa2) (fa3) (fa4) (fa5) (fa6) (fa7)
83 xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15
84 (ftmp1) (ftmp2) (ftmp3) (ft0) (ft1) (ft2) (ft3) (ft4)
86 *******************************************************************************/
88 s4 nregdescfloat[] = {
89 REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
90 REG_RES, REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
95 const s4 abi_registers_float_argument[] = {
106 const s4 abi_registers_float_saved[] = {
110 const s4 abi_registers_float_temporary[] = {
119 /* md_param_alloc **************************************************************
123 *******************************************************************************/
125 void md_param_alloc(methoddesc *md)
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) {
148 if (iarg < INT_ARG_CNT) {
149 pd->inmemory = false;
151 pd->regoff = abi_registers_integer_argument[iarg];
156 pd->index = stacksize;
157 pd->regoff = stacksize * 8;
164 if (farg < FLT_ARG_CNT) {
165 pd->inmemory = false;
167 pd->regoff = abi_registers_float_argument[farg];
172 pd->index = stacksize;
173 pd->regoff = stacksize * 8;
180 /* Since XMM0 (==A0) is used for passing return values, this
181 argument register usage has to be regarded, too. */
183 if (IS_FLT_DBL_TYPE(md->returntype.type))
187 /* fill register and stack usage */
189 md->argintreguse = iarg;
190 md->argfltreguse = farg;
191 md->memuse = stacksize;
195 /* md_param_alloc_native *******************************************************
197 Pre-allocate arguments according the native ABI.
199 *******************************************************************************/
201 void md_param_alloc_native(methoddesc *md)
203 /* On x86_64 we use the same ABI for JIT method calls as for
204 native method calls. */
210 /* md_return_alloc *************************************************************
212 Precolor the Java Stackelement containing the Return Value. Only
213 for float/ double types straight forward possible, since INT_LNG
214 types use "reserved" registers Float/Double values use a00 as
218 jd: jitdata of the current method
219 stackslot: Java Stackslot to contain the Return Value
222 if precoloring was possible:
223 VAR(stackslot->varnum)->flags = PREALLOC
224 ->vv.regoff = [REG_RESULT|REG_FRESULT]
225 rd->arg[flt|int]reguse set to a value according the register usage
227 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
229 *******************************************************************************/
231 void md_return_alloc(jitdata *jd, stackptr stackslot)
237 /* get required compiler data */
244 /* precoloring only straightforward possible with flt/dbl types
245 For Address/Integer/Long REG_RESULT == rax == REG_ITMP1 and so
246 could be destroyed if the return value Stack Slot "lives too
249 if (IS_FLT_DBL_TYPE(md->returntype.type)) {
250 /* In Leafmethods Local Vars holding parameters are precolored
251 to their argument register -> so leafmethods with
252 paramcount > 0 could already use a00! */
254 if (!jd->isleafmethod || (md->paramcount == 0)) {
255 /* Only precolor the stackslot, if it is not a SAVEDVAR
256 <-> has not to survive method invokations */
258 if (!(stackslot->flags & SAVEDVAR)) {
260 VAR(stackslot->varnum)->flags = PREALLOC;
263 if (rd->argfltreguse < 1)
264 rd->argfltreguse = 1;
266 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
274 * These are local overrides for various environment variables in Emacs.
275 * Please do not remove this and leave it at the end of the file, where
276 * Emacs will automagically detect them.
277 * ---------------------------------------------------------------------
280 * indent-tabs-mode: t