annotate dyncall/dyncall_callvm_x64.c @ 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 ddfb9577a00e
children ba70fb631bea
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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 File: dyncall/dyncall_callvm_x64.c
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 Description:
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: 466
diff changeset
9 Copyright (c) 2007-2022 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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 /* MS Windows x64 calling convention, AMD64 SystemV ABI. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 #include "dyncall_callvm_x64.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33 #include "dyncall_alloc.h"
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
34 #include "dyncall_aggregate.h"
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
35
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
36 #include <stdint.h>
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
37 #include <string.h>
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
38 #include <assert.h>
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
366
ad5f9803f52f - removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents: 347
diff changeset
41 /*
ad5f9803f52f - removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents: 347
diff changeset
42 ** x64 SystemV calling convention
ad5f9803f52f - removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents: 347
diff changeset
43 **
ad5f9803f52f - removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents: 347
diff changeset
44 ** - hybrid return-type call (bool ... pointer)
ad5f9803f52f - removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents: 347
diff changeset
45 **
ad5f9803f52f - removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents: 347
diff changeset
46 */
ad5f9803f52f - removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents: 347
diff changeset
47
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
48 #if defined(DC_UNIX)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
49 extern void dcCall_x64_sysv(DCsize stacksize, DCpointer stackdata, DCpointer regdata_i, DCpointer regdata_f, DCpointer target);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
50 extern void dcCall_x64_sysv_aggr(DCsize stacksize, DCpointer stackdata, DCpointer regdata_i, DCpointer regdata_f, DCpointer target, DCpointer ret_regs);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
51 #else
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
52 extern void dcCall_x64_win64(DCsize stacksize, DCpointer stackdata, DCpointer regdata, DCpointer target);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
53 extern void dcCall_x64_win64_aggr(DCsize stacksize, DCpointer stackdata, DCpointer regdata, DCpointer target, DCpointer aggr_mem);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
54 #endif
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
55 extern void dcCall_x64_syscall_sysv(DCpointer argdata, DCpointer target);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
56
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
57
366
ad5f9803f52f - removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents: 347
diff changeset
58
ad5f9803f52f - removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents: 347
diff changeset
59
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 static void dc_callvm_free_x64(DCCallVM* in_self)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62 dcFreeMem(in_self);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
65
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
66 static void dc_callvm_reset_x64(DCCallVM* in_self)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68 DCCallVM_x64* self = (DCCallVM_x64*)in_self;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69 dcVecReset(&self->mVecHead);
84
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
70 self->mRegCount.i = self->mRegCount.f = 0;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
71 self->mAggrReturnReg = -1;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
72 #if defined(DC_WINDOWS)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
73 self->mpAggrVecCopies = ((DCchar*)dcVecData(&self->mVecHead)) + self->mVecHead.mTotal;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
74 #endif
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
77
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
78
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
79
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
80 static void dc_callvm_argLongLong_x64(DCCallVM* in_self, DClonglong x)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
81 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
82 /* A long long always has 64 bits on the supported x64 platforms (lp64 on unix and llp64 on windows). */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
83 DCCallVM_x64* self = (DCCallVM_x64*)in_self;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
84
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
85 self->mRegCount.i += (self->mRegCount.i == self->mAggrReturnReg);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
86
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
87 if(self->mRegCount.i < numIntRegs)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
88 self->mRegData.i[self->mRegCount.i++] = x;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
89 else
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
90 dcVecAppend(&self->mVecHead, &x, sizeof(DClonglong));
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
91 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
92
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
93
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
94 static void dc_callvm_argBool_x64(DCCallVM* in_self, DCbool x)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
95 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
96 dc_callvm_argLongLong_x64(in_self, (DClonglong)x);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
97 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
98
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
99
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
100 static void dc_callvm_argChar_x64(DCCallVM* in_self, DCchar x)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
101 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
102 dc_callvm_argLongLong_x64(in_self, x);
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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
106 static void dc_callvm_argShort_x64(DCCallVM* in_self, DCshort x)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
107 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
108 dc_callvm_argLongLong_x64(in_self, x);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
109 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
110
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
111
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
112 static void dc_callvm_argInt_x64(DCCallVM* in_self, DCint x)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
113 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
114 dc_callvm_argLongLong_x64(in_self, x);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
115 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
116
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
117
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
118 static void dc_callvm_argLong_x64(DCCallVM* in_self, DClong x)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
119 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
120 dc_callvm_argLongLong_x64(in_self, x);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
121 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
122
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
123
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
124 static void dc_callvm_argDouble_x64(DCCallVM* in_self, DCdouble x)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
125 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
126 DCCallVM_x64* self = (DCCallVM_x64*)in_self;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
127
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
128 #if defined(DC_WINDOWS)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
129 self->mRegCount.f += (self->mRegCount.f == self->mAggrReturnReg);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
130 #endif
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
131
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
132 if(self->mRegCount.f < numFloatRegs)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
133 self->mRegData.f[self->mRegCount.f++] = x;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
134 else
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
135 dcVecAppend(&self->mVecHead, &x, sizeof(DCdouble));
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
136 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
137
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
138
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
139 static void dc_callvm_argFloat_x64(DCCallVM* in_self, DCfloat x)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
140 {
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
141 /* Although not promoted to doubles, floats are stored with 64bits in this API.*/
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
142 union {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
143 DCdouble d;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
144 DCfloat f;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
145 } f;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
146 f.f = x;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
147
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
148 dc_callvm_argDouble_x64(in_self, f.d);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
149 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
150
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
151
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
152 static void dc_callvm_argPointer_x64(DCCallVM* in_self, DCpointer x)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
153 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
154 DCCallVM_x64* self = (DCCallVM_x64*)in_self;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
155
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
156 self->mRegCount.i += (self->mRegCount.i == self->mAggrReturnReg);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
157
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
158 if(self->mRegCount.i < numIntRegs)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
159 *(DCpointer*)&self->mRegData.i[self->mRegCount.i++] = x;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
160 else
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
161 dcVecAppend(&self->mVecHead, &x, sizeof(DCpointer));
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
162 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
163
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
164
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
165 static void dc_callvm_argAggr_x64(DCCallVM* in_self, const DCaggr* ag, const void* x)
0
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: 466
diff changeset
167 int i;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
168 DCCallVM_x64* self = (DCCallVM_x64*)in_self;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
169
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
170 if (!ag) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
171 /* non-trivial aggrs (C++) are passed via pointer (win and sysv callconv),
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
172 * copy has to be provided by user, as dyncall cannot do such copies*/
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
173 dc_callvm_argPointer_x64(in_self, (DCpointer)x);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
174 return;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
175 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
176
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
177 #if defined(DC_UNIX)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
178 DCRegCount_x64 n_regs = { self->mRegCount.i, self->mRegCount.f };
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
179
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
180 if(ag->sysv_classes[0] != SYSVC_MEMORY) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
181 /* reclassify aggr w/ respect to remaining regs, might need to pass it all via the stack */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
182 for(i=0; ag->sysv_classes[i] && i<DC_SYSV_MAX_NUM_CLASSES; ++i) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
183 DCuchar clz = ag->sysv_classes[i];
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
184 n_regs.i += (clz == SYSVC_INTEGER);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
185 n_regs.f += (clz == SYSVC_SSE);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
186 /* @@@AGGR implement when implementing x87 types */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
187 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
188 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
189
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
190 if(ag->sysv_classes[0] == SYSVC_MEMORY || (n_regs.i > numIntRegs) || (n_regs.f > numFloatRegs))
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
191 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
192 dcVecAppend(&self->mVecHead, x, ag->size);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
193 dcVecSkip(&self->mVecHead, (ag->size + (sizeof(DClonglong)-1) & -sizeof(DClonglong)) - ag->size); /* realign to qword */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
194 return;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
195 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
196
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
197 for(i=0; ag->sysv_classes[i] && i<DC_SYSV_MAX_NUM_CLASSES; ++i)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
198 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
199 switch (ag->sysv_classes[i]) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
200 case SYSVC_INTEGER: dc_callvm_argLongLong_x64(in_self, ((DClonglong*)x)[i]); break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
201 case SYSVC_SSE: dc_callvm_argDouble_x64 (in_self, ((DCdouble *)x)[i]); break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
202 /* @@@AGGR implement when implementing x87 types */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
203 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
204 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
205
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
206 #else
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
207
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
208 switch (ag->size) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
209 case 1: dc_callvm_argChar_x64 (in_self, *(DCchar *)x); break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
210 case 2: dc_callvm_argShort_x64 (in_self, *(DCshort *)x); break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
211 case 4: dc_callvm_argLong_x64 (in_self, *(DClong *)x); break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
212 case 8: dc_callvm_argLongLong_x64(in_self, *(DClonglong*)x); break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
213 default:
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
214 /* pass the aggr indirectly via hidden pointer; requires caller-made copy
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
215 * to mimic pass-by-value semantics (or a call that modifies the param
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
216 * would corrupt the source aggr)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
217 * place those copies at the end of the param vector (aligned to 16b for
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
218 * this calling convention); it's a bit of a hack, but should be safe: in
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
219 * any case the vector has to be big enough to hold all params */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
220 self->mpAggrVecCopies = (void*)((intptr_t)((DCchar*)self->mpAggrVecCopies - ag->size) & -16);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
221 x = memcpy(self->mpAggrVecCopies, x, ag->size);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
222 dc_callvm_argPointer_x64(in_self, (DCpointer)x);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
223 break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
224 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
225 #endif
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
226 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
227
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
228
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
229 /* Call. */
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
230 static void dc_callvm_call_x64(DCCallVM* in_self, DCpointer target)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
231 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
232 DCCallVM_x64* self = (DCCallVM_x64*)in_self;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
233 #if defined(DC_UNIX)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
234 dcCall_x64_sysv(
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
235 #else
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
236 dcCall_x64_win64(
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
237 #endif
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
238 dcVecSize(&self->mVecHead), /* Size of stack data. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
239 dcVecData(&self->mVecHead), /* Pointer to stack arguments. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
240 self->mRegData.i, /* Pointer to register arguments (ints on SysV). */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
241 #if defined(DC_UNIX)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
242 self->mRegData.f, /* Pointer to floating point register arguments. */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
243 #endif
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
244 target
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
245 );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
246 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
247
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
248
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
249 static void dc_callvm_begin_aggr_x64(DCCallVM* in_self, const DCaggr *ag)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
250 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
251 DCCallVM_x64* self = (DCCallVM_x64*)in_self;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
252
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
253 assert(self->mRegCount.i == 0 && self->mRegCount.f == 0 && "dc_callvm_begin_aggr_x64 should be called before any function arguments are declared");
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
254 #if defined(DC_UNIX)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
255 if (!ag || (ag->sysv_classes[0] == SYSVC_MEMORY)) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
256 #else
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
257 if (!ag || ag->size > 8) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
258 #endif
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
259 /* pass pointer to aggregate as hidden first argument */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
260 self->mAggrReturnReg = 0;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
261 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
262 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
263
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
264
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
265 #if defined(DC_WINDOWS)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
266 static void dc_callvm_begin_aggr_x64_win64_this(DCCallVM* in_self, const DCaggr *ag)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
267 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
268 DCCallVM_x64* self = (DCCallVM_x64*)in_self;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
269
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
270 assert(self->mRegCount.i == 0 && self->mRegCount.f == 0 && "dc_callvm_begin_aggr_x64_win64_this should be called before any function arguments are declared");
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
271
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
272 if (!ag || ag->size > 8) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
273 /* thiscall: this-ptr comes first, then pointer to aggregate as hidden (second) argument */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
274 self->mAggrReturnReg = 1;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
275 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
276 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
277 #endif
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
278
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
279
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
280 static void dc_callvm_call_x64_aggr(DCCallVM* in_self, DCpointer target, const DCaggr *ag, DCpointer ret)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
281 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
282 DCCallVM_x64* self = (DCCallVM_x64*)in_self;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
283
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
284 #if defined(DC_UNIX)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
285
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
286 if (self->mAggrReturnReg != -1) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
287 /* call regular dcCall_x64_sysv here, w/ pointer to the aggr in first arg */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
288 self->mRegData.i[self->mAggrReturnReg] = (int64)ret;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
289
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
290 dcCall_x64_sysv(
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
291 dcVecSize(&self->mVecHead), /* rdi: Size of stack data. */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
292 dcVecData(&self->mVecHead), /* rsi: Pointer to stack arguments. */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
293 self->mRegData.i, /* rdx: Pointer to register arguments (ints on SysV). */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
294 self->mRegData.f, /* rcx: Pointer to floating point register arguments. */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
295 target /* r8 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
296 );
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
297 } else {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
298 int i;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
299 DCchar ret_regs[32]; /* 4 qwords: 2 for ints, 2 for floats */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
300 DCchar *ret_regs_i = ret_regs+0;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
301 DCchar *ret_regs_f = ret_regs+16;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
302 DCsize st_size = ag->size;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
303 DCchar* dst = (char*)ret;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
304 dcCall_x64_sysv_aggr(
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
305 dcVecSize(&self->mVecHead), /* rdi: Size of stack data. */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
306 dcVecData(&self->mVecHead), /* rsi: Pointer to stack arguments. */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
307 self->mRegData.i, /* rdx: Pointer to register arguments (ints on SysV). */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
308 self->mRegData.f, /* rcx: Pointer to floating point register arguments. */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
309 target, /* r8 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
310 ret_regs /* r9 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
311 );
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
312 /* reassemble aggr to be returned from reg data */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
313 for(i=0; ag->sysv_classes[i] && i<DC_SYSV_MAX_NUM_CLASSES; ++i) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
314 DCchar** src;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
315 int ll = 8;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
316 switch(ag->sysv_classes[i]) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
317 case SYSVC_INTEGER: src = &ret_regs_i; break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
318 case SYSVC_SSE: src = &ret_regs_f; break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
319 /* @@@AGGR implement when implementing x87 types */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
320 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
321 while(ll-- && st_size--)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
322 *dst++ = *(*src)++;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
323 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
324 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
325
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
326 #else
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
327
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
328 if (self->mAggrReturnReg != -1) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
329 /* call regular dcCall_x64_sysv here, w/ pointer to the aggr in first arg */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
330 self->mRegData.i[self->mAggrReturnReg] = (int64)ret;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
331
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
332 dcCall_x64_win64(
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
333 dcVecSize(&self->mVecHead), /* rcx: Size of stack data. */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
334 dcVecData(&self->mVecHead), /* rdx: Pointer to stack arguments. */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
335 self->mRegData.i, /* r8: Pointer to register arguments */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
336 target /* r9 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
337 );
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
338 } else {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
339 DCchar ret_reg[8]; /* 1 qword */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
340 DCsize st_size = ag->size; /* guaranteed to be <= 8 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
341 DCchar* dst = (char*)ret;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
342 DCchar* src = ret_reg;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
343 dcCall_x64_win64_aggr(
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
344 dcVecSize(&self->mVecHead), /* rcx: Size of stack data. */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
345 dcVecData(&self->mVecHead), /* rdx: Pointer to stack arguments. */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
346 self->mRegData.i, /* r8: Pointer to register arguments */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
347 target, /* r9 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
348 ret_reg /* stack */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
349 );
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
350 while(st_size--)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
351 *dst++ = *src++;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
352 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
353
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
354 #endif
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
355 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
356
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
357
84
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
358 static void dc_callvm_mode_x64(DCCallVM* in_self, DCint mode);
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
359
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
360 DCCallVM_vt gVT_x64 =
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
361 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
362 &dc_callvm_free_x64
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
363 , &dc_callvm_reset_x64
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
364 , &dc_callvm_mode_x64
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
365 , &dc_callvm_argBool_x64
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
366 , &dc_callvm_argChar_x64
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
367 , &dc_callvm_argShort_x64
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
368 , &dc_callvm_argInt_x64
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
369 , &dc_callvm_argLong_x64
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
370 , &dc_callvm_argLongLong_x64
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
371 , &dc_callvm_argFloat_x64
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
372 , &dc_callvm_argDouble_x64
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
373 , &dc_callvm_argPointer_x64
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
374 , &dc_callvm_argAggr_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
375 , (DCvoidvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
376 , (DCboolvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
377 , (DCcharvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
378 , (DCshortvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
379 , (DCintvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
380 , (DClongvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
381 , (DClonglongvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
382 , (DCfloatvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
383 , (DCdoublevmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
384 , (DCpointervmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
385 , (DCaggrvmfunc*) &dc_callvm_call_x64_aggr
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
386 , (DCbeginaggrvmfunc*)&dc_callvm_begin_aggr_x64
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
387 };
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
388
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
389
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
390 #if defined(DC_WINDOWS)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
391 /* --- win64 thiscalls ------------------------------------------------------------- */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
392
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
393 DCCallVM_vt gVT_x64_win64_this =
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
394 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
395 &dc_callvm_free_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
396 , &dc_callvm_reset_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
397 , &dc_callvm_mode_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
398 , &dc_callvm_argBool_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
399 , &dc_callvm_argChar_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
400 , &dc_callvm_argShort_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
401 , &dc_callvm_argInt_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
402 , &dc_callvm_argLong_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
403 , &dc_callvm_argLongLong_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
404 , &dc_callvm_argFloat_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
405 , &dc_callvm_argDouble_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
406 , &dc_callvm_argPointer_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
407 , &dc_callvm_argAggr_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
408 , (DCvoidvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
409 , (DCboolvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
410 , (DCcharvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
411 , (DCshortvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
412 , (DCintvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
413 , (DClongvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
414 , (DClonglongvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
415 , (DCfloatvmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
416 , (DCdoublevmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
417 , (DCpointervmfunc*) &dc_callvm_call_x64
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
418 , (DCaggrvmfunc*) &dc_callvm_call_x64_aggr
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
419 , (DCbeginaggrvmfunc*)&dc_callvm_begin_aggr_x64_win64_this
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
420 };
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
421
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
422 #endif
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
423
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
424 /* --- syscall ------------------------------------------------------------- */
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
425
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
426 #if defined(DC_UNIX)
341
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
427 void dc_callvm_call_x64_syscall_sysv(DCCallVM* in_self, DCpointer target)
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
428 {
347
a2a42f477662 - C declaration order fix
Tassilo Philipp
parents: 341
diff changeset
429 DCCallVM_x64* self;
a2a42f477662 - C declaration order fix
Tassilo Philipp
parents: 341
diff changeset
430
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
431 /* syscalls can have up to 6 args, required to be "Only values of class INTEGER or class MEMORY" (from */
347
a2a42f477662 - C declaration order fix
Tassilo Philipp
parents: 341
diff changeset
432 /* SysV manual), so we can use self->mRegData.i directly; verify this has space for at least 6 values, though. */
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
433 assert(numIntRegs >= 6);
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
434
347
a2a42f477662 - C declaration order fix
Tassilo Philipp
parents: 341
diff changeset
435 self = (DCCallVM_x64*)in_self;
341
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
436 dcCall_x64_syscall_sysv(self->mRegData.i, target);
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
437 }
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
438
341
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
439 DCCallVM_vt gVT_x64_syscall_sysv =
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
440 {
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
441 &dc_callvm_free_x64
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
442 , &dc_callvm_reset_x64
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
443 , &dc_callvm_mode_x64
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
444 , &dc_callvm_argBool_x64
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
445 , &dc_callvm_argChar_x64
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
446 , &dc_callvm_argShort_x64
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
447 , &dc_callvm_argInt_x64
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
448 , &dc_callvm_argLong_x64
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
449 , &dc_callvm_argLongLong_x64
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
450 , &dc_callvm_argFloat_x64
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
451 , &dc_callvm_argDouble_x64
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
452 , &dc_callvm_argPointer_x64
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
453 , NULL /* argAggr */
341
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
454 , (DCvoidvmfunc*) &dc_callvm_call_x64_syscall_sysv
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
455 , (DCboolvmfunc*) &dc_callvm_call_x64_syscall_sysv
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
456 , (DCcharvmfunc*) &dc_callvm_call_x64_syscall_sysv
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
457 , (DCshortvmfunc*) &dc_callvm_call_x64_syscall_sysv
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
458 , (DCintvmfunc*) &dc_callvm_call_x64_syscall_sysv
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
459 , (DClongvmfunc*) &dc_callvm_call_x64_syscall_sysv
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
460 , (DClonglongvmfunc*) &dc_callvm_call_x64_syscall_sysv
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
461 , (DCfloatvmfunc*) &dc_callvm_call_x64_syscall_sysv
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
462 , (DCdoublevmfunc*) &dc_callvm_call_x64_syscall_sysv
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
463 , (DCpointervmfunc*) &dc_callvm_call_x64_syscall_sysv
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
464 , NULL /* callAggr */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
465 , NULL /* beginAggr */
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
466 };
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
467 #endif
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
468
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
469
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
470
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
471 /* mode */
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
472
84
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
473 static void dc_callvm_mode_x64(DCCallVM* in_self, DCint mode)
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
474 {
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
475 DCCallVM_x64* self = (DCCallVM_x64*)in_self;
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
476 DCCallVM_vt* vt;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
477
84
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
478 switch(mode) {
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
479 case DC_CALL_C_DEFAULT:
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
480 #if defined(DC_UNIX)
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
481 case DC_CALL_C_DEFAULT_THIS:
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
482 case DC_CALL_C_X64_SYSV: /* = DC_CALL_C_X64_SYSV_THIS */
84
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
483 #else
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
484 case DC_CALL_C_X64_WIN64:
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
485 #endif
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
486 case DC_CALL_C_ELLIPSIS:
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
487 case DC_CALL_C_ELLIPSIS_VARARGS:
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
488 vt = &gVT_x64;
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
489 break;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
490 #if defined(DC_WINDOWS)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
491 case DC_CALL_C_DEFAULT_THIS:
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
492 case DC_CALL_C_X64_WIN64_THIS:
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
493 vt = &gVT_x64_win64_this;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
494 break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
495 #endif
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
496 case DC_CALL_SYS_DEFAULT:
466
ddfb9577a00e introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents: 366
diff changeset
497 #if defined(DC_UNIX)
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
498 case DC_CALL_SYS_X64_SYSCALL_SYSV:
341
ab2d78e48ca2 - gen-masm
Tassilo Philipp
parents: 339
diff changeset
499 vt = &gVT_x64_syscall_sysv; break;
466
ddfb9577a00e introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents: 366
diff changeset
500 #else
339
4f9f49fb82ce - x64 SysV syscall support
Tassilo Philipp
parents: 281
diff changeset
501 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; return;
466
ddfb9577a00e introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents: 366
diff changeset
502 #endif
84
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
503 default:
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
504 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE;
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
505 return;
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
506 }
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
507 dc_callvm_base_init(&self->mInterface, vt);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
508 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
509
84
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
510 /* Public API. */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
511 DCCallVM* dcNewCallVM(DCsize size)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
512 {
84
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
513 DCCallVM_x64* p = (DCCallVM_x64*)dcAllocMem(sizeof(DCCallVM_x64)+size);
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
514
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
515 dc_callvm_mode_x64((DCCallVM*)p, DC_CALL_C_DEFAULT);
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
516
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
517 /* Since we store register parameters in DCCallVM_x64 directly, adjust the stack size. */
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
518 size -= sizeof(DCRegData_x64);
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
519 size = (((signed long)size) < 0) ? 0 : size;
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
520 dcVecInit(&p->mVecHead, size);
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
521 dc_callvm_reset_x64((DCCallVM*)p);
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
522
67961454902b - bigger cleanup in callvm code
cslag
parents: 0
diff changeset
523 return (DCCallVM*)p;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
524 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
525