aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/luajit-2.0/src/lj_ccall.h
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/luajit-2.0/src/lj_ccall.h')
-rw-r--r--libraries/luajit-2.0/src/lj_ccall.h143
1 files changed, 143 insertions, 0 deletions
diff --git a/libraries/luajit-2.0/src/lj_ccall.h b/libraries/luajit-2.0/src/lj_ccall.h
new file mode 100644
index 0000000..0641625
--- /dev/null
+++ b/libraries/luajit-2.0/src/lj_ccall.h
@@ -0,0 +1,143 @@
1/*
2** FFI C call handling.
3** Copyright (C) 2005-2011 Mike Pall. See Copyright Notice in luajit.h
4*/
5
6#ifndef _LJ_CCALL_H
7#define _LJ_CCALL_H
8
9#include "lj_obj.h"
10#include "lj_ctype.h"
11
12#if LJ_HASFFI
13
14/* -- C calling conventions ----------------------------------------------- */
15
16#if LJ_TARGET_X86ORX64
17
18#if LJ_TARGET_X86
19#define CCALL_NARG_GPR 2 /* For fastcall arguments. */
20#define CCALL_NARG_FPR 0
21#define CCALL_NRET_GPR 2
22#define CCALL_NRET_FPR 1 /* For FP results on x87 stack. */
23#define CCALL_ALIGN_STACKARG 0 /* Don't align argument on stack. */
24#elif LJ_ABI_WIN
25#define CCALL_NARG_GPR 4
26#define CCALL_NARG_FPR 4
27#define CCALL_NRET_GPR 1
28#define CCALL_NRET_FPR 1
29#define CCALL_SPS_EXTRA 4
30#else
31#define CCALL_NARG_GPR 6
32#define CCALL_NARG_FPR 8
33#define CCALL_NRET_GPR 2
34#define CCALL_NRET_FPR 2
35#define CCALL_VECTOR_REG 1 /* Pass vectors in registers. */
36#endif
37
38#define CCALL_SPS_FREE 1
39
40typedef LJ_ALIGN(16) union FPRArg {
41 double d[2];
42 float f[4];
43 uint8_t b[16];
44 uint16_t s[8];
45 int i[4];
46 int64_t l[2];
47} FPRArg;
48
49typedef intptr_t GPRArg;
50
51#elif LJ_TARGET_ARM
52
53#define CCALL_NARG_GPR 4
54#define CCALL_NARG_FPR 0
55#define CCALL_NRET_GPR 2 /* For softfp double. */
56#define CCALL_NRET_FPR 0
57#define CCALL_SPS_FREE 0
58
59typedef intptr_t GPRArg;
60
61#elif LJ_TARGET_PPC
62
63#define CCALL_NARG_GPR 8
64#define CCALL_NARG_FPR 8
65#define CCALL_NRET_GPR 4 /* For complex double. */
66#define CCALL_NRET_FPR 1
67#define CCALL_SPS_EXTRA 4
68#define CCALL_SPS_FREE 0
69
70typedef intptr_t GPRArg;
71typedef double FPRArg;
72
73#elif LJ_TARGET_PPCSPE
74
75#define CCALL_NARG_GPR 8
76#define CCALL_NARG_FPR 0
77#define CCALL_NRET_GPR 4 /* For softfp complex double. */
78#define CCALL_NRET_FPR 0
79#define CCALL_SPS_FREE 0 /* NYI */
80
81typedef intptr_t GPRArg;
82
83#else
84#error "Missing calling convention definitions for this architecture"
85#endif
86
87#ifndef CCALL_SPS_EXTRA
88#define CCALL_SPS_EXTRA 0
89#endif
90#ifndef CCALL_VECTOR_REG
91#define CCALL_VECTOR_REG 0
92#endif
93#ifndef CCALL_ALIGN_STACKARG
94#define CCALL_ALIGN_STACKARG 1
95#endif
96
97#define CCALL_NUM_GPR \
98 (CCALL_NARG_GPR > CCALL_NRET_GPR ? CCALL_NARG_GPR : CCALL_NRET_GPR)
99#define CCALL_NUM_FPR \
100 (CCALL_NARG_FPR > CCALL_NRET_FPR ? CCALL_NARG_FPR : CCALL_NRET_FPR)
101
102/* Check against constants in lj_ctype.h. */
103LJ_STATIC_ASSERT(CCALL_NUM_GPR <= CCALL_MAX_GPR);
104LJ_STATIC_ASSERT(CCALL_NUM_FPR <= CCALL_MAX_FPR);
105
106#define CCALL_MAXSTACK 32
107
108/* -- C call state -------------------------------------------------------- */
109
110typedef struct CCallState {
111 void (*func)(void); /* Pointer to called function. */
112 uint32_t spadj; /* Stack pointer adjustment. */
113 uint8_t nsp; /* Number of stack slots. */
114 uint8_t retref; /* Return value by reference. */
115#if LJ_TARGET_X64
116 uint8_t ngpr; /* Number of arguments in GPRs. */
117 uint8_t nfpr; /* Number of arguments in FPRs. */
118#elif LJ_TARGET_X86
119 uint8_t resx87; /* Result on x87 stack: 1:float, 2:double. */
120#elif LJ_TARGET_PPC
121 uint8_t nfpr; /* Number of arguments in FPRs. */
122#endif
123#if CCALL_NUM_FPR
124#if LJ_32
125 int32_t align1;
126#endif
127 FPRArg fpr[CCALL_NUM_FPR]; /* Arguments/results in FPRs. */
128#endif
129 GPRArg gpr[CCALL_NUM_GPR]; /* Arguments/results in GPRs. */
130 GPRArg stack[CCALL_MAXSTACK]; /* Stack slots. */
131} CCallState;
132
133/* -- C call handling ----------------------------------------------------- */
134
135/* Really belongs to lj_vm.h. */
136LJ_ASMF void LJ_FASTCALL lj_vm_ffi_call(CCallState *cc);
137
138LJ_FUNC CTypeID lj_ccall_ctid_vararg(CTState *cts, cTValue *o);
139LJ_FUNC int lj_ccall_func(lua_State *L, GCcdata *cd);
140
141#endif
142
143#endif