* src/vm/jit/mips/codegen.c: Ported to unified_variables.
[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 5615 2006-10-01 22:55:11Z edwin $
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    VAR(stackslot->varnum)->flags       = PREALLOC
202                                      ->regoff      = [REG_RESULT|REG_FRESULT]
203
204 *******************************************************************************/
205
206 void md_return_alloc(jitdata *jd, stackptr stackslot)
207 {
208         methodinfo *m;
209         methoddesc *md;
210
211         /* get required compiler data */
212
213         m = jd->m;
214
215         md = m->parseddesc;
216
217         /* Only precolor the stackslot, if it is not a SAVEDVAR <-> has
218            not to survive method invokations. */
219
220         if (!(stackslot->flags & SAVEDVAR)) {
221
222                 VAR(stackslot->varnum)->flags = PREALLOC;
223
224                 if (IS_INT_LNG_TYPE(md->returntype.type))
225                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
226                 else
227                         VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
228         }
229 }
230
231
232 /*
233  * These are local overrides for various environment variables in Emacs.
234  * Please do not remove this and leave it at the end of the file, where
235  * Emacs will automagically detect them.
236  * ---------------------------------------------------------------------
237  * Local variables:
238  * mode: c
239  * indent-tabs-mode: t
240  * c-basic-offset: 4
241  * tab-width: 4
242  * End:
243  */