Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_callvm_arm64.c @ 663:127b569978cc default tip
- another tweak handling clang trying to be too smart (see last commit)
author | Tassilo Philipp |
---|---|
date | Sun, 24 Mar 2024 13:52:44 +0100 |
parents | cab0031c6691 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: dyncall | |
5 File: dyncall/dyncall_callvm_arm64.c | |
6 Description: ARM 64-bit ABI implementation | |
7 License: | |
8 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
376
diff
changeset
|
9 Copyright (c) 2015-2020 Daniel Adler <dadler@uni-goettingen.de>, |
281 | 10 Tassilo Philipp <tphilipp@potion-studios.com> |
0 | 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 #include "dyncall_callvm_arm64.h" | |
28 #include "dyncall_alloc.h" | |
371
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
29 #include "dyncall_macros.h" |
0 | 30 |
31 | |
366
ad5f9803f52f
- removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents:
281
diff
changeset
|
32 void dcCall_arm64(DCpointer target, DCpointer data, DCsize size, DCpointer regdata); |
ad5f9803f52f
- removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents:
281
diff
changeset
|
33 |
ad5f9803f52f
- removal of some unnecessary headers that only contained internally used forward declarations, so no need to have them
Tassilo Philipp
parents:
281
diff
changeset
|
34 |
0 | 35 static void reset(DCCallVM* in_p) |
36 { | |
37 DCCallVM_arm64* p = (DCCallVM_arm64*)in_p; | |
38 p->i = 0; | |
39 p->f = 0; | |
40 dcVecReset(&p->mVecHead); | |
41 } | |
42 | |
43 | |
44 static void deinit(DCCallVM* in_self) | |
45 { | |
46 dcFreeMem(in_self); | |
47 } | |
48 | |
49 | |
50 | |
51 static void a_i64(DCCallVM* in_self, DClonglong x) | |
52 { | |
53 DCCallVM_arm64* p = (DCCallVM_arm64*)in_self; | |
54 if (p->i < 8) { | |
55 p->I[p->i] = x; | |
56 p->i++; | |
57 } else { | |
58 dcVecAppend(&p->mVecHead, &x, sizeof(DClonglong)); | |
59 } | |
60 } | |
61 | |
651 | 62 static void a_bool (DCCallVM* self, DCbool x) { a_i64(self, (DClonglong)x); } |
63 static void a_char (DCCallVM* self, DCchar x) { a_i64(self, x); } | |
64 static void a_short (DCCallVM* self, DCshort x) { a_i64(self, x); } | |
65 static void a_int (DCCallVM* self, DCint x) { a_i64(self, x); } | |
66 static void a_long (DCCallVM* self, DClong x) { a_i64(self, x); } | |
0 | 67 static void a_pointer (DCCallVM* self, DCpointer x) { a_i64(self, (DClonglong) x ); } |
68 | |
69 static void a_float(DCCallVM* in_p, DCfloat x) | |
70 { | |
71 DCCallVM_arm64* p = (DCCallVM_arm64*)in_p; | |
72 | |
73 if (p->f < 8) { | |
74 p->u.S[ p->f << 1 ] = x; | |
75 p->f++; | |
76 } else { | |
77 dcVecAppend(&p->mVecHead, &x, sizeof(DCfloat)); | |
371
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
78 dcVecSkip(&p->mVecHead, 4); /* align to 8-bytes */ |
0 | 79 } |
80 } | |
81 | |
82 static void a_double(DCCallVM* in_p, DCdouble x) | |
83 { | |
84 DCCallVM_arm64* p = (DCCallVM_arm64*)in_p; | |
85 if (p->f < 8) { | |
86 p->u.D[ p->f ] = x; | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
376
diff
changeset
|
87 p->f++; |
0 | 88 } else { |
89 dcVecAppend(&p->mVecHead, &x, sizeof(DCdouble)); | |
90 } | |
91 } | |
92 | |
93 void call(DCCallVM* in_p, DCpointer target) | |
94 { | |
95 DCCallVM_arm64* p = (DCCallVM_arm64*)in_p; | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
376
diff
changeset
|
96 |
0 | 97 /* |
98 ** copy 'size' argument is given in number of 16-byte 'pair' blocks. | |
99 */ | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
376
diff
changeset
|
100 |
0 | 101 dcCall_arm64(target, dcVecData(&p->mVecHead), ( dcVecSize(&p->mVecHead) + 15 ) & -16, &p->u.S[0]); |
102 } | |
103 | |
84 | 104 static void mode(DCCallVM* in_self, DCint mode); |
105 | |
0 | 106 DCCallVM_vt vt_arm64 = |
107 { | |
108 &deinit | |
109 , &reset | |
110 , &mode | |
111 , &a_bool | |
112 , &a_char | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
376
diff
changeset
|
113 , &a_short |
0 | 114 , &a_int |
115 , &a_long | |
116 , &a_i64 | |
117 , &a_float | |
118 , &a_double | |
119 , &a_pointer | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
120 , NULL /* argAggr */ |
0 | 121 , (DCvoidvmfunc*) &call |
122 , (DCboolvmfunc*) &call | |
123 , (DCcharvmfunc*) &call | |
124 , (DCshortvmfunc*) &call | |
125 , (DCintvmfunc*) &call | |
126 , (DClongvmfunc*) &call | |
127 , (DClonglongvmfunc*) &call | |
128 , (DCfloatvmfunc*) &call | |
129 , (DCdoublevmfunc*) &call | |
130 , (DCpointervmfunc*) &call | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
131 , NULL /* callAggr */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
132 , NULL /* beginAggr */ |
0 | 133 }; |
134 | |
371
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
135 #ifdef DC__OS_Win64 |
376
041cb6ad4d50
- simplified callvm setup for win/arm64 a bit, no behaviour changes
Tassilo Philipp
parents:
371
diff
changeset
|
136 /* for variadic, everything is pushed like ints as no FP regs are used, so |
041cb6ad4d50
- simplified callvm setup for win/arm64 a bit, no behaviour changes
Tassilo Philipp
parents:
371
diff
changeset
|
137 allocate arguments to an imaginary stack, where the first 64 bytes of |
371
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
138 the stack are loaded into x0-x7, and any remaining arguments on the stack */ |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
139 |
376
041cb6ad4d50
- simplified callvm setup for win/arm64 a bit, no behaviour changes
Tassilo Philipp
parents:
371
diff
changeset
|
140 static void var_float (DCCallVM* in_p, DCfloat x) { DClonglong tmp = 0; *(DCfloat*)&tmp = x; a_i64(in_p, tmp); } |
041cb6ad4d50
- simplified callvm setup for win/arm64 a bit, no behaviour changes
Tassilo Philipp
parents:
371
diff
changeset
|
141 static void var_double(DCCallVM* in_p, DCdouble x) { a_i64(in_p, *(DClonglong *)&x); } |
371
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
142 |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
143 DCCallVM_vt vt_arm64_win_varargs = |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
144 { |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
145 &deinit |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
146 , &reset |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
147 , &mode |
376
041cb6ad4d50
- simplified callvm setup for win/arm64 a bit, no behaviour changes
Tassilo Philipp
parents:
371
diff
changeset
|
148 , &a_bool |
041cb6ad4d50
- simplified callvm setup for win/arm64 a bit, no behaviour changes
Tassilo Philipp
parents:
371
diff
changeset
|
149 , &a_char |
041cb6ad4d50
- simplified callvm setup for win/arm64 a bit, no behaviour changes
Tassilo Philipp
parents:
371
diff
changeset
|
150 , &a_short |
041cb6ad4d50
- simplified callvm setup for win/arm64 a bit, no behaviour changes
Tassilo Philipp
parents:
371
diff
changeset
|
151 , &a_int |
041cb6ad4d50
- simplified callvm setup for win/arm64 a bit, no behaviour changes
Tassilo Philipp
parents:
371
diff
changeset
|
152 , &a_long |
371
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
153 , &a_i64 |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
154 , &var_float |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
155 , &var_double |
376
041cb6ad4d50
- simplified callvm setup for win/arm64 a bit, no behaviour changes
Tassilo Philipp
parents:
371
diff
changeset
|
156 , &a_pointer |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
157 , NULL /* argAggr */ |
371
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
158 , (DCvoidvmfunc*) &call |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
159 , (DCboolvmfunc*) &call |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
160 , (DCcharvmfunc*) &call |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
161 , (DCshortvmfunc*) &call |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
162 , (DCintvmfunc*) &call |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
163 , (DClongvmfunc*) &call |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
164 , (DClonglongvmfunc*) &call |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
165 , (DCfloatvmfunc*) &call |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
166 , (DCdoublevmfunc*) &call |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
167 , (DCpointervmfunc*) &call |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
168 , NULL /* callAggr */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
169 , NULL /* beginAggr */ |
371
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
170 }; |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
171 #endif |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
172 |
84 | 173 static void mode(DCCallVM* in_self, DCint mode) |
0 | 174 { |
84 | 175 DCCallVM_arm64* self = (DCCallVM_arm64*)in_self; |
176 DCCallVM_vt* vt; | |
0 | 177 |
178 switch(mode) { | |
371
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
179 case DC_CALL_C_ELLIPSIS: |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
180 case DC_CALL_C_ELLIPSIS_VARARGS: |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
181 #ifdef DC__OS_Win64 |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
182 vt = &vt_arm64_win_varargs; |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
183 break; |
451299d50c1a
- windows arm64 support (dyncall, dyncallback, cmake support for armasm64), thanks Bernhard Urban-Forster!
Tassilo Philipp
parents:
366
diff
changeset
|
184 #endif /* if not win64, use below */ |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
376
diff
changeset
|
185 case DC_CALL_C_DEFAULT: |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
376
diff
changeset
|
186 case DC_CALL_C_DEFAULT_THIS: |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
376
diff
changeset
|
187 case DC_CALL_C_ARM64: |
0 | 188 vt = &vt_arm64; |
189 break; | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
376
diff
changeset
|
190 default: |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
376
diff
changeset
|
191 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; |
0 | 192 return; |
193 } | |
84 | 194 dc_callvm_base_init(&self->mInterface, vt); |
0 | 195 } |
196 | |
84 | 197 /* Public API. */ |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
376
diff
changeset
|
198 DCCallVM* dcNewCallVM(DCsize size) |
84 | 199 { |
200 DCCallVM_arm64* p = (DCCallVM_arm64*)dcAllocMem(sizeof(DCCallVM_arm64)+size); | |
201 | |
202 mode((DCCallVM*)p, DC_CALL_C_DEFAULT); | |
203 | |
204 dcVecInit(&p->mVecHead, size); | |
205 reset((DCCallVM*)p); | |
206 | |
207 return (DCCallVM*)p; | |
208 } | |
209 |