1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
|
/*
AngelCode Scripting Library
Copyright (c) 2003-2015 Andreas Jonsson
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
The original version of this library can be located at:
http://www.angelcode.com/angelscript/
Andreas Jonsson
andreas@angelcode.com
*/
//
// as_callfunc_arm.cpp
//
// These functions handle the actual calling of system functions on the arm platform
//
// Written by Fredrik Ehnbom in June 2009, based on as_callfunc_x86.cpp
//
// The code was complemented to support Linux with ARM by Carlos Luna in December, 2012.
//
// Added support for functor methods by Jordi Oliveras Rovira in April, 2014.
// This code has to conform to both AAPCS and the modified ABI for iOS
//
// Reference:
//
// AAPCS: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf
// iOS: http://developer.apple.com/library/ios/documentation/Xcode/Conceptual/iPhoneOSABIReference/iPhoneOSABIReference.pdf
#include "as_config.h"
#ifndef AS_MAX_PORTABILITY
#ifdef AS_ARM
#include "as_callfunc.h"
#include "as_scriptengine.h"
#include "as_texts.h"
#include "as_tokendef.h"
#include "as_context.h"
#if defined(AS_SOFTFP)
// This code supports the soft-float ABI, i.e. g++ -mfloat-abi=softfp
//
// The code for iOS, Android, Marmalade and Windows Phone goes here
BEGIN_AS_NAMESPACE
extern "C" asQWORD armFunc (const asDWORD *, int, asFUNCTION_t);
extern "C" asQWORD armFuncR0 (const asDWORD *, int, asFUNCTION_t, asDWORD r0);
extern "C" asQWORD armFuncR0R1 (const asDWORD *, int, asFUNCTION_t, asDWORD r0, asDWORD r1);
extern "C" asQWORD armFuncObjLast (const asDWORD *, int, asFUNCTION_t, asDWORD obj);
extern "C" asQWORD armFuncR0ObjLast (const asDWORD *, int, asFUNCTION_t, asDWORD r0, asDWORD obj);
asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &/*retQW2*/, void *secondObject)
{
asCScriptEngine *engine = context->m_engine;
asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf;
int callConv = sysFunc->callConv;
asQWORD retQW = 0;
asFUNCTION_t func = sysFunc->func;
int paramSize = sysFunc->paramSize;
asFUNCTION_t *vftable;
if( sysFunc->hostReturnInMemory )
{
// The return is made in memory
callConv++;
}
bool isThisCallMethod = callConv >= ICC_THISCALL_OBJLAST;
asDWORD paramBuffer[64+2];
// Android & Linux needs to align 64bit types on even registers, but this isn't done on iOS or Windows Phone
// TODO: optimize runtime: There should be a check for this in PrepareSystemFunction() so this
// doesn't have to be done for functions that don't have any 64bit types
#if !defined(AS_ANDROID) && !defined(AS_LINUX)
// In cases of thiscall methods, the callstack is configured as a standard thiscall
// adding the secondObject as first or last element in callstack
if( sysFunc->takesObjByVal || isThisCallMethod )
#endif
{
#if defined(AS_ANDROID) || defined(AS_LINUX)
// mask is used as a toggler to skip uneven registers.
int mask = 1;
if( isThisCallMethod )
{
mask = 0;
}
else
{
// Check for object pointer as first argument
switch( callConv )
{
case ICC_THISCALL:
case ICC_CDECL_OBJFIRST:
case ICC_VIRTUAL_THISCALL:
case ICC_THISCALL_RETURNINMEM:
case ICC_CDECL_OBJFIRST_RETURNINMEM:
case ICC_VIRTUAL_THISCALL_RETURNINMEM:
mask = 0;
break;
default:
break;
}
}
// Check for hidden address in case of return by value
if( sysFunc->hostReturnInMemory )
mask = !mask;
#endif
paramSize = 0;
int spos = 0;
int dpos = 2;
if( isThisCallMethod && (callConv >= ICC_THISCALL_OBJFIRST &&
callConv <= ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM) )
{
// Add the object pointer as the first parameter
paramBuffer[dpos++] = (asDWORD)secondObject;
paramSize++;
}
for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ )
{
// TODO: runtime optimize: Declare a reference to descr->parameterTypes[n] so the array doesn't have to be access all the time
if( descr->parameterTypes[n].IsObject() && !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() )
{
#ifdef COMPLEX_OBJS_PASSED_BY_REF
if( descr->parameterTypes[n].GetTypeInfo()->flags & COMPLEX_MASK )
{
paramBuffer[dpos++] = args[spos++];
paramSize++;
}
else
#endif
{
#if defined(AS_ANDROID) || defined(AS_LINUX)
if( (descr->parameterTypes[n].GetTypeInfo()->flags & asOBJ_APP_CLASS_ALIGN8) &&
((dpos & 1) == mask) )
{
// 64 bit value align
dpos++;
paramSize++;
}
#endif
// Copy the object's memory to the buffer
memcpy(¶mBuffer[dpos], *(void**)(args+spos), descr->parameterTypes[n].GetSizeInMemoryBytes());
// Delete the original memory
engine->CallFree(*(char**)(args+spos));
spos++;
dpos += descr->parameterTypes[n].GetSizeInMemoryDWords();
paramSize += descr->parameterTypes[n].GetSizeInMemoryDWords();
}
}
else
{
#if defined(AS_ANDROID) || defined(AS_LINUX)
// Should an alignment be performed?
if( !descr->parameterTypes[n].IsObjectHandle() &&
!descr->parameterTypes[n].IsReference() &&
descr->parameterTypes[n].GetSizeOnStackDWords() == 2 &&
((dpos & 1) == mask) )
{
// 64 bit value align
dpos++;
paramSize++;
}
#endif
// Copy the value directly
paramBuffer[dpos++] = args[spos++];
if( descr->parameterTypes[n].GetSizeOnStackDWords() > 1 )
paramBuffer[dpos++] = args[spos++];
paramSize += descr->parameterTypes[n].GetSizeOnStackDWords();
}
}
if( isThisCallMethod && (callConv >= ICC_THISCALL_OBJLAST &&
callConv <= ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM) )
{
// Add the object pointer as the last parameter
paramBuffer[dpos++] = (asDWORD)secondObject;
paramSize++;
}
// Keep a free location at the beginning
args = ¶mBuffer[2];
}
switch( callConv )
{
case ICC_CDECL_RETURNINMEM: // fall through
case ICC_STDCALL_RETURNINMEM:
retQW = armFuncR0(args, paramSize<<2, func, (asDWORD)retPointer);
break;
case ICC_CDECL: // fall through
case ICC_STDCALL:
retQW = armFunc(args, paramSize<<2, func);
break;
case ICC_THISCALL: // fall through
case ICC_CDECL_OBJFIRST:
case ICC_THISCALL_OBJFIRST:
case ICC_THISCALL_OBJLAST:
retQW = armFuncR0(args, paramSize<<2, func, (asDWORD)obj);
break;
case ICC_THISCALL_RETURNINMEM:
case ICC_THISCALL_OBJFIRST_RETURNINMEM:
case ICC_THISCALL_OBJLAST_RETURNINMEM:
#ifdef __GNUC__
// On GNUC the address where the return value will be placed should be put in R0
retQW = armFuncR0R1(args, paramSize<<2, func, (asDWORD)retPointer, (asDWORD)obj);
#else
// On Windows the R0 should always hold the object pointer, and the address for the return value comes after
retQW = armFuncR0R1(args, paramSize<<2, func, (asDWORD)obj, (asDWORD)retPointer);
#endif
break;
case ICC_CDECL_OBJFIRST_RETURNINMEM:
retQW = armFuncR0R1(args, paramSize<<2, func, (asDWORD)retPointer, (asDWORD)obj);
break;
case ICC_VIRTUAL_THISCALL:
case ICC_VIRTUAL_THISCALL_OBJFIRST:
case ICC_VIRTUAL_THISCALL_OBJLAST:
// Get virtual function table from the object pointer
vftable = *(asFUNCTION_t**)obj;
retQW = armFuncR0(args, paramSize<<2, vftable[FuncPtrToUInt(func)>>2], (asDWORD)obj);
break;
case ICC_VIRTUAL_THISCALL_RETURNINMEM:
case ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM:
case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM:
// Get virtual function table from the object pointer
vftable = *(asFUNCTION_t**)obj;
#ifdef __GNUC__
// On GNUC the address where the return value will be placed should be put in R0
retQW = armFuncR0R1(args, (paramSize+1)<<2, vftable[FuncPtrToUInt(func)>>2], (asDWORD)retPointer, (asDWORD)obj);
#else
// On Windows the R0 should always hold the object pointer, and the address for the return value comes after
retQW = armFuncR0R1(args, (paramSize+1)<<2, vftable[FuncPtrToUInt(func)>>2], (asDWORD)obj, (asDWORD)retPointer);
#endif
break;
case ICC_CDECL_OBJLAST:
retQW = armFuncObjLast(args, paramSize<<2, func, (asDWORD)obj);
break;
case ICC_CDECL_OBJLAST_RETURNINMEM:
retQW = armFuncR0ObjLast(args, paramSize<<2, func, (asDWORD)retPointer, (asDWORD)obj);
break;
default:
context->SetInternalException(TXT_INVALID_CALLING_CONVENTION);
}
return retQW;
}
END_AS_NAMESPACE
#elif !defined(AS_SOFTFP)
// This code supports the hard-float ABI, i.e. g++ -mfloat-abi=hard
// The main difference is that the floating point values are passed in the fpu registers
#define VFP_OFFSET 70
#define STACK_OFFSET 6
#define PARAM_BUFFER_SIZE 104
BEGIN_AS_NAMESPACE
extern "C" asQWORD armFunc (const asDWORD *, int, asFUNCTION_t);
extern "C" asQWORD armFuncR0 (const asDWORD *, int, asFUNCTION_t, asDWORD r0);
extern "C" asQWORD armFuncR0R1 (const asDWORD *, int, asFUNCTION_t, asDWORD r0, asDWORD r1);
extern "C" asQWORD armFuncObjLast (const asDWORD *, int, asFUNCTION_t, asDWORD obj);
extern "C" asQWORD armFuncR0ObjLast (const asDWORD *, int, asFUNCTION_t, asDWORD r0, asDWORD obj);
asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &/*retQW2*/, void *secondObject)
{
asCScriptEngine *engine = context->m_engine;
asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf;
int callConv = sysFunc->callConv;
asQWORD retQW = 0;
asFUNCTION_t func = sysFunc->func;
int paramSize = sysFunc->paramSize;
asFUNCTION_t *vftable;
//---------------------------------------------------------------------------- RPi
int freeFloatSlot = VFP_OFFSET;
int freeDoubleSlot = VFP_OFFSET;
int stackPos = STACK_OFFSET;
int stackSize = 0;
//----------------------------------------------------------------------------
//---------------------------------------------------------------------------- RPi
// Well divide paramBuffer into several segments:
//
// 0-1 Unused
// 2-5 (+8 / +0 asm) values that should be placed in R0 - R3
// 6-67 (+24 / +16 asm) values that should be placed on the stack
// 68 (+272 / +264 asm) number of values stored in r registers (R0 - R3)
// 69 (+276 / +268 asm) number of args stored on the stack
// 70-85 (+280 / +272 asm) values that should be placed in VFP registers (16)
// 86-87 (+344 / +336 asm) sp original value - sp final value - for debugging
// 88-103 (+352 / +344 asm) Check area for free-used VFP registers
//
// Total number of elements: 104
//
// When passing the paramBuffer to the asm routines via the args pointer we are
// offsetting the start of the array to being at element # 2. Thats why in asm
// all addresses must have an offset of -2 words (-8 bytes).
//---------------------------------------------------------------------------- RPi
asDWORD paramBuffer[PARAM_BUFFER_SIZE];
memset(paramBuffer, 0, sizeof(asDWORD) * PARAM_BUFFER_SIZE);
if( sysFunc->hostReturnInMemory )
{
// TODO: runtime optimize: This check should be done in PrepareSystemFunction
if ( !( descr->returnType.GetTypeInfo()->flags & COMPLEX_RETURN_MASK ) &&
( descr->returnType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALLFLOATS ) &&
descr->returnType.GetSizeInMemoryBytes() <= 8 )
callConv--;
// The return is made in memory
callConv++;
}
bool isThisCallMethod = callConv >= ICC_THISCALL_OBJLAST;
// Linux needs to align 64bit types on even registers, but this isn't done on iOS or Windows Phone
// TODO: optimize runtime: There should be a check for this in PrepareSystemFunction() so this
// doesn't have to be done for functions that don't have any 64bit types
{
// mask is used as a toggler to skip uneven registers.
int mask = 1;
if( isThisCallMethod )
{
mask = 0;
}
else
{
// Check for object pointer as first argument
switch( callConv )
{
case ICC_THISCALL:
case ICC_CDECL_OBJFIRST:
case ICC_VIRTUAL_THISCALL:
case ICC_THISCALL_RETURNINMEM:
case ICC_CDECL_OBJFIRST_RETURNINMEM:
case ICC_VIRTUAL_THISCALL_RETURNINMEM:
mask = 0;
break;
default:
break;
}
}
// Check for hidden address in case of return by value
if( sysFunc->hostReturnInMemory )
mask = !mask;
paramSize = 0;
int spos = 0;
int dpos = 2;
if( isThisCallMethod && (callConv >= ICC_THISCALL_OBJFIRST &&
callConv <= ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM) )
{
// Add the object pointer as the first parameter
paramBuffer[dpos++] = (asDWORD)secondObject;
paramSize++;
}
for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ )
{
// TODO: runtime optimize: Declare a reference to descr->parameterTypes[n] so the array doesn't have to be access all the time
if( descr->parameterTypes[n].IsObject() && !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() &&
!(descr->parameterTypes[n].GetTypeInfo()->flags & asOBJ_APP_ARRAY) )
{
#ifdef COMPLEX_OBJS_PASSED_BY_REF
if( descr->parameterTypes[n].GetTypeInfo()->flags & COMPLEX_MASK )
{
paramBuffer[dpos++] = args[spos++];
paramSize++;
}
else
#endif
{
if( (descr->parameterTypes[n].GetTypeInfo()->flags & asOBJ_APP_CLASS_ALIGN8) )
{
if ( (dpos & 1) == mask )
{
// 64 bit value align
dpos++;
paramSize++;
}
if ( (stackPos & 1) == mask )
{
// 64 bit value align
stackPos++;
stackSize++;
}
}
// Copy the object's memory to the buffer
if (descr->parameterTypes[n].GetTypeInfo()->flags & asOBJ_APP_CLASS_ALLFLOATS)
{
int target = (freeFloatSlot > freeDoubleSlot) ? freeFloatSlot : freeDoubleSlot;
if ( descr->parameterTypes[n].GetSizeInMemoryDWords() <= ( (VFP_OFFSET + 16) - target) )
{
memcpy(¶mBuffer[target], *(void**)(args+spos), descr->parameterTypes[n].GetSizeInMemoryBytes());
memset(¶mBuffer[target + 18], (asDWORD)1, descr->parameterTypes[n].GetSizeInMemoryDWords());
target += descr->parameterTypes[n].GetSizeInMemoryDWords();
freeFloatSlot = freeDoubleSlot = target;
}
else
{
memcpy(¶mBuffer[stackPos], *(void**)(args+spos), descr->parameterTypes[n].GetSizeInMemoryBytes());
stackPos += descr->parameterTypes[n].GetSizeInMemoryDWords();
stackSize += descr->parameterTypes[n].GetSizeOnStackDWords();
}
}
else
{
memcpy(¶mBuffer[dpos], *(void**)(args+spos), descr->parameterTypes[n].GetSizeInMemoryBytes());
dpos += descr->parameterTypes[n].GetSizeInMemoryDWords();
paramSize += descr->parameterTypes[n].GetSizeInMemoryDWords();
}
// Delete the original memory
engine->CallFree(*(char**)(args+spos));
spos++;
}
continue;
}
else if( descr->parameterTypes[n].IsFloatType() && !descr->parameterTypes[n].IsReference() )
{
// Are there any "s" registers available?
if ( freeFloatSlot < (VFP_OFFSET + 16) )
{
if (freeFloatSlot == freeDoubleSlot)
freeDoubleSlot += 2;
paramBuffer[freeFloatSlot + 18] = (asDWORD)1;
paramBuffer[freeFloatSlot++] = args[spos++];
while(freeFloatSlot < (VFP_OFFSET + 16) && paramBuffer[freeFloatSlot + 18] != 0)
freeFloatSlot++;
}
// If not, then store the float arg in the stack area
else
{
paramBuffer[stackPos++] = args[spos++];
stackSize++;
}
continue;
}
else if( descr->parameterTypes[n].IsDoubleType() && !descr->parameterTypes[n].IsReference() )
{
// Are there any "d" registers available?
if ( freeDoubleSlot < (VFP_OFFSET + 15) )
{
if (freeFloatSlot == freeDoubleSlot)
freeFloatSlot += 2;
// Copy two dwords for the double
paramBuffer[freeDoubleSlot + 18] = (asDWORD)1;
paramBuffer[freeDoubleSlot + 19] = (asDWORD)1;
paramBuffer[freeDoubleSlot++] = args[spos++];
paramBuffer[freeDoubleSlot++] = args[spos++];
while(freeDoubleSlot < (VFP_OFFSET + 15) && paramBuffer[freeDoubleSlot + 18] != 0)
freeDoubleSlot += 2;
}
// If not, then store the double arg in the stack area
else
{
if ( (stackPos & 1) == mask )
{
// 64 bit value align
stackPos++;
stackSize++;
}
paramBuffer[stackPos++] = args[spos++];
paramBuffer[stackPos++] = args[spos++];
stackSize += 2;
}
continue;
}
else
{
// Copy the value directly to "r" registers or the stack, checking for alignment
if (paramSize < 4)
{
// Should an alignment be performed?
if( (dpos & 1) == mask && descr->parameterTypes[n].GetSizeOnStackDWords() == 2 &&
!descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() &&
!descr->parameterTypes[n].IsAnyType() )
{
// 64 bit value align
dpos++;
paramSize++;
}
paramBuffer[dpos++] = args[spos++];
paramSize += descr->parameterTypes[n].GetSizeOnStackDWords();
}
else
{
// Should an alignment be performed?
if( (stackPos & 1) == mask && descr->parameterTypes[n].GetSizeOnStackDWords() == 2 &&
!descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() &&
!descr->parameterTypes[n].IsAnyType() )
{
// 64 bit value align
stackPos++;
stackSize++;
}
paramBuffer[stackPos++] = args[spos++];
stackSize += descr->parameterTypes[n].GetSizeOnStackDWords();
}
if( descr->parameterTypes[n].GetSizeOnStackDWords() > 1 )
{
if (paramSize < 5)
paramBuffer[dpos++] = args[spos++];
else
paramBuffer[stackPos++] = args[spos++];
}
}// else...
}// Loop
if( isThisCallMethod && (callConv >= ICC_THISCALL_OBJLAST &&
callConv <= ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM) )
{
if (paramSize < 4)
{
paramBuffer[dpos++] = (asDWORD)secondObject;
paramSize++;
}
else
{
paramBuffer[stackPos++] = (asDWORD)secondObject;
stackSize++;
}
}
// Keep a free location at the beginning
args = ¶mBuffer[2];
}
paramBuffer[69] = static_cast<asDWORD>(stackSize<<2);
switch( callConv )
{
case ICC_CDECL_RETURNINMEM: // fall through
case ICC_STDCALL_RETURNINMEM:
retQW = armFuncR0(args, paramSize<<2, func, (asDWORD)retPointer);
break;
case ICC_CDECL: // fall through
case ICC_STDCALL:
retQW = armFunc(args, paramSize<<2, func);
break;
case ICC_THISCALL: // fall through
case ICC_CDECL_OBJFIRST:
case ICC_THISCALL_OBJFIRST:
case ICC_THISCALL_OBJLAST:
retQW = armFuncR0(args, paramSize<<2, func, (asDWORD)obj);
break;
case ICC_THISCALL_RETURNINMEM:
case ICC_THISCALL_OBJFIRST_RETURNINMEM:
case ICC_THISCALL_OBJLAST_RETURNINMEM:
// On GNUC the address where the return value will be placed should be put in R0
retQW = armFuncR0R1(args, paramSize<<2, func, (asDWORD)retPointer, (asDWORD)obj);
break;
case ICC_CDECL_OBJFIRST_RETURNINMEM:
retQW = armFuncR0R1(args, paramSize<<2, func, (asDWORD)retPointer, (asDWORD)obj);
break;
case ICC_VIRTUAL_THISCALL:
case ICC_VIRTUAL_THISCALL_OBJFIRST:
case ICC_VIRTUAL_THISCALL_OBJLAST:
// Get virtual function table from the object pointer
vftable = *(asFUNCTION_t**)obj;
retQW = armFuncR0(args, paramSize<<2, vftable[FuncPtrToUInt(func)>>2], (asDWORD)obj);
break;
case ICC_VIRTUAL_THISCALL_RETURNINMEM:
case ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM:
case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM:
// Get virtual function table from the object pointer
vftable = *(asFUNCTION_t**)obj;
// On GNUC the address where the return value will be placed should be put in R0
retQW = armFuncR0R1(args, (paramSize+1)<<2, vftable[FuncPtrToUInt(func)>>2], (asDWORD)retPointer, (asDWORD)obj);
break;
case ICC_CDECL_OBJLAST:
retQW = armFuncObjLast(args, paramSize<<2, func, (asDWORD)obj);
break;
case ICC_CDECL_OBJLAST_RETURNINMEM:
retQW = armFuncR0ObjLast(args, paramSize<<2, func, (asDWORD)retPointer, (asDWORD)obj);
break;
default:
context->SetInternalException(TXT_INVALID_CALLING_CONVENTION);
}
// On Linux with arm the float and double values are returns in the
// floating point registers, s0 and s1. Objects that contain only
// float types and are not considered complex are also returned in the
// floating point registers.
if( sysFunc->hostReturnFloat )
{
retQW = paramBuffer[VFP_OFFSET];
if ( sysFunc->hostReturnSize > 1 )
retQW = *( (asQWORD*)¶mBuffer[VFP_OFFSET] );
}
else if ( descr->returnType.IsObject() )
{
// TODO: runtime optimize: This should be identified with a flag determined in PrepareSystemFunction
if ( !descr->returnType.IsObjectHandle() &&
!descr->returnType.IsReference() &&
!(descr->returnType.GetTypeInfo()->flags & COMPLEX_RETURN_MASK) &&
(descr->returnType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALLFLOATS) )
memcpy( retPointer, ¶mBuffer[VFP_OFFSET], descr->returnType.GetSizeInMemoryBytes() );
}
return retQW;
}
END_AS_NAMESPACE
#endif // AS_LINUX
#endif // AS_ARM
#endif // AS_MAX_PORTABILITY
|