Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_callvm_mips_n64.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 |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: dyncall | |
5 File: dyncall/dyncall_callvm_mips_n64.c | |
6 Description: mips "n64" ABI callvm implementation | |
7 License: | |
8 | |
366
ad5f9803f52f
- removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents:
305
diff
changeset
|
9 Copyright (c) 2007-2020 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 | |
30 dyncall callvm for 64bit MIPS family of processors | |
31 | |
32 SUPPORTED CALLING CONVENTIONS | |
33 n64 | |
34 | |
35 REVISION | |
36 2010/05/30 initial | |
37 | |
38 in contrast to o32, there is no space reserved for parameters | |
39 passed over registers. | |
40 more registers are used and registers are always used. | |
41 | |
42 stack is always 16-byte aligned at entry (call to call-kernel automatically | |
43 aligns argument stack. | |
44 | |
45 integer and float register-file is interleaved either taking one slot up | |
46 skipping the other. | |
47 | |
48 | |
49 */ | |
50 | |
51 | |
52 #include "dyncall_callvm_mips_n64.h" | |
53 #include "dyncall_alloc.h" | |
54 #include "dyncall_utils.h" | |
55 | |
366
ad5f9803f52f
- removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents:
305
diff
changeset
|
56 |
ad5f9803f52f
- removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents:
305
diff
changeset
|
57 void dcCall_mips_n64(DCpointer target, DCRegData_mips_n64* regdata, DCsize stksize, DCpointer stkdata); |
ad5f9803f52f
- removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents:
305
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:
305
diff
changeset
|
59 |
0 | 60 static void dc_callvm_reset_mips_n64(DCCallVM* in_self) |
61 { | |
62 DCCallVM_mips_n64* self = (DCCallVM_mips_n64*)in_self; | |
63 dcVecReset(&self->mVecHead); | |
64 self->mRegCount = 0; | |
305 | 65 #if defined(DC__ABI_HARDFLOAT) |
0 | 66 self->mRegData.mUseDouble = 0LL; |
305 | 67 #endif /* DC__ABI_HARDFLOAT */ |
0 | 68 } |
69 | |
70 | |
71 static void dc_callvm_free_mips_n64(DCCallVM* in_self) | |
72 { | |
73 dcFreeMem(in_self); | |
74 } | |
75 | |
76 /* pass arguments : | |
77 | |
78 - promote to 64-bit integer. | |
79 - fill up integers and float - left-to-right otherwise go over stack. | |
80 */ | |
81 | |
82 /* arg int -- fillup 64-bit integer register file OR push on stack */ | |
83 | |
305 | 84 static void dc_callvm_argLongLong_mips_n64(DCCallVM* in_self, DClonglong x) |
0 | 85 { |
86 DCCallVM_mips_n64* self = (DCCallVM_mips_n64*)in_self; | |
87 /* fillup integer register file */ | |
88 if (self->mRegCount < 8) | |
305 | 89 self->mRegData.mIntData[self->mRegCount++] = x; |
0 | 90 else |
305 | 91 dcVecAppend(&self->mVecHead, &x, sizeof(DClonglong)); |
0 | 92 } |
93 | |
305 | 94 static void dc_callvm_argInt_mips_n64(DCCallVM* in_self, DCint x) |
0 | 95 { |
305 | 96 dc_callvm_argLongLong_mips_n64(in_self, (DClonglong)x); |
0 | 97 } |
98 | |
99 static void dc_callvm_argPointer_mips_n64(DCCallVM* in_self, DCpointer x) | |
100 { | |
305 | 101 dc_callvm_argLongLong_mips_n64(in_self, *(DClonglong*)&x); |
0 | 102 } |
103 | |
104 static void dc_callvm_argBool_mips_n64(DCCallVM* in_self, DCbool x) | |
105 { | |
106 dc_callvm_argLongLong_mips_n64(in_self, (DClonglong)x); | |
107 } | |
108 | |
109 static void dc_callvm_argChar_mips_n64(DCCallVM* in_self, DCchar x) | |
110 { | |
111 dc_callvm_argLongLong_mips_n64(in_self, (DClonglong)x); | |
112 } | |
113 | |
114 static void dc_callvm_argShort_mips_n64(DCCallVM* in_self, DCshort x) | |
115 { | |
116 dc_callvm_argLongLong_mips_n64(in_self, (DClonglong)x); | |
117 } | |
118 | |
119 static void dc_callvm_argLong_mips_n64(DCCallVM* in_self, DClong x) | |
120 { | |
121 dc_callvm_argLongLong_mips_n64(in_self, (DClonglong)x); | |
122 } | |
123 | |
124 static void dc_callvm_argDouble_mips_n64(DCCallVM* in_self, DCdouble x) | |
125 { | |
305 | 126 #if defined(DC__ABI_HARDFLOAT) |
0 | 127 DCCallVM_mips_n64* self = (DCCallVM_mips_n64*)in_self; |
128 if (self->mRegCount < 8) { | |
129 self->mRegData.mUseDouble |= 1<<( self->mRegCount ); | |
130 self->mRegData.mFloatData[self->mRegCount++].d = x; | |
131 } else { | |
305 | 132 dcVecAppend(&self->mVecHead, &x, sizeof(DCdouble)); |
0 | 133 } |
305 | 134 #else |
135 dc_callvm_argLongLong_mips_n64(in_self, *(DClonglong*)&x); | |
136 #endif /* DC__ABI_HARDFLOAT */ | |
0 | 137 } |
138 | |
139 static void dc_callvm_argFloat_mips_n64(DCCallVM* in_self, DCfloat x) | |
140 { | |
305 | 141 #if defined(DC__ABI_HARDFLOAT) |
0 | 142 DCCallVM_mips_n64* self = (DCCallVM_mips_n64*)in_self; |
143 if (self->mRegCount < 8) { | |
144 /*self->mRegData.mFloatData[self->mRegCount++].d = (DCdouble) x;*/ | |
145 self->mRegData.mFloatData[self->mRegCount++].f = x; | |
146 } else { | |
305 | 147 dcVecAppend(&self->mVecHead, &x, sizeof(DCfloat)); |
148 dcVecSkip(&self->mVecHead, sizeof(DCfloat)); | |
0 | 149 } |
305 | 150 #else |
151 DCfloat f[] = {x,0.f}; | |
152 # if defined(DC__Endian_BIG) | |
465
e2899b4ff713
- // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents:
366
diff
changeset
|
153 /* floats in regs always right justified */ |
305 | 154 if (((DCCallVM_mips_n64*)in_self)->mRegCount < 8) { |
155 f[1] = f[0]; | |
156 f[0] = 0.f; | |
157 } | |
158 # endif /* DC__Endian_BIG */ | |
159 dc_callvm_argLongLong_mips_n64(in_self, *(DClonglong*)&f); | |
160 #endif /* DC__ABI_HARDFLOAT */ | |
0 | 161 } |
162 | |
163 | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
128
diff
changeset
|
164 /* Ellipsis calls: |
0 | 165 - float is promoted to double (due to ANSI C). |
166 - double is passed via integer register-file (due to MIPS ABI). | |
167 */ | |
168 | |
169 static void dc_callvm_argDouble_mips_n64_ellipsis(DCCallVM* in_self, DCdouble x) | |
170 { | |
171 dc_callvm_argLongLong_mips_n64(in_self, * ( (DClonglong*) &x ) ); | |
172 } | |
173 | |
174 static void dc_callvm_argFloat_mips_n64_ellipsis(DCCallVM* in_self, DCfloat x) | |
175 { | |
176 dc_callvm_argDouble_mips_n64_ellipsis(in_self, (DCdouble) x ); | |
177 } | |
178 | |
179 | |
180 /* Call. */ | |
181 | |
182 void dc_callvm_call_mips_n64(DCCallVM* in_self, DCpointer target) | |
183 { | |
184 DCCallVM_mips_n64* self = (DCCallVM_mips_n64*)in_self; | |
185 /* at minimum provide 16-bytes | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
128
diff
changeset
|
186 which hold the first four integer register as spill area |
0 | 187 and are automatically loaded to $4-$7 |
188 */ | |
189 size_t size = DC_MAX(16, ( ( (unsigned) dcVecSize(&self->mVecHead) ) +7UL ) & (-8UL) ); | |
190 dcCall_mips_n64(target, &self->mRegData, size, dcVecData(&self->mVecHead)); | |
191 } | |
192 | |
193 static void dc_callvm_mode_mips_n64(DCCallVM* in_self,DCint mode); | |
194 | |
195 DCCallVM_vt gVT_mips_n64 = | |
196 { | |
197 &dc_callvm_free_mips_n64 | |
198 , &dc_callvm_reset_mips_n64 | |
199 , &dc_callvm_mode_mips_n64 | |
200 , &dc_callvm_argBool_mips_n64 | |
201 , &dc_callvm_argChar_mips_n64 | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
128
diff
changeset
|
202 , &dc_callvm_argShort_mips_n64 |
0 | 203 , &dc_callvm_argInt_mips_n64 |
204 , &dc_callvm_argLong_mips_n64 | |
205 , &dc_callvm_argLongLong_mips_n64 | |
206 , &dc_callvm_argFloat_mips_n64 | |
207 , &dc_callvm_argDouble_mips_n64 | |
208 , &dc_callvm_argPointer_mips_n64 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
209 , NULL /* argAggr */ |
0 | 210 , (DCvoidvmfunc*) &dc_callvm_call_mips_n64 |
211 , (DCboolvmfunc*) &dc_callvm_call_mips_n64 | |
212 , (DCcharvmfunc*) &dc_callvm_call_mips_n64 | |
213 , (DCshortvmfunc*) &dc_callvm_call_mips_n64 | |
214 , (DCintvmfunc*) &dc_callvm_call_mips_n64 | |
215 , (DClongvmfunc*) &dc_callvm_call_mips_n64 | |
216 , (DClonglongvmfunc*) &dc_callvm_call_mips_n64 | |
217 , (DCfloatvmfunc*) &dc_callvm_call_mips_n64 | |
218 , (DCdoublevmfunc*) &dc_callvm_call_mips_n64 | |
219 , (DCpointervmfunc*) &dc_callvm_call_mips_n64 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
220 , NULL /* callAggr */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
221 , NULL /* beginAggr */ |
0 | 222 }; |
223 | |
224 DCCallVM_vt gVT_mips_n64_ellipsis = | |
225 { | |
226 &dc_callvm_free_mips_n64 | |
227 , &dc_callvm_reset_mips_n64 | |
228 , &dc_callvm_mode_mips_n64 | |
229 , &dc_callvm_argBool_mips_n64 | |
230 , &dc_callvm_argChar_mips_n64 | |
231 , &dc_callvm_argShort_mips_n64 | |
232 , &dc_callvm_argInt_mips_n64 | |
233 , &dc_callvm_argLong_mips_n64 | |
234 , &dc_callvm_argLongLong_mips_n64 | |
235 , &dc_callvm_argFloat_mips_n64_ellipsis | |
236 , &dc_callvm_argDouble_mips_n64_ellipsis | |
237 , &dc_callvm_argPointer_mips_n64 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
238 , NULL /* argAggr */ |
0 | 239 , (DCvoidvmfunc*) &dc_callvm_call_mips_n64 |
240 , (DCboolvmfunc*) &dc_callvm_call_mips_n64 | |
241 , (DCcharvmfunc*) &dc_callvm_call_mips_n64 | |
242 , (DCshortvmfunc*) &dc_callvm_call_mips_n64 | |
243 , (DCintvmfunc*) &dc_callvm_call_mips_n64 | |
244 , (DClongvmfunc*) &dc_callvm_call_mips_n64 | |
245 , (DClonglongvmfunc*) &dc_callvm_call_mips_n64 | |
246 , (DCfloatvmfunc*) &dc_callvm_call_mips_n64 | |
247 , (DCdoublevmfunc*) &dc_callvm_call_mips_n64 | |
248 , (DCpointervmfunc*) &dc_callvm_call_mips_n64 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
249 , NULL /* callAggr */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
250 , NULL /* beginAggr */ |
0 | 251 }; |
252 | |
84 | 253 static void dc_callvm_mode_mips_n64(DCCallVM* in_self, DCint mode) |
0 | 254 { |
84 | 255 DCCallVM_mips_n64* self = (DCCallVM_mips_n64*)in_self; |
256 DCCallVM_vt* vt; | |
257 | |
0 | 258 switch(mode) { |
259 case DC_CALL_C_DEFAULT: | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
465
diff
changeset
|
260 case DC_CALL_C_DEFAULT_THIS: |
84 | 261 case DC_CALL_C_MIPS64_N64: |
128
9a554d1c4da6
- mips n64 vararg call fixes if non-variadic arguments are floats
cslag
parents:
84
diff
changeset
|
262 case DC_CALL_C_ELLIPSIS: |
84 | 263 vt = &gVT_mips_n64; |
0 | 264 break; |
84 | 265 case DC_CALL_C_ELLIPSIS_VARARGS: |
266 vt = &gVT_mips_n64_ellipsis; | |
0 | 267 break; |
268 default: | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
128
diff
changeset
|
269 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; |
84 | 270 return; |
0 | 271 } |
84 | 272 dc_callvm_base_init(&self->mInterface, vt); |
0 | 273 } |
274 | |
84 | 275 /* Public API. */ |
276 DCCallVM* dcNewCallVM(DCsize size) | |
0 | 277 { |
84 | 278 DCCallVM_mips_n64* p = (DCCallVM_mips_n64*)dcAllocMem(sizeof(DCCallVM_mips_n64)+size); |
279 | |
280 dc_callvm_mode_mips_n64((DCCallVM*)p, DC_CALL_C_DEFAULT); | |
281 | |
282 dcVecInit(&p->mVecHead, size); | |
283 dc_callvm_reset_mips_n64((DCCallVM*)p); | |
284 | |
285 return (DCCallVM*)p; | |
0 | 286 } |
287 |