2257477be9bccf76fb51388c3c3e634487f395c6
[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 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Christian Thalinger
28
29    Changes: Christian Ullrich
30
31    $Id: md-abi.c 4069 2006-01-02 16:03:57Z twisti $
32
33 */
34
35
36 #include "config.h"
37 #include "vm/types.h"
38
39 #include "vm/jit/alpha/md-abi.h"
40
41 #include "vm/descriptor.h"
42 #include "vm/global.h"
43
44
45 /* register descripton array **************************************************/
46
47 s4 nregdescint[] = {
48         REG_RET, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, 
49         REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, 
50         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP,
51         REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES,
52         REG_END
53 };
54
55 s4 nregdescfloat[] = {
56         REG_RET, REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
57         REG_SAV, REG_SAV, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, 
58         REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP,
59         REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES,
60         REG_END
61 };
62
63
64 /* md_param_alloc **************************************************************
65
66    XXX
67
68 *******************************************************************************/
69
70 void md_param_alloc(methoddesc *md)
71 {
72         paramdesc *pd;
73         s4         i;
74         s4         reguse;
75         s4         stacksize;
76
77         /* set default values */
78
79         reguse = 0;
80         stacksize = 0;
81
82         /* get params field of methoddesc */
83
84         pd = md->params;
85
86         for (i = 0; i < md->paramcount; i++, pd++) {
87                 switch (md->paramtypes[i].type) {
88                 case TYPE_INT:
89                 case TYPE_ADR:
90                 case TYPE_LNG:
91                         if (i < INT_ARG_CNT) {
92                                 pd->inmemory = false;
93                                 pd->regoff = reguse;
94                                 reguse++;
95                                 md->argintreguse = reguse;
96
97                         } else {
98                                 pd->inmemory = true;
99                                 pd->regoff = stacksize;
100                                 stacksize++;
101                         }
102                         break;
103                 case TYPE_FLT:
104                 case TYPE_DBL:
105                         if (i < FLT_ARG_CNT) {
106                                 pd->inmemory = false;
107                                 pd->regoff = reguse;
108                                 reguse++;
109                                 md->argfltreguse = reguse;
110                         } else {
111                                 pd->inmemory = true;
112                                 pd->regoff = stacksize;
113                                 stacksize++;
114                         }
115                         break;
116                 }
117         }
118
119         /* fill register and stack usage */
120
121         md->memuse = stacksize;
122 }
123
124
125 /* md_return_alloc *************************************************************
126
127    Precolor the Java Stackelement containing the Return Value. Since
128    alpha has a dedicated return register (not an reused arg or
129    reserved reg), this is striaghtforward possible, as long, as this
130    stackelement does not have to survive a method invokation
131    (SAVEDVAR)
132
133    --- in
134    m:                       Methodinfo of current method
135    return_type:             Return Type of the Method (TYPE_INT.. TYPE_ADR)
136                                                         TYPE_VOID is not allowed!
137    stackslot:               Java Stackslot to contain the Return Value
138    
139    --- out
140    if precoloring was possible:
141    stackslot->varkind       =ARGVAR
142                         ->varnum        =-1
143                         ->flags         =0
144                         ->regoff        =[REG_RESULT, REG_FRESULT]
145
146 *******************************************************************************/
147
148 void md_return_alloc(methodinfo *m, registerdata *rd, s4 return_type,
149                                          stackptr stackslot)
150 {
151         /* Only precolor the stackslot, if it is not a SAVEDVAR <-> has not   */
152         /* to survive method invokations */
153
154         if (!(stackslot->flags & SAVEDVAR)) {
155                 stackslot->varkind = ARGVAR;
156                 stackslot->varnum = -1;
157                 stackslot->flags = 0;
158
159                 if (IS_INT_LNG_TYPE(return_type)) {
160                         stackslot->regoff = REG_RESULT;
161                 } else { /* float/double */
162                         stackslot->regoff = REG_FRESULT;
163                 }
164         }
165 }
166
167
168 /*
169  * These are local overrides for various environment variables in Emacs.
170  * Please do not remove this and leave it at the end of the file, where
171  * Emacs will automagically detect them.
172  * ---------------------------------------------------------------------
173  * Local variables:
174  * mode: c
175  * indent-tabs-mode: t
176  * c-basic-offset: 4
177  * tab-width: 4
178  * End:
179  */