Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_callvm_mips_n32.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 | 71c884e610f0 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: dyncall | |
5 File: dyncall/dyncall_callvm_mips_n32.c | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
84
diff
changeset
|
6 Description: mips64 "n32" ABI callvm implementation |
0 | 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 | |
28 /* | |
29 | |
30 dyncall callvm for 64bit MIPS family of processors | |
31 | |
32 SUPPORTED CALLING CONVENTIONS | |
33 n32 | |
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_n32.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:
281
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:
281
diff
changeset
|
57 void dcCall_mips_n32(DCpointer target, DCRegData_mips_n32* 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:
281
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:
281
diff
changeset
|
59 |
0 | 60 static void dc_callvm_reset_mips_n32(DCCallVM* in_self) |
61 { | |
62 DCCallVM_mips_n32* self = (DCCallVM_mips_n32*)in_self; | |
63 dcVecReset(&self->mVecHead); | |
64 self->mRegCount = 0; | |
65 self->mRegData.mUseDouble = 0LL; | |
66 } | |
67 | |
68 | |
69 static void dc_callvm_free_mips_n32(DCCallVM* in_self) | |
70 { | |
71 dcFreeMem(in_self); | |
72 } | |
73 | |
74 /* pass arguments : | |
75 | |
76 - promote to 64-bit integer. | |
77 - fill up integers and float - left-to-right otherwise go over stack. | |
78 */ | |
79 | |
80 /* arg int -- fillup 64-bit integer register file OR push on stack */ | |
81 | |
82 static void dc_callvm_argLongLong_mips_n32(DCCallVM* in_self, DClonglong Lv) | |
83 { | |
84 DCCallVM_mips_n32* self = (DCCallVM_mips_n32*)in_self; | |
85 /* fillup integer register file */ | |
86 if (self->mRegCount < 8) | |
87 self->mRegData.mIntData[self->mRegCount++] = Lv; | |
88 else | |
89 dcVecAppend(&self->mVecHead, &Lv, sizeof(DClonglong)); | |
90 } | |
91 | |
92 static void dc_callvm_argInt_mips_n32(DCCallVM* in_self, DCint i) | |
93 { | |
94 dc_callvm_argLongLong_mips_n32(in_self, (DClonglong) i ); | |
95 } | |
96 | |
97 static void dc_callvm_argPointer_mips_n32(DCCallVM* in_self, DCpointer x) | |
98 { | |
99 dc_callvm_argLongLong_mips_n32(in_self, * (DClonglong*) &x ); | |
100 } | |
101 | |
102 static void dc_callvm_argBool_mips_n32(DCCallVM* in_self, DCbool x) | |
103 { | |
104 dc_callvm_argLongLong_mips_n32(in_self, (DClonglong)x); | |
105 } | |
106 | |
107 static void dc_callvm_argChar_mips_n32(DCCallVM* in_self, DCchar x) | |
108 { | |
109 dc_callvm_argLongLong_mips_n32(in_self, (DClonglong)x); | |
110 } | |
111 | |
112 static void dc_callvm_argShort_mips_n32(DCCallVM* in_self, DCshort x) | |
113 { | |
114 dc_callvm_argLongLong_mips_n32(in_self, (DClonglong)x); | |
115 } | |
116 | |
117 static void dc_callvm_argLong_mips_n32(DCCallVM* in_self, DClong x) | |
118 { | |
119 dc_callvm_argLongLong_mips_n32(in_self, (DClonglong)x); | |
120 } | |
121 | |
122 static void dc_callvm_argDouble_mips_n32(DCCallVM* in_self, DCdouble x) | |
123 { | |
124 DCCallVM_mips_n32* self = (DCCallVM_mips_n32*)in_self; | |
125 if (self->mRegCount < 8) { | |
126 self->mRegData.mUseDouble |= 1<<( self->mRegCount ); | |
127 self->mRegData.mFloatData[self->mRegCount++].d = x; | |
128 } else { | |
129 dcVecAppend(&self->mVecHead, &x, sizeof(DCdouble) ); | |
130 } | |
131 } | |
132 | |
133 static void dc_callvm_argFloat_mips_n32(DCCallVM* in_self, DCfloat x) | |
134 { | |
135 DCCallVM_mips_n32* self = (DCCallVM_mips_n32*)in_self; | |
136 if (self->mRegCount < 8) { | |
137 /*self->mRegData.mFloatData[self->mRegCount++].d = (DCdouble) x;*/ | |
138 self->mRegData.mFloatData[self->mRegCount++].f = x; | |
139 } else { | |
140 dcVecAppend(&self->mVecHead, &x, sizeof(DCfloat) ); | |
141 dcVecSkip(&self->mVecHead, sizeof(DCfloat) ); | |
142 } | |
143 } | |
144 | |
145 | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
84
diff
changeset
|
146 /* Ellipsis calls: |
0 | 147 - float is promoted to double (due to ANSI C). |
148 - double is passed via integer register-file (due to MIPS ABI). | |
149 */ | |
150 | |
151 static void dc_callvm_argDouble_mips_n32_ellipsis(DCCallVM* in_self, DCdouble x) | |
152 { | |
153 dc_callvm_argLongLong_mips_n32(in_self, * ( (DClonglong*) &x ) ); | |
154 } | |
155 | |
156 static void dc_callvm_argFloat_mips_n32_ellipsis(DCCallVM* in_self, DCfloat x) | |
157 { | |
158 dc_callvm_argDouble_mips_n32_ellipsis(in_self, (DCdouble) x ); | |
159 } | |
160 | |
161 | |
162 /* Call. */ | |
163 | |
164 void dc_callvm_call_mips_n32(DCCallVM* in_self, DCpointer target) | |
165 { | |
166 DCCallVM_mips_n32* self = (DCCallVM_mips_n32*)in_self; | |
167 /* at minimum provide 16-bytes | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
84
diff
changeset
|
168 which hold the first four integer register as spill area |
0 | 169 and are automatically loaded to $4-$7 |
170 */ | |
171 size_t size = DC_MAX(16, ( ( (unsigned) dcVecSize(&self->mVecHead) ) +7UL ) & (-8UL) ); | |
172 dcCall_mips_n32(target, &self->mRegData, size, dcVecData(&self->mVecHead)); | |
173 } | |
174 | |
175 /* Forward Declaration. */ | |
176 static void dc_callvm_mode_mips_n32(DCCallVM* in_self,DCint mode); | |
177 | |
178 DCCallVM_vt gVT_mips_n32 = | |
179 { | |
180 &dc_callvm_free_mips_n32 | |
181 , &dc_callvm_reset_mips_n32 | |
182 , &dc_callvm_mode_mips_n32 | |
183 , &dc_callvm_argBool_mips_n32 | |
184 , &dc_callvm_argChar_mips_n32 | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
84
diff
changeset
|
185 , &dc_callvm_argShort_mips_n32 |
0 | 186 , &dc_callvm_argInt_mips_n32 |
187 , &dc_callvm_argLong_mips_n32 | |
188 , &dc_callvm_argLongLong_mips_n32 | |
189 , &dc_callvm_argFloat_mips_n32 | |
190 , &dc_callvm_argDouble_mips_n32 | |
191 , &dc_callvm_argPointer_mips_n32 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
192 , NULL /* argAggr */ |
0 | 193 , (DCvoidvmfunc*) &dc_callvm_call_mips_n32 |
194 , (DCboolvmfunc*) &dc_callvm_call_mips_n32 | |
195 , (DCcharvmfunc*) &dc_callvm_call_mips_n32 | |
196 , (DCshortvmfunc*) &dc_callvm_call_mips_n32 | |
197 , (DCintvmfunc*) &dc_callvm_call_mips_n32 | |
198 , (DClongvmfunc*) &dc_callvm_call_mips_n32 | |
199 , (DClonglongvmfunc*) &dc_callvm_call_mips_n32 | |
200 , (DCfloatvmfunc*) &dc_callvm_call_mips_n32 | |
201 , (DCdoublevmfunc*) &dc_callvm_call_mips_n32 | |
202 , (DCpointervmfunc*) &dc_callvm_call_mips_n32 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
203 , NULL /* callAggr */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
204 , NULL /* beginAggr */ |
0 | 205 }; |
206 | |
207 DCCallVM_vt gVT_mips_n32_ellipsis = | |
208 { | |
209 &dc_callvm_free_mips_n32 | |
210 , &dc_callvm_reset_mips_n32 | |
211 , &dc_callvm_mode_mips_n32 | |
212 , &dc_callvm_argBool_mips_n32 | |
213 , &dc_callvm_argChar_mips_n32 | |
214 , &dc_callvm_argShort_mips_n32 | |
215 , &dc_callvm_argInt_mips_n32 | |
216 , &dc_callvm_argLong_mips_n32 | |
217 , &dc_callvm_argLongLong_mips_n32 | |
218 , &dc_callvm_argFloat_mips_n32_ellipsis | |
219 , &dc_callvm_argDouble_mips_n32_ellipsis | |
220 , &dc_callvm_argPointer_mips_n32 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
221 , NULL /* argAggr */ |
0 | 222 , (DCvoidvmfunc*) &dc_callvm_call_mips_n32 |
223 , (DCboolvmfunc*) &dc_callvm_call_mips_n32 | |
224 , (DCcharvmfunc*) &dc_callvm_call_mips_n32 | |
225 , (DCshortvmfunc*) &dc_callvm_call_mips_n32 | |
226 , (DCintvmfunc*) &dc_callvm_call_mips_n32 | |
227 , (DClongvmfunc*) &dc_callvm_call_mips_n32 | |
228 , (DClonglongvmfunc*) &dc_callvm_call_mips_n32 | |
229 , (DCfloatvmfunc*) &dc_callvm_call_mips_n32 | |
230 , (DCdoublevmfunc*) &dc_callvm_call_mips_n32 | |
231 , (DCpointervmfunc*) &dc_callvm_call_mips_n32 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
232 , NULL /* callAggr */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
233 , NULL /* beginAggr */ |
0 | 234 }; |
235 | |
84 | 236 static void dc_callvm_mode_mips_n32(DCCallVM* in_self, DCint mode) |
0 | 237 { |
84 | 238 DCCallVM_mips_n32* self = (DCCallVM_mips_n32*)in_self; |
239 DCCallVM_vt* vt; | |
240 | |
0 | 241 switch(mode) { |
242 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
|
243 case DC_CALL_C_DEFAULT_THIS: |
84 | 244 case DC_CALL_C_MIPS64_N32: |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
84
diff
changeset
|
245 case DC_CALL_C_ELLIPSIS: |
84 | 246 vt = &gVT_mips_n32; |
0 | 247 break; |
84 | 248 case DC_CALL_C_ELLIPSIS_VARARGS: |
249 vt = &gVT_mips_n32_ellipsis; | |
0 | 250 break; |
251 default: | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
84
diff
changeset
|
252 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; |
84 | 253 return; |
0 | 254 } |
84 | 255 dc_callvm_base_init(&self->mInterface, vt); |
0 | 256 } |
257 | |
84 | 258 /* Public API. */ |
259 DCCallVM* dcNewCallVM(DCsize size) | |
0 | 260 { |
84 | 261 DCCallVM_mips_n32* p = (DCCallVM_mips_n32*)dcAllocMem(sizeof(DCCallVM_mips_n32)+size); |
262 | |
263 dc_callvm_mode_mips_n32((DCCallVM*)p, DC_CALL_C_DEFAULT); | |
264 | |
265 dcVecInit(&p->mVecHead, size); | |
266 dc_callvm_reset_mips_n32((DCCallVM*)p); | |
267 | |
268 return (DCCallVM*)p; | |
0 | 269 } |
270 |