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