Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_callvm_mips_o32.c @ 305:b104c5beec8b
- softfloat support for mips64/n64 abi
author | Tassilo Philipp |
---|---|
date | Wed, 23 May 2018 11:41:34 +0200 |
parents | d55f9d508074 |
children | 6ffb6a00cf55 |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: dyncall | |
5 File: dyncall/dyncall_callvm_mips_o32.c | |
6 Description: mips "o32" 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 mips o32 abi | |
31 | |
32 REVISION | |
33 2010/06/03 initial | |
34 | |
35 NOTES: | |
36 we need an argument counter for supporting floating point arguments | |
37 correctly. | |
38 | |
39 first two (if any) double/float arguments are mapped via a common structure -- | |
40 code must take care to write the right float argument indices which | |
41 differs on C and Assembly-side depending on endianness. (therefore | |
42 both sources have two variants 'mipseb' and 'mipsel'.) | |
43 (only for the first two float/double arguments) see float/double handling | |
44 | |
45 although, the abi does not expect usage of floats if first argument is | |
46 not floating point, the call kernel can be used universal for all cases. | |
47 | |
48 */ | |
49 | |
50 | |
51 #include "dyncall_callvm_mips_o32.h" | |
52 #include "dyncall_alloc.h" | |
53 #include "dyncall_utils.h" | |
54 | |
55 | |
56 static void dc_callvm_reset_mips_o32(DCCallVM* in_self) | |
57 { | |
58 DCCallVM_mips_o32* self = (DCCallVM_mips_o32*)in_self; | |
59 dcVecReset(&self->mVecHead); | |
60 self->mArgCount = 0; | |
61 } | |
62 | |
63 | |
64 static void dc_callvm_free_mips_o32(DCCallVM* in_self) | |
65 { | |
66 dcFreeMem(in_self); | |
67 } | |
68 | |
69 /* arg int -- fillup integer register file OR push on stack */ | |
70 | |
71 static void dc_callvm_argInt_mips_o32(DCCallVM* in_self, DCint i) | |
72 { | |
73 DCCallVM_mips_o32* self = (DCCallVM_mips_o32*)in_self; | |
74 dcVecAppend(&self->mVecHead, &i, sizeof(DCint)); | |
75 self->mArgCount++; | |
76 } | |
77 | |
78 static void dc_callvm_argPointer_mips_o32(DCCallVM* in_self, DCpointer x) | |
79 { | |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
80 dc_callvm_argInt_mips_o32(in_self, *(DCint*)&x); |
0 | 81 } |
82 | |
83 static void dc_callvm_argBool_mips_o32(DCCallVM* in_self, DCbool x) | |
84 { | |
85 dc_callvm_argInt_mips_o32(in_self, (DCint)x); | |
86 } | |
87 | |
88 static void dc_callvm_argChar_mips_o32(DCCallVM* in_self, DCchar x) | |
89 { | |
90 dc_callvm_argInt_mips_o32(in_self, (DCint)x); | |
91 } | |
92 | |
93 static void dc_callvm_argShort_mips_o32(DCCallVM* in_self, DCshort x) | |
94 { | |
95 dc_callvm_argInt_mips_o32(in_self, (DCint)x); | |
96 } | |
97 | |
98 static void dc_callvm_argLong_mips_o32(DCCallVM* in_self, DClong x) | |
99 { | |
100 dc_callvm_argInt_mips_o32(in_self, (DCint)x); | |
101 } | |
102 | |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
103 static void dc_callvm_argLongLong_mips_o32(DCCallVM* in_self, DClonglong x) |
0 | 104 { |
105 DCCallVM_mips_o32* self = (DCCallVM_mips_o32*)in_self; | |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
106 |
0 | 107 /* 64-bit values need to be aligned on 8 byte boundaries */ |
108 dcVecSkip(&self->mVecHead, dcVecSize(&self->mVecHead) & 4); | |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
109 dcVecAppend(&self->mVecHead, &x, sizeof(DClonglong)); |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
110 self->mArgCount++; |
0 | 111 } |
112 | |
113 static void dc_callvm_argFloat_mips_o32(DCCallVM* in_self, DCfloat x) | |
114 { | |
115 DCCallVM_mips_o32* self = (DCCallVM_mips_o32*)in_self; | |
116 | |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
117 dcVecAppend(&self->mVecHead, &x, sizeof(DCfloat)); |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
118 |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
119 #if defined(DC__ABI_HARDFLOAT) |
0 | 120 if (self->mArgCount < 2) { |
305 | 121 /* @@@ unsure if we should zero init, here; seems to work as-is */ |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
122 # if defined(DC__Endian_LITTLE) |
0 | 123 self->mRegData.u[self->mArgCount].f[0] = x; |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
124 # else |
305 | 125 self->mRegData.u[self->mArgCount].f[1] = x; // floats in regs always right justified |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
126 # endif |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
127 # if 0 |
0 | 128 self->mRegData.u[self->mArgCount].f[1] = x; |
129 call kernel | |
130 | |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
131 mips: |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
132 lwc1 $f12, 4($5) <--- byte offset 4 |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
133 lwc1 $f13, 0($5) |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
134 lwc1 $f14, 12($5) <--- byte offset 12 |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
135 lwc1 $f15, 8($5) |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
136 mipsel: |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
137 lwc1 $f12, 0($5) <--- byte offset 4 |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
138 lwc1 $f13, 4($5) |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
139 lwc1 $f14, 8($5) <--- byte offset 12 |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
140 lwc1 $f15, 12($5) |
0 | 141 |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
142 # if defined(DC__Endian_LITTLE) |
0 | 143 /* index 0 and 2 */ |
144 self->mRegData.floats[self->mArgCount*2] = x; | |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
145 # else |
0 | 146 /* index 1 and 3 */ |
147 self->mRegData.floats[self->mArgCount*2+1] = x; | |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
148 # endif |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
149 # endif |
0 | 150 } |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
151 #endif /* DC__ABI_HARDFLOAT */ |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
152 |
0 | 153 self->mArgCount++; |
154 } | |
155 | |
156 static void dc_callvm_argDouble_mips_o32(DCCallVM* in_self, DCdouble x) | |
157 { | |
158 DCCallVM_mips_o32* self = (DCCallVM_mips_o32*)in_self; | |
159 /* 64-bit values need to be aligned on 8 byte boundaries */ | |
160 dcVecSkip(&self->mVecHead, dcVecSize(&self->mVecHead) & 4); | |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
161 dcVecAppend(&self->mVecHead, &x, sizeof(DCdouble)); |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
162 |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
163 #if defined(DC__ABI_HARDFLOAT) |
0 | 164 if (self->mArgCount < 2) |
165 self->mRegData.u[self->mArgCount].d = x; | |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
166 #endif /* DC__ABI_HARDFLOAT */ |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
167 |
0 | 168 self->mArgCount++; |
169 } | |
170 | |
171 /* Call. */ | |
172 void dc_callvm_call_mips_o32(DCCallVM* in_self, DCpointer target) | |
173 { | |
174 DCCallVM_mips_o32* self = (DCCallVM_mips_o32*)in_self; | |
175 /* at minimum provide 16-bytes | |
176 which hold the first four integer register as spill area | |
177 and are automatically loaded to $4-$7 | |
178 */ | |
179 | |
180 size_t size = DC_MAX(16, ( ( (unsigned) dcVecSize(&self->mVecHead) ) +7UL ) & (-8UL) ); | |
181 | |
182 dcCall_mips_o32(target, &self->mRegData, size, dcVecData(&self->mVecHead)); | |
183 } | |
184 | |
84 | 185 static void dc_callvm_mode_mips_o32(DCCallVM* in_self, DCint mode); |
186 | |
0 | 187 DCCallVM_vt gVT_mips_o32 = |
188 { | |
189 &dc_callvm_free_mips_o32 | |
190 , &dc_callvm_reset_mips_o32 | |
191 , &dc_callvm_mode_mips_o32 | |
192 , &dc_callvm_argBool_mips_o32 | |
193 , &dc_callvm_argChar_mips_o32 | |
194 , &dc_callvm_argShort_mips_o32 | |
195 , &dc_callvm_argInt_mips_o32 | |
196 , &dc_callvm_argLong_mips_o32 | |
197 , &dc_callvm_argLongLong_mips_o32 | |
198 , &dc_callvm_argFloat_mips_o32 | |
199 , &dc_callvm_argDouble_mips_o32 | |
200 , &dc_callvm_argPointer_mips_o32 | |
201 , NULL /* argStruct */ | |
202 , (DCvoidvmfunc*) &dc_callvm_call_mips_o32 | |
203 , (DCboolvmfunc*) &dc_callvm_call_mips_o32 | |
204 , (DCcharvmfunc*) &dc_callvm_call_mips_o32 | |
205 , (DCshortvmfunc*) &dc_callvm_call_mips_o32 | |
206 , (DCintvmfunc*) &dc_callvm_call_mips_o32 | |
207 , (DClongvmfunc*) &dc_callvm_call_mips_o32 | |
208 , (DClonglongvmfunc*) &dc_callvm_call_mips_o32 | |
209 , (DCfloatvmfunc*) &dc_callvm_call_mips_o32 | |
210 , (DCdoublevmfunc*) &dc_callvm_call_mips_o32 | |
211 , (DCpointervmfunc*) &dc_callvm_call_mips_o32 | |
212 , NULL /* callStruct */ | |
213 }; | |
214 | |
84 | 215 /* mode: only a single mode available currently. */ |
216 static void dc_callvm_mode_mips_o32(DCCallVM* in_self, DCint mode) | |
0 | 217 { |
84 | 218 DCCallVM_mips_o32* self = (DCCallVM_mips_o32*)in_self; |
219 DCCallVM_vt* vt; | |
220 | |
221 switch(mode) { | |
222 case DC_CALL_C_DEFAULT: | |
223 case DC_CALL_C_MIPS32_O32: | |
224 case DC_CALL_C_ELLIPSIS: | |
225 case DC_CALL_C_ELLIPSIS_VARARGS: | |
226 vt = &gVT_mips_o32; | |
227 break; | |
228 default: | |
229 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; | |
230 return; | |
231 } | |
232 dc_callvm_base_init(&self->mInterface, vt); | |
0 | 233 } |
234 | |
84 | 235 /* Public API. */ |
0 | 236 DCCallVM* dcNewCallVM(DCsize size) |
237 { | |
84 | 238 DCCallVM_mips_o32* p = (DCCallVM_mips_o32*)dcAllocMem(sizeof(DCCallVM_mips_o32)+size); |
239 | |
240 dc_callvm_mode_mips_o32((DCCallVM*)p, DC_CALL_C_DEFAULT); | |
241 | |
242 dcVecInit(&p->mVecHead, size); | |
243 dc_callvm_reset_mips_o32((DCCallVM*)p); | |
244 | |
245 return (DCCallVM*)p; | |
0 | 246 } |
247 |