as_callfunc_arm_gcc.S 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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. Assembly routines for the ARM call convention
  25. Written by Fredrik Ehnbom in June 2009
  26. Adapted to GNUC by darktemplar216 in September 2009
  27. Modified by Lasse Oorni for 8-byte stack alignment in May 2012
  28. The assembler routines for Linux were written by Carlos Luna in December 2012
  29. */
  30. #if defined(__arm__) || defined(__ARM__) || defined(I3D_ARCH_ARM)
  31. #if !defined(__linux__) || defined(__ANDROID__) || defined(ANDROID) || defined(__SOFTFP__)
  32. /* iOS, Android, and Marmalade goes here */
  33. .global armFunc
  34. .global armFuncR0
  35. .global armFuncR0R1
  36. .global armFuncObjLast
  37. .global armFuncR0ObjLast
  38. /* --------------------------------------------------------------------------------------------*/
  39. armFunc:
  40. stmdb sp!, {r4-r8, lr}
  41. mov r6, r0 /* arg table */
  42. movs r7, r1 /* arg size (also set the condition code flags so that we detect if there are no arguments) */
  43. mov r4, r2 /* function address */
  44. mov r8, #0
  45. beq nomoreargs
  46. /* Load the first 4 arguments into r0-r3 */
  47. cmp r7, #4
  48. ldrge r0, [r6],#4
  49. cmp r7, #2*4
  50. ldrge r1, [r6],#4
  51. cmp r7, #3*4
  52. ldrge r2, [r6],#4
  53. cmp r7, #4*4
  54. ldrge r3, [r6],#4
  55. ble nomoreargs
  56. /* Load the rest of the arguments onto the stack */
  57. sub r7, r7, #4*4 /* skip the 4 registers already loaded into r0-r3 */
  58. add r8, r7, #4 /* ensure 8-byte stack alignment */
  59. bic r8, r8, #4
  60. sub sp, sp, r8
  61. mov r12, sp /* copy size != frame size, so store frame start sp */
  62. stackargsloop:
  63. ldr r5, [r6], #4
  64. str r5, [sp], #4
  65. subs r7, r7, #4
  66. bne stackargsloop
  67. mov sp, r12
  68. nomoreargs:
  69. blx r4
  70. add sp, sp, r8
  71. ldmia sp!, {r4-r8, pc}
  72. /* --------------------------------------------------------------------------------------------*/
  73. armFuncObjLast:
  74. stmdb sp!, {r4-r8, lr}
  75. mov r6, r0 /* arg table */
  76. movs r7, r1 /* arg size (also set the condition code flags so that we detect if there are no arguments) */
  77. mov r4, r2 /* function address */
  78. mov r8, #0
  79. mov r0, r3 /* objlast. might get overwritten */
  80. mov r5, r3 /* objlast to temp reg */
  81. beq nomoreargsarmFuncObjLast
  82. /* Load the first 4 arguments into r0-r3 */
  83. cmp r7, #4
  84. ldrge r0, [r6],#4
  85. cmp r7, #2*4
  86. ldrge r1, [r6],#4
  87. movlt r1, r5
  88. cmp r7, #3*4
  89. ldrge r2, [r6],#4
  90. movlt r2, r5
  91. cmp r7, #4*4
  92. ldrge r3, [r6],#4
  93. movlt r3, r5
  94. blt nomoreargsarmFuncObjLast
  95. /* Load the rest of the arguments onto the stack */
  96. sub r7, r7, #4*4 /* skip the 4 registers already loaded into r0-r3 */
  97. add r8, r7, #8 /* account for the objlast pointer, ensure 8-byte stack alignment */
  98. bic r8, r8, #4
  99. str r5, [sp,#-4] /* store the objlast on stack, twice in case we adjusted alignment */
  100. str r5, [sp,#-8]
  101. sub sp, sp, r8 /* adjust frame */
  102. cmp r7, #0 /* we may also have come here with no extra params */
  103. beq nomoreargsarmFuncObjLast
  104. mov r12, sp /* copy size != frame size, so store frame start sp */
  105. stackargslooparmFuncObjLast:
  106. ldr r5, [r6], #4
  107. str r5, [sp], #4
  108. subs r7, r7, #4
  109. bne stackargslooparmFuncObjLast
  110. mov sp, r12
  111. nomoreargsarmFuncObjLast:
  112. blx r4
  113. add sp, sp, r8
  114. ldmia sp!, {r4-r8, pc}
  115. /* --------------------------------------------------------------------------------------------*/
  116. armFuncR0ObjLast:
  117. stmdb sp!, {r4-r8, lr}
  118. ldr r5, [sp,#6*4] /* objlast to temp reg */
  119. mov r6, r0 /* arg table */
  120. movs r7, r1 /* arg size (also set the condition code flags so that we detect if there are no arguments) */
  121. mov r4, r2 /* function address */
  122. mov r8, #0
  123. mov r0, r3 /* r0 explicitly set */
  124. mov r1, r5 /* objlast. might get overwritten */
  125. beq nomoreargsarmFuncR0ObjLast
  126. /* Load the first 3 arguments into r1-r3 */
  127. cmp r7, #1*4
  128. ldrge r1, [r6],#4
  129. cmp r7, #2*4
  130. ldrge r2, [r6],#4
  131. movlt r2, r5
  132. cmp r7, #3*4
  133. ldrge r3, [r6],#4
  134. movlt r3, r5
  135. blt nomoreargsarmFuncR0ObjLast
  136. /* Load the rest of the arguments onto the stack */
  137. sub r7, r7, #3*4 /* skip the 3 registers already loaded into r1-r3 */
  138. add r8, r7, #8 /* account for the objlast pointer, ensure 8-byte stack alignment */
  139. bic r8, r8, #4
  140. str r5, [sp,#-4] /* store the objlast on stack, twice in case we adjusted alignment */
  141. str r5, [sp,#-8]
  142. sub sp, sp, r8 /* adjust frame */
  143. cmp r7, #0 /* we may also have come here with no extra params */
  144. beq nomoreargsarmFuncR0ObjLast
  145. mov r12, sp /* copy size != frame size, so store frame start sp */
  146. stackargslooparmFuncR0ObjLast:
  147. ldr r5, [r6], #4
  148. str r5, [sp], #4
  149. subs r7, r7, #4
  150. bne stackargslooparmFuncR0ObjLast
  151. mov sp, r12
  152. nomoreargsarmFuncR0ObjLast:
  153. blx r4
  154. add sp, sp, r8
  155. ldmia sp!, {r4-r8, pc}
  156. /* --------------------------------------------------------------------------------------------*/
  157. armFuncR0:
  158. stmdb sp!, {r4-r8, lr}
  159. mov r6, r0 /* arg table */
  160. movs r7, r1 /* arg size (also set the condition code flags so that we detect if there are no arguments) */
  161. mov r4, r2 /* function address */
  162. mov r8, #0
  163. mov r0, r3 /* r0 explicitly set */
  164. beq nomoreargsarmFuncR0
  165. /* Load the first 3 arguments into r1-r3 */
  166. cmp r7, #1*4
  167. ldrge r1, [r6],#4
  168. cmp r7, #2*4
  169. ldrge r2, [r6],#4
  170. cmp r7, #3*4
  171. ldrge r3, [r6],#4
  172. ble nomoreargsarmFuncR0
  173. /* Load the rest of the arguments onto the stack */
  174. sub r7, r7, #3*4 /* skip the 3 registers already loaded into r1-r3 */
  175. add r8, r7, #4 /* ensure 8-byte stack alignment */
  176. bic r8, r8, #4
  177. sub sp, sp, r8
  178. mov r12, sp /* copy size != frame size, so store frame start sp */
  179. stackargslooparmFuncR0:
  180. ldr r5, [r6], #4
  181. str r5, [sp], #4
  182. subs r7, r7, #4
  183. bne stackargslooparmFuncR0
  184. mov sp, r12
  185. nomoreargsarmFuncR0:
  186. blx r4
  187. add sp, sp, r8
  188. ldmia sp!, {r4-r8, pc}
  189. /* --------------------------------------------------------------------------------------------*/
  190. armFuncR0R1:
  191. stmdb sp!, {r4-r8, lr}
  192. mov r6, r0 /* arg table */
  193. movs r7, r1 /* arg size (also set the condition code flags so that we detect if there are no arguments) */
  194. mov r4, r2 /* function address */
  195. mov r8, #0
  196. mov r0, r3 /* r0 explicitly set */
  197. ldr r1, [sp, #6*4] /* r1 explicitly set too */
  198. beq nomoreargsarmFuncR0R1
  199. /* Load the first 2 arguments into r2-r3 */
  200. cmp r7, #1*4
  201. ldrge r2, [r6],#4
  202. cmp r7, #2*4
  203. ldrge r3, [r6],#4
  204. ble nomoreargsarmFuncR0R1
  205. /* Load the rest of the arguments onto the stack */
  206. sub r7, r7, #2*4 /* skip the 2 registers already loaded into r2-r3 */
  207. add r8, r7, #4 /* ensure 8-byte stack alignment */
  208. bic r8, r8, #4
  209. sub sp, sp, r8
  210. mov r12, sp /* copy size != frame size, so store frame start sp */
  211. stackargslooparmFuncR0R1:
  212. ldr r5, [r6], #4
  213. str r5, [sp], #4
  214. subs r7, r7, #4
  215. bne stackargslooparmFuncR0R1
  216. mov sp, r12
  217. nomoreargsarmFuncR0R1:
  218. blx r4
  219. add sp, sp, r8
  220. ldmia sp!, {r4-r8, pc}
  221. /* --------------------------------------------------------------------------------------------*/
  222. #elif defined(__linux__) && !defined(__SOFTFP__)
  223. /* The Linux code goes here */
  224. /* These codes are suitable for armeabi + vfp / armeabihf */
  225. /* when using armeabi + vfp, please set C_FLAGS -mfloat-abi=softfp -mfpu=vfp */
  226. /* using armeabihf, please set C_FLAGS -mfloat-abi=hard -mfpu=vfpv3-d16 */
  227. /* if you prefer to run in ARM mode, please add -marm to C_FLAGS */
  228. /* while using thumb mode, please add -mthumb -Wa,-mimplicit-it=thumb */
  229. /* SP is a multiple of 8 when control first enters a program.*/
  230. /* This places an obligation on authors of low level OS, RTOS, and runtime library code to align SP at all points */
  231. /* at which control first enters a body of (AAPCS-conforming) code. (please read "ARM IHI 0046B" document)*/
  232. .section .text
  233. .align 2 /* Align the function code to a 4-byte (2^n) word boundary. */
  234. #if defined(__thumb__) || defined(__thumb2__)
  235. .thumb
  236. .syntax unified
  237. #else
  238. .arm /* Use ARM instructions instead of Thumb.*/
  239. #endif
  240. .globl armFunc /* Make the function globally accessible.*/
  241. armFunc:
  242. push {r4-r8, r10, r11, lr} /* sp must be 8-byte alignment for ABI compliance, so the pushed registers must be even */
  243. mov r6, r0 /* arg table */
  244. movs r7, r1 /* arg size (also set the condition code flags so that we detect if there are no arguments) */
  245. mov r4, r2 /* function address */
  246. /* Load float and double args into d0-d7 and s0-s15 */
  247. add r10, r6, #272 /* r10 (r6 + 272) points to the first value for the VFP registers */
  248. mov r8, #0
  249. vldmia.64 r10, {d0-d7} /* Load contents starting at r10 into registers d0-d7 */
  250. /* If there are no arguments to set into r0-r3 */
  251. /* go check if there are arguments for the stack */
  252. beq stackargs
  253. /* Load the first 4 arguments into r0-r3 */
  254. cmp r7, #4
  255. ldrge r0, [r6]
  256. cmp r7, #8
  257. ldrge r1, [r6, #4]
  258. cmp r7, #12
  259. ldrge r2, [r6, #8]
  260. cmp r7, #16
  261. ldrge r3, [r6, #12]
  262. stackargs:
  263. ldr r5, [r6, #268] /* Load stack size into r5 */
  264. movs r7, r5 /* Load stack size into r7, checking for 0 args */
  265. /* If there are no args for the stack, branch */
  266. beq nomoreargs
  267. /* Load the rest of the arguments onto the stack */
  268. /* Ensure 8-byte stack alignment */
  269. mov r8, sp
  270. sub sp, sp, r7
  271. add r6, r6, #16 /* Set r6 to point to the first arg to be placed on the stack */
  272. sub r12, sp, #8
  273. bic r12, r12, #7 /* thumb mode couldn't support "bic sp, sp, #7" instruction */
  274. sub r8, r8, r12
  275. mov sp, r12 /* copy size != frame size, so store frame start sp, r12(ip) is not callee saved register */
  276. stackargsloop:
  277. ldr r5, [r6], #4
  278. subs r7, r7, #4
  279. str r5, [sp], #4
  280. bne stackargsloop
  281. mov sp, r12
  282. nomoreargs:
  283. #if defined (___ARM_ARCH_4T__) || defined (__ARM_ARCH_4__)
  284. mov lr, pc /* older ARM didn't support blx */
  285. mov pc, r4
  286. #else
  287. blx r4
  288. #endif
  289. add sp, sp, r8
  290. vstmia.64 r10, {d0-d7} /* Copy contents of registers d0-d7 to the address stored in r10 */
  291. pop {r4-r8, r10, r11, pc}
  292. /* --------------------------------------------------------------------------------------------*/
  293. .align 2 /* Align the function code to a 4-byte (2^n) word boundary. */
  294. #if defined(__thumb__) || defined(__thumb2__)
  295. .thumb
  296. .syntax unified
  297. #else
  298. .arm /* Use ARM instructions instead of Thumb.*/
  299. #endif
  300. .globl armFuncObjLast /* Make the function globally accessible.*/
  301. armFuncObjLast:
  302. push {r4-r8, r10, r11, lr} /* We´re storing r11 just to keep the stack aligned to an 8 byte boundary */
  303. mov r6, r0 /* arg table */
  304. movs r7, r1 /* arg size (also set the condition code flags so that we detect if there are no arguments) */
  305. mov r4, r2 /* function address */
  306. mov r0, r3 /* objlast. might get overwritten */
  307. mov r5, #0 /* This will hold an offset of #4 only if objlast couldn´t be placed into an "r" register */
  308. /* Load float and double args into d0-d7 and s0-s15 (r10 holds pointer to first float value) */
  309. add r10, r6, #272 /* r10 (r6 + 272) points to the first value for the VFP registers */
  310. mov r8, #0
  311. vldmia.64 r10, {d0-d7} /* Load contents starting at r10 into registers d0-d7 */
  312. /* If there are no arguments to set into r0-r3 */
  313. /* go check if there are arguments for the stack */
  314. beq stackargsFuncObjLast
  315. mov r5, r3 /* store objlast in r5 temporarily */
  316. /* Load the first 4 arguments into r0-r3 */
  317. cmp r7, #4
  318. ldrge r0, [r6]
  319. cmp r7, #8
  320. ldrge r1, [r6,#4]
  321. movlt r1, r5
  322. cmp r7, #12
  323. ldrge r2, [r6,#8]
  324. movlt r2, r5
  325. cmp r7, #16
  326. ldrge r3, [r6,#12]
  327. movlt r3, r5
  328. movlt r5, #0 /* If objlast got placed into a register, r5 = 0 */
  329. blt stackargsFuncObjLast /* If objlast got placed into a register, go to stackargsFuncObjLast */
  330. str r5, [r6, #12] /* Put objlast in r6 + 12 */
  331. mov r5, #4 /* Set r5 with an offset of #4, so objlast can be loaded into the stack */
  332. stackargsFuncObjLast:
  333. ldr r7, [r6, #268] /* Load stack size into r7 */
  334. add r7, r7, r5 /* Add the offset placed in r5 (could be #0 or #4) */
  335. cmp r7, #0 /* Check for 0 args */
  336. /* If there are no args for the stack, branch */
  337. beq nomoreargsarmFuncObjLast
  338. /* Load the rest of the arguments onto the stack */
  339. /* Ensure 8-byte stack alignment */
  340. mov r8, sp
  341. sub sp, sp, r7
  342. add r6, r6, #16 /* Set r6 to point to the first arg to be placed on the stack */
  343. sub r12, sp, #8
  344. sub r6, r6, r5 /* r6 = r6 - r5 (r5 can be #0 or #4) */
  345. bic r12, r12, #7 /* thumb mode couldn't support "bic sp, sp, #7" instruction */
  346. sub r8, r8, r12
  347. mov sp, r12 /* copy size != frame size, so store frame start sp, r12(ip) is not callee saved register */
  348. stackargslooparmFuncObjLast:
  349. ldr r5, [r6], #4
  350. subs r7, r7, #4
  351. str r5, [sp], #4
  352. bne stackargslooparmFuncObjLast
  353. mov sp, r12
  354. nomoreargsarmFuncObjLast:
  355. #if defined (___ARM_ARCH_4T__) || defined (__ARM_ARCH_4__)
  356. mov lr, pc
  357. mov pc, r4
  358. #else
  359. blx r4
  360. #endif
  361. add sp, sp, r8
  362. vstmia.64 r10, {d0-d7} /* Copy contents of registers d0-d10 to the address stored in r10 */
  363. pop {r4-r8, r10,r11, pc}
  364. /* ------------------------------------------------------------------------------------------- */
  365. .align 2 /* Align the function code to a 4-byte (2^n) word boundary. */
  366. #if defined(__thumb__) || defined(__thumb2__)
  367. .thumb
  368. .syntax unified
  369. #else
  370. .arm /* Use ARM instructions instead of Thumb.*/
  371. #endif
  372. .globl armFuncR0ObjLast /* Make the function globally accessible.*/
  373. armFuncR0ObjLast:
  374. push {r4-r8, r10, r11, lr}
  375. ldr r5, [sp,#32] /* objlast to temp reg */
  376. mov r6, r0 /* arg table */
  377. movs r7, r1 /* arg size (also set the condition code flags so that we detect if there are no arguments) */
  378. mov r4, r2 /* function address */
  379. mov r0, r3 /* r0 explicitly set */
  380. mov r1, r5 /* objlast. might get overwritten */
  381. mov r5, #0 /* This will hold an offset of #4 or #8 if objlast or one arg couldn´t be placed into an "r" register */
  382. /* Load float and double args into d0-d7 and s0-s15 (r10 holds pointer to first float value) */
  383. add r10, r6, #272 /* r10 (r6 + 272) points to the first value for the VFP registers */
  384. mov r8, #0
  385. vldmia.64 r10, {d0-d7} /* Load contents starting at r10 into registers d0-d7 */
  386. /* If there are no arguments to set into r0-r3 */
  387. /* go check if there are arguments for the stack */
  388. beq stackargsFuncR0ObjLast
  389. mov r5, r1 /* store objlast in r5 temporarily */
  390. /* Load the first 3 arguments into r1-r3 */
  391. cmp r7, #4
  392. ldrge r1, [r6]
  393. cmp r7, #8
  394. ldrge r2, [r6,#4]
  395. movlt r2, r5
  396. cmp r7, #12
  397. ldrge r3, [r6,#8]
  398. movlt r3, r5
  399. movlt r5, #0 /* If objlast got placed into a register, r5 = 0 */
  400. blt stackargsFuncR0ObjLast /* If objlast got placed into a register, go to stackargsFuncR0ObjLast */
  401. cmp r7, #16 /* Else if we have one last arg set the offset accordingly and store the arg in the array */
  402. ldrge r7, [r6, #12]
  403. strge r7, [r6, #8]
  404. str r5, [r6, #12] /* Put objlast in r6 + 12 */
  405. movge r5, #4 /* Set r5 with an offset of #4 if there´s one last arg that couldn´t be placed in r registers */
  406. add r5, r5, #4 /* Set r5 with an offset of + #4, so objlast can be loaded into the stack */
  407. stackargsFuncR0ObjLast:
  408. ldr r7, [r6, #268] /* Load stack size into r7 */
  409. add r7, r7, r5 /* Add the offset placed in r5 (could be #0 or #4) */
  410. cmp r7, #0 /* Check for 0 args */
  411. /* If there are no args for the stack, branch */
  412. beq nomoreargsarmFuncR0ObjLast
  413. /* Load the rest of the arguments onto the stack */
  414. /* Ensure 8-byte stack alignment */
  415. mov r8, sp
  416. sub sp, sp, r7
  417. add r6, r6, #16 /* Set r6 to point to the first arg to be placed on the stack */
  418. sub r12, sp, #8
  419. sub r6, r6, r5 /* r6 = r6 - r5 (r5 can be #0 or #4) */
  420. bic r12, r12, #7 /* thumb mode couldn't support "bic sp, sp, #7" instruction */
  421. sub r8, r8, r12
  422. mov sp, r12 /* copy size != frame size, so store frame start sp, r12(ip) is not callee saved register */
  423. stackargslooparmFuncR0ObjLast:
  424. ldr r5, [r6], #4
  425. subs r7, r7, #4
  426. str r5, [sp], #4
  427. bne stackargslooparmFuncR0ObjLast
  428. mov sp, r12
  429. nomoreargsarmFuncR0ObjLast:
  430. #if defined (___ARM_ARCH_4T__) || defined (__ARM_ARCH_4__)
  431. mov lr, pc
  432. mov pc, r4
  433. #else
  434. blx r4
  435. #endif
  436. add sp, sp, r8
  437. vstmia.64 r10, {d0-d7} /* Copy contents of registers d0-d10 to the address stored in r10 */
  438. pop {r4-r8, r10, r11, pc}
  439. /* ------------------------------------------------------------------------------------------- */
  440. .align 2 /* Align the function code to a 4-byte (2^n) word boundary. */
  441. #if defined(__thumb__) || defined(__thumb2__)
  442. .thumb
  443. .syntax unified
  444. #else
  445. .arm /* Use ARM instructions instead of Thumb.*/
  446. #endif
  447. .globl armFuncR0 /* Make the function globally accessible.*/
  448. armFuncR0:
  449. push {r4-r8, r10, r11, lr}
  450. mov r6, r0 /* arg table */
  451. movs r7, r1 /* arg size (also set the condition code flags so that we detect if there are no arguments) */
  452. mov r4, r2 /* function address */
  453. mov r11, #0 /* This will hold an offset of #4 only if the last arg that should have been placed into an "r" reg needs to go to the stack */
  454. mov r0, r3 /* r0 explicitly set */
  455. /* Load float and double args into d0-d7 and s0-s15 (r10 holds pointer to first float value) */
  456. add r10, r6, #272 /* r10 (r6 + 272) points to the first value for the VFP registers */
  457. mov r8, #0
  458. vldmia.64 r10, {d0-d7} /* Load contents starting at r10 into registers d0-d7 */
  459. /* If there are no arguments to set into r0-r3 */
  460. /* go check if there are arguments for the stack */
  461. beq stackargsarmFuncR0
  462. /* Load the first 3 arguments into r1-r3 */
  463. cmp r7, #4
  464. ldrge r1, [r6]
  465. cmp r7, #8
  466. ldrge r2, [r6, #4]
  467. cmp r7, #12
  468. ldrge r3, [r6, #8]
  469. cmp r7, #16
  470. movge r11, #4 /* If there is still one arg to be placed, set the offset in r11 to #4 */
  471. stackargsarmFuncR0:
  472. ldr r5, [r6, #268] /* Load stack size into r5 */
  473. add r5, r11 /* Add the offset placed in r11 (could be #0 or #4) */
  474. movs r7, r5 /* Load stack size into r7, checking for 0 args */
  475. /* If there are no args for the stack, branch */
  476. beq nomoreargsarmFuncR0
  477. /* Load the rest of the arguments onto the stack */
  478. /* Ensure 8-byte stack alignment */
  479. mov r8, sp
  480. sub sp, sp, r7
  481. add r6, r6, #16 /* Set r6 to point to the first arg to be placed on the stack */
  482. sub r12, sp, #8
  483. sub r6, r6, r11 /* r6 = r6 - r11 (r11 can be #0 or #4) */
  484. bic r12, r12, #7 /* thumb mode couldn't support "bic sp, sp, #7" instruction */
  485. sub r8, r8, r12
  486. mov sp, r12 /* copy size != frame size, so store frame start sp, r12(ip) is not callee saved register */
  487. stackargslooparmFuncR0:
  488. ldr r5, [r6], #4
  489. subs r7, r7, #4
  490. str r5, [sp], #4
  491. bne stackargslooparmFuncR0
  492. mov sp, r12
  493. nomoreargsarmFuncR0:
  494. #if defined (___ARM_ARCH_4T__) || defined (__ARM_ARCH_4__)
  495. mov lr, pc
  496. mov pc, r4
  497. #else
  498. blx r4
  499. #endif
  500. add sp, sp, r8
  501. vstmia.64 r10, {d0-d7} /* Copy contents of registers d0-d10 to the address stored in r10 */
  502. pop {r4-r8, r10, r11, pc}
  503. /* ------------------------------------------------------------------------------------------- */
  504. .align 2 /* Align the function code to a 4-byte (2^n) word boundary. */
  505. #if defined(__thumb__) || defined(__thumb2__)
  506. .thumb
  507. .syntax unified
  508. #else
  509. .arm /* Use ARM instructions instead of Thumb.*/
  510. #endif
  511. .globl armFuncR0R1 /* Make the function globally accessible.*/
  512. armFuncR0R1:
  513. push {r4-r8, r10, r11, lr}
  514. mov r6, r0 /* arg table */
  515. movs r7, r1 /* arg size (also set the condition code flags so that we detect if there are no arguments) */
  516. mov r4, r2 /* function address */
  517. mov r11, #0 /* This will hold an offset of #4 or #8 only if the last arg (or last 2 args) that should have been placed into "r" regs need to go to the stack */
  518. mov r0, r3 /* r0 explicitly set */
  519. ldr r1, [sp, #32] /* r1 explicitly set too */
  520. /* Load float and double args into d0-d7 and s0-s15 (r10 holds pointer to first float value) */
  521. add r10, r6, #272 /* r10 (r6 + 272) points to the first value for the VFP registers */
  522. mov r8, #0
  523. vldmia.64 r10, {d0-d7} /* Load contents starting at r10 into registers d0-d7 */
  524. /* If there are no arguments to set into r2-r3 */
  525. /* go check if there are arguments for the stack */
  526. beq stackargsarmFuncR0R1
  527. /* Load the first 2 arguments into r2-r3 */
  528. cmp r7, #4
  529. ldrge r2, [r6]
  530. cmp r7, #8
  531. ldrge r3, [r6, #4]
  532. cmp r7, #12
  533. movge r11, #4 /* If there is a third arg to be placed, set the offset in r11 to #4 */
  534. cmp r7, #16
  535. movge r11, #8 /* If there is a fourth arg to be placed, set the offset in r11 to #8 */
  536. ldrlt r7, [r6, #8] /* Else copy the third arg to the correct place in the array */
  537. strlt r7, [r6, #12]
  538. stackargsarmFuncR0R1:
  539. ldr r5, [r6, #268] /* Load stack size into r5 */
  540. add r5, r11 /* Add the offset placed in r11 (could be #0 or #4 or #8) */
  541. movs r7, r5 /* Load stack size into r7, checking for 0 args */
  542. /* If there are no args for the stack, branch */
  543. beq nomoreargsarmFuncR0R1
  544. /* Load the rest of the arguments onto the stack */
  545. /* Ensure 8-byte stack alignment */
  546. mov r8, sp
  547. sub sp, sp, r7
  548. add r6, r6, #16 /* Set r6 to point to the first arg to be placed on the stack */
  549. sub r12, sp, #8
  550. sub r6, r6, r11 /* r6 = r6 - r11 (r11 can be #0 or #4 or #8) */
  551. bic r12, r12, #7 /* thumb mode couldn't support "bic sp, sp, #7" instruction */
  552. sub r8, r8, r12
  553. mov sp, r12 /* copy size != frame size, so store frame start sp, r12(ip) is not callee saved register */
  554. stackargslooparmFuncR0R1:
  555. ldr r5, [r6], #4
  556. subs r7, r7, #4
  557. str r5, [sp], #4
  558. bne stackargslooparmFuncR0R1
  559. mov sp, r12
  560. nomoreargsarmFuncR0R1:
  561. #if defined (___ARM_ARCH_4T__) || defined (__ARM_ARCH_4__)
  562. mov lr, pc
  563. mov pc, r4
  564. #else
  565. blx r4
  566. #endif
  567. add sp, sp, r8
  568. vstmia.64 r10, {d0-d7} /* Copy contents of registers d0-d10 to the address stored in r10 */
  569. pop {r4-r8, r10, r11, pc}
  570. #endif /* hard float abi */
  571. #if defined(__linux__) && defined(__ELF__)
  572. /* ref: http://hardened.gentoo.org/gnu-stack.xml */
  573. .section .note.GNU-stack,"",%progbits
  574. #endif
  575. #endif /* arm */