1 2#ifdef _M_ARM 3 4#include <kxarm.h> 5 6 LEAF_ENTRY call_method 7 __assertfail 8 LEAF_END call_method 9 10#elif defined(_M_AMD64) 11 12#include <asm.inc> 13.code64 14 15EXTERN __chkstk:PROC 16 17// DWORD_PTR 18// call_method( 19// void *func, // rcx 20// int nb_args, // edx 21// const DWORD_PTR *args ); 22PUBLIC call_method 23FUNC call_method 24 push rbp 25 .PUSHREG rbp 26 push rsi 27 .PUSHREG rsi 28 push rdi 29 .PUSHREG rdi 30 mov rbp, rsp 31 .SETFRAME rbp, 0 32 .ENDPROLOG 33 34 // We need at least space for 4 parameters (home space) 35 mov rax, 4 36 cmp rdx, rax 37 cmovg rax, rdx 38 39 // Allocate dynamic stack space (aligned to 16 bytes) 40 lea rax, [rax * 8 + 15] 41 and rax, HEX(0FFFFFFFFFFFFFFF0) 42 call __chkstk 43 sub rsp, rax 44 45 // Save function pointer in rax 46 mov rax, rcx 47 48 // Copy parameters to the stack 49 mov rcx, rdx 50 mov rdi, rsp 51 mov rsi, r8 52 rep movsq 53 54 // Set up parameter registers for the call 55 mov rcx, qword ptr [rsp + 0] 56 mov rdx, qword ptr [rsp + 8] 57 mov r8, qword ptr [rsp + 16] 58 mov r9, qword ptr [rsp + 24] 59 movq xmm0, qword ptr [rsp + 0] 60 movq xmm1, qword ptr [rsp + 8] 61 movq xmm2, qword ptr [rsp + 16] 62 movq xmm3, qword ptr [rsp + 24] 63 call rax 64 65 lea rsp, [rbp] 66 pop rdi 67 pop rsi 68 pop rbp 69 ret 70ENDFUNC 71 72PUBLIC call_double_method 73call_double_method: 74 jmp call_method 75 76#else 77 78#include <asm.inc> 79.code32 80 81PUBLIC _call_method 82_call_method: 83 push ebp 84 mov ebp, esp 85 push esi 86 push edi 87 mov edx, dword ptr ds:[ebp + 12] 88 mov edi, esp 89 shl edx, 2 90 jz cm1 91 sub edi, edx 92 and edi, HEX(0FFFFFFF0) 93 mov esp, edi 94 mov ecx, dword ptr ds:[ebp + 12] 95 mov esi, dword ptr ds:[ebp + 16] 96 cld 97 rep movsd 98cm1: 99 call dword ptr ds:[ebp + 8] 100 sub edi, esp 101 mov ecx,[ebp + 20] 102 mov [ecx], edi 103 lea esp, [ebp - 8] 104 pop edi 105 pop esi 106 pop ebp 107 ret 108 109PUBLIC _call_double_method 110_call_double_method: 111 jmp _call_method 112 113#endif 114 115 END 116