Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_callvm_arm32_arm_armhf.c @ 368:f28b7f4f5749
- removed some pseudo-op on non-darwin platforms to make clang's integrated assembler happy
author | Tassilo Philipp |
---|---|
date | Wed, 05 Aug 2020 15:50:49 +0200 |
parents | ad5f9803f52f |
children | ddfb9577a00e |
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 | |
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
|
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 | |
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
|
31 /* |
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 ** arm32 armhf mode calling convention calls |
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 | |
165 , NULL /* argStruct */ | |
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 | |
176 , NULL /* callStruct */ | |
177 }; | |
178 | |
51 | 179 DCCallVM_vt vt_armhf_ellipsis = |
180 { | |
181 &deinit | |
182 , &reset | |
183 , &mode | |
184 , &a_bool | |
185 , &a_char | |
186 , &a_short | |
187 , &a_int | |
188 , &a_long | |
189 , &a_longlong | |
190 , &a_float_ellipsis | |
191 , &a_double_ellipsis | |
192 , &a_pointer | |
193 , NULL /* argStruct */ | |
194 , (DCvoidvmfunc*) &call | |
195 , (DCboolvmfunc*) &call | |
196 , (DCcharvmfunc*) &call | |
197 , (DCshortvmfunc*) &call | |
198 , (DCintvmfunc*) &call | |
199 , (DClongvmfunc*) &call | |
200 , (DClonglongvmfunc*) &call | |
201 , (DCfloatvmfunc*) &call | |
202 , (DCdoublevmfunc*) &call | |
203 , (DCpointervmfunc*) &call | |
204 , NULL /* callStruct */ | |
205 }; | |
206 | |
84 | 207 static void mode(DCCallVM* in_self, DCint mode) |
0 | 208 { |
84 | 209 DCCallVM_arm32_armhf* self = (DCCallVM_arm32_armhf*)in_self; |
210 DCCallVM_vt* vt; | |
0 | 211 |
212 switch(mode) { | |
51 | 213 case DC_CALL_C_DEFAULT: |
214 case DC_CALL_C_ARM_ARMHF: | |
84 | 215 vt = &vt_armhf; |
51 | 216 break; |
0 | 217 case DC_CALL_C_ELLIPSIS: |
218 case DC_CALL_C_ELLIPSIS_VARARGS: | |
84 | 219 vt = &vt_armhf_ellipsis; |
0 | 220 break; |
51 | 221 default: |
84 | 222 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; |
0 | 223 return; |
224 } | |
84 | 225 dc_callvm_base_init(&self->mInterface, vt); |
0 | 226 } |
227 | |
84 | 228 /* Public API. */ |
229 DCCallVM* dcNewCallVM(DCsize size) | |
230 { | |
231 /* Store at least 16 bytes (4 words for first 4 int args) for internal spill area. Assembly code depends on it. */ | |
232 DCCallVM_arm32_armhf* p = (DCCallVM_arm32_armhf*)dcAllocMem(sizeof(DCCallVM_arm32_armhf)+size+16); | |
233 | |
234 mode((DCCallVM*)p, DC_CALL_C_DEFAULT); | |
235 | |
236 dcVecInit(&p->mVecHead, size); | |
237 reset((DCCallVM*)p); | |
238 | |
239 return (DCCallVM*)p; | |
240 } | |
241 |