* configure.ac (AC_CHECK_HEADERS): Added sys/socket.h.
[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    $Id: md-abi.c 8123 2007-06-20 23:50:55Z michi $
26
27 */
28
29
30 #include "config.h"
31 #include "vm/types.h"
32
33 #include "vm/jit/alpha/md-abi.h"
34
35 #include "vm/global.h"
36
37 #include "vm/jit/abi.h"
38
39 #include "vmcore/descriptor.h"
40
41
42 /* register descripton array **************************************************/
43
44 s4 nregdescint[] = {
45         /*   v0,      t0,      t1,      t2,      t3,      t4,      t5,      t6,   */
46         REG_RET, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, 
47
48         /*   t7,      s0,      s1,      s2,      s3,      s4,      s5,      s6,   */
49         REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, 
50
51         /*   a0,      a1,      a2,      a3,      a4,      a5,      t8,      t9,   */
52         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP,
53
54         /*  t10,   itmp1,      ra,      pv,      at,   itmp3,      sp,    zero,   */
55         REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES,
56
57         REG_END
58 };
59
60 const char *abi_registers_integer_name[] = {
61         "v0",  "t0",  "t1",  "t2",  "t3",  "t4",  "t5",  "t6",
62         "t7",  "s0",  "s1",  "s2",  "s3",  "s4",  "s5",  "s6",
63         "a0",  "a1",  "a2",  "a3",  "a4",  "a5",  "t8",  "t9",
64         "t10", "t11", "ra",  "pv",  "at",  "gp",  "sp",  "zero"
65 };
66
67 const s4 abi_registers_integer_argument[] = {
68         16, /* a0  */
69         17, /* a1  */
70         18, /* a2  */
71         19, /* a3  */
72         20, /* a4  */
73         21, /* a5  */
74 };
75
76 const s4 abi_registers_integer_saved[] = {
77         9,  /* s0  */
78         10, /* s1  */
79         11, /* s2  */
80         12, /* s3  */
81         13, /* s4  */
82         14, /* s5  */
83         15, /* s6  */
84 };
85
86 const s4 abi_registers_integer_temporary[] = {
87         1,  /* t0  */
88         2,  /* t1  */
89         3,  /* t2  */
90         4,  /* t3  */
91         5,  /* t4  */
92         6,  /* t5  */
93         7,  /* t6  */
94         8,  /* t7  */
95         22, /* t8  */
96         23, /* t9  */
97         24, /* t10 */
98 };
99
100
101 s4 nregdescfloat[] = {
102         REG_RET, REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
103         REG_SAV, REG_SAV, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, 
104         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP,
105         REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES,
106         REG_END
107 };
108
109
110 const s4 abi_registers_float_argument[] = {
111         16, /* fa0  */
112         17, /* fa1  */
113         18, /* fa2  */
114         19, /* fa3  */
115         20, /* fa4  */
116         21, /* fa5  */
117 };
118
119 const s4 abi_registers_float_saved[] = {
120         2,  /* fs0  */
121         3,  /* fs1  */
122         4,  /* fs2  */
123         5,  /* fs3  */
124         6,  /* fs4  */
125         7,  /* fs5  */
126         8,  /* fs6  */
127         9,  /* fs7  */
128 };
129
130 const s4 abi_registers_float_temporary[] = {
131         1,  /* ft0  */
132         10, /* ft1  */
133         11, /* ft2  */
134         12, /* ft3  */
135         13, /* ft4  */
136         14, /* ft5  */
137         15, /* ft6  */
138         22, /* ft7  */
139         23, /* ft8  */
140         24, /* ft9  */
141         25, /* ft10 */
142         26, /* ft11 */
143         27, /* ft12 */
144 };
145
146
147 /* md_param_alloc **************************************************************
148
149    Allocate the parameters of the given method descriptor according to the
150    calling convention of the platform.
151
152 *******************************************************************************/
153
154 void md_param_alloc(methoddesc *md)
155 {
156         paramdesc *pd;
157         s4         i;
158         s4         reguse;
159         s4         stacksize;
160
161         /* set default values */
162
163         reguse    = 0;
164         stacksize = 0;
165
166         /* get params field of methoddesc */
167
168         pd = md->params;
169
170         for (i = 0; i < md->paramcount; i++, pd++) {
171                 switch (md->paramtypes[i].type) {
172                 case TYPE_INT:
173                 case TYPE_ADR:
174                 case TYPE_LNG:
175                         if (i < INT_ARG_CNT) {
176                                 pd->inmemory = false;
177                                 pd->regoff   = abi_registers_integer_argument[reguse];
178                                 reguse++;
179                                 md->argintreguse = reguse;
180                         }
181                         else {
182                                 pd->inmemory = true;
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->regoff   = abi_registers_float_argument[reguse];
193                                 reguse++;
194                                 md->argfltreguse = reguse;
195                         }
196                         else {
197                                 pd->inmemory = true;
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, stackptr 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  */