annotate dyncallback/dyncall_callback_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 41e2a01cad32
children 951cbfb5020a
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: dyncallback
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 File: dyncallback/dyncall_callback_x64.S
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 Description: Callback Thunk entry for x64 (portasm version)
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
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
9 Copyright (c) 2011-2022 Daniel Adler <dadler@uni-goettingen.de>,
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
10 Tassilo Philipp <tphilipp@potion-studios.com>
0
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 /* structure sizes */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 SET(DCThunk_size,24)
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
33 SET(DCArgs_size_win64,96) /* 8 (stack_ptr) + 4 (reg_count) + 4 (pad_w) + 4 (aggr_return_register) + 4 (pad) + 8*4 (int regs) + 8 (aggrs) + 8*4 (float regs) */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
34 SET(DCArgs_size_sysv,144) /* 8 (stack_ptr) + 8 (reg_count) + 4 (aggr_return_register) + 4 (pad) + 8*6 (int regs) + 8 (aggrs) + 8*8 (float regs) */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35 SET(DCValue_size,8)
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
36 SET(DCRetRegs_SystemV_size,32)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
38 /* frame local variable offsets relative to %rbp */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40 SET(FRAME_arg0_win64,48)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41 SET(FRAME_arg0_sysv,16)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42 SET(FRAME_return,8)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43 SET(FRAME_parent,0)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
45 /* struct DCCallback layout, relative to ptr passed to functions below via RAX */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47 SET(CTX_thunk,0)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48 SET(CTX_handler,24)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
49 SET(CTX_userdata,32)
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
50 SET(CTX_aggr_ret_reg,40)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
51 SET(CTX_pad,44)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
52 SET(CTX_aggrs_pp,48)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
53 SET(DCCallback_size,56)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
56
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57 GLOBAL(dcCallback_x64_sysv)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58 BEGIN_PROC(dcCallback_x64_sysv)
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
59
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 PUSH(RBP)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 MOV(RSP,RBP)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63 /* initialize DCArgs */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
65 /* float parameters (8 registers spill to DCArgs.reg_data) */
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
66 SUB(LIT(8*8),RSP)
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
67 MOVSD(XMM7, QWORD(RSP,8*7)) /* DCArgs offset 136: float parameter 7 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
68 MOVSD(XMM6, QWORD(RSP,8*6)) /* DCArgs offset 128: float parameter 6 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
69 MOVSD(XMM5, QWORD(RSP,8*5)) /* DCArgs offset 120: float parameter 5 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
70 MOVSD(XMM4, QWORD(RSP,8*4)) /* DCArgs offset 112: float parameter 4 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
71 MOVSD(XMM3, QWORD(RSP,8*3)) /* DCArgs offset 104: float parameter 3 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
72 MOVSD(XMM2, QWORD(RSP,8*2)) /* DCArgs offset 96: float parameter 2 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
73 MOVSD(XMM1, QWORD(RSP,8*1)) /* DCArgs offset 88: float parameter 1 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
74 MOVSD(XMM0, QWORD(RSP,8*0)) /* DCArgs offset 80: float parameter 0 */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
76 /* integer parameters (6 registers spill to DCArgs.reg_data) */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
77 PUSH(R9) /* DCArgs offset 72: parameter 5 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
78 PUSH(R8) /* DCArgs offset 64: parameter 4 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
79 PUSH(RCX) /* DCArgs offset 56: parameter 3 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
80 PUSH(RDX) /* DCArgs offset 48: parameter 2 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
81 PUSH(RSI) /* DCArgs offset 40: parameter 1 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
82 PUSH(RDI) /* DCArgs offset 32: parameter 0 */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
83
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
84 MOV(QWORD(RAX, CTX_aggrs_pp), R8)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
85 PUSH(R8) /* DCArgs offset 24: **aggrs */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
86
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
87 /* get val of aggr_return_register from DCCallback struct into r8's LSBs, clear */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
88 /* MSBs, write DCarg's pad and aggr_return_register at once */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
89 MOVL(DWORD(RAX, CTX_aggr_ret_reg), R8D) /* implicitly zeroes the high bits of R8 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
90 PUSH(R8) /* DCArgs offset 16: pad=0, aggr_return_register=DCCallback.aggr_return_register */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
91 /* register counts for integer/pointer and float regs */
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
92 PUSH(LIT(0)) /* DCArgs offset 12: fcount */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
93 /* DCArgs offset 8: icount */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
94
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
95 LEA(QWORD(RBP,FRAME_arg0_sysv),RDX) /* DCArgs offset 0: *stack_ptr */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
96 PUSH(RDX)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
97
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
98 MOV(RSP,RSI) /* arg 1 RSI : DCArgs* */
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
99
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
100 /* stack space for DCValue or DCRetRegs_SysV (passed to handler as DCValue*) and padding */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
101 SUB(LIT(4*8),RSP) /* 4 qwords for DCRetRegs_SysV */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
102
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
103 /* call handler(*ctx, *args, *value, *userdata) - stack must be 16b aligned, here */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
104 MOV(RAX,RDI) /* arg 0 RDI : DCCallback* (RAX) */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
105 MOV(QWORD(RDI,CTX_userdata),RCX) /* arg 3 RCX : userdata* */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
106 MOV(RSP,RDX) /* arg 2 RDX : DCValue* */
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
107
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
108 CALL_REG(QWORD(RAX,CTX_handler))
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
109
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
110 /* get info about return type, use to select how to store reg-based retval */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
111 CMPL(LIT(-2/*see C*/), DWORD(RSP, 48)) /* rsp+48 = where r8 (aggr_return_register) was pushed */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
112
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
113 /* if retval is small aggregate via regs */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
114 JE(scalar_retval)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
115
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
116 MOV(QWORD(RSP,0),RAX)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
117 MOV(QWORD(RSP,8),RDX)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
118 MOVSD(QWORD(RSP,16),XMM0) /* @@@AGGR needed to be put in xmm in this case? @@@ also not what doc/appendix says, actually */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
119 MOVSD(QWORD(RSP,24),XMM1) /* @@@AGGR needed to be put in xmm in this case? @@@ also not what doc/appendix says, actually */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
120
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
121 /* else (retval is int, float, or ptr to aggregate) */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
122 JMP(epilog)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
123 CSYM(scalar_retval):
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
124
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
125 /* pass return type via registers, handle ints and floats */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
126 MOV(QWORD(RSP,0),RAX)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
127 MOVD(RAX,XMM0)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
128
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
129 CSYM(epilog):
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
130
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
131 MOV(RBP,RSP)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
132 POP(RBP)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
133 RET()
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
134
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
135 END_PROC(dcCallback_x64_sysv)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
136
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
137
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
138 GLOBAL_FRAME(dcCallback_x64_win64)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
139 FRAME_BEGIN_PROC(dcCallback_x64_win64)
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
140
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
141 PUSH(RBP)
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
142 FRAME_PUSH_REG(RBP)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
143 MOV(RSP,RBP)
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
144 FRAME_SET(0, RBP)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
145 FRAME_ENDPROLOG()
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
146
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
147 /* initialize DCArgs */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
148
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
149 /* float parameters (4 registers spill to DCArgs.reg_data) */
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
150 SUB(LIT(4*8),RSP)
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
151 MOVSD(XMM3, QWORD(RSP,8*3)) /* DCArgs offset 88: float parameter 3 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
152 MOVSD(XMM2, QWORD(RSP,8*2)) /* DCArgs offset 80: float parameter 2 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
153 MOVSD(XMM1, QWORD(RSP,8*1)) /* DCArgs offset 72: float parameter 1 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
154 MOVSD(XMM0, QWORD(RSP,8*0)) /* DCArgs offset 64: float parameter 0 */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
155
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
156 /* integer parameters (4 registers spill to DCArgs.reg_data) */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
157 PUSH(R9) /* DCArgs offset 56: parameter 3 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
158 PUSH(R8) /* DCArgs offset 48: parameter 2 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
159 PUSH(RDX) /* DCArgs offset 40: parameter 1 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
160 PUSH(RCX) /* DCArgs offset 32: parameter 0 */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
161
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
162 MOV(QWORD(RAX, CTX_aggrs_pp), R8)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
163 PUSH(R8) /* DCArgs offset 24: **aggrs */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
164
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
165 /* get val of aggr_return_register from DCCallback struct into r8's LSBs, clear */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
166 /* MSBs, write DCarg's pad and aggr_return_register at once */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
167 MOVL(DWORD(RAX, CTX_aggr_ret_reg), R8D) /* implicitly zeroes the high bits of R8 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
168 PUSH(R8) /* DCArgs offset 16: pad=0, aggr_return_register=DCCallback.aggr_return_register */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
169
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
170 /* register counts for integer/pointer and float regs */
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
171 PUSH(LIT(0)) /* DCArgs offset 12: pad_w */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
172 /* DCArgs offset 8: reg_count */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
173
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
174 LEA(QWORD(RBP,FRAME_arg0_win64),RDX) /* DCArgs offset 0: *stack_ptr */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
175 PUSH(RDX)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
176
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
177 MOV(RSP,RDX) /* arg 1 RDX : DCArgs* */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
178
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
179 /* space for retval (also aligns stack to 16b) */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
180 SUB(LIT(2*8),RSP)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
181
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
182 /* call handler(*ctx, *args, *value, *userdata) - stack must be 16b aligned, here */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
183 MOV(RAX,RCX) /* arg 0 RCX : DCCallback* (RAX) */
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
184 MOV(QWORD(RAX,CTX_userdata),R9) /* arg 3 R9 : userdata* */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
185 MOV(RSP,R8) /* arg 2 R8 : DCValue* */
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
186
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
187 /* spill area */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
188 SUB(LIT(4*8),RSP) /* 4 qwords for spill area */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
189
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
190 CALL_REG(QWORD(RAX,CTX_handler))
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
191
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
192 /* pass return type via registers, handle ints and floats */
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
193 MOV(QWORD(RSP,4*8),RAX)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
194 MOVD(RAX,XMM0)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
195
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
196 MOV(RBP,RSP)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
197 POP(RBP)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
198 RET()
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
199
165
572aff021627 - file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents: 0
diff changeset
200 END_PROC(dcCallback_x64_win64)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
201
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
202
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
203 END_ASM
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
204
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
205 /* vim: set ts=8: */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 402
diff changeset
206