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