Added some missing vim modelines.
[cacao.git] / src / vm / jit / powerpc / netbsd / md-abi.c
1 /* src/vm/jit/powerpc/netbsd/md-abi.c - PowerPC NetBSD ABI
2
3    Copyright (C) 1996-2005, 2006, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27 #include "vm/types.h"
28
29 #include "vm/jit/powerpc/netbsd/md-abi.h"
30
31 #include "vm/descriptor.hpp"
32 #include "vm/global.h"
33
34 #include "vm/jit/abi.h"
35 #include "vm/jit/stack.h"
36
37
38 #define _ALIGN(a)    do { if ((a) & 1) (a)++; } while (0)
39
40
41 /* register descripton array **************************************************/
42
43 s4 nregdescint[] = {
44         /* zero,      sp, NO(sys),   a0/v0,   a0/v1,      a2,      a3,      a4,   */
45         REG_RES, REG_RES, REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
46
47         /*   a5,      a6,      a7,   itmp1,   itmp2,      pv,      s0,      s1,   */
48         REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES, REG_RES, REG_SAV, REG_SAV,
49
50         /*itmp3,      t0,      t1,      t2,      t3,      t4,      t5,      t6,   */
51         REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
52
53         /*   s2,      s3,      s4,      s5,      s6,      s7,      s8,      s9,   */
54         REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
55
56         REG_END
57 };
58
59
60 s4 nregdescfloat[] = {
61         /*ftmp3,  fa0/v0,     fa1,     fa2,     fa3,     fa4,     fa5,     fa6,   */
62         REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
63
64         /*  fa7,     ft0,     ft1,     ft2,     ft3,     ft4,     fs0,     fs1,   */
65         REG_ARG, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_SAV, REG_SAV,
66
67         /*ftmp1,   ftmp2,     ft5,     ft6,     ft7,     ft8,     ft9,    ft10,   */
68         REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
69
70         /*  fs2,     fs3,     fs4,     fs5,     fs6,     fs7,     fs8,     fs9    */
71         REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
72
73         REG_END
74 };
75
76
77 /* md_param_alloc **************************************************************
78
79    Allocate Arguments to Stackslots according the Calling Conventions
80
81    --- in
82    md->paramcount:           Number of arguments for this method
83    md->paramtypes[].type:    Argument types
84
85    --- out
86    md->params[].inmemory:    Argument spilled on stack
87    md->params[].regoff:      Stack offset or rd->arg[int|flt]regs index
88    md->memuse:               Stackslots needed for argument spilling
89    md->argintreguse:         max number of integer arguments used
90    md->argfltreguse:         max number of float arguments used
91
92 *******************************************************************************/
93
94 void md_param_alloc(methoddesc *md)
95 {
96         paramdesc *pd;
97         s4         i;
98         s4         iarg;
99         s4         farg;
100         s4         stacksize;
101
102         /* set default values */
103
104         iarg = 0;
105         farg = 0;
106         stacksize = LA_WORD_SIZE;
107
108         /* get params field of methoddesc */
109
110         pd = md->params;
111
112         for (i = 0; i < md->paramcount; i++, pd++) {
113                 switch (md->paramtypes[i].type) {
114                 case TYPE_INT:
115                 case TYPE_ADR:
116                         if (iarg < INT_ARG_CNT) {
117                                 pd->inmemory = false;
118                                 pd->regoff = iarg;
119                                 iarg++;
120                         } else {
121                                 pd->inmemory = true;
122                                 pd->regoff = stacksize * 4;
123                                 stacksize++;
124                         }
125                         break;
126                 case TYPE_LNG:
127                         if (iarg < INT_ARG_CNT - 1) {
128                                 _ALIGN(iarg);
129                                 pd->inmemory = false;
130                                                              /* rd->arg[int|flt]regs index !! */
131                                 pd->regoff = PACK_REGS(iarg + 1, iarg); 
132                                 iarg += 2;
133                         } else {
134                                 _ALIGN(stacksize);
135                                 pd->inmemory = true;
136                                 pd->regoff = stacksize * 4;
137                                 iarg = INT_ARG_CNT;
138                                 stacksize += 2;
139                         }
140                         break;
141                 case TYPE_FLT:
142                         if (farg < FLT_ARG_CNT) {
143                                 pd->inmemory = false;
144                                 pd->regoff = farg;
145                                 farg++;
146                         } else {
147                                 pd->inmemory = true;
148                                 pd->regoff = stacksize * 4;
149                                 stacksize++;
150                         }
151                         break;
152                 case TYPE_DBL:
153                         if (farg < FLT_ARG_CNT) {
154                                 pd->inmemory = false;
155                                 pd->regoff = farg;
156                                 farg++;
157                         } else {
158                                 _ALIGN(stacksize);
159                                 pd->inmemory = true;
160                                 pd->regoff = stacksize * 4;
161                                 stacksize += 2;
162                         }
163                         break;
164                 }
165         }
166
167         /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return values, this */
168         /* argument register usage has to be regarded, too                        */
169         if (IS_INT_LNG_TYPE(md->returntype.type)) {
170                 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
171                         iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
172         } else {
173                 if (IS_FLT_DBL_TYPE(md->returntype.type))
174                         if (farg < 1)
175                                 farg = 1;
176         }
177
178         /* fill register and stack usage */
179
180         md->argintreguse = iarg;
181         md->argfltreguse = farg;
182         md->memuse = stacksize;
183 }
184
185
186 /* md_return_alloc *************************************************************
187
188    Precolor the Java Stackelement containing the Return Value, if
189    possible.  (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
190    for float/double)
191
192    --- in
193    jd:                      jitdata of current method
194    stackslot:               Java Stackslot to contain the Return Value
195
196    --- out
197    if precoloring was possible:
198    VAR(stackslot->varnum)->flags  = PREALLOC
199    VAR(stackslot->varnum)->vv.regoff = [REG_RESULT, (REG_RESULT2/REG_RESULT), REG_FRESULT]
200    rd->arg[flt|int]reguse   set to a value according the register usage
201
202 *******************************************************************************/
203
204 void md_return_alloc(jitdata *jd, stackelement_t* stackslot)
205 {
206         methodinfo   *m;
207         registerdata *rd;
208         methoddesc   *md;
209
210         /* get required compiler data */
211
212         m  = jd->m;
213         rd = jd->rd;
214
215         md = m->parseddesc;
216
217         /* In Leafmethods Local Vars holding parameters are precolored to
218            their argument register -> so leafmethods with paramcount > 0
219            could already use R3 == a00! */
220
221         if (!m->isleafmethod || (md->paramcount == 0)) {
222                 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
223                    has not to survive method invokations. */
224
225                 if (!(stackslot->flags & SAVEDVAR)) {
226
227                         VAR(stackslot->varnum)->flags = PREALLOC;
228
229                         if (IS_INT_LNG_TYPE(md->returntype.type)) {
230                                 if (!IS_2_WORD_TYPE(md->returntype.type)) {
231                                         if (rd->argintreguse < 1)
232                                                 rd->argintreguse = 1;
233
234                                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
235
236                                 } else {
237                                         if (rd->argintreguse < 2)
238                                                 rd->argintreguse = 2;
239
240                                         VAR(stackslot->varnum)->vv.regoff = PACK_REGS(REG_RESULT2, REG_RESULT);
241                                 }
242
243                         } else { /* float/double */
244                                 if (rd->argfltreguse < 1)
245                                         rd->argfltreguse = 1;
246
247                                 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
248                         }
249                 }
250         }
251 }
252
253
254 /*
255  * These are local overrides for various environment variables in Emacs.
256  * Please do not remove this and leave it at the end of the file, where
257  * Emacs will automagically detect them.
258  * ---------------------------------------------------------------------
259  * Local variables:
260  * mode: c
261  * indent-tabs-mode: t
262  * c-basic-offset: 4
263  * tab-width: 4
264  * End:
265  * vim:noexpandtab:sw=4:ts=4:
266  */