* Nothing important, removed spaces, add empty lines.
[cacao.git] / src / vm / jit / powerpc / linux / md-abi.c
1 /* src/vm/jit/powerpc/linux/md-abi.c - functions for PowerPC Linux 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 3797 2005-11-26 15:56:07Z twisti $
32
33 */
34
35
36 #include "config.h"
37 #include "vm/types.h"
38
39 #include "vm/jit/powerpc/linux/md-abi.h"
40
41 #include "vm/descriptor.h"
42 #include "vm/global.h"
43
44
45 #define _ALIGN(a)    do { if ((a) & 1) (a)++; } while (0)
46
47
48 /* md_param_alloc **************************************************************
49
50    Allocate Arguments to Stackslots according the Calling Conventions
51
52    --- in
53    md->paramcount:           Number of arguments for this method
54    md->paramtypes[].type:    Argument types
55
56    --- out
57    md->params[].inmemory:    Argument spilled on stack
58    md->params[].regoff:      Stack offset or rd->arg[int|flt]regs index
59    md->memuse:               Stackslots needed for argument spilling
60    md->argintreguse:         max number of integer arguments used
61    md->argfltreguse:         max number of float arguments used
62
63 *******************************************************************************/
64
65 void md_param_alloc(methoddesc *md)
66 {
67         paramdesc *pd;
68         s4         i;
69         s4         iarg;
70         s4         farg;
71         s4         stacksize;
72
73         /* set default values */
74
75         iarg = 0;
76         farg = 0;
77         stacksize = LA_WORD_SIZE;
78
79         /* get params field of methoddesc */
80
81         pd = md->params;
82
83         for (i = 0; i < md->paramcount; i++, pd++) {
84                 switch (md->paramtypes[i].type) {
85                 case TYPE_INT:
86                 case TYPE_ADR:
87                         if (iarg < INT_ARG_CNT) {
88                                 pd->inmemory = false;
89                                 pd->regoff = iarg;
90                                 iarg++;
91                         } else {
92                                 pd->inmemory = true;
93                                 pd->regoff = stacksize;
94                                 stacksize++;
95                         }
96                         break;
97                 case TYPE_LNG:
98                         if (iarg < INT_ARG_CNT - 1) {
99                                 _ALIGN(iarg);
100                                 pd->inmemory = false;
101                                                              /* rd->arg[int|flt]regs index !! */
102                                 pd->regoff = PACK_REGS(iarg + 1, iarg); 
103                                 iarg += 2;
104                         } else {
105                                 _ALIGN(stacksize);
106                                 pd->inmemory = true;
107                                 pd->regoff = stacksize;
108                                 iarg = INT_ARG_CNT;
109                                 stacksize += 2;
110                         }
111                         break;
112                 case TYPE_FLT:
113                         if (farg < FLT_ARG_CNT) {
114                                 pd->inmemory = false;
115                                 pd->regoff = farg;
116                                 farg++;
117                         } else {
118                                 pd->inmemory = true;
119                                 pd->regoff = stacksize;
120                                 stacksize++;
121                         }
122                         break;
123                 case TYPE_DBL:
124                         if (farg < FLT_ARG_CNT) {
125                                 pd->inmemory = false;
126                                 pd->regoff = farg;
127                                 farg++;
128                         } else {
129                                 _ALIGN(stacksize);
130                                 pd->inmemory = true;
131                                 pd->regoff = stacksize;
132                                 stacksize += 2;
133                         }
134                         break;
135                 }
136         }
137
138         /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return values, this */
139         /* argument register usage has to be regarded, too                        */
140         if (IS_INT_LNG_TYPE(md->returntype.type)) {
141                 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
142                         iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
143         } else {
144                 if (IS_FLT_DBL_TYPE(md->returntype.type))
145                         if (farg < 1)
146                                 farg = 1;
147         }
148
149         /* fill register and stack usage */
150
151         md->argintreguse = iarg;
152         md->argfltreguse = farg;
153         md->memuse = stacksize;
154 }
155
156
157 /* md_return_alloc *************************************************************
158
159    Precolor the Java Stackelement containing the Return Value, if
160    possible.  (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
161    for float/double)
162
163    --- in
164    m:                       Methodinfo of current method
165    return_type:             Return Type of the Method (TYPE_INT.. TYPE_ADR)
166                             TYPE_VOID is not allowed!
167    stackslot:               Java Stackslot to contain the Return Value
168
169    --- out
170    if precoloring was possible:
171    stackslot->varkind       =ARGVAR
172             ->varnum        =-1
173                 ->flags         =0
174                 ->regoff        =[REG_RESULT, (REG_RESULT2/REG_RESULT), REG_FRESULT]
175    rd->arg[flt|int]reguse   set to a value according the register usage
176
177 *******************************************************************************/
178
179 void md_return_alloc(methodinfo *m, registerdata *rd, s4 return_type,
180                                          stackptr stackslot)
181 {
182         /* In Leafmethods Local Vars holding parameters are precolored to their   */
183         /* argument register -> so leafmethods with paramcount > 0 could already  */
184         /* use  R3 == a00! */
185
186         if (!m->isleafmethod || (m->paramcount == 0)) {
187                 /* Only precolor the stackslot, if it is not a SAVEDVAR <-> has not   */
188                 /* to survive method invokations */
189
190                 if (!(stackslot->flags & SAVEDVAR)) {
191                         stackslot->varkind = ARGVAR;
192                         stackslot->varnum = -1;
193                         stackslot->flags = 0;
194
195                         if ( IS_INT_LNG_TYPE(return_type) ) {
196                                 if (!IS_2_WORD_TYPE(return_type)) {
197                                         if (rd->argintreguse < 1)
198                                                 rd->argintreguse = 1;
199
200                                         stackslot->regoff = REG_RESULT;
201
202                                 } else {
203                                         if (rd->argintreguse < 2)
204                                                 rd->argintreguse = 2;
205
206                                         stackslot->regoff = PACK_REGS(REG_RESULT2, REG_RESULT);
207                                 }
208
209                         } else { /* float/double */
210                                 if (rd->argfltreguse < 1)
211                                         rd->argfltreguse = 1;
212
213                                 stackslot->regoff = REG_FRESULT;
214                         }
215                 }
216         }
217 }
218
219
220 /*
221  * These are local overrides for various environment variables in Emacs.
222  * Please do not remove this and leave it at the end of the file, where
223  * Emacs will automagically detect them.
224  * ---------------------------------------------------------------------
225  * Local variables:
226  * mode: c
227  * indent-tabs-mode: t
228  * c-basic-offset: 4
229  * tab-width: 4
230  * End:
231  */