| 1 |
/* -----------------------------------------------------------------*-C-*- |
| 2 |
ffitarget.h - Copyright (c) 2012 Anthony Green |
| 3 |
Copyright (c) 1996-2003 Red Hat, Inc. |
| 4 |
Target configuration macros for MIPS. |
| 5 |
|
| 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: |
| 13 |
|
| 14 |
The above copyright notice and this permission notice shall be included |
| 15 |
in all copies or substantial portions of the Software. |
| 16 |
|
| 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. |
| 25 |
|
| 26 |
----------------------------------------------------------------------- */ |
| 27 |
|
| 28 |
#ifndef LIBFFI_TARGET_H |
| 29 |
#define LIBFFI_TARGET_H |
| 30 |
|
| 31 |
#ifndef LIBFFI_H |
| 32 |
#error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." |
| 33 |
#endif |
| 34 |
|
| 35 |
#ifdef __rtems__ |
| 36 |
/* |
| 37 |
* Subprogram calling convention - copied from sgidefs.h |
| 38 |
*/ |
| 39 |
#define _MIPS_SIM_ABI32 1 |
| 40 |
#define _MIPS_SIM_NABI32 2 |
| 41 |
#define _MIPS_SIM_ABI64 3 |
| 42 |
#elif !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__linux__) |
| 43 |
# include <sgidefs.h> |
| 44 |
#endif |
| 45 |
|
| 46 |
# ifndef _ABIN32 |
| 47 |
# define _ABIN32 _MIPS_SIM_NABI32 |
| 48 |
# endif |
| 49 |
# ifndef _ABI64 |
| 50 |
# define _ABI64 _MIPS_SIM_ABI64 |
| 51 |
# endif |
| 52 |
# ifndef _ABIO32 |
| 53 |
# define _ABIO32 _MIPS_SIM_ABI32 |
| 54 |
# endif |
| 55 |
|
| 56 |
#if !defined(_MIPS_SIM) |
| 57 |
# error -- something is very wrong -- |
| 58 |
#else |
| 59 |
# if (_MIPS_SIM==_ABIN32 && defined(_ABIN32)) || (_MIPS_SIM==_ABI64 && defined(_ABI64)) |
| 60 |
# define FFI_MIPS_N32 |
| 61 |
# else |
| 62 |
# if (_MIPS_SIM==_ABIO32 && defined(_ABIO32)) |
| 63 |
# define FFI_MIPS_O32 |
| 64 |
# else |
| 65 |
# error -- this is an unsupported platform -- |
| 66 |
# endif |
| 67 |
# endif |
| 68 |
#endif |
| 69 |
|
| 70 |
#ifdef FFI_MIPS_O32 |
| 71 |
/* O32 stack frames have 32bit integer args */ |
| 72 |
# define FFI_SIZEOF_ARG 4 |
| 73 |
#else |
| 74 |
/* N32 and N64 frames have 64bit integer args */ |
| 75 |
# define FFI_SIZEOF_ARG 8 |
| 76 |
# if _MIPS_SIM == _ABIN32 |
| 77 |
# define FFI_SIZEOF_JAVA_RAW 4 |
| 78 |
# endif |
| 79 |
#endif |
| 80 |
|
| 81 |
#define FFI_TARGET_HAS_COMPLEX_TYPE 1 |
| 82 |
#define FFI_FLAG_BITS 2 |
| 83 |
|
| 84 |
/* SGI's strange assembler requires that we multiply by 4 rather |
| 85 |
than shift left by FFI_FLAG_BITS */ |
| 86 |
|
| 87 |
#define FFI_ARGS_D FFI_TYPE_DOUBLE |
| 88 |
#define FFI_ARGS_F FFI_TYPE_FLOAT |
| 89 |
#define FFI_ARGS_DD FFI_TYPE_DOUBLE * 4 + FFI_TYPE_DOUBLE |
| 90 |
#define FFI_ARGS_FF FFI_TYPE_FLOAT * 4 + FFI_TYPE_FLOAT |
| 91 |
#define FFI_ARGS_FD FFI_TYPE_DOUBLE * 4 + FFI_TYPE_FLOAT |
| 92 |
#define FFI_ARGS_DF FFI_TYPE_FLOAT * 4 + FFI_TYPE_DOUBLE |
| 93 |
|
| 94 |
/* Needed for N32 structure returns */ |
| 95 |
#define FFI_TYPE_SMALLSTRUCT FFI_TYPE_UINT8 |
| 96 |
#define FFI_TYPE_SMALLSTRUCT2 FFI_TYPE_SINT8 |
| 97 |
|
| 98 |
#if 0 |
| 99 |
/* The SGI assembler can't handle this.. */ |
| 100 |
#define FFI_TYPE_STRUCT_DD (( FFI_ARGS_DD ) << 4) + FFI_TYPE_STRUCT |
| 101 |
/* (and so on) */ |
| 102 |
#else |
| 103 |
/* ...so we calculate these by hand! */ |
| 104 |
#define FFI_TYPE_STRUCT_D 61 |
| 105 |
#define FFI_TYPE_STRUCT_F 45 |
| 106 |
#define FFI_TYPE_STRUCT_DD 253 |
| 107 |
#define FFI_TYPE_STRUCT_FF 173 |
| 108 |
#define FFI_TYPE_STRUCT_FD 237 |
| 109 |
#define FFI_TYPE_STRUCT_DF 189 |
| 110 |
#define FFI_TYPE_STRUCT_SMALL 93 |
| 111 |
#define FFI_TYPE_STRUCT_SMALL2 109 |
| 112 |
|
| 113 |
#define FFI_TYPE_COMPLEX_SMALL 95 |
| 114 |
#define FFI_TYPE_COMPLEX_SMALL2 111 |
| 115 |
#define FFI_TYPE_COMPLEX_FF 47 |
| 116 |
#define FFI_TYPE_COMPLEX_DD 63 |
| 117 |
#define FFI_TYPE_COMPLEX_LDLD 79 |
| 118 |
|
| 119 |
/* and for n32 soft float, add 16 * 2^4 */ |
| 120 |
#define FFI_TYPE_STRUCT_D_SOFT 317 |
| 121 |
#define FFI_TYPE_STRUCT_F_SOFT 301 |
| 122 |
#define FFI_TYPE_STRUCT_DD_SOFT 509 |
| 123 |
#define FFI_TYPE_STRUCT_FF_SOFT 429 |
| 124 |
#define FFI_TYPE_STRUCT_FD_SOFT 493 |
| 125 |
#define FFI_TYPE_STRUCT_DF_SOFT 445 |
| 126 |
#define FFI_TYPE_STRUCT_SOFT 16 |
| 127 |
#endif |
| 128 |
|
| 129 |
#ifdef LIBFFI_ASM |
| 130 |
#define v0 $2 |
| 131 |
#define v1 $3 |
| 132 |
#define a0 $4 |
| 133 |
#define a1 $5 |
| 134 |
#define a2 $6 |
| 135 |
#define a3 $7 |
| 136 |
#define a4 $8 |
| 137 |
#define a5 $9 |
| 138 |
#define a6 $10 |
| 139 |
#define a7 $11 |
| 140 |
#define t0 $8 |
| 141 |
#define t1 $9 |
| 142 |
#define t2 $10 |
| 143 |
#define t3 $11 |
| 144 |
#define t4 $12 |
| 145 |
#define t5 $13 |
| 146 |
#define t6 $14 |
| 147 |
#define t7 $15 |
| 148 |
#define t8 $24 |
| 149 |
#define t9 $25 |
| 150 |
#define ra $31 |
| 151 |
|
| 152 |
#ifdef FFI_MIPS_O32 |
| 153 |
# define REG_L lw |
| 154 |
# define REG_S sw |
| 155 |
# define SUBU subu |
| 156 |
# define ADDU addu |
| 157 |
# define SRL srl |
| 158 |
# define LI li |
| 159 |
#else /* !FFI_MIPS_O32 */ |
| 160 |
# define REG_L ld |
| 161 |
# define REG_S sd |
| 162 |
# define SUBU dsubu |
| 163 |
# define ADDU daddu |
| 164 |
# define SRL dsrl |
| 165 |
# define LI dli |
| 166 |
# if (_MIPS_SIM==_ABI64) |
| 167 |
# define LA dla |
| 168 |
# define EH_FRAME_ALIGN 3 |
| 169 |
# define FDE_ADDR_BYTES .8byte |
| 170 |
# else |
| 171 |
# define LA la |
| 172 |
# define EH_FRAME_ALIGN 2 |
| 173 |
# define FDE_ADDR_BYTES .4byte |
| 174 |
# endif /* _MIPS_SIM==_ABI64 */ |
| 175 |
#endif /* !FFI_MIPS_O32 */ |
| 176 |
#else /* !LIBFFI_ASM */ |
| 177 |
# ifdef __GNUC__ |
| 178 |
# ifdef FFI_MIPS_O32 |
| 179 |
/* O32 stack frames have 32bit integer args */ |
| 180 |
typedef unsigned int ffi_arg __attribute__((__mode__(__SI__))); |
| 181 |
typedef signed int ffi_sarg __attribute__((__mode__(__SI__))); |
| 182 |
#else |
| 183 |
/* N32 and N64 frames have 64bit integer args */ |
| 184 |
typedef unsigned int ffi_arg __attribute__((__mode__(__DI__))); |
| 185 |
typedef signed int ffi_sarg __attribute__((__mode__(__DI__))); |
| 186 |
# endif |
| 187 |
# else |
| 188 |
# ifdef FFI_MIPS_O32 |
| 189 |
/* O32 stack frames have 32bit integer args */ |
| 190 |
typedef __uint32_t ffi_arg; |
| 191 |
typedef __int32_t ffi_sarg; |
| 192 |
# else |
| 193 |
/* N32 and N64 frames have 64bit integer args */ |
| 194 |
typedef __uint64_t ffi_arg; |
| 195 |
typedef __int64_t ffi_sarg; |
| 196 |
# endif |
| 197 |
# endif /* __GNUC__ */ |
| 198 |
|
| 199 |
typedef enum ffi_abi { |
| 200 |
FFI_FIRST_ABI = 0, |
| 201 |
FFI_O32, |
| 202 |
FFI_N32, |
| 203 |
FFI_N64, |
| 204 |
FFI_O32_SOFT_FLOAT, |
| 205 |
FFI_N32_SOFT_FLOAT, |
| 206 |
FFI_N64_SOFT_FLOAT, |
| 207 |
FFI_LAST_ABI, |
| 208 |
|
| 209 |
#ifdef FFI_MIPS_O32 |
| 210 |
#ifdef __mips_soft_float |
| 211 |
FFI_DEFAULT_ABI = FFI_O32_SOFT_FLOAT |
| 212 |
#else |
| 213 |
FFI_DEFAULT_ABI = FFI_O32 |
| 214 |
#endif |
| 215 |
#else |
| 216 |
# if _MIPS_SIM==_ABI64 |
| 217 |
# ifdef __mips_soft_float |
| 218 |
FFI_DEFAULT_ABI = FFI_N64_SOFT_FLOAT |
| 219 |
# else |
| 220 |
FFI_DEFAULT_ABI = FFI_N64 |
| 221 |
# endif |
| 222 |
# else |
| 223 |
# ifdef __mips_soft_float |
| 224 |
FFI_DEFAULT_ABI = FFI_N32_SOFT_FLOAT |
| 225 |
# else |
| 226 |
FFI_DEFAULT_ABI = FFI_N32 |
| 227 |
# endif |
| 228 |
# endif |
| 229 |
#endif |
| 230 |
} ffi_abi; |
| 231 |
|
| 232 |
#define FFI_EXTRA_CIF_FIELDS unsigned rstruct_flag; unsigned mips_nfixedargs |
| 233 |
#define FFI_TARGET_SPECIFIC_VARIADIC |
| 234 |
#endif /* !LIBFFI_ASM */ |
| 235 |
|
| 236 |
/* ---- Definitions for closures ----------------------------------------- */ |
| 237 |
|
| 238 |
#define FFI_CLOSURES 1 |
| 239 |
#define FFI_GO_CLOSURES 1 |
| 240 |
#define FFI_NATIVE_RAW_API 0 |
| 241 |
|
| 242 |
#if defined(FFI_MIPS_O32) || (_MIPS_SIM ==_ABIN32) |
| 243 |
# define FFI_TRAMPOLINE_SIZE 20 |
| 244 |
#else |
| 245 |
# define FFI_TRAMPOLINE_SIZE 56 |
| 246 |
#endif |
| 247 |
|
| 248 |
#endif |
| 249 |
|