* src/vm/jit/alpha/md-abi.c (regs): Renamed to
[cacao.git] / src / vm / jit / alpha / md-abi.c
1 /* src/vm/jit/alpha/md-abi.c - functions for Alpha ABI
2
3    Copyright (C) 1996-2005, 2006, 2007 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    $Id: md-abi.c 7335 2007-02-12 10:43:33Z twisti $
26
27 */
28
29
30 #include "config.h"
31 #include "vm/types.h"
32
33 #include "vm/jit/alpha/md-abi.h"
34
35 #include "vm/global.h"
36
37 #include "vm/jit/abi.h"
38
39 #include "vmcore/descriptor.h"
40
41
42 /* register descripton array **************************************************/
43
44 s4 nregdescint[] = {
45         /*   v0,      t0,      t1,      t2,      t3,      t4,      t5,      t6,   */
46         REG_RET, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, 
47
48         /*   t7,      s0,      s1,      s2,      s3,      s4,      s5,      s6,   */
49         REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, 
50
51         /*   a0,      a1,      a2,      a3,      a4,      a5,      t8,      t9,   */
52         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP,
53
54         /*  t10,   itmp1,      ra,      pv,      at,   itmp3,      sp,    zero,   */
55         REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES,
56
57         REG_END
58 };
59
60 const char *abi_registers_integer_name[] = {
61         "v0",  "t0",  "t1",  "t2",  "t3",  "t4",  "t5",  "t6",
62         "t7",  "s0",  "s1",  "s2",  "s3",  "s4",  "s5",  "s6",
63         "a0",  "a1",  "a2",  "a3",  "a4",  "a5",  "t8",  "t9",
64         "t10", "t11", "ra",  "pv",  "at",  "gp",  "sp",  "zero"
65 };
66
67
68 s4 nregdescfloat[] = {
69         REG_RET, REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
70         REG_SAV, REG_SAV, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, 
71         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP,
72         REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES,
73         REG_END
74 };
75
76
77 /* md_param_alloc **************************************************************
78
79    Allocate the parameters of the given method descriptor according to the
80    calling convention of the platform.
81
82 *******************************************************************************/
83
84 void md_param_alloc(methoddesc *md)
85 {
86         paramdesc *pd;
87         s4         i;
88         s4         reguse;
89         s4         stacksize;
90
91         /* set default values */
92
93         reguse = 0;
94         stacksize = 0;
95
96         /* get params field of methoddesc */
97
98         pd = md->params;
99
100         for (i = 0; i < md->paramcount; i++, pd++) {
101                 switch (md->paramtypes[i].type) {
102                 case TYPE_INT:
103                 case TYPE_ADR:
104                 case TYPE_LNG:
105                         if (i < INT_ARG_CNT) {
106                                 pd->inmemory = false;
107                                 pd->regoff   = reguse;
108                                 reguse++;
109                                 md->argintreguse = reguse;
110                         }
111                         else {
112                                 pd->inmemory = true;
113                                 pd->regoff   = stacksize;
114                                 stacksize++;
115                         }
116                         break;
117
118                 case TYPE_FLT:
119                 case TYPE_DBL:
120                         if (i < FLT_ARG_CNT) {
121                                 pd->inmemory = false;
122                                 pd->regoff   = reguse;
123                                 reguse++;
124                                 md->argfltreguse = reguse;
125                         }
126                         else {
127                                 pd->inmemory = true;
128                                 pd->regoff   = stacksize;
129                                 stacksize++;
130                         }
131                         break;
132                 }
133         }
134
135         /* fill register and stack usage */
136
137         md->memuse = stacksize;
138 }
139
140
141 /* md_param_alloc_native *******************************************************
142
143    Pre-allocate arguments according to the native ABI.
144
145 *******************************************************************************/
146
147 void md_param_alloc_native(methoddesc *md)
148 {
149         /* On Alpha we use the same ABI for JIT method calls as for native
150            method calls. */
151
152         md_param_alloc(md);
153 }
154
155
156 /* md_return_alloc *************************************************************
157
158    Precolor the Java Stackelement containing the Return Value. Since
159    alpha has a dedicated return register (not an reused arg or
160    reserved reg), this is striaghtforward possible, as long, as this
161    stackelement does not have to survive a method invokation
162    (SAVEDVAR)
163
164    --- in
165    jd:                      jitdata of the current method
166    stackslot:               Java Stackslot to contain the Return Value
167    
168    --- out
169    if precoloring was possible:
170    VAR(stackslot->varnum)->flags       = PREALLOC
171                                      ->vv.regoff   = [REG_RESULT|REG_FRESULT]
172    rd->arg[flt|int]reguse   set to a value according the register usage
173
174    NOTE: Do not pass a LOCALVAR in stackslot->varnum.
175 *******************************************************************************/
176
177 void md_return_alloc(jitdata *jd, stackptr stackslot)
178 {
179         methodinfo *m;
180         methoddesc *md;
181
182         /* get required compiler data */
183
184         m = jd->m;
185
186         md = m->parseddesc;
187
188         /* Only precolor the stackslot, if it is not a SAVEDVAR <-> has
189            not to survive method invokations. */
190
191         if (!(stackslot->flags & SAVEDVAR)) {
192
193                 VAR(stackslot->varnum)->flags = PREALLOC;
194
195                 if (IS_INT_LNG_TYPE(md->returntype.type))
196                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
197                 else
198                         VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
199         }
200 }
201
202
203 /*
204  * These are local overrides for various environment variables in Emacs.
205  * Please do not remove this and leave it at the end of the file, where
206  * Emacs will automagically detect them.
207  * ---------------------------------------------------------------------
208  * Local variables:
209  * mode: c
210  * indent-tabs-mode: t
211  * c-basic-offset: 4
212  * tab-width: 4
213  * End:
214  */