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