Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_callvm_mips_n64.c @ 318:3124f4c4f293
- dynload_plain test code build fix for windows
author | Tassilo Philipp |
---|---|
date | Wed, 13 Nov 2019 01:21:02 +0100 |
parents | b104c5beec8b |
children | ad5f9803f52f |
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 | |
281 | 9 Copyright (c) 2007-2018 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 | |
56 static void dc_callvm_reset_mips_n64(DCCallVM* in_self) | |
57 { | |
58 DCCallVM_mips_n64* self = (DCCallVM_mips_n64*)in_self; | |
59 dcVecReset(&self->mVecHead); | |
60 self->mRegCount = 0; | |
305 | 61 #if defined(DC__ABI_HARDFLOAT) |
0 | 62 self->mRegData.mUseDouble = 0LL; |
305 | 63 #endif /* DC__ABI_HARDFLOAT */ |
0 | 64 } |
65 | |
66 | |
67 static void dc_callvm_free_mips_n64(DCCallVM* in_self) | |
68 { | |
69 dcFreeMem(in_self); | |
70 } | |
71 | |
72 /* pass arguments : | |
73 | |
74 - promote to 64-bit integer. | |
75 - fill up integers and float - left-to-right otherwise go over stack. | |
76 */ | |
77 | |
78 /* arg int -- fillup 64-bit integer register file OR push on stack */ | |
79 | |
305 | 80 static void dc_callvm_argLongLong_mips_n64(DCCallVM* in_self, DClonglong x) |
0 | 81 { |
82 DCCallVM_mips_n64* self = (DCCallVM_mips_n64*)in_self; | |
83 /* fillup integer register file */ | |
84 if (self->mRegCount < 8) | |
305 | 85 self->mRegData.mIntData[self->mRegCount++] = x; |
0 | 86 else |
305 | 87 dcVecAppend(&self->mVecHead, &x, sizeof(DClonglong)); |
0 | 88 } |
89 | |
305 | 90 static void dc_callvm_argInt_mips_n64(DCCallVM* in_self, DCint x) |
0 | 91 { |
305 | 92 dc_callvm_argLongLong_mips_n64(in_self, (DClonglong)x); |
0 | 93 } |
94 | |
95 static void dc_callvm_argPointer_mips_n64(DCCallVM* in_self, DCpointer x) | |
96 { | |
305 | 97 dc_callvm_argLongLong_mips_n64(in_self, *(DClonglong*)&x); |
0 | 98 } |
99 | |
100 static void dc_callvm_argBool_mips_n64(DCCallVM* in_self, DCbool x) | |
101 { | |
102 dc_callvm_argLongLong_mips_n64(in_self, (DClonglong)x); | |
103 } | |
104 | |
105 static void dc_callvm_argChar_mips_n64(DCCallVM* in_self, DCchar x) | |
106 { | |
107 dc_callvm_argLongLong_mips_n64(in_self, (DClonglong)x); | |
108 } | |
109 | |
110 static void dc_callvm_argShort_mips_n64(DCCallVM* in_self, DCshort x) | |
111 { | |
112 dc_callvm_argLongLong_mips_n64(in_self, (DClonglong)x); | |
113 } | |
114 | |
115 static void dc_callvm_argLong_mips_n64(DCCallVM* in_self, DClong x) | |
116 { | |
117 dc_callvm_argLongLong_mips_n64(in_self, (DClonglong)x); | |
118 } | |
119 | |
120 static void dc_callvm_argDouble_mips_n64(DCCallVM* in_self, DCdouble x) | |
121 { | |
305 | 122 #if defined(DC__ABI_HARDFLOAT) |
0 | 123 DCCallVM_mips_n64* self = (DCCallVM_mips_n64*)in_self; |
124 if (self->mRegCount < 8) { | |
125 self->mRegData.mUseDouble |= 1<<( self->mRegCount ); | |
126 self->mRegData.mFloatData[self->mRegCount++].d = x; | |
127 } else { | |
305 | 128 dcVecAppend(&self->mVecHead, &x, sizeof(DCdouble)); |
0 | 129 } |
305 | 130 #else |
131 dc_callvm_argLongLong_mips_n64(in_self, *(DClonglong*)&x); | |
132 #endif /* DC__ABI_HARDFLOAT */ | |
0 | 133 } |
134 | |
135 static void dc_callvm_argFloat_mips_n64(DCCallVM* in_self, DCfloat x) | |
136 { | |
305 | 137 #if defined(DC__ABI_HARDFLOAT) |
0 | 138 DCCallVM_mips_n64* self = (DCCallVM_mips_n64*)in_self; |
139 if (self->mRegCount < 8) { | |
140 /*self->mRegData.mFloatData[self->mRegCount++].d = (DCdouble) x;*/ | |
141 self->mRegData.mFloatData[self->mRegCount++].f = x; | |
142 } else { | |
305 | 143 dcVecAppend(&self->mVecHead, &x, sizeof(DCfloat)); |
144 dcVecSkip(&self->mVecHead, sizeof(DCfloat)); | |
0 | 145 } |
305 | 146 #else |
147 DCfloat f[] = {x,0.f}; | |
148 # if defined(DC__Endian_BIG) | |
149 // floats in regs always right justified | |
150 if (((DCCallVM_mips_n64*)in_self)->mRegCount < 8) { | |
151 f[1] = f[0]; | |
152 f[0] = 0.f; | |
153 } | |
154 # endif /* DC__Endian_BIG */ | |
155 dc_callvm_argLongLong_mips_n64(in_self, *(DClonglong*)&f); | |
156 #endif /* DC__ABI_HARDFLOAT */ | |
0 | 157 } |
158 | |
159 | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
128
diff
changeset
|
160 /* Ellipsis calls: |
0 | 161 - float is promoted to double (due to ANSI C). |
162 - double is passed via integer register-file (due to MIPS ABI). | |
163 */ | |
164 | |
165 static void dc_callvm_argDouble_mips_n64_ellipsis(DCCallVM* in_self, DCdouble x) | |
166 { | |
167 dc_callvm_argLongLong_mips_n64(in_self, * ( (DClonglong*) &x ) ); | |
168 } | |
169 | |
170 static void dc_callvm_argFloat_mips_n64_ellipsis(DCCallVM* in_self, DCfloat x) | |
171 { | |
172 dc_callvm_argDouble_mips_n64_ellipsis(in_self, (DCdouble) x ); | |
173 } | |
174 | |
175 | |
176 /* Call. */ | |
177 | |
178 void dc_callvm_call_mips_n64(DCCallVM* in_self, DCpointer target) | |
179 { | |
180 DCCallVM_mips_n64* self = (DCCallVM_mips_n64*)in_self; | |
181 /* at minimum provide 16-bytes | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
128
diff
changeset
|
182 which hold the first four integer register as spill area |
0 | 183 and are automatically loaded to $4-$7 |
184 */ | |
185 size_t size = DC_MAX(16, ( ( (unsigned) dcVecSize(&self->mVecHead) ) +7UL ) & (-8UL) ); | |
186 dcCall_mips_n64(target, &self->mRegData, size, dcVecData(&self->mVecHead)); | |
187 } | |
188 | |
189 static void dc_callvm_mode_mips_n64(DCCallVM* in_self,DCint mode); | |
190 | |
191 DCCallVM_vt gVT_mips_n64 = | |
192 { | |
193 &dc_callvm_free_mips_n64 | |
194 , &dc_callvm_reset_mips_n64 | |
195 , &dc_callvm_mode_mips_n64 | |
196 , &dc_callvm_argBool_mips_n64 | |
197 , &dc_callvm_argChar_mips_n64 | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
128
diff
changeset
|
198 , &dc_callvm_argShort_mips_n64 |
0 | 199 , &dc_callvm_argInt_mips_n64 |
200 , &dc_callvm_argLong_mips_n64 | |
201 , &dc_callvm_argLongLong_mips_n64 | |
202 , &dc_callvm_argFloat_mips_n64 | |
203 , &dc_callvm_argDouble_mips_n64 | |
204 , &dc_callvm_argPointer_mips_n64 | |
205 , NULL /* argStruct */ | |
206 , (DCvoidvmfunc*) &dc_callvm_call_mips_n64 | |
207 , (DCboolvmfunc*) &dc_callvm_call_mips_n64 | |
208 , (DCcharvmfunc*) &dc_callvm_call_mips_n64 | |
209 , (DCshortvmfunc*) &dc_callvm_call_mips_n64 | |
210 , (DCintvmfunc*) &dc_callvm_call_mips_n64 | |
211 , (DClongvmfunc*) &dc_callvm_call_mips_n64 | |
212 , (DClonglongvmfunc*) &dc_callvm_call_mips_n64 | |
213 , (DCfloatvmfunc*) &dc_callvm_call_mips_n64 | |
214 , (DCdoublevmfunc*) &dc_callvm_call_mips_n64 | |
215 , (DCpointervmfunc*) &dc_callvm_call_mips_n64 | |
216 , NULL /* callStruct */ | |
217 }; | |
218 | |
219 DCCallVM_vt gVT_mips_n64_ellipsis = | |
220 { | |
221 &dc_callvm_free_mips_n64 | |
222 , &dc_callvm_reset_mips_n64 | |
223 , &dc_callvm_mode_mips_n64 | |
224 , &dc_callvm_argBool_mips_n64 | |
225 , &dc_callvm_argChar_mips_n64 | |
226 , &dc_callvm_argShort_mips_n64 | |
227 , &dc_callvm_argInt_mips_n64 | |
228 , &dc_callvm_argLong_mips_n64 | |
229 , &dc_callvm_argLongLong_mips_n64 | |
230 , &dc_callvm_argFloat_mips_n64_ellipsis | |
231 , &dc_callvm_argDouble_mips_n64_ellipsis | |
232 , &dc_callvm_argPointer_mips_n64 | |
233 , NULL /* argStruct */ | |
234 , (DCvoidvmfunc*) &dc_callvm_call_mips_n64 | |
235 , (DCboolvmfunc*) &dc_callvm_call_mips_n64 | |
236 , (DCcharvmfunc*) &dc_callvm_call_mips_n64 | |
237 , (DCshortvmfunc*) &dc_callvm_call_mips_n64 | |
238 , (DCintvmfunc*) &dc_callvm_call_mips_n64 | |
239 , (DClongvmfunc*) &dc_callvm_call_mips_n64 | |
240 , (DClonglongvmfunc*) &dc_callvm_call_mips_n64 | |
241 , (DCfloatvmfunc*) &dc_callvm_call_mips_n64 | |
242 , (DCdoublevmfunc*) &dc_callvm_call_mips_n64 | |
243 , (DCpointervmfunc*) &dc_callvm_call_mips_n64 | |
244 , NULL /* callStruct */ | |
245 }; | |
246 | |
84 | 247 static void dc_callvm_mode_mips_n64(DCCallVM* in_self, DCint mode) |
0 | 248 { |
84 | 249 DCCallVM_mips_n64* self = (DCCallVM_mips_n64*)in_self; |
250 DCCallVM_vt* vt; | |
251 | |
0 | 252 switch(mode) { |
253 case DC_CALL_C_DEFAULT: | |
84 | 254 case DC_CALL_C_MIPS64_N64: |
128
9a554d1c4da6
- mips n64 vararg call fixes if non-variadic arguments are floats
cslag
parents:
84
diff
changeset
|
255 case DC_CALL_C_ELLIPSIS: |
84 | 256 vt = &gVT_mips_n64; |
0 | 257 break; |
84 | 258 case DC_CALL_C_ELLIPSIS_VARARGS: |
259 vt = &gVT_mips_n64_ellipsis; | |
0 | 260 break; |
261 default: | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
128
diff
changeset
|
262 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; |
84 | 263 return; |
0 | 264 } |
84 | 265 dc_callvm_base_init(&self->mInterface, vt); |
0 | 266 } |
267 | |
84 | 268 /* Public API. */ |
269 DCCallVM* dcNewCallVM(DCsize size) | |
0 | 270 { |
84 | 271 DCCallVM_mips_n64* p = (DCCallVM_mips_n64*)dcAllocMem(sizeof(DCCallVM_mips_n64)+size); |
272 | |
273 dc_callvm_mode_mips_n64((DCCallVM*)p, DC_CALL_C_DEFAULT); | |
274 | |
275 dcVecInit(&p->mVecHead, size); | |
276 dc_callvm_reset_mips_n64((DCCallVM*)p); | |
277 | |
278 return (DCCallVM*)p; | |
0 | 279 } |
280 |