Lines Matching +full:- +full:- +full:dest +full:- +full:dir
1 /* -----------------------------------------------------------------------
2 ffi.c - Copyright (c) 2017 Anthony Green
30 ----------------------------------------------------------------------- */
40 all further uses in this file will refer to the 80-bit type. */
55 /* Stack is not 16-byte aligned on Windows. */
66 int i, n, flags, cabi = cif->abi; in ffi_prep_cif_machdep()
82 switch (cif->rtype->type) in ffi_prep_cif_machdep()
121 if (cif->rtype->size == 1) in ffi_prep_cif_machdep()
123 else if (cif->rtype->size == 2) in ffi_prep_cif_machdep()
125 else if (cif->rtype->size == 4) in ffi_prep_cif_machdep()
127 else if (cif->rtype->size == 8) in ffi_prep_cif_machdep()
150 switch (cif->rtype->elements[0]->type) in ffi_prep_cif_machdep()
178 cif->flags = flags; in ffi_prep_cif_machdep()
180 for (i = 0, n = cif->nargs; i < n; i++) in ffi_prep_cif_machdep()
182 ffi_type *t = cif->arg_types[i]; in ffi_prep_cif_machdep()
184 bytes = FFI_ALIGN (bytes, t->alignment); in ffi_prep_cif_machdep()
185 bytes += FFI_ALIGN (t->size, FFI_SIZEOF_ARG); in ffi_prep_cif_machdep()
187 cif->bytes = bytes; in ffi_prep_cif_machdep()
224 unsigned regs[3]; /* 20-28 */
229 int dir; /* parameter growth direction */ member
240 [FFI_PASCAL] = { -1, R_ECX, 0 },
242 [FFI_REGISTER] = { -1, R_ECX, 3, { R_EAX, R_EDX, R_ECX } },
266 int flags, cabi, i, n, dir, narg_reg; in ffi_call_int() local
269 flags = cif->flags; in ffi_call_int()
270 cabi = cif->abi; in ffi_call_int()
272 dir = pabi->dir; in ffi_call_int()
286 rsize = cif->rtype->size; in ffi_call_int()
295 bytes = STACK_ALIGN (cif->bytes); in ffi_call_int()
297 argp = (dir < 0 ? stack + bytes : stack); in ffi_call_int()
302 frame->fn = fn; in ffi_call_int()
303 frame->flags = flags; in ffi_call_int()
304 frame->rvalue = rvalue; in ffi_call_int()
305 frame->regs[pabi->static_chain] = (unsigned)closure; in ffi_call_int()
312 if (pabi->nregs > 0) in ffi_call_int()
314 frame->regs[pabi->regs[0]] = (unsigned)rvalue; in ffi_call_int()
325 arg_types = cif->arg_types; in ffi_call_int()
326 for (i = 0, n = cif->nargs; i < n; i++) in ffi_call_int()
330 size_t z = ty->size; in ffi_call_int()
331 int t = ty->type; in ffi_call_int()
337 if (t != FFI_TYPE_FLOAT && narg_reg < pabi->nregs) in ffi_call_int()
338 frame->regs[pabi->regs[narg_reg++]] = val; in ffi_call_int()
339 else if (dir < 0) in ffi_call_int()
341 argp -= 4; in ffi_call_int()
356 as 64-bit integer or struct, all following integer paramters in ffi_call_int()
371 if (t == FFI_TYPE_STRUCT && ty->alignment >= 16) in ffi_call_int()
374 if (dir < 0) in ffi_call_int()
378 argp -= za; in ffi_call_int()
389 FFI_ASSERT (dir > 0 || argp == stack); in ffi_call_int()
416 unsigned regs[3]; /* 16-24 */
425 ffi_cif *cif = frame->cif; in ffi_closure_inner()
426 int cabi, i, n, flags, dir, narg_reg; in ffi_closure_inner() local
433 cabi = cif->abi; in ffi_closure_inner()
434 flags = cif->flags; in ffi_closure_inner()
436 rvalue = frame->rettemp; in ffi_closure_inner()
438 dir = pabi->dir; in ffi_closure_inner()
439 argp = (dir < 0 ? stack + STACK_ALIGN (cif->bytes) : stack); in ffi_closure_inner()
444 if (pabi->nregs > 0) in ffi_closure_inner()
446 rvalue = (void *)frame->regs[pabi->regs[0]]; in ffi_closure_inner()
448 frame->rettemp[0] = (unsigned)rvalue; in ffi_closure_inner()
455 frame->rettemp[0] = (unsigned)rvalue; in ffi_closure_inner()
459 n = cif->nargs; in ffi_closure_inner()
462 arg_types = cif->arg_types; in ffi_closure_inner()
466 size_t z = ty->size; in ffi_closure_inner()
467 int t = ty->type; in ffi_closure_inner()
472 if (t != FFI_TYPE_FLOAT && narg_reg < pabi->nregs) in ffi_closure_inner()
473 valp = &frame->regs[pabi->regs[narg_reg++]]; in ffi_closure_inner()
474 else if (dir < 0) in ffi_closure_inner()
476 argp -= 4; in ffi_closure_inner()
491 if (t == FFI_TYPE_STRUCT && ty->alignment >= 16) in ffi_closure_inner()
495 as 64-bit integer or struct, all following integer paramters in ffi_closure_inner()
503 if (dir < 0) in ffi_closure_inner()
507 argp -= za; in ffi_closure_inner()
521 frame->fun (cif, rvalue, avalue, frame->user_data); in ffi_closure_inner()
524 return flags + (cif->bytes << X86_RET_POP_SHIFT); in ffi_closure_inner()
536 char *tramp = closure->tramp; in ffi_prep_closure_loc()
537 void (*dest)(void); in ffi_prep_closure_loc() local
540 switch (cif->abi) in ffi_prep_closure_loc()
546 dest = ffi_closure_i386; in ffi_prep_closure_loc()
550 dest = ffi_closure_STDCALL; in ffi_prep_closure_loc()
553 dest = ffi_closure_REGISTER; in ffi_prep_closure_loc()
564 /* jmp dest */ in ffi_prep_closure_loc()
566 *(unsigned *)(tramp + 6) = (unsigned)dest - ((unsigned)codeloc + 10); in ffi_prep_closure_loc()
568 closure->cif = cif; in ffi_prep_closure_loc()
569 closure->fun = fun; in ffi_prep_closure_loc()
570 closure->user_data = user_data; in ffi_prep_closure_loc()
583 void (*dest)(void); in ffi_prep_go_closure() local
585 switch (cif->abi) in ffi_prep_go_closure()
589 dest = ffi_go_closure_ECX; in ffi_prep_go_closure()
593 dest = ffi_go_closure_EAX; in ffi_prep_go_closure()
597 dest = ffi_go_closure_STDCALL; in ffi_prep_go_closure()
604 closure->tramp = dest; in ffi_prep_go_closure()
605 closure->cif = cif; in ffi_prep_go_closure()
606 closure->fun = fun; in ffi_prep_go_closure()
611 /* ------- Native raw API support -------------------------------- */
625 char *tramp = closure->tramp; in ffi_prep_raw_closure_loc()
626 void (*dest)(void); in ffi_prep_raw_closure_loc() local
633 for (i = cif->nargs-1; i >= 0; i--) in ffi_prep_raw_closure_loc()
634 switch (cif->arg_types[i]->type) in ffi_prep_raw_closure_loc()
641 switch (cif->abi) in ffi_prep_raw_closure_loc()
644 dest = ffi_closure_raw_THISCALL; in ffi_prep_raw_closure_loc()
647 dest = ffi_closure_raw_SYSV; in ffi_prep_raw_closure_loc()
657 /* jmp dest */ in ffi_prep_raw_closure_loc()
659 *(unsigned *)(tramp + 6) = (unsigned)dest - ((unsigned)codeloc + 10); in ffi_prep_raw_closure_loc()
661 closure->cif = cif; in ffi_prep_raw_closure_loc()
662 closure->fun = fun; in ffi_prep_raw_closure_loc()
663 closure->user_data = user_data; in ffi_prep_raw_closure_loc()
678 flags = cif->flags; in ffi_raw_call()
679 cabi = cif->abi; in ffi_raw_call()
694 rsize = cif->rtype->size; in ffi_raw_call()
703 bytes = STACK_ALIGN (cif->bytes); in ffi_raw_call()
710 frame->fn = fn; in ffi_raw_call()
711 frame->flags = flags; in ffi_raw_call()
712 frame->rvalue = rvalue; in ffi_raw_call()
719 if (pabi->nregs > 0) in ffi_raw_call()
721 frame->regs[pabi->regs[0]] = (unsigned)rvalue; in ffi_raw_call()
729 bytes -= sizeof(void *); in ffi_raw_call()
733 arg_types = cif->arg_types; in ffi_raw_call()
734 for (i = 0, n = cif->nargs; narg_reg < pabi->nregs && i < n; i++) in ffi_raw_call()
737 size_t z = ty->size; in ffi_raw_call()
738 int t = ty->type; in ffi_raw_call()
743 frame->regs[pabi->regs[narg_reg++]] = val; in ffi_raw_call()
753 bytes -= z; in ffi_raw_call()