* src/vm/jit/x86_64/codegen.c (codegen_emit PUTFIELDCONST, PUTSTATICCONST):
[cacao.git] / src / vm / jit / m68k / linux / md-abi.c
1 /* src/vm/jit/m68k/linux/md-abi.c - linux specific abi functions
2
3    Copyright (C) 1996-2005, 2006, 2007, 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
27 #include "config.h"
28
29 #include <assert.h>
30
31 #include "md-abi.h"
32
33 #include "vm/types.h"
34
35 #include "vm/jit/abi.h"
36
37 /* Integer register description */
38 /*                        D0,      D1,   ITMP1,   ITMP2,   ITMP3,      D5,      D6,      D7 */
39 s4 nregdescint[] = { REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_SAV, REG_SAV, REG_SAV, REG_END };
40
41 const char *abi_registers_integer_name [] = { "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7" };
42
43 const s4 abi_registers_integer_argument[]       ;
44 const s4 abi_registers_integer_saved[]          = {5,6,7};
45 const s4 abi_registers_integer_temporary[]      = {0,1};
46
47 /* Address register description */
48 /* A6 is used as framepointer by native code, so be sure it is REG_RES */
49 /*                        A0,      A1,   ATMP1,   ATMP2,   ATMP3,      A5,  REG_FP, REG_SP */
50 #if 0
51 s4 nregdescadr[] = { REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_SAV, REG_RES, REG_RES, REG_END };
52 #else
53 s4 nregdescadr[] = { REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_SAV, REG_SAV, REG_RES, REG_END };
54 #endif
55
56 const char *abi_registers_address_name [] = { "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7" };
57
58 const s4 abi_registers_address_argument[]       ;
59 #if 0
60 const s4 abi_registers_address_saved[]          = {5};
61 #else
62 const s4 abi_registers_address_saved[]          = {5,6};
63 #endif
64 const s4 abi_registers_address_temporary[]      = {0,1};
65
66
67 /* Floatingpoint register description */
68 /*                        F0,      F1,   FTMP1,   FTMP2,   FTMP3,      F5,      F6,      F7 */
69 #if !defined(ENABLE_SOFTFLOAT)
70 s4 nregdescfloat[] = { REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_SAV, REG_SAV, REG_SAV, REG_END };
71 #else
72 s4 nregdescfloat[] = { REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_END };
73 #endif
74
75 const char *abi_registers_float_name [] = { "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7" };
76
77 const s4 abi_registers_float_argument[]         ;
78 const s4 abi_registers_float_saved[]            = {5,6,7};
79 const s4 abi_registers_float_temporary[]        = {0,1};
80
81
82 /* md_param_alloc_native *******************************************************
83  *
84  *    Pre-allocate arguments according the native ABI.
85  *
86  *    *******************************************************************************/
87
88 void md_param_alloc_native(methoddesc *md)
89 {
90         paramdesc       *pd;
91         s4      stacksize;
92         s4      i;
93
94         pd = md->params;
95         stacksize = 0;
96
97         for (i=0; i<md->paramcount; i++, pd++)  {
98                 pd->inmemory = true;
99                 pd->regoff = stacksize * 4;
100                 pd->index = stacksize;
101                 stacksize += IS_2_WORD_TYPE(md->paramtypes[i].type) ? 2:1;
102         }
103
104         md->memuse = stacksize;
105         md->argintreguse = 0;
106         md->argfltreguse = 0;
107         md->argadrreguse = 0;
108
109 }
110
111
112 /* md_param_alloc **************************************************************
113  *
114  *    Allocate Arguments to Stackslots according the Calling Conventions
115  *
116  *       --- in
117  *       md->paramcount:           Number of arguments for this method
118  *       md->paramtypes[].type:    Argument types
119  *
120  *       --- out
121  *       md->params[].inmemory:    Argument spilled on stack
122  *       md->params[].regoff:      Stack offset or rd->arg[int|flt]regs index
123  *       md->memuse:               Stackslots needed for argument spilling
124  *       md->argintreguse:         max number of integer arguments used
125  *       md->argfltreguse:         max number of float arguments used
126  *
127  ********************************************************************************/
128 void md_param_alloc(methoddesc *md)
129 {
130         paramdesc       *pd;
131         s4      stacksize;
132         s4      i;
133
134         pd = md->params;
135         stacksize = 0;
136
137         for (i=0; i<md->paramcount; i++, pd++)  {
138                 pd->inmemory = true;
139                 pd->regoff = stacksize * 8;
140                 pd->index = stacksize;
141                 stacksize ++;
142         }
143
144         md->memuse = stacksize;
145         md->argintreguse = 0;
146         md->argfltreguse = 0;
147         md->argadrreguse = 0;
148 }
149
150 /* md_return_alloc *************************************************************
151
152    Precolor the Java Stackelement containing the Return Value, if
153    possible. We stick to the abi as closed as possible and therefore use
154    %d0 for all word types %d0-%d1 for 2 word types. %f0-%f1 for floats/doubles
155 *******************************************************************************/
156
157 void md_return_alloc(jitdata *jd, stackelement_t *stackslot)
158
159
160 /* The Problem: %a0, %a1, %d0 and %d1 are scratch registers by platform abi
161  * so they are defined REG_TMP, which i think is correct. But a preallocated
162  * register has to be REG_SAV it seems. One could make theese REG_SAV but 
163  * then there would be a abi mismatch with native functions...for now no
164  * return_alloc.*/
165
166 #if 0
167         methodinfo   *m;
168         registerdata *rd;
169         methoddesc   *md;
170
171         /* get required compiler data */
172
173         m  = jd->m;
174         rd = jd->rd;
175
176         md = m->parseddesc;
177
178         /* XXX wondering if this is correct */
179         assert(rd->argintreguse == 0);
180         assert(rd->argadrreguse == 0);
181         assert(rd->argfltreguse == 0);
182
183         VAR(stackslot->varnum)->flags = PREALLOC;
184         switch (md->returntype.type)    {
185                 case TYPE_INT:
186                 case TYPE_ADR:
187                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
188                         break;
189                 case TYPE_LNG:
190                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
191                         break;
192
193                 case TYPE_FLT:
194                 case TYPE_DBL:
195                         VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
196                         break;
197
198                 default: assert(0);
199         }
200 #endif
201
202 }
203
204 /*
205  * These are local overrides for various environment variables in Emacs.
206  * Please do not remove this and leave it at the end of the file, where
207  * Emacs will automagically detect them.
208  * ---------------------------------------------------------------------
209  * Local variables:
210  * mode: c
211  * indent-tabs-mode: t
212  * c-basic-offset: 4
213  * tab-width: 4
214  * End:
215  * vim:noexpandtab:sw=4:ts=4:
216  */