Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_callvm_mips_o32.c @ 217:87c695673522
dynload darwin/mach-o update:
- removed unnecessarily complex darwin loader interface, and sharing with dynload_unix now
- mach-o symbol resolving refactored:
* to handle symlinks, relative paths, paths with random casing
* loading lib when not already loaded, for API consistency with ELF and PE implementations
author | Tassilo Philipp |
---|---|
date | Thu, 06 Apr 2017 12:00:36 +0200 |
parents | 1ce60358fbad |
children | f5577f6bf97a |
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 | |
9 Copyright (c) 2007-2015 Daniel Adler <dadler@uni-goettingen.de>, | |
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 { | |
80 dc_callvm_argInt_mips_o32(in_self, * (DCint*) &x ); | |
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 | |
103 static void dc_callvm_argLongLong_mips_o32(DCCallVM* in_self, DClonglong Lv) | |
104 { | |
105 DCCallVM_mips_o32* self = (DCCallVM_mips_o32*)in_self; | |
106 | |
107 /* 64-bit values need to be aligned on 8 byte boundaries */ | |
108 dcVecSkip(&self->mVecHead, dcVecSize(&self->mVecHead) & 4); | |
109 dcVecAppend(&self->mVecHead, &Lv, sizeof(DClonglong)); | |
110 self->mArgCount += 1; | |
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 | |
117 dcVecAppend(&self->mVecHead, &x, sizeof(DCfloat) ); | |
118 if (self->mArgCount < 2) { | |
101
1ce60358fbad
- mips related cleanup, mostly comments, cpp macro lib
cslag
parents:
84
diff
changeset
|
119 #if defined(DC__Endian_LITTLE) |
0 | 120 self->mRegData.u[self->mArgCount].f[0] = x; |
121 #else | |
122 self->mRegData.u[self->mArgCount].f[1] = x; | |
123 #endif | |
124 #if 0 | |
125 self->mRegData.u[self->mArgCount].f[1] = x; | |
126 call kernel | |
127 | |
128 mips: | |
129 lwc1 $f12, 4($5) <--- byte offset 4 | |
130 lwc1 $f13, 0($5) | |
131 lwc1 $f14, 12($5) <--- byte offset 12 | |
132 lwc1 $f15, 8($5) | |
133 mipsel: | |
134 lwc1 $f12, 0($5) <--- byte offset 4 | |
135 lwc1 $f13, 4($5) | |
136 lwc1 $f14, 8($5) <--- byte offset 12 | |
137 lwc1 $f15, 12($5) | |
138 | |
101
1ce60358fbad
- mips related cleanup, mostly comments, cpp macro lib
cslag
parents:
84
diff
changeset
|
139 #if defined(DC__Endian_LITTLE) |
0 | 140 /* index 0 and 2 */ |
141 self->mRegData.floats[self->mArgCount*2] = x; | |
142 #else | |
143 /* index 1 and 3 */ | |
144 self->mRegData.floats[self->mArgCount*2+1] = x; | |
145 #endif | |
146 #endif | |
147 } | |
148 self->mArgCount++; | |
149 } | |
150 | |
151 static void dc_callvm_argDouble_mips_o32(DCCallVM* in_self, DCdouble x) | |
152 { | |
153 DCCallVM_mips_o32* self = (DCCallVM_mips_o32*)in_self; | |
154 /* 64-bit values need to be aligned on 8 byte boundaries */ | |
155 dcVecSkip(&self->mVecHead, dcVecSize(&self->mVecHead) & 4); | |
156 dcVecAppend(&self->mVecHead, &x, sizeof(DCdouble) ); | |
157 if (self->mArgCount < 2) | |
158 self->mRegData.u[self->mArgCount].d = x; | |
159 self->mArgCount++; | |
160 } | |
161 | |
162 /* Call. */ | |
163 void dc_callvm_call_mips_o32(DCCallVM* in_self, DCpointer target) | |
164 { | |
165 DCCallVM_mips_o32* self = (DCCallVM_mips_o32*)in_self; | |
166 /* at minimum provide 16-bytes | |
167 which hold the first four integer register as spill area | |
168 and are automatically loaded to $4-$7 | |
169 */ | |
170 | |
171 size_t size = DC_MAX(16, ( ( (unsigned) dcVecSize(&self->mVecHead) ) +7UL ) & (-8UL) ); | |
172 | |
173 dcCall_mips_o32(target, &self->mRegData, size, dcVecData(&self->mVecHead)); | |
174 } | |
175 | |
84 | 176 static void dc_callvm_mode_mips_o32(DCCallVM* in_self, DCint mode); |
177 | |
0 | 178 DCCallVM_vt gVT_mips_o32 = |
179 { | |
180 &dc_callvm_free_mips_o32 | |
181 , &dc_callvm_reset_mips_o32 | |
182 , &dc_callvm_mode_mips_o32 | |
183 , &dc_callvm_argBool_mips_o32 | |
184 , &dc_callvm_argChar_mips_o32 | |
185 , &dc_callvm_argShort_mips_o32 | |
186 , &dc_callvm_argInt_mips_o32 | |
187 , &dc_callvm_argLong_mips_o32 | |
188 , &dc_callvm_argLongLong_mips_o32 | |
189 , &dc_callvm_argFloat_mips_o32 | |
190 , &dc_callvm_argDouble_mips_o32 | |
191 , &dc_callvm_argPointer_mips_o32 | |
192 , NULL /* argStruct */ | |
193 , (DCvoidvmfunc*) &dc_callvm_call_mips_o32 | |
194 , (DCboolvmfunc*) &dc_callvm_call_mips_o32 | |
195 , (DCcharvmfunc*) &dc_callvm_call_mips_o32 | |
196 , (DCshortvmfunc*) &dc_callvm_call_mips_o32 | |
197 , (DCintvmfunc*) &dc_callvm_call_mips_o32 | |
198 , (DClongvmfunc*) &dc_callvm_call_mips_o32 | |
199 , (DClonglongvmfunc*) &dc_callvm_call_mips_o32 | |
200 , (DCfloatvmfunc*) &dc_callvm_call_mips_o32 | |
201 , (DCdoublevmfunc*) &dc_callvm_call_mips_o32 | |
202 , (DCpointervmfunc*) &dc_callvm_call_mips_o32 | |
203 , NULL /* callStruct */ | |
204 }; | |
205 | |
84 | 206 /* mode: only a single mode available currently. */ |
207 static void dc_callvm_mode_mips_o32(DCCallVM* in_self, DCint mode) | |
0 | 208 { |
84 | 209 DCCallVM_mips_o32* self = (DCCallVM_mips_o32*)in_self; |
210 DCCallVM_vt* vt; | |
211 | |
212 switch(mode) { | |
213 case DC_CALL_C_DEFAULT: | |
214 case DC_CALL_C_MIPS32_O32: | |
215 case DC_CALL_C_ELLIPSIS: | |
216 case DC_CALL_C_ELLIPSIS_VARARGS: | |
217 vt = &gVT_mips_o32; | |
218 break; | |
219 default: | |
220 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; | |
221 return; | |
222 } | |
223 dc_callvm_base_init(&self->mInterface, vt); | |
0 | 224 } |
225 | |
84 | 226 /* Public API. */ |
0 | 227 DCCallVM* dcNewCallVM(DCsize size) |
228 { | |
84 | 229 DCCallVM_mips_o32* p = (DCCallVM_mips_o32*)dcAllocMem(sizeof(DCCallVM_mips_o32)+size); |
230 | |
231 dc_callvm_mode_mips_o32((DCCallVM*)p, DC_CALL_C_DEFAULT); | |
232 | |
233 dcVecInit(&p->mVecHead, size); | |
234 dc_callvm_reset_mips_o32((DCCallVM*)p); | |
235 | |
236 return (DCCallVM*)p; | |
0 | 237 } |
238 |