Index for intargregs for long Parameters get packed now
[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 2813 2005-06-23 14:30:44Z christian $
32
33 */
34
35
36 #include "vm/jit/powerpc/types.h"
37 #include "vm/jit/powerpc/linux/md-abi.h"
38
39 #include "vm/descriptor.h"
40 #include "vm/global.h"
41
42
43 #define _ALIGN(a)    do { if ((a) & 1) (a)++; } while (0)
44
45
46 /* md_param_alloc **************************************************************
47
48  Allocate Arguments to Stackslots according the Calling Conventions
49
50 --- in
51 md->paramcount:           Number of arguments for this method
52 md->paramtypes[].type:    Argument types
53
54 --- out
55 md->params[].inmemory:    Argument spilled on stack
56 md->params[].regoff:      Stack offset or rd->arg[int|flt]regs index
57 md->memuse:               Stackslots needed for argument spilling
58 md->argintreguse:         max number of integer arguments used
59 md->argfltreguse:         max number of float arguments used
60
61 *******************************************************************************/
62
63 void md_param_alloc(methoddesc *md)
64 {
65         paramdesc *pd;
66         s4         i;
67         s4         iarg;
68         s4         farg;
69         s4         stacksize;
70
71         /* set default values */
72
73         iarg = 0;
74         farg = 0;
75         stacksize = LA_WORD_SIZE;
76
77         /* get params field of methoddesc */
78
79         pd = md->params;
80
81         for (i = 0; i < md->paramcount; i++, pd++) {
82                 switch (md->paramtypes[i].type) {
83                 case TYPE_INT:
84                 case TYPE_ADR:
85                         if (iarg < INT_ARG_CNT) {
86                                 pd->inmemory = false;
87                                 pd->regoff = iarg;
88
89                         } else {
90                                 pd->inmemory = true;
91                                 pd->regoff = stacksize;
92                         }
93                         if (iarg < INT_ARG_CNT)
94                                 iarg++;
95                         else
96                                 stacksize++;
97                         break;
98                 case TYPE_LNG:
99                         if (iarg < INT_ARG_CNT - 1)
100                                 _ALIGN(iarg);
101                         else
102                                 _ALIGN(stacksize);
103                         if (iarg < INT_ARG_CNT - 1) {
104                                 pd->inmemory = false;
105                                                              /* rd->arg[int|flt]regs index !! */
106                                 pd->regoff = PACK_REGS(iarg + 1, iarg); 
107                         } else {
108                                 pd->inmemory = true;
109                                 pd->regoff = stacksize;
110                         }
111                         if (iarg < INT_ARG_CNT - 1)
112                                 iarg += 2;
113                         else {
114                                 iarg = INT_ARG_CNT;
115                                 stacksize += 2;
116                         }
117                         break;
118                 case TYPE_FLT:
119                 case TYPE_DBL:
120                         if ((farg >= FLT_ARG_CNT) && IS_2_WORD_TYPE(md->paramtypes[i].type))
121                                 _ALIGN(stacksize);
122                         if (farg < FLT_ARG_CNT) {
123                                 pd->inmemory = false;
124                                 pd->regoff = farg;
125                         } else {
126                                 pd->inmemory = true;
127                                 pd->regoff = stacksize;
128                         }
129                         if (farg < FLT_ARG_CNT)
130                                 farg++;
131                         else
132                                 if (IS_2_WORD_TYPE(md->paramtypes[i].type))
133                                         stacksize += 2;
134                                 else
135                                         stacksize++;
136                         break;
137                 }
138         }
139
140         /* fill register and stack usage */
141
142         md->argintreguse = iarg;
143         md->argfltreguse = farg;
144         md->memuse = stacksize;
145 }
146
147
148 /*
149  * These are local overrides for various environment variables in Emacs.
150  * Please do not remove this and leave it at the end of the file, where
151  * Emacs will automagically detect them.
152  * ---------------------------------------------------------------------
153  * Local variables:
154  * mode: c
155  * indent-tabs-mode: t
156  * c-basic-offset: 4
157  * tab-width: 4
158  * End:
159  */