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