as_callfunc_arm.cpp 20 KB

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