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