as_callfunc_arm.cpp 20 KB

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