comparison dyncall/dyncall_callvm_sparc64.c @ 84:67961454902b

- bigger cleanup in callvm code * changed init of most callvms to reuse code and for consistency * removed unused functions * general changes for consistency * added some missing cconv defines do mode calls - fixed potential buffer overrun on arm64 - fixed sparc and x64 mode setting (only one mode, but wasn't (pointlessly) resettable) - error code handling (dcGetError) changes, flag is now cleared (work still underway) - Changelog update
author cslag
date Wed, 06 Apr 2016 00:21:51 +0200
parents 3e629dc19168
children
comparison
equal deleted inserted replaced
83:54930a037e8a 84:67961454902b
35 35
36 /* Reset argument buffer. */ 36 /* Reset argument buffer. */
37 static void dc_callvm_reset_sparc64(DCCallVM* in_self) 37 static void dc_callvm_reset_sparc64(DCCallVM* in_self)
38 { 38 {
39 DCCallVM_sparc64* self = (DCCallVM_sparc64*)in_self; 39 DCCallVM_sparc64* self = (DCCallVM_sparc64*)in_self;
40 dcVecResize(&self->mVecHead,DHEAD); 40 dcVecResize(&self->mVecHead, DHEAD);
41 self->mIntRegs = 0; 41 self->mIntRegs = 0;
42 self->mFloatRegs = 0; 42 self->mFloatRegs = 0;
43 self->mUseSingleFlags = 0; 43 self->mUseSingleFlags = 0;
44 } 44 }
45 45
46 /* Construtor. */
47 /* the six output registers %o0-%o5 are always loaded, thus we need to ensure the argument buffer has space for at least 24 bytes. */
48 static DCCallVM* dc_callvm_new_sparc64(DCCallVM_vt* vt, DCsize size)
49 {
50 DCCallVM_sparc64* self = (DCCallVM_sparc64*) dcAllocMem(sizeof(DCCallVM_sparc64)+DHEAD+size);
51 dc_callvm_base_init(&self->mInterface, vt);
52 dcVecInit(&self->mVecHead,DHEAD+size);
53 dc_callvm_reset_sparc64(&self->mInterface);
54 return (DCCallVM*)self;
55 }
56 46
57 /* Destructor. */ 47 /* Destructor. */
58 static void dc_callvm_free_sparc64(DCCallVM* in_self) 48 static void dc_callvm_free_sparc64(DCCallVM* in_self)
59 { 49 {
60 dcFreeMem(in_self); 50 dcFreeMem(in_self);
134 static void dc_callvm_call_sparc64(DCCallVM* in_self, DCpointer target) 124 static void dc_callvm_call_sparc64(DCCallVM* in_self, DCpointer target)
135 { 125 {
136 DCCallVM_sparc64* self = (DCCallVM_sparc64*)in_self; 126 DCCallVM_sparc64* self = (DCCallVM_sparc64*)in_self;
137 dcCall_sparc64(target, dcVecSize(&self->mVecHead), dcVecData(&self->mVecHead)); 127 dcCall_sparc64(target, dcVecSize(&self->mVecHead), dcVecData(&self->mVecHead));
138 } 128 }
129 #endif
130
131 #if 0
132 /* Load integer 32-bit. */
133 static void dc_callvm_argInt_sparc64(DCCallVM* in_self, DCint x)
134 {
135 DCCallVM_sparc64* self = (DCCallVM_sparc64*)in_self;
136 dcVecAppend(&self->mVecHead, &x, sizeof(DCint));
137 }
138
139 /* we propagate Bool,Char,Short,Int to LongLong. */
140
141 static void dc_callvm_argBool_sparc64(DCCallVM* in_self, DCbool x) { dc_callvm_argInt_sparc64(in_self, (DCint)x); }
142 static void dc_callvm_argChar_sparc64(DCCallVM* in_self, DCchar x) { dc_callvm_argInt_sparc64(in_self, (DCint)x); }
143 static void dc_callvm_argShort_sparc64(DCCallVM* in_self, DCshort x) { dc_callvm_argInt_sparc64(in_self, (DCint)x); }
139 #endif 144 #endif
140 145
141 static void dc_callvm_mode_sparc64(DCCallVM* in_self, DCint mode); 146 static void dc_callvm_mode_sparc64(DCCallVM* in_self, DCint mode);
142 147
143 DCCallVM_vt gVT_sparc64_ellipsis = 148 DCCallVM_vt gVT_sparc64_ellipsis =
198 }; 203 };
199 204
200 /* mode: only a single mode available currently. */ 205 /* mode: only a single mode available currently. */
201 static void dc_callvm_mode_sparc64(DCCallVM* in_self, DCint mode) 206 static void dc_callvm_mode_sparc64(DCCallVM* in_self, DCint mode)
202 { 207 {
208 DCCallVM_sparc64* self = (DCCallVM_sparc64*)in_self;
209 DCCallVM_vt* vt;
210
203 switch(mode) { 211 switch(mode) {
204 case DC_CALL_C_DEFAULT: 212 case DC_CALL_C_DEFAULT:
213 case DC_CALL_C_SPARC64:
205 case DC_CALL_C_ELLIPSIS: 214 case DC_CALL_C_ELLIPSIS:
206 case DC_CALL_C_SPARC64: 215 vt = &gVT_sparc64;
207 in_self->mVTpointer = &gVT_sparc64;
208 break; 216 break;
209 case DC_CALL_C_ELLIPSIS_VARARGS: 217 case DC_CALL_C_ELLIPSIS_VARARGS:
210 in_self->mVTpointer = &gVT_sparc64_ellipsis; 218 vt = &gVT_sparc64_ellipsis;
211 break; 219 break;
212 default: 220 default:
213 in_self->mError = DC_ERROR_UNSUPPORTED_MODE; 221 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE;
214 break; 222 return;
215 } 223 }
216 } 224 dc_callvm_base_init(&self->mInterface, vt);
217 225 }
218 226
219 /* Public API. */ 227 /* Public API. */
220 DCCallVM* dcNewCallVM(DCsize size) 228 DCCallVM* dcNewCallVM(DCsize size)
221 { 229 {
222 return dc_callvm_new_sparc64(&gVT_sparc64,size); 230 /* output registers %o0-%o5 are always loaded, thus we need to ensure the argument buffer has space for at least DHEAD bytes. */
223 } 231 DCCallVM_sparc64* p = (DCCallVM_sparc64*)dcAllocMem(sizeof(DCCallVM_sparc64)+DHEAD+size);
224 232
225 #if 0 233 dc_callvm_mode_sparc64((DCCallVM*)p, DC_CALL_C_DEFAULT);
226 /* Load integer 32-bit. */ 234
227 static void dc_callvm_argInt_sparc64(DCCallVM* in_self, DCint x) 235 dcVecInit(&p->mVecHead,DHEAD+size);
228 { 236 dc_callvm_reset_sparc64(&p->mInterface);
229 DCCallVM_sparc64* self = (DCCallVM_sparc64*)in_self; 237
230 dcVecAppend(&self->mVecHead, &x, sizeof(DCint)); 238 return (DCCallVM*)p;
231 } 239 }
232 240
233 /* we propagate Bool,Char,Short,Int to LongLong. */
234
235 static void dc_callvm_argBool_sparc64(DCCallVM* in_self, DCbool x) { dc_callvm_argInt_sparc64(in_self, (DCint)x); }
236 static void dc_callvm_argChar_sparc64(DCCallVM* in_self, DCchar x) { dc_callvm_argInt_sparc64(in_self, (DCint)x); }
237 static void dc_callvm_argShort_sparc64(DCCallVM* in_self, DCshort x) { dc_callvm_argInt_sparc64(in_self, (DCint)x); }
238 #endif
239