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