Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_callvm_mips_o32.c @ 302:d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
- cleanup of some mips files, removed unnecessary file, renamings..
- doc/manual cleanups, changelog entry
author | Tassilo Philipp |
---|---|
date | Mon, 21 May 2018 02:48:12 +0200 |
parents | f5577f6bf97a |
children | b104c5beec8b |
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) { |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
121 # if defined(DC__Endian_LITTLE) |
0 | 122 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
|
123 # else |
0 | 124 self->mRegData.u[self->mArgCount].f[1] = x; |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
125 # endif |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
126 # if 0 |
0 | 127 self->mRegData.u[self->mArgCount].f[1] = x; |
128 call kernel | |
129 | |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
130 mips: |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
131 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
|
132 lwc1 $f13, 0($5) |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
133 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
|
134 lwc1 $f15, 8($5) |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
135 mipsel: |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
136 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
|
137 lwc1 $f13, 4($5) |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
138 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
|
139 lwc1 $f15, 12($5) |
0 | 140 |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
141 # if defined(DC__Endian_LITTLE) |
0 | 142 /* index 0 and 2 */ |
143 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
|
144 # else |
0 | 145 /* index 1 and 3 */ |
146 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
|
147 # endif |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
148 # endif |
0 | 149 } |
302
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
150 #endif /* DC__ABI_HARDFLOAT */ |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
151 |
0 | 152 self->mArgCount++; |
153 } | |
154 | |
155 static void dc_callvm_argDouble_mips_o32(DCCallVM* in_self, DCdouble x) | |
156 { | |
157 DCCallVM_mips_o32* self = (DCCallVM_mips_o32*)in_self; | |
158 /* 64-bit values need to be aligned on 8 byte boundaries */ | |
159 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
|
160 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
|
161 |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
162 #if defined(DC__ABI_HARDFLOAT) |
0 | 163 if (self->mArgCount < 2) |
164 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
|
165 #endif /* DC__ABI_HARDFLOAT */ |
d55f9d508074
- mips softfloat support for o32 callconv (calls and callbacks, little and big endian)
Tassilo Philipp
parents:
281
diff
changeset
|
166 |
0 | 167 self->mArgCount++; |
168 } | |
169 | |
170 /* Call. */ | |
171 void dc_callvm_call_mips_o32(DCCallVM* in_self, DCpointer target) | |
172 { | |
173 DCCallVM_mips_o32* self = (DCCallVM_mips_o32*)in_self; | |
174 /* at minimum provide 16-bytes | |
175 which hold the first four integer register as spill area | |
176 and are automatically loaded to $4-$7 | |
177 */ | |
178 | |
179 size_t size = DC_MAX(16, ( ( (unsigned) dcVecSize(&self->mVecHead) ) +7UL ) & (-8UL) ); | |
180 | |
181 dcCall_mips_o32(target, &self->mRegData, size, dcVecData(&self->mVecHead)); | |
182 } | |
183 | |
84 | 184 static void dc_callvm_mode_mips_o32(DCCallVM* in_self, DCint mode); |
185 | |
0 | 186 DCCallVM_vt gVT_mips_o32 = |
187 { | |
188 &dc_callvm_free_mips_o32 | |
189 , &dc_callvm_reset_mips_o32 | |
190 , &dc_callvm_mode_mips_o32 | |
191 , &dc_callvm_argBool_mips_o32 | |
192 , &dc_callvm_argChar_mips_o32 | |
193 , &dc_callvm_argShort_mips_o32 | |
194 , &dc_callvm_argInt_mips_o32 | |
195 , &dc_callvm_argLong_mips_o32 | |
196 , &dc_callvm_argLongLong_mips_o32 | |
197 , &dc_callvm_argFloat_mips_o32 | |
198 , &dc_callvm_argDouble_mips_o32 | |
199 , &dc_callvm_argPointer_mips_o32 | |
200 , NULL /* argStruct */ | |
201 , (DCvoidvmfunc*) &dc_callvm_call_mips_o32 | |
202 , (DCboolvmfunc*) &dc_callvm_call_mips_o32 | |
203 , (DCcharvmfunc*) &dc_callvm_call_mips_o32 | |
204 , (DCshortvmfunc*) &dc_callvm_call_mips_o32 | |
205 , (DCintvmfunc*) &dc_callvm_call_mips_o32 | |
206 , (DClongvmfunc*) &dc_callvm_call_mips_o32 | |
207 , (DClonglongvmfunc*) &dc_callvm_call_mips_o32 | |
208 , (DCfloatvmfunc*) &dc_callvm_call_mips_o32 | |
209 , (DCdoublevmfunc*) &dc_callvm_call_mips_o32 | |
210 , (DCpointervmfunc*) &dc_callvm_call_mips_o32 | |
211 , NULL /* callStruct */ | |
212 }; | |
213 | |
84 | 214 /* mode: only a single mode available currently. */ |
215 static void dc_callvm_mode_mips_o32(DCCallVM* in_self, DCint mode) | |
0 | 216 { |
84 | 217 DCCallVM_mips_o32* self = (DCCallVM_mips_o32*)in_self; |
218 DCCallVM_vt* vt; | |
219 | |
220 switch(mode) { | |
221 case DC_CALL_C_DEFAULT: | |
222 case DC_CALL_C_MIPS32_O32: | |
223 case DC_CALL_C_ELLIPSIS: | |
224 case DC_CALL_C_ELLIPSIS_VARARGS: | |
225 vt = &gVT_mips_o32; | |
226 break; | |
227 default: | |
228 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; | |
229 return; | |
230 } | |
231 dc_callvm_base_init(&self->mInterface, vt); | |
0 | 232 } |
233 | |
84 | 234 /* Public API. */ |
0 | 235 DCCallVM* dcNewCallVM(DCsize size) |
236 { | |
84 | 237 DCCallVM_mips_o32* p = (DCCallVM_mips_o32*)dcAllocMem(sizeof(DCCallVM_mips_o32)+size); |
238 | |
239 dc_callvm_mode_mips_o32((DCCallVM*)p, DC_CALL_C_DEFAULT); | |
240 | |
241 dcVecInit(&p->mVecHead, size); | |
242 dc_callvm_reset_mips_o32((DCCallVM*)p); | |
243 | |
244 return (DCCallVM*)p; | |
0 | 245 } |
246 |