37735f57dfb574688920acdbb02094d5fff16df9
[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    $Id: arch.h 5330 2006-09-05 18:43:12Z edwin $
26
27 */
28
29
30
31 #include "config.h"
32
33 #include <assert.h>
34
35 #include "md-abi.h"
36
37 #include "vm/types.h"
38
39 #include "vm/jit/abi.h"
40
41 /* Integer register description */
42 /*                        D0,      D1,   ITMP1,   ITMP2,   ITMP3,      D5,      D6,      D7 */
43 s4 nregdescint[] = { REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_SAV, REG_SAV, REG_SAV, REG_END };
44
45 const char *abi_registers_integer_name [] = { "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7" };
46
47 const s4 abi_registers_integer_argument[]       ;
48 const s4 abi_registers_integer_saved[]          = {5,6,7};
49 const s4 abi_registers_integer_temporary[]      = {0,1};
50
51 /* Address register description */
52 /* A6 is used as framepointer by native code, so be sure it is REG_RES */
53 /*                        A0,      A1,   ATMP1,   ATMP2,   ATMP3,      A5,  REG_FP, REG_SP */
54 s4 nregdescadr[] = { REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_SAV, REG_RES, REG_RES, REG_END };
55
56
57 /* Floatingpoint register description */
58 /*                        F0,      F1,   FTMP1,   FTMP2,   FTMP3,      F5,      F6,      F7 */
59 #if !defined(ENABLE_SOFTFLOAT)
60 s4 nregdescfloat[] = { REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_SAV, REG_SAV, REG_SAV, REG_END };
61 #else
62 s4 nregdescfloat[] = { REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_END };
63 #endif
64
65 const char *abi_registers_float_name [] = { "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7" };
66
67 const s4 abi_registers_float_argument[]         ;
68 const s4 abi_registers_float_saved[]            = {5,6,7};
69 const s4 abi_registers_float_temporary[]        = {0,1};
70
71
72 /* md_param_alloc_native *******************************************************
73  *
74  *    Pre-allocate arguments according the native ABI.
75  *
76  *    *******************************************************************************/
77
78 void md_param_alloc_native(methoddesc *md)
79 {
80                 /* For now use system ABI */
81                 md_param_alloc(md);
82 }
83
84
85 /* md_param_alloc **************************************************************
86  *
87  *    Allocate Arguments to Stackslots according the Calling Conventions
88  *
89  *       --- in
90  *       md->paramcount:           Number of arguments for this method
91  *       md->paramtypes[].type:    Argument types
92  *
93  *       --- out
94  *       md->params[].inmemory:    Argument spilled on stack
95  *       md->params[].regoff:      Stack offset or rd->arg[int|flt]regs index
96  *       md->memuse:               Stackslots needed for argument spilling
97  *       md->argintreguse:         max number of integer arguments used
98  *       md->argfltreguse:         max number of float arguments used
99  *
100  ********************************************************************************/
101 void md_param_alloc(methoddesc *md)
102 {
103         paramdesc       *pd;
104         s4      stacksize;
105         s4      i;
106
107         pd = md->params;
108         stacksize = 0;
109
110         for (i=0; i<md->paramcount; i++, pd++)  {
111                 pd->inmemory = true;
112                 pd->regoff = stacksize;
113                 stacksize += IS_2_WORD_TYPE(md->paramtypes[i].type) ? 2:1;
114         }
115
116         md->memuse = stacksize;
117         md->argintreguse = 0;
118         md->argfltreguse = 0;
119         md->argadrreguse = 0;
120 }
121
122 /* md_return_alloc *************************************************************
123
124    Precolor the Java Stackelement containing the Return Value, if
125    possible. We stick to the abi as closed as possible and therefore use
126    %d0 for all word types %d0-%d1 for 2 word types. %f0-%f1 for floats/doubles
127 *******************************************************************************/
128
129 void md_return_alloc(jitdata *jd, stackptr stackslot)
130
131
132 /* The Problem: %a0, %a1, %d0 and %d1 are scratch registers by platform abi
133  * so they are defined REG_TMP, which i think is correct. But a preallocated
134  * register has to be REG_SAV it seems. One could make theese REG_SAV but 
135  * then there would be a abi mismatch with native functions...for now no
136  * return_alloc.*/
137
138 #if 0
139         methodinfo   *m;
140         registerdata *rd;
141         methoddesc   *md;
142
143         /* get required compiler data */
144
145         m  = jd->m;
146         rd = jd->rd;
147
148         md = m->parseddesc;
149
150         /* XXX wondering if this is correct */
151         assert(rd->argintreguse == 0);
152         assert(rd->argadrreguse == 0);
153         assert(rd->argfltreguse == 0);
154
155         VAR(stackslot->varnum)->flags = PREALLOC;
156         switch (md->returntype.type)    {
157                 case TYPE_INT:
158                 case TYPE_ADR:
159                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
160                         break;
161                 case TYPE_LNG:
162                         VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
163                         break;
164
165                 case TYPE_FLT:
166                 case TYPE_DBL:
167                         VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
168                         break;
169
170                 default: assert(0);
171         }
172 #endif
173
174 }
175