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