11a54cd9daf24d1fc8dac8ff8533153a57ad7b1c
[cacao.git] / src / vm / jit / x86_64 / md-abi.c
1 /* src/vm/jit/x86_64/md-abi.c - functions for x86_64 Linux ABI
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
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.
14
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.
19
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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Christian Thalinger
28
29    Changes:
30
31    $Id: md-abi.c 2872 2005-06-29 12:42:19Z christian $
32
33 */
34
35
36 #include "vm/jit/x86_64/types.h"
37 #include "vm/jit/x86_64/md-abi.h"
38
39 #include "vm/descriptor.h"
40 #include "vm/global.h"
41
42
43 /* md_param_alloc **************************************************************
44
45    XXX
46
47 *******************************************************************************/
48
49 void md_param_alloc(methoddesc *md)
50 {
51         paramdesc *pd;
52         s4         i;
53         s4         iarg;
54         s4         farg;
55         s4         stacksize;
56
57         /* set default values */
58
59         iarg = 0;
60         farg = 0;
61         stacksize = 0;
62
63         /* get params field of methoddesc */
64
65         pd = md->params;
66
67         for (i = 0; i < md->paramcount; i++, pd++) {
68                 switch (md->paramtypes[i].type) {
69                 case TYPE_INT:
70                 case TYPE_ADR:
71                 case TYPE_LNG:
72                         if (iarg < INT_ARG_CNT) {
73                                 pd->inmemory = false;
74                                 pd->regoff = iarg;
75
76                         } else {
77                                 pd->inmemory = true;
78                                 pd->regoff = stacksize;
79                         }
80                         if (iarg < INT_ARG_CNT)
81                                 iarg++;
82                         else
83                                 stacksize++;
84                         break;
85                 case TYPE_FLT:
86                 case TYPE_DBL:
87                         if (farg < FLT_ARG_CNT) {
88                                 pd->inmemory = false;
89                                 pd->regoff = farg;
90                         } else {
91                                 pd->inmemory = true;
92                                 pd->regoff = stacksize;
93                         }
94                         if (farg < FLT_ARG_CNT)
95                                 farg++;
96                         else
97                                 stacksize++;
98                         break;
99                 }
100         }
101
102         /* fill register and stack usage */
103
104         md->argintreguse = iarg;
105         md->argfltreguse = farg;
106         md->memuse = stacksize;
107 }
108
109 /* md_return_alloc *************************************************************
110
111  Precolor the Java Stackelement containing the Return Value. Only for float/
112  double types straight forward possible, since INT_LNG types use "reserved"
113  registers
114  Float/Double values use a00 as return register.
115
116 --- in
117 m:                       Methodinfo of current method
118 return_type:             Return Type of the Method (TYPE_INT.. TYPE_ADR)
119                          TYPE_VOID is not allowed!
120 stackslot:               Java Stackslot to contain the Return Value
121
122 --- out
123 if precoloring was possible:
124 stackslot->varkind       =ARGVAR
125          ->varnum        =-1
126                  ->flags         =0
127                  ->regoff        =[REG_RESULT, (REG_RESULT2/REG_RESULT), REG_FRESULT]
128 rd->arg[flt|int]reguse   set to a value according the register usage
129                                  
130
131 *******************************************************************************/
132 void md_return_alloc(methodinfo *m, registerdata *rd, s4 return_type,
133                                          stackptr stackslot) {
134         /* precoloring only straightforward possible with flt/dbl types */
135         if (IS_FLT_DBL_TYPE(return_type)) {
136                 /* In Leafmethods Local Vars holding parameters are precolored to     */
137                 /* their argument register -> so leafmethods with paramcount > 0 could*/
138                 /* already use a00! */
139                 if (!m->isleafmethod || (m->paramcount == 0)) {
140                         /* Only precolor the stackslot, if it is not a SAVEDVAR <-> has   */
141                         /* not to survive method invokations */
142                         if (!(stackslot->flags & SAVEDVAR)) {
143                                 stackslot->varkind = ARGVAR;
144                                 stackslot->varnum = -1;
145                                 stackslot->flags = 0;
146                             /* float/double */
147                                 if (rd->argfltreguse < 1) rd->argfltreguse = 1;
148                                 stackslot->regoff = REG_FRESULT;
149                         }
150                 }
151         }
152 }
153
154 /*
155  * These are local overrides for various environment variables in Emacs.
156  * Please do not remove this and leave it at the end of the file, where
157  * Emacs will automagically detect them.
158  * ---------------------------------------------------------------------
159  * Local variables:
160  * mode: c
161  * indent-tabs-mode: t
162  * c-basic-offset: 4
163  * tab-width: 4
164  * End:
165  */