Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_callvm_mips_n32.c @ 216:28bf0b231bce
- dynload man page clarification about resolving own symbols
author | Tassilo Philipp |
---|---|
date | Thu, 06 Apr 2017 11:40:15 +0200 |
parents | 21537652361e |
children | f5577f6bf97a |
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 | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
84
diff
changeset
|
9 Copyright (c) 2007-2016 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 | |
56 static void dc_callvm_reset_mips_n32(DCCallVM* in_self) | |
57 { | |
58 DCCallVM_mips_n32* self = (DCCallVM_mips_n32*)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_n32(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_n32(DCCallVM* in_self, DClonglong Lv) | |
79 { | |
80 DCCallVM_mips_n32* self = (DCCallVM_mips_n32*)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_n32(DCCallVM* in_self, DCint i) | |
89 { | |
90 dc_callvm_argLongLong_mips_n32(in_self, (DClonglong) i ); | |
91 } | |
92 | |
93 static void dc_callvm_argPointer_mips_n32(DCCallVM* in_self, DCpointer x) | |
94 { | |
95 dc_callvm_argLongLong_mips_n32(in_self, * (DClonglong*) &x ); | |
96 } | |
97 | |
98 static void dc_callvm_argBool_mips_n32(DCCallVM* in_self, DCbool x) | |
99 { | |
100 dc_callvm_argLongLong_mips_n32(in_self, (DClonglong)x); | |
101 } | |
102 | |
103 static void dc_callvm_argChar_mips_n32(DCCallVM* in_self, DCchar x) | |
104 { | |
105 dc_callvm_argLongLong_mips_n32(in_self, (DClonglong)x); | |
106 } | |
107 | |
108 static void dc_callvm_argShort_mips_n32(DCCallVM* in_self, DCshort x) | |
109 { | |
110 dc_callvm_argLongLong_mips_n32(in_self, (DClonglong)x); | |
111 } | |
112 | |
113 static void dc_callvm_argLong_mips_n32(DCCallVM* in_self, DClong x) | |
114 { | |
115 dc_callvm_argLongLong_mips_n32(in_self, (DClonglong)x); | |
116 } | |
117 | |
118 static void dc_callvm_argDouble_mips_n32(DCCallVM* in_self, DCdouble x) | |
119 { | |
120 DCCallVM_mips_n32* self = (DCCallVM_mips_n32*)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_n32(DCCallVM* in_self, DCfloat x) | |
130 { | |
131 DCCallVM_mips_n32* self = (DCCallVM_mips_n32*)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:
84
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_n32_ellipsis(DCCallVM* in_self, DCdouble x) | |
148 { | |
149 dc_callvm_argLongLong_mips_n32(in_self, * ( (DClonglong*) &x ) ); | |
150 } | |
151 | |
152 static void dc_callvm_argFloat_mips_n32_ellipsis(DCCallVM* in_self, DCfloat x) | |
153 { | |
154 dc_callvm_argDouble_mips_n32_ellipsis(in_self, (DCdouble) x ); | |
155 } | |
156 | |
157 | |
158 /* Call. */ | |
159 | |
160 void dc_callvm_call_mips_n32(DCCallVM* in_self, DCpointer target) | |
161 { | |
162 DCCallVM_mips_n32* self = (DCCallVM_mips_n32*)in_self; | |
163 /* at minimum provide 16-bytes | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
84
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_n32(target, &self->mRegData, size, dcVecData(&self->mVecHead)); | |
169 } | |
170 | |
171 /* Forward Declaration. */ | |
172 static void dc_callvm_mode_mips_n32(DCCallVM* in_self,DCint mode); | |
173 | |
174 DCCallVM_vt gVT_mips_n32 = | |
175 { | |
176 &dc_callvm_free_mips_n32 | |
177 , &dc_callvm_reset_mips_n32 | |
178 , &dc_callvm_mode_mips_n32 | |
179 , &dc_callvm_argBool_mips_n32 | |
180 , &dc_callvm_argChar_mips_n32 | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
84
diff
changeset
|
181 , &dc_callvm_argShort_mips_n32 |
0 | 182 , &dc_callvm_argInt_mips_n32 |
183 , &dc_callvm_argLong_mips_n32 | |
184 , &dc_callvm_argLongLong_mips_n32 | |
185 , &dc_callvm_argFloat_mips_n32 | |
186 , &dc_callvm_argDouble_mips_n32 | |
187 , &dc_callvm_argPointer_mips_n32 | |
188 , NULL /* argStruct */ | |
189 , (DCvoidvmfunc*) &dc_callvm_call_mips_n32 | |
190 , (DCboolvmfunc*) &dc_callvm_call_mips_n32 | |
191 , (DCcharvmfunc*) &dc_callvm_call_mips_n32 | |
192 , (DCshortvmfunc*) &dc_callvm_call_mips_n32 | |
193 , (DCintvmfunc*) &dc_callvm_call_mips_n32 | |
194 , (DClongvmfunc*) &dc_callvm_call_mips_n32 | |
195 , (DClonglongvmfunc*) &dc_callvm_call_mips_n32 | |
196 , (DCfloatvmfunc*) &dc_callvm_call_mips_n32 | |
197 , (DCdoublevmfunc*) &dc_callvm_call_mips_n32 | |
198 , (DCpointervmfunc*) &dc_callvm_call_mips_n32 | |
199 , NULL /* callStruct */ | |
200 }; | |
201 | |
202 DCCallVM_vt gVT_mips_n32_ellipsis = | |
203 { | |
204 &dc_callvm_free_mips_n32 | |
205 , &dc_callvm_reset_mips_n32 | |
206 , &dc_callvm_mode_mips_n32 | |
207 , &dc_callvm_argBool_mips_n32 | |
208 , &dc_callvm_argChar_mips_n32 | |
209 , &dc_callvm_argShort_mips_n32 | |
210 , &dc_callvm_argInt_mips_n32 | |
211 , &dc_callvm_argLong_mips_n32 | |
212 , &dc_callvm_argLongLong_mips_n32 | |
213 , &dc_callvm_argFloat_mips_n32_ellipsis | |
214 , &dc_callvm_argDouble_mips_n32_ellipsis | |
215 , &dc_callvm_argPointer_mips_n32 | |
216 , NULL /* argStruct */ | |
217 , (DCvoidvmfunc*) &dc_callvm_call_mips_n32 | |
218 , (DCboolvmfunc*) &dc_callvm_call_mips_n32 | |
219 , (DCcharvmfunc*) &dc_callvm_call_mips_n32 | |
220 , (DCshortvmfunc*) &dc_callvm_call_mips_n32 | |
221 , (DCintvmfunc*) &dc_callvm_call_mips_n32 | |
222 , (DClongvmfunc*) &dc_callvm_call_mips_n32 | |
223 , (DClonglongvmfunc*) &dc_callvm_call_mips_n32 | |
224 , (DCfloatvmfunc*) &dc_callvm_call_mips_n32 | |
225 , (DCdoublevmfunc*) &dc_callvm_call_mips_n32 | |
226 , (DCpointervmfunc*) &dc_callvm_call_mips_n32 | |
227 , NULL /* callStruct */ | |
228 }; | |
229 | |
84 | 230 static void dc_callvm_mode_mips_n32(DCCallVM* in_self, DCint mode) |
0 | 231 { |
84 | 232 DCCallVM_mips_n32* self = (DCCallVM_mips_n32*)in_self; |
233 DCCallVM_vt* vt; | |
234 | |
0 | 235 switch(mode) { |
236 case DC_CALL_C_DEFAULT: | |
84 | 237 case DC_CALL_C_MIPS64_N32: |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
84
diff
changeset
|
238 case DC_CALL_C_ELLIPSIS: |
84 | 239 vt = &gVT_mips_n32; |
0 | 240 break; |
84 | 241 case DC_CALL_C_ELLIPSIS_VARARGS: |
242 vt = &gVT_mips_n32_ellipsis; | |
0 | 243 break; |
244 default: | |
131
21537652361e
- fixed mips64 n32 build (not sure if working, though)
cslag
parents:
84
diff
changeset
|
245 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; |
84 | 246 return; |
0 | 247 } |
84 | 248 dc_callvm_base_init(&self->mInterface, vt); |
0 | 249 } |
250 | |
84 | 251 /* Public API. */ |
252 DCCallVM* dcNewCallVM(DCsize size) | |
0 | 253 { |
84 | 254 DCCallVM_mips_n32* p = (DCCallVM_mips_n32*)dcAllocMem(sizeof(DCCallVM_mips_n32)+size); |
255 | |
256 dc_callvm_mode_mips_n32((DCCallVM*)p, DC_CALL_C_DEFAULT); | |
257 | |
258 dcVecInit(&p->mVecHead, size); | |
259 dc_callvm_reset_mips_n32((DCCallVM*)p); | |
260 | |
261 return (DCCallVM*)p; | |
0 | 262 } |
263 |