0aaf68aa85bf26750d3a4ab2a60c5343cd8342fa
[cacao.git] / src / vm / jit / sparc64 / md-abi.c
1 /* src/vm/jit/sparc64/md-abi.c - functions for Sparc ABI
2
3    Copyright (C) 1996-2005, 2006 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.h 4357 2006-01-22 23:33:38Z twisti $
26
27 */
28
29
30 #include "config.h"
31 #include "vm/types.h"
32
33 #include "vm/jit/sparc64/md-abi.h"
34
35 #include "vm/global.h"
36
37 #include "vm/jit/abi.h"
38
39 #include "vmcore/descriptor.h"
40
41 /* temp */
42 #include "mm/memory.h"
43 #include <assert.h>
44
45 /* helper macros for allocation methods ***************************************/
46 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
47
48 /* register descripton array **************************************************/
49
50 /* callee point-of-view, after SAVE has been called. */
51 s4 nregdescint[] = {
52         /* zero  itmp1/g1 itmp2/g2 itmp3/g3 temp/g4  temp/g5  sys/g6   sys/g7 */  
53         REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES,
54         
55         /* o0    o1       o2       o3       o4       pv/o5    sp/o6    ra/o7  */
56         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES, REG_RES,
57         
58         /* l0    l1       l2       l3       l4       l5       l6       l7     */
59         REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
60         
61         /* i0    i1       i2       i3       i4       pv/i5    fp/i6    ra/i7  */
62         REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_RES, REG_RES, REG_RES,
63         REG_END
64 };
65
66 const char *abi_registers_integer_name[] = {
67                 "zero",  "g1",  "g2",  "g3",  "g4",  "g5",  "g6",  "g7",
68                 "o0",    "o1",  "o2",  "o3",  "o4",  "o5",  "sp",  "o7",
69                 "l0",    "l1",  "l2",  "l3",  "l4",  "l5",  "l6",  "l7",
70                 "i0",    "i1",  "i2",  "i3",  "i4",  "i5",  "fp",  "i7"
71 };
72
73 const s4 abi_registers_integer_argument[] = {
74         8,  /* o0  */
75         9,  /* o1  */
76         10, /* o2  */
77         11, /* o3  */
78         12, /* o4  */
79 };
80
81 const s4 abi_registers_integer_saved[] = {
82         16, /* l0  */
83         17, /* l1  */
84         18, /* l2  */
85         19, /* l3  */
86         20, /* l4  */
87         21, /* l5  */
88         22, /* l6  */
89         23, /* l7  */
90         24, /* i0  */
91         25, /* i1  */
92         26, /* i2  */
93         27, /* i3  */
94         28, /* i4  */
95 };
96
97
98
99 s4 nregdescfloat[] = {
100         REG_RET, REG_RES, REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
101         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP, REG_TMP,
102         REG_END
103 };
104
105
106 const s4 abi_registers_float_argument[] = {
107         8,  /* f16  */
108         9,  /* f18  */
109         10, /* f20  */
110         11, /* f22  */
111         12, /* f24  */
112 };
113
114 const s4 abi_registers_float_temporary[] = {
115         4,  /* f8   */
116         5,  /* f10  */
117         6,  /* f12  */
118         7,  /* f14  */
119         13, /* f26  */
120         14, /* f28  */
121         15, /* f30  */
122 };
123
124 s4 nat_argintregs[] = {
125         REG_OUT0, REG_OUT1, REG_OUT2, REG_OUT3, REG_OUT4, REG_OUT5
126 };
127
128
129 /* md_param_alloc **************************************************************
130
131    Allocate Arguments to Stackslots according the Calling Conventions
132
133    --- in
134    md->paramcount:           Number of arguments for this method
135    md->paramtypes[].type:    Argument types
136
137    --- out
138    md->params[].inmemory:    Argument spilled on stack
139    md->params[].regoff:      Stack offset or rd->arg[int|flt]regs index
140    md->memuse:               Stackslots needed for argument spilling
141    md->argintreguse:         max number of integer arguments used
142    md->argfltreguse:         max number of float arguments used
143
144 *******************************************************************************/
145
146 void md_param_alloc(methoddesc *md)
147 {
148         paramdesc *pd;
149         s4         i;
150         s4         reguse;
151         s4         stacksize;
152
153         /* set default values */
154
155         reguse = 0;
156         stacksize = 0;
157
158         /* get params field of methoddesc */
159
160         pd = md->params;
161
162         for (i = 0; i < md->paramcount; i++, pd++) {
163                 switch (md->paramtypes[i].type) {
164                 case TYPE_INT:
165                 case TYPE_ADR:
166                 case TYPE_LNG:
167                         if (i < INT_ARG_CNT) {
168                                 pd->inmemory = false;
169                                 pd->index = reguse;
170                                 pd->regoff   = abi_registers_integer_argument[reguse];
171                                 reguse++;
172                                 md->argintreguse = reguse;
173                         }
174                         else {
175                                 pd->inmemory = true;
176                                 pd->index = stacksize;
177                                 pd->regoff = stacksize * 8;
178                                 stacksize++;
179                         }
180                         break;
181
182                 case TYPE_FLT:
183                 case TYPE_DBL:
184                         if (i < FLT_ARG_CNT) {
185                                 pd->inmemory = false;
186                                 pd->index = reguse;
187                                 pd->regoff   = abi_registers_float_argument[reguse];
188                                 reguse++;
189                                 md->argfltreguse = reguse;
190                         }
191                         else {
192                                 pd->inmemory = true;
193                                 pd->index = stacksize;
194                                 pd->regoff = stacksize * 8;
195                                 stacksize++;
196                         }
197                         break;
198                 }
199                 assert(pd->regoff != 26);
200         }
201         
202         /* Since O0 is used for passing return values, this */
203         /* argument register usage has to be regarded, too                        */
204         if (IS_INT_LNG_TYPE(md->returntype.type)) {
205                 if (reguse < 1)
206                         md->argintreguse = 1;
207         }
208
209         /* fill register and stack usage */
210
211         md->memuse = stacksize;
212 }
213
214
215 /* md_param_alloc_native *******************************************************
216  *
217  *    Pre-allocate arguments according to the native ABI.
218  *
219  *    *******************************************************************************/
220
221 void md_param_alloc_native(methoddesc *md)
222 {
223         paramdesc *pd;
224         s4         i;
225         s4         reguse;
226         s4         stacksize;
227         s4         min_nat_regs;
228
229         /* Note: regoff will be set relative to a stack base of $sp+16 */
230          
231         /* set default values */
232         reguse = 0;
233         stacksize = 6; /* abi params: allocated, but not used */
234
235         /* when we are above this, we have to increase the stacksize with every */
236         /* single argument to create the proper argument array                  */
237         min_nat_regs = MIN(INT_NATARG_CNT, FLT_NATARG_CNT);
238
239         /* get params field of methoddesc */
240
241         pd = md->params;
242
243         for (i = 0; i < md->paramcount; i++, pd++) {
244                 switch (md->paramtypes[i].type) {
245                 case TYPE_INT:
246                 case TYPE_ADR:
247                 case TYPE_LNG:
248                         if (i < INT_NATARG_CNT) {
249                                 pd->inmemory = false;
250                                 pd->regoff = nat_argintregs[reguse];
251                                 reguse++;
252                                 md->argintreguse = reguse;
253
254                         } else {
255                                 pd->inmemory = true;
256                                 pd->regoff = reguse * 8;
257                                 reguse++;
258                         }
259                         break;
260                 case TYPE_FLT:
261                 case TYPE_DBL:
262                         if (i < FLT_NATARG_CNT) {
263                                 pd->inmemory = false;
264                                 pd->regoff = reguse;
265                                 reguse++;
266                                 md->argfltreguse = reguse;
267                         } else {
268                                 pd->inmemory = true;
269                                 pd->regoff = reguse * 8;
270                                 reguse++;
271                         }
272
273                         break;
274                 }
275
276                 if (i >= min_nat_regs)
277                         stacksize++;
278         }
279         
280         /* Since O0 is used for passing return values, this */
281         /* argument register usage has to be regarded, too                        */
282         if (IS_INT_LNG_TYPE(md->returntype.type)) {
283                 if (reguse < 1)
284                         md->argintreguse = 1;
285         }
286
287         /* fill register and stack usage */
288
289         md->memuse = stacksize;
290 }
291
292 /* md_return_alloc *************************************************************
293
294   XXX
295
296 *******************************************************************************/
297
298 void md_return_alloc(jitdata *jd, stackptr stackslot)
299 {
300         /* XXX */
301 }
302
303
304 /*
305  * These are local overrides for various environment variables in Emacs.
306  * Please do not remove this and leave it at the end of the file, where
307  * Emacs will automagically detect them.
308  * ---------------------------------------------------------------------
309  * Local variables:
310  * mode: c
311  * indent-tabs-mode: t
312  * c-basic-offset: 4
313  * tab-width: 4
314  * End:
315  */