Machine dependent stuff.
[cacao.git] / src / vm / jit / powerpc / darwin / md-abi.h
1 /* src/vm/jit/powerpc/darwin/md-abi.h - defines for PowerPC Darwin 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:
30
31    $Id: md-abi.h 2539 2005-05-31 15:55:54Z twisti $
32
33 */
34
35
36 #ifndef _MD_ABI_H
37 #define _MD_ABI_H
38
39 /* preallocated registers *****************************************************/
40
41 /* integer registers */
42   
43 #define REG_RESULT       3   /* to deliver method results                     */
44 #define REG_RESULT2      4   /* to deliver long method results                */
45
46 #define REG_PV          13   /* procedure vector, must be provided by caller  */
47 #define REG_METHODPTR   12   /* pointer to the place from where the procedure */
48                              /* vector has been fetched                       */
49 #define REG_ITMP1       11   /* temporary register                            */
50 #define REG_ITMP2       12   /* temporary register and method pointer         */
51 #define REG_ITMP3        0   /* temporary register                            */
52
53 #define REG_ITMP1_XPTR  11   /* exception pointer = temporary register 1      */
54 #define REG_ITMP2_XPC   12   /* exception pc = temporary register 2           */
55
56 #define REG_SP           1   /* stack pointer                                 */
57 #define REG_ZERO         0   /* almost always zero: only in address calc.     */
58
59 /* floating point registers */
60
61 #define REG_FRESULT      1   /* to deliver floating point method results      */
62 #define REG_FTMP1       16   /* temporary floating point register             */
63 #define REG_FTMP2       17   /* temporary floating point register             */
64 #define REG_FTMP3        0   /* temporary floating point register             */
65
66 #define REG_IFTMP        0   /* temporary integer and floating point register */
67
68
69 #define INT_REG_CNT     32   /* number of integer registers                   */
70 #define INT_SAV_CNT     10   /* number of int callee saved registers          */
71 #define INT_ARG_CNT      8   /* number of int argument registers              */
72 #define INT_TMP_CNT      8   /* number of integer temporary registers         */
73 #define INT_RES_CNT      3   /* number of integer reserved registers          */
74
75 #define FLT_REG_CNT     32   /* number of float registers                     */
76 #define FLT_SAV_CNT     10   /* number of float callee saved registers        */
77 #define FLT_ARG_CNT     13   /* number of float argument registers            */
78 #define FLT_TMP_CNT      6   /* number of float temporary registers           */
79 #define FLT_RES_CNT      3   /* number of float reserved registers            */
80
81 #define TRACE_ARGS_NUM   8
82
83
84 /* ABI defines ****************************************************************/
85
86 #define LA_SIZE         24   /* linkage area size                             */
87 #define LA_SIZE_ALIGNED 32   /* linkage area size aligned to 16-byte          */
88 #define LA_WORD_SIZE     6   /* linkage area size in words: 6 * 4 = 24        */
89
90 #define LA_LR_OFFSET     8   /* link register offset in linkage area          */
91
92 /* #define ALIGN_FRAME_SIZE(sp)       (sp) */
93
94
95 /* SET_ARG_STACKSLOTS **********************************************************
96
97 Macro for stack.c to set Argument Stackslots
98
99 Sets the first call_argcount stackslots of curstack to varkind ARGVAR, if
100 they to not have the SAVEDVAR flag set. According to the calling
101 conventions these stackslots are assigned argument registers or memory
102 locations
103
104 --- in
105 i,call_argcount:  Number of arguments for this method
106 curstack:         instack of the method invokation
107 call_returntype:  return type
108
109 --- uses
110 i, copy
111
112 --- out
113 copy:             Points to first stackslot after the parameters
114 rd->argintreguse: max. number of used integer argument register so far
115 rd->argfltreguse: max. number of used float argument register so far
116 rd->ifmemuse:     max. number of stackslots used for spilling parameters
117                   so far
118
119 *******************************************************************************/
120
121 #define SET_ARG_STACKSLOTS \
122         do { \
123                 s4 iarg = 0; \
124                 s4 farg = 0; \
125                 s4 iarg_max = 0; \
126                 s4 stacksize; \
127                 \
128                 stacksize = 6; \
129                 \
130                 copy = curstack; \
131                 for (;i > 0; i--) { \
132                         stacksize += (IS_2_WORD_TYPE(copy->type)) ? 2 : 1; \
133                         if (IS_FLT_DBL_TYPE(copy->type)) \
134                                 farg++; \
135                         copy = copy->prev; \
136                 } \
137                 if (rd->argfltreguse < farg) \
138                         rd->argfltreguse = farg; \
139                 \
140                 /* REG_FRESULT == FLOAT ARGUMENT REGISTER 0 */                                  \
141                 if (IS_FLT_DBL_TYPE(call_returntype))                                                   \
142                         if (rd->argfltreguse < 1)                                                                       \
143                                 rd->argfltreguse = 1;                                                                   \
144                                                                                                                                                 \
145                 if (stacksize > rd->ifmemuse)                                                                   \
146                         rd->ifmemuse = stacksize;                                                                       \
147                                                                                                                                                 \
148                 i = call_argcount;                                                                                              \
149                 copy = curstack;                                                                                                \
150                 while (--i >= 0) {                                                                                              \
151                         stacksize -= (IS_2_WORD_TYPE(copy->type)) ? 2 : 1;                      \
152                         if (IS_FLT_DBL_TYPE(copy->type)) {                                                      \
153                                 farg--;                                                                                                 \
154                                 if (!(copy->flags & SAVEDVAR)) {                                                \
155                                         copy->varnum = i;                                                                       \
156                                         copy->varkind = ARGVAR;                                                         \
157                                         if (farg < rd->fltreg_argnum) {                                         \
158                                                 copy->flags = 0;                                                                \
159                                                 copy->regoff = rd->argfltregs[farg];                    \
160                                         } else {                                                                                        \
161                                                 copy->flags = INMEMORY;                                                 \
162                                                 copy->regoff = stacksize;                                               \
163                                         }                                                                                                       \
164                                 }                                                                                                               \
165                         } else {                                                                                                        \
166                                 iarg = stacksize - 6;                                                                   \
167                                 if (iarg+(IS_2_WORD_TYPE(copy->type) ? 2 : 1) > iarg_max) \
168                                         iarg_max = iarg+(IS_2_WORD_TYPE(copy->type) ? 2 : 1); \
169                                                                                                                                                 \
170                                 if (!(copy->flags & SAVEDVAR)) {                                                \
171                                         copy->varnum = i;                                                                       \
172                                         copy->varkind = ARGVAR;                                                         \
173                                         if ((iarg+((IS_2_WORD_TYPE(copy->type)) ? 1 : 0)) < rd->intreg_argnum) { \
174                                                 copy->flags = 0;                                                                \
175                                                 copy->regoff = rd->argintregs[iarg];                    \
176                                         } else {                                                                                        \
177                                                 copy->flags = INMEMORY;                                                 \
178                                                 copy->regoff = stacksize;                                               \
179                                         } \
180                                 } \
181                         } \
182                         copy = copy->prev; \
183                 } \
184                 if (rd->argintreguse < iarg_max) \
185                         rd->argintreguse = iarg_max; \
186                 if (IS_INT_LNG_TYPE(call_returntype)) { \
187                         /* REG_RESULT  == INTEGER ARGUMENT REGISTER 0 */ \
188                         /* REG_RESULT2 == INTEGER ARGUMENT REGISTER 1 */ \
189                         if (IS_2_WORD_TYPE(call_returntype)) { \
190                                 if (rd->argintreguse < 2) \
191                                         rd->argintreguse = 2; \
192                         } else { \
193                                 if (rd->argintreguse < 1) \
194                                         rd->argintreguse = 1; \
195                         } \
196                 } \
197         } while (0)
198
199
200 #endif /* _MD_ABI_H */
201
202
203 /*
204  * These are local overrides for various environment variables in Emacs.
205  * Please do not remove this and leave it at the end of the file, where
206  * Emacs will automagically detect them.
207  * ---------------------------------------------------------------------
208  * Local variables:
209  * mode: c
210  * indent-tabs-mode: t
211  * c-basic-offset: 4
212  * tab-width: 4
213  * End:
214  */