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