Update missing changes for 3.0.9r4.
[libffi.git] / src / mips / ffitarget.h
1 /* -----------------------------------------------------------------*-C-*-
2 ffitarget.h - Copyright (c) 1996-2003 Red Hat, Inc.
3 Target configuration macros for MIPS.
4
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 ``Software''), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
12
13 The above copyright notice and this permission notice shall be included
14 in all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 DEALINGS IN THE SOFTWARE.
24
25 ----------------------------------------------------------------------- */
26
27 #ifndef LIBFFI_TARGET_H
28 #define LIBFFI_TARGET_H
29
30 #ifdef linux
31 # include <asm/sgidefs.h>
32 #else
33 # include <sgidefs.h>
34 #endif
35 # ifndef _ABIN32
36 # define _ABIN32 _MIPS_SIM_NABI32
37 # endif
38 # ifndef _ABI64
39 # define _ABI64 _MIPS_SIM_ABI64
40 # endif
41 # ifndef _ABIO32
42 # define _ABIO32 _MIPS_SIM_ABI32
43 # endif
44
45 #if !defined(_MIPS_SIM)
46 -- something is very wrong --
47 #else
48 # if (_MIPS_SIM==_ABIN32 && defined(_ABIN32)) || (_MIPS_SIM==_ABI64 && defined(_ABI64))
49 # define FFI_MIPS_N32
50 # else
51 # if (_MIPS_SIM==_ABIO32 && defined(_ABIO32))
52 # define FFI_MIPS_O32
53 # else
54 -- this is an unsupported platform --
55 # endif
56 # endif
57 #endif
58
59 #ifdef FFI_MIPS_O32
60 /* O32 stack frames have 32bit integer args */
61 # define FFI_SIZEOF_ARG 4
62 #else
63 /* N32 and N64 frames have 64bit integer args */
64 # define FFI_SIZEOF_ARG 8
65 # if _MIPS_SIM == _ABIN32
66 # define FFI_SIZEOF_JAVA_RAW 4
67 # endif
68 #endif
69
70 #define FFI_FLAG_BITS 2
71
72 /* SGI's strange assembler requires that we multiply by 4 rather
73 than shift left by FFI_FLAG_BITS */
74
75 #define FFI_ARGS_D FFI_TYPE_DOUBLE
76 #define FFI_ARGS_F FFI_TYPE_FLOAT
77 #define FFI_ARGS_DD FFI_TYPE_DOUBLE * 4 + FFI_TYPE_DOUBLE
78 #define FFI_ARGS_FF FFI_TYPE_FLOAT * 4 + FFI_TYPE_FLOAT
79 #define FFI_ARGS_FD FFI_TYPE_DOUBLE * 4 + FFI_TYPE_FLOAT
80 #define FFI_ARGS_DF FFI_TYPE_FLOAT * 4 + FFI_TYPE_DOUBLE
81
82 /* Needed for N32 structure returns */
83 #define FFI_TYPE_SMALLSTRUCT FFI_TYPE_UINT8
84 #define FFI_TYPE_SMALLSTRUCT2 FFI_TYPE_SINT8
85
86 #if 0
87 /* The SGI assembler can't handle this.. */
88 #define FFI_TYPE_STRUCT_DD (( FFI_ARGS_DD ) << 4) + FFI_TYPE_STRUCT
89 /* (and so on) */
90 #else
91 /* ...so we calculate these by hand! */
92 #define FFI_TYPE_STRUCT_D 61
93 #define FFI_TYPE_STRUCT_F 45
94 #define FFI_TYPE_STRUCT_DD 253
95 #define FFI_TYPE_STRUCT_FF 173
96 #define FFI_TYPE_STRUCT_FD 237
97 #define FFI_TYPE_STRUCT_DF 189
98 #define FFI_TYPE_STRUCT_SMALL 93
99 #define FFI_TYPE_STRUCT_SMALL2 109
100
101 /* and for n32 soft float, add 16 * 2^4 */
102 #define FFI_TYPE_STRUCT_D_SOFT 317
103 #define FFI_TYPE_STRUCT_F_SOFT 301
104 #define FFI_TYPE_STRUCT_DD_SOFT 509
105 #define FFI_TYPE_STRUCT_FF_SOFT 429
106 #define FFI_TYPE_STRUCT_FD_SOFT 493
107 #define FFI_TYPE_STRUCT_DF_SOFT 445
108 #define FFI_TYPE_STRUCT_SOFT 16
109 #endif
110
111 #ifdef LIBFFI_ASM
112 #define v0 $2
113 #define v1 $3
114 #define a0 $4
115 #define a1 $5
116 #define a2 $6
117 #define a3 $7
118 #define a4 $8
119 #define a5 $9
120 #define a6 $10
121 #define a7 $11
122 #define t0 $8
123 #define t1 $9
124 #define t2 $10
125 #define t3 $11
126 #define t4 $12
127 #define t5 $13
128 #define t6 $14
129 #define t7 $15
130 #define t8 $24
131 #define t9 $25
132 #define ra $31
133
134 #ifdef FFI_MIPS_O32
135 # define REG_L lw
136 # define REG_S sw
137 # define SUBU subu
138 # define ADDU addu
139 # define SRL srl
140 # define LI li
141 #else /* !FFI_MIPS_O32 */
142 # define REG_L ld
143 # define REG_S sd
144 # define SUBU dsubu
145 # define ADDU daddu
146 # define SRL dsrl
147 # define LI dli
148 # if (_MIPS_SIM==_ABI64)
149 # define LA dla
150 # define EH_FRAME_ALIGN 3
151 # define FDE_ADDR_BYTES .8byte
152 # else
153 # define LA la
154 # define EH_FRAME_ALIGN 2
155 # define FDE_ADDR_BYTES .4byte
156 # endif /* _MIPS_SIM==_ABI64 */
157 #endif /* !FFI_MIPS_O32 */
158 #else /* !LIBFFI_ASM */
159 # ifdef __GNUC__
160 # ifdef FFI_MIPS_O32
161 /* O32 stack frames have 32bit integer args */
162 typedef unsigned int ffi_arg __attribute__((__mode__(__SI__)));
163 typedef signed int ffi_sarg __attribute__((__mode__(__SI__)));
164 #else
165 /* N32 and N64 frames have 64bit integer args */
166 typedef unsigned int ffi_arg __attribute__((__mode__(__DI__)));
167 typedef signed int ffi_sarg __attribute__((__mode__(__DI__)));
168 # endif
169 # else
170 # ifdef FFI_MIPS_O32
171 /* O32 stack frames have 32bit integer args */
172 typedef __uint32_t ffi_arg;
173 typedef __int32_t ffi_sarg;
174 # else
175 /* N32 and N64 frames have 64bit integer args */
176 typedef __uint64_t ffi_arg;
177 typedef __int64_t ffi_sarg;
178 # endif
179 # endif /* __GNUC__ */
180
181 typedef enum ffi_abi {
182 FFI_FIRST_ABI = 0,
183 FFI_O32,
184 FFI_N32,
185 FFI_N64,
186 FFI_O32_SOFT_FLOAT,
187 FFI_N32_SOFT_FLOAT,
188 FFI_N64_SOFT_FLOAT,
189
190 #ifdef FFI_MIPS_O32
191 #ifdef __mips_soft_float
192 FFI_DEFAULT_ABI = FFI_O32_SOFT_FLOAT,
193 #else
194 FFI_DEFAULT_ABI = FFI_O32,
195 #endif
196 #else
197 # if _MIPS_SIM==_ABI64
198 # ifdef __mips_soft_float
199 FFI_DEFAULT_ABI = FFI_N64_SOFT_FLOAT,
200 # else
201 FFI_DEFAULT_ABI = FFI_N64,
202 # endif
203 # else
204 # ifdef __mips_soft_float
205 FFI_DEFAULT_ABI = FFI_N32_SOFT_FLOAT,
206 # else
207 FFI_DEFAULT_ABI = FFI_N32,
208 # endif
209 # endif
210 #endif
211
212 FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
213 } ffi_abi;
214
215 #define FFI_EXTRA_CIF_FIELDS unsigned rstruct_flag
216 #endif /* !LIBFFI_ASM */
217
218 /* ---- Definitions for closures ----------------------------------------- */
219
220 #if defined(FFI_MIPS_O32)
221 #define FFI_CLOSURES 1
222 #define FFI_TRAMPOLINE_SIZE 20
223 #else
224 /* N32/N64. */
225 # define FFI_CLOSURES 1
226 #if _MIPS_SIM==_ABI64
227 #define FFI_TRAMPOLINE_SIZE 52
228 #else
229 #define FFI_TRAMPOLINE_SIZE 20
230 #endif
231 #endif /* FFI_MIPS_O32 */
232 #define FFI_NATIVE_RAW_API 0
233
234 #endif
235