Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_callvm_x64.c @ 553:a93bb23fca8c
win build fix
author | Tassilo Philipp |
---|---|
date | Mon, 20 Jun 2022 15:25:01 +0200 |
parents | ba70fb631bea |
children |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: dyncall | |
5 File: dyncall/dyncall_callvm_x64.c | |
6 Description: | |
7 License: | |
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 | 10 Tassilo Philipp <tphilipp@potion-studios.com> |
11 | |
12 Permission to use, copy, modify, and distribute this software for any | |
13 purpose with or without fee is hereby granted, provided that the above | |
14 copyright notice and this permission notice appear in all copies. | |
15 | |
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
23 | |
24 */ | |
25 | |
26 | |
27 | |
28 | |
29 /* MS Windows x64 calling convention, AMD64 SystemV ABI. */ | |
30 | |
31 | |
32 #include "dyncall_callvm_x64.h" | |
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 | 39 |
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 | 60 static void dc_callvm_free_x64(DCCallVM* in_self) |
61 { | |
62 dcFreeMem(in_self); | |
63 } | |
64 | |
65 | |
66 static void dc_callvm_reset_x64(DCCallVM* in_self) | |
67 { | |
68 DCCallVM_x64* self = (DCCallVM_x64*)in_self; | |
69 dcVecReset(&self->mVecHead); | |
84 | 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 | 75 } |
76 | |
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 | 80 static void dc_callvm_argLongLong_x64(DCCallVM* in_self, DClonglong x) |
81 { | |
82 /* A long long always has 64 bits on the supported x64 platforms (lp64 on unix and llp64 on windows). */ | |
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 | 87 if(self->mRegCount.i < numIntRegs) |
88 self->mRegData.i[self->mRegCount.i++] = x; | |
89 else | |
90 dcVecAppend(&self->mVecHead, &x, sizeof(DClonglong)); | |
91 } | |
92 | |
93 | |
94 static void dc_callvm_argBool_x64(DCCallVM* in_self, DCbool x) | |
95 { | |
96 dc_callvm_argLongLong_x64(in_self, (DClonglong)x); | |
97 } | |
98 | |
99 | |
100 static void dc_callvm_argChar_x64(DCCallVM* in_self, DCchar x) | |
101 { | |
102 dc_callvm_argLongLong_x64(in_self, x); | |
103 } | |
104 | |
105 | |
106 static void dc_callvm_argShort_x64(DCCallVM* in_self, DCshort x) | |
107 { | |
108 dc_callvm_argLongLong_x64(in_self, x); | |
109 } | |
110 | |
111 | |
112 static void dc_callvm_argInt_x64(DCCallVM* in_self, DCint x) | |
113 { | |
114 dc_callvm_argLongLong_x64(in_self, x); | |
115 } | |
116 | |
117 | |
118 static void dc_callvm_argLong_x64(DCCallVM* in_self, DClong x) | |
119 { | |
120 dc_callvm_argLongLong_x64(in_self, x); | |
121 } | |
122 | |
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 | 125 { |
126 DCCallVM_x64* self = (DCCallVM_x64*)in_self; | |
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 | 141 /* Although not promoted to doubles, floats are stored with 64bits in this API.*/ |
142 union { | |
143 DCdouble d; | |
144 DCfloat f; | |
145 } f; | |
146 f.f = x; | |
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 | 149 } |
150 | |
151 | |
152 static void dc_callvm_argPointer_x64(DCCallVM* in_self, DCpointer x) | |
153 { | |
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 | 158 if(self->mRegCount.i < numIntRegs) |
159 *(DCpointer*)&self->mRegData.i[self->mRegCount.i++] = x; | |
160 else | |
161 dcVecAppend(&self->mVecHead, &x, sizeof(DCpointer)); | |
162 } | |
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 | 166 { |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
167 int i; |
0 | 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) { |
546 | 171 /* non-trivial aggrs (C++) are passed via pointer (win and sysv callconv), |
172 * copy has to be provided by user, as dyncall cannot do such copies*/ | |
533
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 | 226 } |
227 | |
228 | |
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 | 231 { |
232 DCCallVM_x64* self = (DCCallVM_x64*)in_self; | |
233 #if defined(DC_UNIX) | |
234 dcCall_x64_sysv( | |
235 #else | |
236 dcCall_x64_win64( | |
237 #endif | |
238 dcVecSize(&self->mVecHead), /* Size of stack data. */ | |
239 dcVecData(&self->mVecHead), /* Pointer to stack arguments. */ | |
240 self->mRegData.i, /* Pointer to register arguments (ints on SysV). */ | |
241 #if defined(DC_UNIX) | |
242 self->mRegData.f, /* Pointer to floating point register arguments. */ | |
243 #endif | |
244 target | |
245 ); | |
246 } | |
247 | |
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 |
553 | 257 if (!ag || ag->size > 8 || /*not a power of 2?*/(ag->size & (ag->size - 1))) { |
533
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 |
546 | 272 /* thiscall: this-ptr comes first, then pointer to aggregate as hidden (second) argument */ |
273 self->mAggrReturnReg = 1; | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
274 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
275 #endif |
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 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
278 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
|
279 { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
280 DCCallVM_x64* self = (DCCallVM_x64*)in_self; |
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 #if defined(DC_UNIX) |
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 (self->mAggrReturnReg != -1) { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
285 /* 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
|
286 self->mRegData.i[self->mAggrReturnReg] = (int64)ret; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
287 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
288 dcCall_x64_sysv( |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
289 dcVecSize(&self->mVecHead), /* rdi: Size of stack data. */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
290 dcVecData(&self->mVecHead), /* rsi: Pointer to stack arguments. */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
291 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
|
292 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
|
293 target /* r8 */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
294 ); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
295 } else { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
296 int i; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
297 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
|
298 DCchar *ret_regs_i = ret_regs+0; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
299 DCchar *ret_regs_f = ret_regs+16; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
300 DCsize st_size = ag->size; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
301 DCchar* dst = (char*)ret; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
302 dcCall_x64_sysv_aggr( |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
303 dcVecSize(&self->mVecHead), /* rdi: Size of stack data. */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
304 dcVecData(&self->mVecHead), /* rsi: Pointer to stack arguments. */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
305 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
|
306 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
|
307 target, /* r8 */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
308 ret_regs /* r9 */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
309 ); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
310 /* reassemble aggr to be returned from reg data */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
311 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
|
312 DCchar** src; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
313 int ll = 8; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
314 switch(ag->sysv_classes[i]) { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
315 case SYSVC_INTEGER: src = &ret_regs_i; break; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
316 case SYSVC_SSE: src = &ret_regs_f; break; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
317 /* @@@AGGR implement when implementing x87 types */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
318 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
319 while(ll-- && st_size--) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
320 *dst++ = *(*src)++; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
321 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
322 } |
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 #else |
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 if (self->mAggrReturnReg != -1) { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
327 /* 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
|
328 self->mRegData.i[self->mAggrReturnReg] = (int64)ret; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
329 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
330 dcCall_x64_win64( |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
331 dcVecSize(&self->mVecHead), /* rcx: Size of stack data. */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
332 dcVecData(&self->mVecHead), /* rdx: Pointer to stack arguments. */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
333 self->mRegData.i, /* r8: Pointer to register arguments */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
334 target /* r9 */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
335 ); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
336 } else { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
337 DCchar ret_reg[8]; /* 1 qword */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
338 DCsize st_size = ag->size; /* guaranteed to be <= 8 */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
339 DCchar* dst = (char*)ret; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
340 DCchar* src = ret_reg; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
341 dcCall_x64_win64_aggr( |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
342 dcVecSize(&self->mVecHead), /* rcx: Size of stack data. */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
343 dcVecData(&self->mVecHead), /* rdx: Pointer to stack arguments. */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
344 self->mRegData.i, /* r8: Pointer to register arguments */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
345 target, /* r9 */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
346 ret_reg /* stack */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
347 ); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
348 while(st_size--) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
349 *dst++ = *src++; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
350 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
351 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
352 #endif |
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 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
355 |
84 | 356 static void dc_callvm_mode_x64(DCCallVM* in_self, DCint mode); |
357 | |
0 | 358 DCCallVM_vt gVT_x64 = |
359 { | |
360 &dc_callvm_free_x64 | |
361 , &dc_callvm_reset_x64 | |
362 , &dc_callvm_mode_x64 | |
363 , &dc_callvm_argBool_x64 | |
364 , &dc_callvm_argChar_x64 | |
339 | 365 , &dc_callvm_argShort_x64 |
0 | 366 , &dc_callvm_argInt_x64 |
367 , &dc_callvm_argLong_x64 | |
368 , &dc_callvm_argLongLong_x64 | |
369 , &dc_callvm_argFloat_x64 | |
370 , &dc_callvm_argDouble_x64 | |
371 , &dc_callvm_argPointer_x64 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
372 , &dc_callvm_argAggr_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
373 , (DCvoidvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
374 , (DCboolvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
375 , (DCcharvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
376 , (DCshortvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
377 , (DCintvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
378 , (DClongvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
379 , (DClonglongvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
380 , (DCfloatvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
381 , (DCdoublevmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
382 , (DCpointervmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
383 , (DCaggrvmfunc*) &dc_callvm_call_x64_aggr |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
384 , (DCbeginaggrvmfunc*)&dc_callvm_begin_aggr_x64 |
0 | 385 }; |
386 | |
339 | 387 |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
388 #if defined(DC_WINDOWS) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
389 /* --- win64 thiscalls ------------------------------------------------------------- */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
390 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
391 DCCallVM_vt gVT_x64_win64_this = |
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 &dc_callvm_free_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
394 , &dc_callvm_reset_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
395 , &dc_callvm_mode_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
396 , &dc_callvm_argBool_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
397 , &dc_callvm_argChar_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
398 , &dc_callvm_argShort_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
399 , &dc_callvm_argInt_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
400 , &dc_callvm_argLong_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
401 , &dc_callvm_argLongLong_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
402 , &dc_callvm_argFloat_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
403 , &dc_callvm_argDouble_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
404 , &dc_callvm_argPointer_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
405 , &dc_callvm_argAggr_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
406 , (DCvoidvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
407 , (DCboolvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
408 , (DCcharvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
409 , (DCshortvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
410 , (DCintvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
411 , (DClongvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
412 , (DClonglongvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
413 , (DCfloatvmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
414 , (DCdoublevmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
415 , (DCpointervmfunc*) &dc_callvm_call_x64 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
416 , (DCaggrvmfunc*) &dc_callvm_call_x64_aggr |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
417 , (DCbeginaggrvmfunc*)&dc_callvm_begin_aggr_x64_win64_this |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
418 }; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
419 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
420 #endif |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
421 |
339 | 422 /* --- syscall ------------------------------------------------------------- */ |
423 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
424 #if defined(DC_UNIX) |
341 | 425 void dc_callvm_call_x64_syscall_sysv(DCCallVM* in_self, DCpointer target) |
339 | 426 { |
347 | 427 DCCallVM_x64* self; |
428 | |
339 | 429 /* syscalls can have up to 6 args, required to be "Only values of class INTEGER or class MEMORY" (from */ |
347 | 430 /* SysV manual), so we can use self->mRegData.i directly; verify this has space for at least 6 values, though. */ |
339 | 431 assert(numIntRegs >= 6); |
432 | |
347 | 433 self = (DCCallVM_x64*)in_self; |
341 | 434 dcCall_x64_syscall_sysv(self->mRegData.i, target); |
339 | 435 } |
436 | |
341 | 437 DCCallVM_vt gVT_x64_syscall_sysv = |
339 | 438 { |
439 &dc_callvm_free_x64 | |
440 , &dc_callvm_reset_x64 | |
441 , &dc_callvm_mode_x64 | |
442 , &dc_callvm_argBool_x64 | |
443 , &dc_callvm_argChar_x64 | |
444 , &dc_callvm_argShort_x64 | |
445 , &dc_callvm_argInt_x64 | |
446 , &dc_callvm_argLong_x64 | |
447 , &dc_callvm_argLongLong_x64 | |
448 , &dc_callvm_argFloat_x64 | |
449 , &dc_callvm_argDouble_x64 | |
450 , &dc_callvm_argPointer_x64 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
451 , NULL /* argAggr */ |
341 | 452 , (DCvoidvmfunc*) &dc_callvm_call_x64_syscall_sysv |
453 , (DCboolvmfunc*) &dc_callvm_call_x64_syscall_sysv | |
454 , (DCcharvmfunc*) &dc_callvm_call_x64_syscall_sysv | |
455 , (DCshortvmfunc*) &dc_callvm_call_x64_syscall_sysv | |
456 , (DCintvmfunc*) &dc_callvm_call_x64_syscall_sysv | |
457 , (DClongvmfunc*) &dc_callvm_call_x64_syscall_sysv | |
458 , (DClonglongvmfunc*) &dc_callvm_call_x64_syscall_sysv | |
459 , (DCfloatvmfunc*) &dc_callvm_call_x64_syscall_sysv | |
460 , (DCdoublevmfunc*) &dc_callvm_call_x64_syscall_sysv | |
461 , (DCpointervmfunc*) &dc_callvm_call_x64_syscall_sysv | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
462 , NULL /* callAggr */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
463 , NULL /* beginAggr */ |
339 | 464 }; |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
465 #endif |
339 | 466 |
467 | |
468 | |
469 /* mode */ | |
470 | |
84 | 471 static void dc_callvm_mode_x64(DCCallVM* in_self, DCint mode) |
472 { | |
473 DCCallVM_x64* self = (DCCallVM_x64*)in_self; | |
474 DCCallVM_vt* vt; | |
0 | 475 |
84 | 476 switch(mode) { |
477 case DC_CALL_C_DEFAULT: | |
478 #if defined(DC_UNIX) | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
479 case DC_CALL_C_DEFAULT_THIS: |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
480 case DC_CALL_C_X64_SYSV: /* = DC_CALL_C_X64_SYSV_THIS */ |
84 | 481 #else |
482 case DC_CALL_C_X64_WIN64: | |
483 #endif | |
484 case DC_CALL_C_ELLIPSIS: | |
485 case DC_CALL_C_ELLIPSIS_VARARGS: | |
486 vt = &gVT_x64; | |
487 break; | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
488 #if defined(DC_WINDOWS) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
489 case DC_CALL_C_DEFAULT_THIS: |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
490 case DC_CALL_C_X64_WIN64_THIS: |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
491 vt = &gVT_x64_win64_this; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
492 break; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
493 #endif |
339 | 494 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
|
495 #if defined(DC_UNIX) |
339 | 496 case DC_CALL_SYS_X64_SYSCALL_SYSV: |
341 | 497 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
|
498 #else |
339 | 499 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
|
500 #endif |
84 | 501 default: |
502 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; | |
503 return; | |
504 } | |
505 dc_callvm_base_init(&self->mInterface, vt); | |
0 | 506 } |
507 | |
84 | 508 /* Public API. */ |
0 | 509 DCCallVM* dcNewCallVM(DCsize size) |
510 { | |
84 | 511 DCCallVM_x64* p = (DCCallVM_x64*)dcAllocMem(sizeof(DCCallVM_x64)+size); |
512 | |
513 dc_callvm_mode_x64((DCCallVM*)p, DC_CALL_C_DEFAULT); | |
514 | |
515 /* Since we store register parameters in DCCallVM_x64 directly, adjust the stack size. */ | |
516 size -= sizeof(DCRegData_x64); | |
517 size = (((signed long)size) < 0) ? 0 : size; | |
518 dcVecInit(&p->mVecHead, size); | |
519 dc_callvm_reset_x64((DCCallVM*)p); | |
520 | |
521 return (DCCallVM*)p; | |
0 | 522 } |
523 |