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