annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /*
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 Package: dyncall
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 Library: dyncall
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
5 File: dyncall/dyncall_call_x64.S
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 Description: All x64 abi call kernel implementation
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 License:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
9 Copyright (c) 2007-2020 Daniel Adler <dadler@uni-goettingen.de>,
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 Tassilo Philipp <tphilipp@potion-studios.com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
28 #include "../portasm/portasm-x64.S"
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 BEGIN_ASM
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 /*---------------------------------------------------------------------------
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
33
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34 Call Kernel for x64 System V
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
35
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
36 Input:
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
37 RDI : size of arguments to be passed via stack
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
38 RSI : pointer to arguments to be passed via the stack
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
39 RDX : pointer to arguments of integral/pointer type to be passed via registers
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
40 RCX : pointer to arguments of floating point type to be passed via registers
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
41 R8 : target function pointer
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42 Notes:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43 RSP+8: is always 16-byte aligned (32-byte align if __m256 is used)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46 GLOBAL(dcCall_x64_sysv)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47 BEGIN_PROC(dcCall_x64_sysv)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48 PUSH(RBP) /* Pseudo-prolog - preserve RBP. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
49 PUSH(RBX) /* Preserve RBX and store pointer to function in it. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50 MOV(RSP,RBP) /* Store stack pointer in RBP. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51 MOV(R8 ,RBX)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52 MOVSD(QWORD(RCX,0) ,XMM0) /* Copy first 8 floats to XMM0-XMM7. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53 MOVSD(QWORD(RCX,8) ,XMM1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54 MOVSD(QWORD(RCX,16),XMM2)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55 MOVSD(QWORD(RCX,24),XMM3)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
56 MOVSD(QWORD(RCX,32),XMM4)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57 MOVSD(QWORD(RCX,40),XMM5)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58 MOVSD(QWORD(RCX,48),XMM6)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59 MOVSD(QWORD(RCX,56),XMM7)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 ADD(LIT(31),RDI) /* Align stack to 32-byte. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62 AND(LIT(-32),RDI)
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
63 ADD(LIT(8),RDI) /* Adjust by 8-byte for the return-address. */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 SUB(RDI,RSP) /* Setup stack frame by subtracting the size of arguments. */
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
65
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
66 MOV(RDI,RCX) /* Store number of bytes to copy to stack in RCX (for rep movsb). */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67 MOV(RSP,RDI) /* Store pointer to beginning of stack arguments in RDI (for rep movsb). */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
69 REP(MOVSB) /* copy bytes (@@@ should be optimized, movq?). */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71 MOV(QWORD(RDX,0),RDI) /* copy first six int/pointer arguments to RDI, RSI, RDX, RCX, R8, R9. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
72 MOV(QWORD(RDX,8),RSI)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
73 MOV(QWORD(RDX,24),RCX)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
74 MOV(QWORD(RDX,32),R8)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75 MOV(QWORD(RDX,40),R9)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76 MOV(QWORD(RDX,16),RDX) /* Set RDX last to not overwrite it to soon. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
77
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
78 MOVB(LIT(8),AL) /* Put upper bound of number of used xmm registers in AL. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
79 CALL_REG(RBX) /* Call function. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
80
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
81 MOV(RBP,RSP) /* Restore stack pointer. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
82 POP(RBX) /* Restore RBX. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
83 POP(RBP) /* Pseudo-epilog. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
84 RET()
183
e38d33230b09 - typo fix in x64 asm end_proc use (only affected masm)
Tassilo Philipp
parents: 166
diff changeset
85 END_PROC(dcCall_x64_sysv)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
86
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
87 /* wrapper for dcCall_x64_sysv to grab 4 regs used to return (small) aggregate by value */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
88 GLOBAL(dcCall_x64_sysv_aggr)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
89 BEGIN_PROC(dcCall_x64_sysv_aggr)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
90 PUSH(R9) /* preserve ptr to copy retval regs to (also realigns stack) */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
91 CALL(CSYM(dcCall_x64_sysv)) /* params (in regs) passed-through to next call, as-is */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
92 POP(R9) /* get ptr to retval regs back */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
93
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
94 /* copy regs holding aggregate data to provided space (pointed to by r12) */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
95 MOV(RAX, QWORD(R9,0))
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
96 MOV(RDX, QWORD(R9,8))
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
97 MOVSD(XMM0, QWORD(R9,16))
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
98 MOVSD(XMM1, QWORD(R9,24))
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
99
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
100 RET()
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
101 END_PROC(dcCall_x64_sysv_aggr)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
102
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
103 /*---------------------------------------------------------------------------
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
104
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
105 Call Kernel for x64 Win64
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
106
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
107 Input:
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
108 RCX : size of arguments to be passed via stack
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
109 RDX : pointer to arguments to be passed via the stack
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
110 R8 : pointer to arguments of integral/pointer type to be passed via registers
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
111 R9 : target function pointer
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
112
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
113 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
114
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
115 GLOBAL_FRAME(dcCall_x64_win64)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
116 FRAME_BEGIN_PROC(dcCall_x64_win64)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
117
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
118 PUSH(RBP) /* Pseudo-prolog - preserve RBP. */
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
119 FRAME_PUSH_REG(RBP)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
120 PUSH(RSI) /* Preserve RSI and RDI. */
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
121 FRAME_PUSH_REG(RSI)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
122 PUSH(RDI)
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
123 FRAME_PUSH_REG(RDI)
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
124
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
125 MOV(RSP,RBP) /* Store stack pointer in RBP. */
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
126 FRAME_SET(0, RBP)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
127 FRAME_ENDPROLOG()
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
128
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
129 ADD(LIT(15),RCX) /* Align stack size to 16 bytes. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
130 AND(LIT(-16),RCX)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
131 SUB(RCX,RSP) /* Setup stack frame by subtracting the size of the arguments. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
132
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
133
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
134 MOV(RDX, RSI) /* Let RSI point to the arguments. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
135 MOV(RSP, RDI) /* Store pointer to beginning of stack arguments in RDI (for rep movsb). */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
136 MOV(R9, RAX) /* Put function address in RAX. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
137
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
138 REP(MOVSB) /* @@@ should be optimized (e.g. movq) */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
139
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
140 MOV(QWORD(R8,0),RCX) /* Copy first four arguments to RCX, RDX, R9, R8 ( and XMM0-XMM3. ) */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
141 MOV(QWORD(R8,8),RDX)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
142 MOV(QWORD(R8,24),R9)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
143 MOV(QWORD(R8,16),R8)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
144
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
145 MOVD(RCX, XMM0)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
146 MOVD(RDX, XMM1)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
147 MOVD(R8, XMM2)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
148 MOVD(R9, XMM3)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
149
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
150 PUSH(R9) /* Push first four arguments onto the stack preserve area. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
151 PUSH(R8)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
152 PUSH(RDX)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
153 PUSH(RCX)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
154
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
155 CALL_REG(RAX) /* Invoke function. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
156
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
157 MOV(RBP, RSP) /* Restore stack pointer (such that we can pop the preserved vALues). */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
158
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
159 POP(RDI) /* Restore RSI and RDI. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
160 POP(RSI)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
161 POP(RBP) /* Pseudo-epilog. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
162
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
163 RET()
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
164
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
165 END_PROC(dcCall_x64_win64)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
166
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
167 GLOBAL(dcCall_x64_win64_aggr)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
168 BEGIN_PROC(dcCall_x64_win64_aggr)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
169 SUB(LIT(8), RSP) /* Re-align the stack */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
170 CALL(CSYM(dcCall_x64_win64)) /* params (in regs) passed-through to next call, as-is */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
171 ADD(LIT(8), RSP) /* Restore the stack pointer */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
172
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
173 MOV(QWORD(RSP, 40), R8) /* ptr to aggregate mem -> R8 (passed as only stack arg, 0x40 to skip ret addr and spill area */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
174 MOV(RAX, QWORD(R8, 0)) /* Copy aggregate value to memory */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
175
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
176 RET()
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
177 END_PROC(dcCall_x64_win64_aggr)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
178
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
179 /*---------------------------------------------------------------------------
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
180
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
181 Call Kernel for x64 System V syscalls
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
182
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
183 Input:
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
184 RDI : pointer to arguments
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
185 RSI : syscall id
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
186
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
187 */
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
188
341
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
189 GLOBAL(dcCall_x64_syscall_sysv)
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
190 BEGIN_PROC(dcCall_x64_syscall_sysv)
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
191
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
192 MOV(RSI,RAX) /* load system call id. */
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
193 MOV(QWORD(RDI,40),R9) /* copy first six int/pointer arguments to RDI, RSI, RDX, R10, R8, R9. */
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
194 MOV(QWORD(RDI,32),R8)
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
195 MOV(QWORD(RDI,24),R10)
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
196 MOV(QWORD(RDI,16),RDX)
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
197 MOV(QWORD(RDI,8),RSI)
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
198 MOV(QWORD(RDI,0),RDI) /* Set RDI last to not overwrite it to soon. */
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
199 SYSCALL
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
200 RET()
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
201
341
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
202 END_PROC(dcCall_x64_syscall_sysv)
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
203
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
204 END_ASM
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
205
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
206 /* vim: set ts=8: */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 341
diff changeset
207