Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_callvm_arm32_arm_armhf.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_arm32_arm_armhf.c | |
6 Description: ARM 'armhf' ABI implementation | |
7 License: | |
8 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
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 #include "dyncall_callvm_arm32_arm_armhf.h" | |
28 #include "dyncall_alloc.h" | |
29 | |
30 | |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
31 /* |
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
32 ** arm32 armhf mode calling convention calls |
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
|
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 ** - 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:
281
diff
changeset
|
35 ** |
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
|
36 ** Note the return type of this declaration is intentially of double-word size (despite |
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
|
37 ** the return value not being used in the code below). |
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
|
38 ** On some platforms the compiler generates cleanup code in the caller |
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
|
39 ** (dyncall_callvm_arm32_arm_armhf.c's call()) that reuses- thus overwrites - r0 and r1. |
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
|
40 ** With this "hint", we preserve those registers by letting the compiler assume both |
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
|
41 ** registers are used for the return type. |
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
|
42 */ |
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
|
43 DClonglong dcCall_arm32_armhf(DCpointer target, DCpointer stackdata, DCsize size, DCfloat* p_s16); |
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
|
44 |
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
|
45 |
0 | 46 static void deinit(DCCallVM* in_self) |
47 { | |
48 dcFreeMem(in_self); | |
49 } | |
50 | |
51 | |
52 static void reset(DCCallVM* in_p) | |
53 { | |
54 DCCallVM_arm32_armhf* p = (DCCallVM_arm32_armhf*)in_p; | |
55 p->i = 0; | |
56 p->s = 0; | |
57 p->d = 0; | |
58 dcVecResize(&p->mVecHead, 16); | |
59 } | |
60 | |
61 static void a_int(DCCallVM* in_self, DCint x) | |
62 { | |
63 DCCallVM_arm32_armhf* p = (DCCallVM_arm32_armhf*)in_self; | |
64 if (p->i < 16) { | |
65 * (DCint*) dcVecAt(&p->mVecHead, p->i) = x; | |
66 p->i += 4; | |
67 } else { | |
68 dcVecAppend(&p->mVecHead, &x, sizeof(DCint)); | |
69 } | |
70 } | |
71 | |
72 static void a_bool (DCCallVM* in_self, DCbool x) { a_int(in_self, (DCint)x); } | |
73 static void a_char (DCCallVM* in_self, DCchar x) { a_int(in_self, x); } | |
74 static void a_short (DCCallVM* in_self, DCshort x) { a_int(in_self, x); } | |
75 static void a_long (DCCallVM* in_self, DClong x) { a_int(in_self, x); } | |
51 | 76 |
0 | 77 static void a_longlong(DCCallVM* in_self, DClonglong x) |
78 { | |
79 DCCallVM_arm32_armhf* p = (DCCallVM_arm32_armhf*)in_self; | |
80 | |
81 p->i = (p->i+4) & -8; | |
82 if (p->i < 16) { | |
83 * (DClonglong*) dcVecAt(&p->mVecHead, p->i) = x; | |
84 p->i += 8; | |
85 } else { | |
86 /* 64 bit values need to be aligned on 8 byte boundaries */ | |
87 dcVecSkip(&p->mVecHead, dcVecSize(&p->mVecHead) & 4); | |
88 dcVecAppend(&p->mVecHead, &x, sizeof(DClonglong)); | |
89 } | |
90 } | |
51 | 91 |
0 | 92 static void a_pointer(DCCallVM* in_p, DCpointer x) { a_int(in_p, (DCint) x ); } |
93 | |
94 static void a_float(DCCallVM* in_p, DCfloat x) | |
95 { | |
96 DCCallVM_arm32_armhf* p = (DCCallVM_arm32_armhf*)in_p; | |
97 if (p->s < 16) { | |
98 p->S[p->s++] = x; | |
99 if (p->d < p->s) { | |
100 p->d = (p->s+1) & ~(1U); | |
101 } else { | |
102 p->s = p->d; | |
103 } | |
104 } else { | |
105 dcVecAppend(&p->mVecHead, &x, sizeof(DCfloat)); | |
51 | 106 } |
0 | 107 } |
108 | |
109 static void a_double(DCCallVM* in_p, DCdouble x) | |
110 { | |
47 | 111 union { |
112 DCdouble d; | |
113 DCchar b[8]; | |
114 } v; | |
115 | |
0 | 116 DCCallVM_arm32_armhf* p = (DCCallVM_arm32_armhf*)in_p; |
117 if (p->d < 16) { | |
146
0ab08c1541f0
- fixed armhf ellipsis calls, were ignoring spill area
cslag
parents:
84
diff
changeset
|
118 * (DCdouble*) &p->S[p->d] = x; |
0 | 119 p->d += 2; |
120 if (!(p->s & 1)) { | |
51 | 121 /* if s is even it always equals d. otherwise, s points to an odd float register. */ |
0 | 122 p->s = p->d; |
123 } | |
124 } else { | |
47 | 125 p->s = 16; /* fp registers all full - need to use stack now: stop filling gaps for single precision, also */ |
0 | 126 v.d = x; |
127 /* 64 bit values need to be aligned on 8 byte boundaries */ | |
128 dcVecSkip(&p->mVecHead, dcVecSize(&p->mVecHead) & 4); | |
129 dcVecAppend(&p->mVecHead, &v.b[0], sizeof(DCdouble)); | |
130 } | |
131 } | |
132 | |
51 | 133 static void a_float_ellipsis(DCCallVM* in_p, DCfloat x) |
134 { | |
135 a_int(in_p, *(DCint*)&x); | |
136 } | |
137 | |
138 static void a_double_ellipsis(DCCallVM* in_p, DCdouble x) | |
139 { | |
140 a_longlong(in_p, *(DClonglong*)&x); | |
141 } | |
142 | |
0 | 143 void call(DCCallVM* in_p, DCpointer target) |
144 { | |
145 DCCallVM_arm32_armhf* p = (DCCallVM_arm32_armhf*)in_p; | |
146 dcCall_arm32_armhf(target, dcVecData(&p->mVecHead), dcVecSize(&p->mVecHead), &p->S[0]); | |
147 } | |
148 | |
84 | 149 static void mode(DCCallVM* in_self,DCint mode); |
150 | |
0 | 151 DCCallVM_vt vt_armhf = |
152 { | |
153 &deinit | |
154 , &reset | |
155 , &mode | |
156 , &a_bool | |
157 , &a_char | |
51 | 158 , &a_short |
0 | 159 , &a_int |
160 , &a_long | |
161 , &a_longlong | |
162 , &a_float | |
163 , &a_double | |
164 , &a_pointer | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
165 , NULL /* argAggr */ |
0 | 166 , (DCvoidvmfunc*) &call |
167 , (DCboolvmfunc*) &call | |
168 , (DCcharvmfunc*) &call | |
169 , (DCshortvmfunc*) &call | |
170 , (DCintvmfunc*) &call | |
171 , (DClongvmfunc*) &call | |
172 , (DClonglongvmfunc*) &call | |
173 , (DCfloatvmfunc*) &call | |
174 , (DCdoublevmfunc*) &call | |
175 , (DCpointervmfunc*) &call | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
176 , NULL /* callAggr */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
177 , NULL /* beginAggr */ |
0 | 178 }; |
179 | |
51 | 180 DCCallVM_vt vt_armhf_ellipsis = |
181 { | |
182 &deinit | |
183 , &reset | |
184 , &mode | |
185 , &a_bool | |
186 , &a_char | |
187 , &a_short | |
188 , &a_int | |
189 , &a_long | |
190 , &a_longlong | |
191 , &a_float_ellipsis | |
192 , &a_double_ellipsis | |
193 , &a_pointer | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
194 , NULL /* argAggr */ |
51 | 195 , (DCvoidvmfunc*) &call |
196 , (DCboolvmfunc*) &call | |
197 , (DCcharvmfunc*) &call | |
198 , (DCshortvmfunc*) &call | |
199 , (DCintvmfunc*) &call | |
200 , (DClongvmfunc*) &call | |
201 , (DClonglongvmfunc*) &call | |
202 , (DCfloatvmfunc*) &call | |
203 , (DCdoublevmfunc*) &call | |
204 , (DCpointervmfunc*) &call | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
205 , NULL /* callAggr */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
206 , NULL /* beginAggr */ |
51 | 207 }; |
208 | |
84 | 209 static void mode(DCCallVM* in_self, DCint mode) |
0 | 210 { |
84 | 211 DCCallVM_arm32_armhf* self = (DCCallVM_arm32_armhf*)in_self; |
212 DCCallVM_vt* vt; | |
0 | 213 |
214 switch(mode) { | |
51 | 215 case DC_CALL_C_DEFAULT: |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
216 case DC_CALL_C_DEFAULT_THIS: |
51 | 217 case DC_CALL_C_ARM_ARMHF: |
84 | 218 vt = &vt_armhf; |
51 | 219 break; |
0 | 220 case DC_CALL_C_ELLIPSIS: |
221 case DC_CALL_C_ELLIPSIS_VARARGS: | |
84 | 222 vt = &vt_armhf_ellipsis; |
0 | 223 break; |
51 | 224 default: |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
366
diff
changeset
|
225 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; |
0 | 226 return; |
227 } | |
84 | 228 dc_callvm_base_init(&self->mInterface, vt); |
0 | 229 } |
230 | |
84 | 231 /* Public API. */ |
232 DCCallVM* dcNewCallVM(DCsize size) | |
233 { | |
234 /* Store at least 16 bytes (4 words for first 4 int args) for internal spill area. Assembly code depends on it. */ | |
235 DCCallVM_arm32_armhf* p = (DCCallVM_arm32_armhf*)dcAllocMem(sizeof(DCCallVM_arm32_armhf)+size+16); | |
236 | |
237 mode((DCCallVM*)p, DC_CALL_C_DEFAULT); | |
238 | |
239 dcVecInit(&p->mVecHead, size); | |
240 reset((DCCallVM*)p); | |
241 | |
242 return (DCCallVM*)p; | |
243 } | |
244 |