Proper x86_64 mnemonics
[cacao.git] / src / vm / jit / alpha / md-abi.c
1 /* src/vm/jit/alpha/md-abi.c - functions for Alpha ABI
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
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.
12
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.
17
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
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27 #include "vm/types.h"
28
29 #include "vm/jit/alpha/md-abi.h"
30
31 #include "vm/global.h"
32
33 #include "vm/jit/abi.h"
34
35 #include "vmcore/descriptor.h"
36
37
38 /* register descripton array **************************************************/
39
40 s4 nregdescint[] = {
41         /*   v0,      t0,      t1,      t2,      t3,      t4,      t5,      t6,   */
42         REG_RET, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, 
43
44         /*   t7,      s0,      s1,      s2,      s3,      s4,      s5,      s6,   */
45         REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, 
46
47         /*   a0,      a1,      a2,      a3,      a4,      a5,      t8,      t9,   */
48         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP,
49
50         /*  t10,   itmp1,      ra,      pv,      at,   itmp3,      sp,    zero,   */
51         REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES,
52
53         REG_END
54 };
55
56 const char *abi_registers_integer_name[] = {
57         "v0",  "t0",  "t1",  "t2",  "t3",  "t4",  "t5",  "t6",
58         "t7",  "s0",  "s1",  "s2",  "s3",  "s4",  "s5",  "s6",
59         "a0",  "a1",  "a2",  "a3",  "a4",  "a5",  "t8",  "t9",
60         "t10", "t11", "ra",  "pv",  "at",  "gp",  "sp",  "zero"
61 };
62
63 const s4 abi_registers_integer_argument[] = {
64         16, /* a0  */
65         17, /* a1  */
66         18, /* a2  */
67         19, /* a3  */
68         20, /* a4  */
69         21, /* a5  */
70 };
71
72 const s4 abi_registers_integer_saved[] = {
73         9,  /* s0  */
74         10, /* s1  */
75         11, /* s2  */
76         12, /* s3  */
77         13, /* s4  */
78         14, /* s5  */
79         15, /* s6  */
80 };
81
82 const s4 abi_registers_integer_temporary[] = {
83         1,  /* t0  */
84         2,  /* t1  */
85         3,  /* t2  */
86         4,  /* t3  */
87         5,  /* t4  */
88         6,  /* t5  */
89         7,  /* t6  */
90         8,  /* t7  */
91         22, /* t8  */
92         23, /* t9  */
93         24, /* t10 */
94 };
95
96
97 s4 nregdescfloat[] = {
98         REG_RET, REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
99         REG_SAV, REG_SAV, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, 
100         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP,
101         REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES,
102         REG_END
103 };
104
105
106 const s4 abi_registers_float_argument[] = {
107         16, /* fa0  */
108         17, /* fa1  */
109         18, /* fa2  */
110         19, /* fa3  */
111         20, /* fa4  */
112         21, /* fa5  */
113 };
114
115 const s4 abi_registers_float_saved[] = {
116         2,  /* fs0  */
117         3,  /* fs1  */
118         4,  /* fs2  */
119         5,  /* fs3  */
120         6,  /* fs4  */
121         7,  /* fs5  */
122         8,  /* fs6  */
123         9,  /* fs7  */
124 };
125
126 const s4 abi_registers_float_temporary[] = {
127         1,  /* ft0  */
128         10, /* ft1  */
129         11, /* ft2  */
130         12, /* ft3  */
131         13, /* ft4  */
132         14, /* ft5  */
133         15, /* ft6  */
134         22, /* ft7  */
135         23, /* ft8  */
136         24, /* ft9  */
137         25, /* ft10 */
138         26, /* ft11 */
139         27, /* ft12 */
140 };
141
142
143 /* md_param_alloc **************************************************************
144
145    Allocate the parameters of the given method descriptor according to the
146    calling convention of the platform.
147
148 *******************************************************************************/
149
150 void md_param_alloc(methoddesc *md)
151 {
152         paramdesc *pd;
153         s4         i;
154         s4         reguse;
155         s4         stacksize;
156
157         /* set default values */
158
159         reguse    = 0;
160         stacksize = 0;
161
162         /* get params field of methoddesc */
163
164         pd = md->params;
165
166         for (i = 0; i < md->paramcount; i++, pd++) {
167                 switch (md->paramtypes[i].type) {
168                 case TYPE_INT:
169                 case TYPE_ADR:
170                 case TYPE_LNG:
171                         if (i < INT_ARG_CNT) {
172                                 pd->inmemory = false;
173                                 pd->index    = reguse;
174                                 pd->regoff   = abi_registers_integer_argument[reguse];
175                                 reguse++;
176                                 md->argintreguse = reguse;
177                         }
178                         else {
179                                 pd->inmemory = true;
180                                 pd->index    = stacksize;
181                                 pd->regoff   = stacksize * 8;
182                                 stacksize++;
183                         }
184                         break;
185
186                 case TYPE_FLT:
187                 case TYPE_DBL:
188                         if (i < FLT_ARG_CNT) {
189                                 pd->inmemory = false;
190                                 pd->index    = reguse;
191                                 pd->regoff   = abi_registers_float_argument[reguse];
192                                 reguse++;
193                                 md->argfltreguse = reguse;
194                         }
195                         else {
196                                 pd->inmemory = true;
197                                 pd->index    = stacksize;
198                                 pd->regoff   = stacksize * 8;
199                                 stacksize++;
200                         }
201                         break;
202                 }
203         }
204
205         /* fill register and stack usage */
206
207         md->memuse = stacksize;
208 }
209
210
211 /* md_param_alloc_native *******************************************************
212
213    Pre-allocate arguments according to the native ABI.
214
215 *******************************************************************************/
216
217 void md_param_alloc_native(methoddesc *md)
218 {
219         /* On Alpha we use the same ABI for JIT method calls as for native
220            method calls. */
221
222         md_param_alloc(md);
223 }
224
225
226 /* md_return_alloc *************************************************************
227
228    Precolor the Java Stackelement containing the Return Value. Since
229    alpha has a dedicated return register (not an reused arg or
230    reserved reg), this is striaghtforward possible, as long, as this
231    stackelement does not have to survive a method invokation
232    (SAVEDVAR)
233
234    --- in
235    jd:                      jitdata of the current method
236    stackslot:               Java Stackslot to contain the Return Value
237    
238    --- out
239    if precoloring was possible:
240    VAR(stackslot->varnum)->flags       = PREALLOC
241                                      ->vv.regoff   = [REG_RESULT|REG_FRESULT]
242    rd->arg[flt|int]reguse   set to a value according the register usage
243
244    NOTE: Do not pass a LOCALVAR in stackslot->varnum.
245 *******************************************************************************/
246
247 void md_return_alloc(jitdata *jd, stackelement_t *stackslot)
248 {
249         methodinfo *m;
250         methoddesc *md;
251
252         /* get required compiler data */
253
254         m = jd->m;
255
256         md = m->parseddesc;
257
258         /* Only precolor the stackslot, if it is not a SAVEDVAR <-> has
259            not to survive method invokations. */
260
261         if (!(stackslot->flags & SAVEDVAR)) {
262
263                 VAR(stackslot->varnum)->flags = PREALLOC;
264
265                 if (IS_INT_LNG_TYPE(md->returntype.type))
266                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
267                 else
268                         VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
269         }
270 }
271
272
273 /*
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  * ---------------------------------------------------------------------
278  * Local variables:
279  * mode: c
280  * indent-tabs-mode: t
281  * c-basic-offset: 4
282  * tab-width: 4
283  * End:
284  */