Proper x86_64 mnemonics
[cacao.git] / src / vm / jit / s390 / md-abi.c
1 /* src/vm/jit/s390/md-abi.c - s390 Linux ABI
2
3    Copyright (C) 1996-2005, 2006, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include "vm/global.h"
29 #include "vm/types.h"
30
31 #include "vm/jit/jit.h"
32 #include "vm/jit/stack.h"
33
34 #include "vm/jit/s390/md-abi.h"
35
36 #include "vmcore/descriptor.h"
37
38 #include <assert.h>
39
40
41 /* register descripton array **************************************************/
42
43 s4 nregdescint[] = {
44         /*itmp3,   itmp1,      a0,      a1,      a2,      a3,      a4,      s0, */
45         REG_RES, REG_RES, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_SAV,
46         /*   s1,      s2,      s3,      s4,      s5,    pv,  ra/itmp2,      sp */
47         REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_RES, REG_RES, REG_RES,
48     REG_END
49 };
50
51 const char *abi_registers_integer_name[] = {
52         "r0", "r1", "r2", "r3",
53         "r4", "r5", "r6", "r7",
54         "r8", "r9", "r10", "r11",
55         "r12", "r13", "r14", "r15"
56 };
57
58 const s4 abi_registers_integer_argument[] = {
59         2, /* r2/a0 */
60         3, /* r3/a1 */
61         4, /* r4/a2 */
62         5, /* r5/a3 */
63         6  /* r6/a4 */
64 };
65
66 const s4 abi_registers_integer_saved[] = {
67         7,  /* r7/s0 */
68         8,  /* r8/s1 */
69         9,  /* r9/s2 */
70         10, /* r10/s3 */
71         11, /* r11/s4 */
72         12  /* r12/s5 */
73 };
74
75 const s4 abi_registers_integer_temporary[] = {
76         -1 /* none */
77 };
78
79 s4 nregdescfloat[] = {
80         REG_ARG, REG_TMP, REG_ARG, REG_TMP, REG_RES, REG_TMP, REG_RES, REG_TMP,
81         REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
82     REG_END
83 };
84
85 const s4 abi_registers_float_argument[] = {
86         0, /* f0/fa0 */
87         2  /* f2/fa2 */
88 };
89
90 const s4 abi_registers_float_saved[] = {
91         -1 /* none */
92 };
93
94 const s4 abi_registers_float_temporary[] = {
95         1,  /* f1/ft0 */
96         3,  /* f3/ft1 */
97         5,  /* f5/ft2 */
98         7,  /* f7/ft3 */
99         8,  /* f8/ft4 */
100         9,  /* f9/ft5 */
101         10, /* f10/ft6 */
102         11, /* f11/ft7 */
103         12, /* f12/ft8 */
104         13, /* f13/ft9 */
105         14, /* f14/ft10 */
106         15  /* f15/ft11 */
107 };
108
109 /* md_param_alloc_intern *******************************************************
110
111    Allocates parameters to registers or stackslots for both native and java
112    methods.
113
114    --- in:
115    slot: size in bytes of a stack slot
116    slots1w: number of stack slots used by a 1 word type parameter
117    slots2w: number of stack slots used by a 2 word type parameter
118    stackoff: offset on stack frame where to start placing arguments
119
120 *******************************************************************************/
121
122 static void md_param_alloc_intern(methoddesc *md, s4 slot, s4 slots1w, s4 slots2w, s4 stackoff)
123 {
124         paramdesc *pd;
125         s4         i;
126         s4         iarg;
127         s4         farg;
128         s4         stacksize;
129
130         /* set default values */
131
132         iarg = 0;
133         farg = 0;
134         stacksize = 0;
135
136         /* get params field of methoddesc */
137
138         pd = md->params;
139
140         for (i = 0; i < md->paramcount; i++, pd++) {
141                 switch (md->paramtypes[i].type) {
142                 case TYPE_INT:
143                 case TYPE_ADR:
144                         if (iarg < INT_ARG_CNT) {
145                                 pd->inmemory  = false;
146                                 pd->regoff    = abi_registers_integer_argument[iarg]; 
147                                 pd->index     = iarg;
148                                 iarg++;
149                         }
150                         else {
151                                 pd->inmemory  = true;
152                                 pd->regoff    = (stacksize * slot) + stackoff;
153                                 pd->index     = stacksize;
154                                 stacksize += slots1w;
155                         }
156                         break;
157
158                 case TYPE_LNG:
159                         if (iarg < INT_ARG_CNT - 1) {
160                                 /* _ALIGN(iarg); */
161                                 pd->inmemory  = false;
162                                 pd->regoff    = 
163                                         PACK_REGS(abi_registers_integer_argument[iarg + 1], 
164                                                           abi_registers_integer_argument[iarg]); 
165                                 pd->index     = PACK_REGS(iarg + 1, iarg);
166                                 iarg += 2;
167                         }
168                         else {
169                                 /* _ALIGN(stacksize); */
170                                 pd->inmemory  = true;
171                                 pd->regoff    = (stacksize * slot) + stackoff;
172                                 pd->index     = stacksize;
173                                 iarg          = INT_ARG_CNT;
174                                 stacksize    += slots2w;
175                         }
176                         break;
177
178                 case TYPE_FLT:
179                         if (farg < FLT_ARG_CNT) {
180                                 pd->inmemory  = false;
181                                 pd->regoff    = abi_registers_float_argument[farg]; 
182                                 pd->index     = farg;
183                                 farg++;
184                         }
185                         else {
186                                 pd->inmemory  = true;
187                                 pd->regoff    = (stacksize * slot) + stackoff;
188                                 pd->index     = stacksize;
189                                 stacksize += slots1w;
190                         }
191                         break;
192
193                 case TYPE_DBL:
194                         if (farg < FLT_ARG_CNT) {
195                                 pd->inmemory  = false;
196                                 pd->regoff    = abi_registers_float_argument[farg]; 
197                                 pd->index     = farg;
198                                 farg++;
199                         }
200                         else {
201                                 /* _ALIGN(stacksize); */
202                                 pd->inmemory  = true;
203                                 pd->regoff    = (stacksize * slot) + stackoff;
204                                 pd->index     = stacksize;
205                                 stacksize    += slots2w;
206                         }
207                         break;
208
209                 default:
210                         assert(0);
211                 }
212         }
213
214         /* Since A0+A1/FA0 are used for passing return
215            values, this argument register usage has to be regarded,
216            too. */
217
218         if (IS_INT_LNG_TYPE(md->returntype.type)) {
219                 if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
220                         iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
221         }
222         else {
223                 if (IS_FLT_DBL_TYPE(md->returntype.type))
224                         if (farg < 1)
225                                 farg = 1;
226         }
227
228         /* fill register and stack usage */
229
230         md->argintreguse = iarg;
231         md->argfltreguse = farg;
232         md->memuse = stacksize;
233 }
234
235 void md_param_alloc(methoddesc *md)
236 {
237         md_param_alloc_intern(md, 8, 1, 1, 0);
238 }
239
240 void md_param_alloc_native(methoddesc *md)
241 {
242         md_param_alloc_intern(md, 4, 1, 2, 96);
243 }
244
245
246 /* md_return_alloc *************************************************************
247
248    Precolor the Java Stackelement containing the Return Value. Only
249    for float/ double types straight forward possible, since INT_LNG
250    types use "reserved" registers Float/Double values use a00 as
251    return register.
252
253    --- in
254    jd:                      jitdata of the current method
255    stackslot:               Java Stackslot to contain the Return Value
256
257    --- out
258    if precoloring was possible:
259    VAR(stackslot->varnum)->flags     = PREALLOC
260                                      ->vv.regoff = [REG_RESULT|REG_FRESULT]
261    rd->arg[flt|int]reguse   set to a value according the register usage
262
263    NOTE: Do not pass a LOCALVAR in stackslot->varnum.
264
265 *******************************************************************************/
266
267 void md_return_alloc(jitdata *jd, stackelement_t* stackslot)
268 {
269         methodinfo   *m;
270         codeinfo     *code;
271         registerdata *rd;
272         methoddesc   *md;
273
274         /* get required compiler data */
275
276         m    = jd->m;
277         code = jd->code;
278         rd   = jd->rd;
279
280         md = m->parseddesc;
281
282         /* In Leafmethods Local Vars holding parameters are precolored to
283            their argument register -> so leafmethods with paramcount > 0
284            could already use R3 == a00! */
285
286         if (!code_is_leafmethod(code) || (md->paramcount == 0)) {
287                 /* Only precolor the stackslot, if it is not a SAVEDVAR <->
288                    has not to survive method invokations. */
289
290                 if (!(stackslot->flags & SAVEDVAR)) {
291                         VAR(stackslot->varnum)->flags = PREALLOC;
292
293                         if (IS_INT_LNG_TYPE(md->returntype.type)) {
294                                 if (!IS_2_WORD_TYPE(md->returntype.type)) {
295                                         if (rd->argintreguse < 1)
296                                                 rd->argintreguse = 1;
297
298                                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
299                                 }
300                                 else {
301                                         if (rd->argintreguse < 2)
302                                                 rd->argintreguse = 2;
303
304                                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
305                                 }
306                         }
307                         else { /* float/double */
308                                 if (rd->argfltreguse < 1)
309                                         rd->argfltreguse = 1;
310
311                                 VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
312                         }
313                 }
314         }
315 }
316
317
318 /*
319  * These are local overrides for various environment variables in Emacs.
320  * Please do not remove this and leave it at the end of the file, where
321  * Emacs will automagically detect them.
322  * ---------------------------------------------------------------------
323  * Local variables:
324  * mode: c
325  * indent-tabs-mode: t
326  * c-basic-offset: 4
327  * tab-width: 4
328  * End:
329  */