comparison dyncall/dyncall_call_x64.S @ 533:71c884e610f0

- integration of patches from Raphael Luba, Thekla, Inc.: * integration of aggregate-by-value (struct, union) support patch for x64 (win and sysv) * windows/x64 asm additions to specify how stack unwinds (help for debuggers, exception handling, etc.) * see Changelog for details - new calling convention modes for thiscalls (platform agnostic, was specific before) * new signature character for platform agnostic thiscalls ('*' / DC_SIGCHAR_CC_THISCALL) - dcCallF(), dcVCallF(), dcArgF() and dcVArgF(): * added support for aggregates-by-value (wasn't part of patch) * change that those functions don't implicitly call dcReset() anymore, which was unflexible (breaking change) - added macros to feature test implementation for aggregate-by-value and syscall support - changed libdyncall_s.lib and libdyncallback_s.lib order in callback test makefiles, as some toolchains are picky about order - doc: * man page updates to describe aggregate interface * manual overview changes to highlight platforms with aggregate-by-value support - test/plain: replaced tests w/ old/stale sctruct interface with new aggregate one
author Tassilo Philipp
date Thu, 21 Apr 2022 13:35:47 +0200
parents ab2d78e48ca2
children
comparison
equal deleted inserted replaced
532:d4bf63ab9164 533:71c884e610f0
82 POP(RBX) /* Restore RBX. */ 82 POP(RBX) /* Restore RBX. */
83 POP(RBP) /* Pseudo-epilog. */ 83 POP(RBP) /* Pseudo-epilog. */
84 RET() 84 RET()
85 END_PROC(dcCall_x64_sysv) 85 END_PROC(dcCall_x64_sysv)
86 86
87 /* wrapper for dcCall_x64_sysv to grab 4 regs used to return (small) aggregate by value */
88 GLOBAL(dcCall_x64_sysv_aggr)
89 BEGIN_PROC(dcCall_x64_sysv_aggr)
90 PUSH(R9) /* preserve ptr to copy retval regs to (also realigns stack) */
91 CALL(CSYM(dcCall_x64_sysv)) /* params (in regs) passed-through to next call, as-is */
92 POP(R9) /* get ptr to retval regs back */
93
94 /* copy regs holding aggregate data to provided space (pointed to by r12) */
95 MOV(RAX, QWORD(R9,0))
96 MOV(RDX, QWORD(R9,8))
97 MOVSD(XMM0, QWORD(R9,16))
98 MOVSD(XMM1, QWORD(R9,24))
99
100 RET()
101 END_PROC(dcCall_x64_sysv_aggr)
102
87 /*--------------------------------------------------------------------------- 103 /*---------------------------------------------------------------------------
88 104
89 Call Kernel for x64 Win64 105 Call Kernel for x64 Win64
90 106
91 Input: 107 Input:
94 R8 : pointer to arguments of integral/pointer type to be passed via registers 110 R8 : pointer to arguments of integral/pointer type to be passed via registers
95 R9 : target function pointer 111 R9 : target function pointer
96 112
97 */ 113 */
98 114
99 GLOBAL(dcCall_x64_win64) 115 GLOBAL_FRAME(dcCall_x64_win64)
100 BEGIN_PROC(dcCall_x64_win64) 116 FRAME_BEGIN_PROC(dcCall_x64_win64)
101 117
102 PUSH(RBP) /* Pseudo-prolog - preserve RBP. */ 118 PUSH(RBP) /* Pseudo-prolog - preserve RBP. */
119 FRAME_PUSH_REG(RBP)
103 PUSH(RSI) /* Preserve RSI and RDI. */ 120 PUSH(RSI) /* Preserve RSI and RDI. */
121 FRAME_PUSH_REG(RSI)
104 PUSH(RDI) 122 PUSH(RDI)
123 FRAME_PUSH_REG(RDI)
105 124
106 MOV(RSP,RBP) /* Store stack pointer in RBP. */ 125 MOV(RSP,RBP) /* Store stack pointer in RBP. */
126 FRAME_SET(0, RBP)
127 FRAME_ENDPROLOG()
107 128
108 ADD(LIT(15),RCX) /* Align stack size to 16 bytes. */ 129 ADD(LIT(15),RCX) /* Align stack size to 16 bytes. */
109 AND(LIT(-16),RCX) 130 AND(LIT(-16),RCX)
110 SUB(RCX,RSP) /* Setup stack frame by subtracting the size of the arguments. */ 131 SUB(RCX,RSP) /* Setup stack frame by subtracting the size of the arguments. */
111 132
140 POP(RBP) /* Pseudo-epilog. */ 161 POP(RBP) /* Pseudo-epilog. */
141 162
142 RET() 163 RET()
143 164
144 END_PROC(dcCall_x64_win64) 165 END_PROC(dcCall_x64_win64)
166
167 GLOBAL(dcCall_x64_win64_aggr)
168 BEGIN_PROC(dcCall_x64_win64_aggr)
169 SUB(LIT(8), RSP) /* Re-align the stack */
170 CALL(CSYM(dcCall_x64_win64)) /* params (in regs) passed-through to next call, as-is */
171 ADD(LIT(8), RSP) /* Restore the stack pointer */
172
173 MOV(QWORD(RSP, 40), R8) /* ptr to aggregate mem -> R8 (passed as only stack arg, 0x40 to skip ret addr and spill area */
174 MOV(RAX, QWORD(R8, 0)) /* Copy aggregate value to memory */
175
176 RET()
177 END_PROC(dcCall_x64_win64_aggr)
145 178
146 /*--------------------------------------------------------------------------- 179 /*---------------------------------------------------------------------------
147 180
148 Call Kernel for x64 System V syscalls 181 Call Kernel for x64 System V syscalls
149 182
168 201
169 END_PROC(dcCall_x64_syscall_sysv) 202 END_PROC(dcCall_x64_syscall_sysv)
170 203
171 END_ASM 204 END_ASM
172 205
206 /* vim: set ts=8: */
207