comparison dyncall/dyncall_callvm_x64.c @ 339:4f9f49fb82ce

- x64 SysV syscall support
author Tassilo Philipp
date Sat, 04 Jan 2020 01:07:49 +0100
parents f5577f6bf97a
children ab2d78e48ca2
comparison
equal deleted inserted replaced
338:ee2b6e54b074 339:4f9f49fb82ce
4 Library: dyncall 4 Library: dyncall
5 File: dyncall/dyncall_callvm_x64.c 5 File: dyncall/dyncall_callvm_x64.c
6 Description: 6 Description:
7 License: 7 License:
8 8
9 Copyright (c) 2007-2018 Daniel Adler <dadler@uni-goettingen.de>, 9 Copyright (c) 2007-2020 Daniel Adler <dadler@uni-goettingen.de>,
10 Tassilo Philipp <tphilipp@potion-studios.com> 10 Tassilo Philipp <tphilipp@potion-studios.com>
11 11
12 Permission to use, copy, modify, and distribute this software for any 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 13 purpose with or without fee is hereby granted, provided that the above
14 copyright notice and this permission notice appear in all copies. 14 copyright notice and this permission notice appear in all copies.
165 &dc_callvm_free_x64 165 &dc_callvm_free_x64
166 , &dc_callvm_reset_x64 166 , &dc_callvm_reset_x64
167 , &dc_callvm_mode_x64 167 , &dc_callvm_mode_x64
168 , &dc_callvm_argBool_x64 168 , &dc_callvm_argBool_x64
169 , &dc_callvm_argChar_x64 169 , &dc_callvm_argChar_x64
170 , &dc_callvm_argShort_x64 170 , &dc_callvm_argShort_x64
171 , &dc_callvm_argInt_x64 171 , &dc_callvm_argInt_x64
172 , &dc_callvm_argLong_x64 172 , &dc_callvm_argLong_x64
173 , &dc_callvm_argLongLong_x64 173 , &dc_callvm_argLongLong_x64
174 , &dc_callvm_argFloat_x64 174 , &dc_callvm_argFloat_x64
175 , &dc_callvm_argDouble_x64 175 , &dc_callvm_argDouble_x64
186 , (DCdoublevmfunc*) &dc_callvm_call_x64 186 , (DCdoublevmfunc*) &dc_callvm_call_x64
187 , (DCpointervmfunc*) &dc_callvm_call_x64 187 , (DCpointervmfunc*) &dc_callvm_call_x64
188 , NULL /* callStruct */ 188 , NULL /* callStruct */
189 }; 189 };
190 190
191 /* mode: only a single mode available currently. */ 191
192 /* --- syscall ------------------------------------------------------------- */
193
194 #include <assert.h>
195 void dc_callvm_call_x64_sys_syscall_sysv(DCCallVM* in_self, DCpointer target)
196 {
197 /* syscalls can have up to 6 args, required to be "Only values of class INTEGER or class MEMORY" (from */
198 /* SysV manual), so we can use self->mRegData.i directly; verify this holds at least 6 values, though. */
199 assert(numIntRegs >= 6);
200
201 DCCallVM_x64* self = (DCCallVM_x64*)in_self;
202 dcCall_x64_sys_syscall_sysv(self->mRegData.i, target);
203 }
204
205 DCCallVM_vt gVT_x64_sys_syscall_sysv =
206 {
207 &dc_callvm_free_x64
208 , &dc_callvm_reset_x64
209 , &dc_callvm_mode_x64
210 , &dc_callvm_argBool_x64
211 , &dc_callvm_argChar_x64
212 , &dc_callvm_argShort_x64
213 , &dc_callvm_argInt_x64
214 , &dc_callvm_argLong_x64
215 , &dc_callvm_argLongLong_x64
216 , &dc_callvm_argFloat_x64
217 , &dc_callvm_argDouble_x64
218 , &dc_callvm_argPointer_x64
219 , NULL /* argStruct */
220 , (DCvoidvmfunc*) &dc_callvm_call_x64_sys_syscall_sysv
221 , (DCboolvmfunc*) &dc_callvm_call_x64_sys_syscall_sysv
222 , (DCcharvmfunc*) &dc_callvm_call_x64_sys_syscall_sysv
223 , (DCshortvmfunc*) &dc_callvm_call_x64_sys_syscall_sysv
224 , (DCintvmfunc*) &dc_callvm_call_x64_sys_syscall_sysv
225 , (DClongvmfunc*) &dc_callvm_call_x64_sys_syscall_sysv
226 , (DClonglongvmfunc*) &dc_callvm_call_x64_sys_syscall_sysv
227 , (DCfloatvmfunc*) &dc_callvm_call_x64_sys_syscall_sysv
228 , (DCdoublevmfunc*) &dc_callvm_call_x64_sys_syscall_sysv
229 , (DCpointervmfunc*) &dc_callvm_call_x64_sys_syscall_sysv
230 , NULL /* callStruct */
231 };
232
233
234
235 /* mode */
236
192 static void dc_callvm_mode_x64(DCCallVM* in_self, DCint mode) 237 static void dc_callvm_mode_x64(DCCallVM* in_self, DCint mode)
193 { 238 {
194 DCCallVM_x64* self = (DCCallVM_x64*)in_self; 239 DCCallVM_x64* self = (DCCallVM_x64*)in_self;
195 DCCallVM_vt* vt; 240 DCCallVM_vt* vt;
196 241
203 #endif 248 #endif
204 case DC_CALL_C_ELLIPSIS: 249 case DC_CALL_C_ELLIPSIS:
205 case DC_CALL_C_ELLIPSIS_VARARGS: 250 case DC_CALL_C_ELLIPSIS_VARARGS:
206 vt = &gVT_x64; 251 vt = &gVT_x64;
207 break; 252 break;
253 case DC_CALL_SYS_DEFAULT:
254 # if defined DC_UNIX
255 case DC_CALL_SYS_X64_SYSCALL_SYSV:
256 vt = &gVT_x64_sys_syscall_sysv; break;
257 # else
258 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; return;
259 # endif
208 default: 260 default:
209 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE; 261 self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE;
210 return; 262 return;
211 } 263 }
212 dc_callvm_base_init(&self->mInterface, vt); 264 dc_callvm_base_init(&self->mInterface, vt);