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
31 #include "vm/jit/x86_64/md-abi.h"
33 #include "vm/global.h"
35 #include "vm/jit/abi.h"
36 #include "vm/jit/jit.h" /* for REG_* (maybe can be removed) */
38 #include "vmcore/descriptor.h"
41 /* register descripton array **************************************************/
44 REG_RET, REG_ARG, REG_ARG, REG_TMP, REG_RES, REG_SAV, REG_ARG, REG_ARG,
45 REG_ARG, REG_ARG, REG_RES, REG_RES, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
49 const char *abi_registers_integer_name[] = {
50 "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
51 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
54 const s4 abi_registers_integer_argument[] = {
63 const s4 abi_registers_integer_saved[] = {
71 const s4 abi_registers_integer_temporary[] = {
76 /* float registers *************************************************************
78 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7,
79 (fa0) (fa1) (fa2) (fa3) (fa4) (fa5) (fa6) (fa7)
81 xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15
82 (ftmp1) (ftmp2) (ftmp3) (ft0) (ft1) (ft2) (ft3) (ft4)
84 *******************************************************************************/
86 s4 nregdescfloat[] = {
87 REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
88 REG_RES, REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
93 const s4 abi_registers_float_argument[] = {
104 const s4 abi_registers_float_saved[] = {
108 const s4 abi_registers_float_temporary[] = {
117 /* md_param_alloc **************************************************************
121 *******************************************************************************/
123 void md_param_alloc(methoddesc *md)
131 /* set default values */
137 /* get params field of methoddesc */
141 for (i = 0; i < md->paramcount; i++, pd++) {
142 switch (md->paramtypes[i].type) {
146 if (iarg < INT_ARG_CNT) {
147 pd->inmemory = false;
149 pd->regoff = abi_registers_integer_argument[iarg];
154 pd->index = stacksize;
155 pd->regoff = stacksize * 8;
162 if (farg < FLT_ARG_CNT) {
163 pd->inmemory = false;
165 pd->regoff = abi_registers_float_argument[farg];
170 pd->index = stacksize;
171 pd->regoff = stacksize * 8;
178 /* Since XMM0 (==A0) is used for passing return values, this
179 argument register usage has to be regarded, too. */
181 if (IS_FLT_DBL_TYPE(md->returntype.type))
185 /* fill register and stack usage */
187 md->argintreguse = iarg;
188 md->argfltreguse = farg;
189 md->memuse = stacksize;
193 /* md_param_alloc_native *******************************************************
195 Pre-allocate arguments according the native ABI.
197 *******************************************************************************/
199 void md_param_alloc_native(methoddesc *md)
201 /* On x86_64 we use the same ABI for JIT method calls as for
202 native method calls. */
208 /* md_return_alloc *************************************************************
210 Precolor the Java Stackelement containing the Return Value. Only
211 for float/ double types straight forward possible, since INT_LNG
212 types use "reserved" registers Float/Double values use a00 as
216 jd: jitdata of the current method
217 stackslot: Java Stackslot to contain the Return Value
220 if precoloring was possible:
221 VAR(stackslot->varnum)->flags = PREALLOC
222 ->vv.regoff = [REG_RESULT|REG_FRESULT]
223 rd->arg[flt|int]reguse set to a value according the register usage
225 NOTE: Do not pass a LOCALVAR in stackslot->varnum.
227 *******************************************************************************/
229 void md_return_alloc(jitdata *jd, stackptr stackslot)
235 /* 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 (!jd->isleafmethod || (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