1#ifndef _NSEEL_GLUE_AARCH64_H_
2#define _NSEEL_GLUE_AARCH64_H_
29#define GLUE_MAX_SPILL_REGS 8
30#define GLUE_SAVE_TO_SPILL_SIZE(x) (4)
31#define GLUE_RESTORE_SPILL_TO_FPREG2_SIZE(x) (4)
35 *(
unsigned int *)
b = 0x1e604101 + (ws<<5);
39 *(
unsigned int *)
b = 0x1e604008 + ws;
43#define GLUE_HAS_FPREG2 1
50#define GLUE_MAX_FPSTACK_SIZE 0
51#define GLUE_MAX_JMPSIZE ((1<<20) - 1024)
57 unsigned int *
a = (
unsigned int*) endOfInstruction - 1;
60 if ((
a[0] & 0xFC000000) == 0x14000000)
63 a[0] = 0x14000000 | (offset & 0x3FFFFFF);
65 else if ((
a[0] & 0xFF000000) == 0x54000000)
68 a[0] = 0x54000000 | (
a[0] & 0xF) | ((offset & 0x7FFFF) << 5);
85#define GLUE_MOV_PX_DIRECTVALUE_TOFPREG2_SIZE 16
86#define GLUE_MOV_PX_DIRECTVALUE_SIZE 12
89 static const unsigned int tab[3] = {
95 unsigned int *
p=(
unsigned int *)
b;
98 p[0] = tab[0] | wv | ((
v&0xFFFF)<<5);
99 p[1] = tab[1] | wv | (((
v>>16)&0xFFFF)<<5);
100 p[2] = tab[2] | wv | (((
v>>32)&0xFFFF)<<5);
101 if (wvo == -2)
p[3] = 0xfd400001;
105#define GLUE_FUNC_ENTER_SIZE 4
107#define GLUE_FUNC_LEAVE_SIZE 0
108const static unsigned int GLUE_RET[]={ 0xa8c17bfd, 0xd65f03c0 };
112 const static unsigned int GLUE_SET_WTP_FROM_R19 = 0xaa1303f6;
113 if (
out)
memcpy(
out,&GLUE_SET_WTP_FROM_R19,
sizeof(GLUE_SET_WTP_FROM_R19));
120#define GLUE_STORE_P1_TO_STACK_AT_OFFS_SIZE(offs) ((offs)>=32768 ? 8 : 4)
126 *(
unsigned int *)
b = 0x914003e1 + ((offs>>12)<<10);
132 ((
unsigned int *)
b)[1] = 0xf9000020 + offs;
139 *(
unsigned int *)
b = 0xf90003e0 + offs;
143#define GLUE_MOVE_PX_STACKPTR_SIZE 4
147 *(
unsigned int *)
b = 0x910003e0 + wv;
150#define GLUE_MOVE_STACK_SIZE 4
156 *(
unsigned int*)
b = 0x914003ff | (((amt+4095)>>12)<<10);
158 *(
unsigned int*)
b = 0x910003ff | (amt << 10);
164 *(
unsigned int*)
b = 0xd14003ff | (((amt+4095)>>12)<<10);
166 *(
unsigned int*)
b = 0xd10003ff | (amt << 10);
170#define GLUE_POP_PX_SIZE 4
173 ((
unsigned int *)
b)[0] = 0xf84107e0 | wv;
176#define GLUE_SET_PX_FROM_P1_SIZE 4
179 *(
unsigned int *)
b = 0xaa0003e0 | wv;
193 unsigned int *bufptr = (
unsigned int *)buf;
194 *bufptr++ = 0xfc4107e7;
197 *bufptr++ = 0xfd000007;
206 unsigned int *bufptr = (
unsigned int *)buf;
207 *bufptr++ = 0xfd400007;
210 *bufptr++ = 0xfd000007;
217#define GLUE_CALL_CODE(bp, cp, rt) do { \
219 if (!(h->compile_flags&NSEEL_CODE_COMPILE_FLAG_NOFPSTATE) && \
220 !((f=glue_getscr())&(1<<24))) { \
221 glue_setscr(f|(1<<24)); \
222 eel_callcode64(bp, cp, rt); \
224 } else eel_callcode64(bp, cp, rt);\
231 static const double consttab[] = {
244 "stp x29, x30, [sp, #-64]!\n"
245 "stp x18, x20, [sp, 16]\n"
246 "stp x21, x19, [sp, 32]\n"
247 "stp x22, x23, [sp, 48]\n"
253 "ldp x29, x30, [sp], 16\n"
254 "ldp x18, x20, [sp], 16\n"
255 "ldp x21, x19, [sp], 16\n"
256 "ldp x22, x23, [sp], 16\n"
257 ::
"r" (
cp),
"r" (bp),
"r" (
rt),
"r" (consttab) :
"x0",
"x1",
"x2",
"x3",
"x4",
"x5",
"x6",
"x7",
258 "x8",
"x9",
"x10",
"x11",
"x12",
"x13",
"x14",
"x15",
259 "v8",
"v9",
"v10",
"v11",
"v12",
"v13",
"v14",
"v15");
266 unsigned int *
p=(
unsigned int *)_p;
270 while (((
p[0]>>5)&0xffff)!=0xdead ||
271 ((
p[1]>>5)&0xffff)!=0xbeef ||
272 ((
p[2]>>5)&0xffff)!=0xbeef)
p++;
274 p[0] = (
p[0] & 0xFFE0001F) | ((newv&0xffff)<<5);
275 p[1] = (
p[1] & 0xFFE0001F) | (((newv>>16)&0xffff)<<5);
276 p[2] = (
p[2] & 0xFFE0001F) | (((newv>>32)&0xffff)<<5);
278 return (
unsigned char *)(
p+2);
281#define GLUE_SET_PX_FROM_WTP_SIZE sizeof(int)
284 *(
unsigned int *)
b = 0xaa1603e0 + wv;
291 unsigned int *bufptr = (
unsigned int *)buf;
295 *bufptr++ = 0xfd000000;
300#define GLUE_POP_FPSTACK_SIZE 0
312#define GLUE_PUSH_VAL_AT_PX_TO_FPSTACK_SIZE 4
315 *(
unsigned int *)
b = 0xfd400000 + (wv<<5);
318#define GLUE_POP_FPSTACK_TO_WTP_TO_PX_SIZE (sizeof(GLUE_POP_FPSTACK_TO_WTP) + GLUE_SET_PX_FROM_WTP_SIZE)
331 while ((*(
int*)
fn & 0xFC000000) == 0x14000000)
333 int offset = (*(
int*)
fn & 0x3FFFFFF);
334 if (offset & 0x2000000)
335 offset |= 0xFC000000;
337 fn = (
int*)
fn + offset;
339 static const unsigned int sig[3] = { 0xaa0003e0, 0xaa0103e1, 0xaa0203e2 };
340 unsigned char *
p = (
unsigned char *)
fn;
342 while (memcmp(
p,sig,
sizeof(sig)))
p+=4;
346 while (memcmp(
p,sig,
sizeof(sig)))
p+=4;
347 *
size =
p - (
unsigned char *)
fn;
355 asm volatile (
"mrs %0, fpcr" :
"=r" (rv));
360 asm volatile (
"msr fpcr, %0" ::
"r"(
v));
365 unsigned long *
s = (
unsigned long*)_s;
366 s[0] = glue_getscr();
367 glue_setscr(
s[0] | (1<<24));
371 unsigned long *
s = (
unsigned long*)_s;
375#define GLUE_HAS_FUSE 1
378 if (left_size>=4 && right_size == 4)
380 unsigned int instr = ((
unsigned int *)
code)[-1];
381 if (spill_reg >= 0 && (instr & 0xfffffc1f) == 0x1e604001)
383 const int src_reg = (instr>>5)&0x1f;
384 if (src_reg == spill_reg + 8)
386 instr = ((
unsigned int *)
code)[0];
387 if ((instr & 0xffffcfff) == 0x1e600820)
389 ((
unsigned int *)
code)[-1] = instr + ((src_reg-1) << 5);
uint8_t a
Definition Spc_Cpu.h:141
unsigned v[N_MAX]
Definition inflate.c:1584
unsigned s
Definition inflate.c:1555
void(* eel_leavefp)(int s[2])
Definition eel_import.h:43
void(* eel_enterfp)(int s[2])
Definition eel_import.h:42
static const unsigned int GLUE_PUSH_P1PTR_AS_VALUE[]
Definition glue_aarch64.h:183
static void GLUE_MOVE_STACK(void *b, int amt)
Definition glue_aarch64.h:151
static void GLUE_SET_PX_FROM_WTP(void *b, int wv)
Definition glue_aarch64.h:282
static void GLUE_POP_FPSTACK_TO_WTP_TO_PX(unsigned char *buf, int wv)
Definition glue_aarch64.h:319
static void GLUE_MOV_PX_DIRECTVALUE_GEN(void *b, INT_PTR v, int wv)
Definition glue_aarch64.h:87
static const unsigned int GLUE_POP_FPSTACK_TOSTACK[]
Definition glue_aarch64.h:303
static const unsigned int GLUE_POP_FPSTACK[1]
Definition glue_aarch64.h:301
static void GLUE_RESTORE_SPILL_TO_FPREG2(void *b, int ws)
Definition glue_aarch64.h:33
#define GLUE_SET_PX_FROM_WTP_SIZE
Definition glue_aarch64.h:281
static void * GLUE_realAddress(void *fn, int *size)
Definition glue_aarch64.h:329
static const unsigned int GLUE_FUNC_LEAVE[1]
Definition glue_aarch64.h:106
static const unsigned int GLUE_POP_FPSTACK_TO_WTP[]
Definition glue_aarch64.h:308
#define GLUE_MOV_PX_DIRECTVALUE_SIZE
Definition glue_aarch64.h:86
static int GLUE_RESET_WTP(unsigned char *out, void *ptr)
Definition glue_aarch64.h:110
static int GLUE_POP_VALUE_TO_ADDR(unsigned char *buf, void *destptr)
Definition glue_aarch64.h:189
static void GLUE_SAVE_TO_SPILL(void *b, int ws)
Definition glue_aarch64.h:37
static void GLUE_MOVE_PX_STACKPTR_GEN(void *b, int wv)
Definition glue_aarch64.h:144
static const unsigned int GLUE_JMP_NC[]
Definition glue_aarch64.h:72
static unsigned int GLUE_POP_STACK_TO_FPREG2[]
Definition glue_aarch64.h:46
static int GLUE_FUSE(compileContext *ctx, unsigned char *code, int left_size, int right_size, int fuse_flags, int spill_reg)
Definition glue_aarch64.h:376
static const unsigned int GLUE_JMP_IF_P1_NZ[]
Definition glue_aarch64.h:79
static const unsigned int GLUE_FUNC_ENTER[2]
Definition glue_aarch64.h:104
static const unsigned int GLUE_SET_P1_Z[]
Definition glue_aarch64.h:325
static const unsigned int GLUE_RET[]
Definition glue_aarch64.h:108
static const unsigned int GLUE_JMP_IF_P1_Z[]
Definition glue_aarch64.h:74
static void GLUE_STORE_P1_TO_STACK_AT_OFFS(void *b, int offs)
Definition glue_aarch64.h:121
static void GLUE_POP_PX(void *b, int wv)
Definition glue_aarch64.h:171
static const unsigned int GLUE_COPY_FPSTACK_TO_FPREG2[]
Definition glue_aarch64.h:45
static int GLUE_POP_FPSTACK_TO_PTR(unsigned char *buf, void *destptr)
Definition glue_aarch64.h:287
static unsigned char * EEL_GLUE_set_immediate(void *_p, INT_PTR newv)
Definition glue_aarch64.h:264
static void GLUE_PUSH_VAL_AT_PX_TO_FPSTACK(void *b, int wv)
Definition glue_aarch64.h:313
static void GLUE_SET_PX_FROM_P1(void *b, int wv)
Definition glue_aarch64.h:177
static unsigned long __attribute__((unused)) glue_getscr()
Definition glue_aarch64.h:352
static void eel_callcode64(INT_PTR bp, INT_PTR cp, INT_PTR rt)
Definition glue_aarch64.h:227
static const unsigned int GLUE_PUSH_P1[1]
Definition glue_aarch64.h:118
static const unsigned int GLUE_SET_P1_NZ[]
Definition glue_aarch64.h:326
static int GLUE_COPY_VALUE_AT_P1_TO_PTR(unsigned char *buf, void *destptr)
Definition glue_aarch64.h:202
#define GLUE_JMP_SET_OFFSET(endOfInstruction, offset)
Definition glue_arm.h:52
INT_PTR INT_PTR rt
Definition glue_arm.h:222
float out
Definition lilv_test.c:1461
struct _compileContext compileContext
#define NSEEL_CLOSEFACTOR
Definition ns-eel-int.h:101
const char const char const char const char char * fn
Definition swell-functions.h:168
intptr_t INT_PTR
Definition swell-types.h:42
uch * p
Definition crypt.c:594
memcpy(hh, h, RAND_HEAD_LEN)
char * cp
Definition unix.c:513
typedef int(UZ_EXP MsgFn)()