* src/vm/jit/mips/codegen.c (codegen): Use jd->isleafmethod. Pass
[cacao.git] / src / vm / jit / mips / md-abi.c
1 /* src/vm/jit/mips/md-abi.c - functions for MIPS 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: Christian Thalinger
28
29    Changes: Christian Ullrich
30
31    $Id: md-abi.c 5114 2006-07-12 14:53:28Z twisti $
32
33 */
34
35
36 #include "config.h"
37 #include "vm/types.h"
38
39 #include "vm/jit/mips/md-abi.h"
40
41 #include "vm/descriptor.h"
42 #include "vm/global.h"
43 #include "vm/jit/abi.h"
44
45
46 /* register descripton array **************************************************/
47
48 #if SIZEOF_VOID_P == 8
49
50 /* MIPS64 */
51
52 s4 nregdescint[] = {
53         REG_RES, REG_RES, REG_RET, REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
54         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
55         REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
56         REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES,
57         REG_END
58 };
59
60 s4 nregdescfloat[] = {
61         /*  fv0,   ftmp1,   ftmp2,   ftmp3,     ft0,     ft1,     ft2,     ft3,   */
62         REG_RET, REG_RES, REG_RES, REG_RES, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
63
64         /*  ft4,     ft5,     ft6,     ft7,     fa0,     fa1,     fa2,     fa3,   */
65         REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
66
67         /*  fa4,     fa5,     fa6,     fa7,     ft8,     ft9,    ft10,    ft11,   */
68         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
69
70         /*  fs0,    ft12,     fs1,    ft13,     fs2,    ft14,     fs3     ft15    */
71         REG_SAV, REG_TMP, REG_SAV, REG_TMP, REG_SAV, REG_TMP, REG_SAV, REG_TMP,
72
73         REG_END
74 };
75
76 #else /* SIZEOF_VOID_P == 8 */
77
78 /* MIPS32 */
79
80 s4 nregdescint[] = {
81         /* zero,   itmp1,      v0,      v1,      a0,      a1,      a2,      a3,   */
82         REG_RES, REG_RES, REG_RET, REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG,
83
84         /*   t0,      t1,      t2,      t3,      t4,      t5,      t6,      t7,   */
85         REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
86
87         /*   s0,      s1,      s2,      s3,      s4,      s5,      s6,      s7,   */
88         REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
89
90         /*itmp2,   itmp3, k0(sys), k1(sys),      gp,      sp,      pv,      ra    */
91         REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES,
92
93         REG_END
94 };
95
96 #if !defined(ENABLE_SOFT_FLOAT)
97
98 s4 nregdescfloat[] = {
99         /*  fv0,            ftmp1,            ftmp2,            ftmp3,            */
100         REG_RET, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES,
101
102         /*  ft0,              ft1,              fa0,              fa1,            */
103         REG_TMP, REG_RES, REG_TMP, REG_RES, REG_ARG, REG_RES, REG_ARG, REG_RES,
104
105         /*  ft2,              ft3,              fs0,              fs1,            */
106         REG_TMP, REG_RES, REG_TMP, REG_RES, REG_SAV, REG_RES, REG_SAV, REG_RES,
107
108         /*  fs2,              fs3,              fs4,              fs5             */
109         REG_SAV, REG_RES, REG_SAV, REG_RES, REG_SAV, REG_RES, REG_SAV, REG_RES,
110
111         REG_END
112 };
113
114 #else /* !defined(ENABLE_SOFT_FLOAT) */
115
116 s4 nregdescfloat[] = {
117         REG_END
118 };
119
120 #endif /* !defined(ENABLE_SOFT_FLOAT) */
121
122 #endif /* SIZEOF_VOID_P == 8 */
123
124
125 /* md_param_alloc **************************************************************
126
127    XXX
128
129 *******************************************************************************/
130
131 void md_param_alloc(methoddesc *md)
132 {
133         paramdesc *pd;
134         s4         i;
135         s4         reguse;
136         s4         stacksize;
137
138         /* set default values */
139
140         reguse = 0;
141         stacksize = 0;
142
143         /* get params field of methoddesc */
144
145         pd = md->params;
146
147         for (i = 0; i < md->paramcount; i++, pd++) {
148                 switch (md->paramtypes[i].type) {
149                 case TYPE_INT:
150                 case TYPE_ADR:
151                 case TYPE_LNG:
152                         if (i < INT_ARG_CNT) {
153                                 pd->inmemory = false;
154                                 pd->regoff = reguse;
155                                 reguse++;
156                                 md->argintreguse = reguse;
157                         } else {
158                                 pd->inmemory = true;
159                                 pd->regoff = stacksize;
160                                 stacksize++;
161                         }
162                         break;
163                 case TYPE_FLT:
164                 case TYPE_DBL:
165                         if (i < FLT_ARG_CNT) {
166                                 pd->inmemory = false;
167                                 pd->regoff = reguse;
168                                 reguse++;
169                                 md->argfltreguse = reguse;
170                         } else {
171                                 pd->inmemory = true;
172                                 pd->regoff = stacksize;
173                                 stacksize++;
174                         }
175                         break;
176                 }
177         }
178
179         /* fill register and stack usage */
180
181         md->memuse = stacksize;
182 }
183
184
185 /* md_return_alloc *************************************************************
186
187    Precolor the Java Stackelement containing the Return Value. Since
188    mips has a dedicated return register (not an reused arg or reserved
189    reg), this is striaghtforward possible, as long, as this
190    stackelement does not have to survive a method invokation
191    (SAVEDVAR)
192
193    --- in
194    m:                       Methodinfo of current method
195    return_type:             Return Type of the Method (TYPE_INT.. TYPE_ADR)
196                             TYPE_VOID is not allowed!
197    stackslot:               Java Stackslot to contain the Return Value
198    
199    --- out
200    if precoloring was possible:
201    stackslot->varkind       =ARGVAR
202             ->varnum        =-1
203             ->flags         =0
204             ->regoff        =[REG_RESULT, REG_FRESULT]
205
206 *******************************************************************************/
207
208 void md_return_alloc(jitdata *jd, stackptr stackslot)
209 {
210         methodinfo *m;
211         methoddesc *md;
212
213         /* get required compiler data */
214
215         m = jd->m;
216
217         md = m->parseddesc;
218
219         /* Only precolor the stackslot, if it is not a SAVEDVAR <-> has
220            not to survive method invokations. */
221
222         if (!(stackslot->flags & SAVEDVAR)) {
223                 stackslot->varkind = ARGVAR;
224                 stackslot->varnum  = -1;
225                 stackslot->flags   = 0;
226
227                 if (IS_INT_LNG_TYPE(md->returntype.type))
228                         stackslot->regoff = REG_RESULT;
229                 else
230                         stackslot->regoff = REG_FRESULT;
231         }
232 }
233
234
235 /*
236  * These are local overrides for various environment variables in Emacs.
237  * Please do not remove this and leave it at the end of the file, where
238  * Emacs will automagically detect them.
239  * ---------------------------------------------------------------------
240  * Local variables:
241  * mode: c
242  * indent-tabs-mode: t
243  * c-basic-offset: 4
244  * tab-width: 4
245  * End:
246  */