as_callfunc_arm_xcode.S 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2009 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. // Assembly routines for the ARM call convention
  24. // Written by Fredrik Ehnbom in June 2009
  25. // Adapted to GNUC by darktemplar216 in September 2009
  26. // Small fixed to work under XCode GCC by Gilad Novik in October 2009
  27. #if defined(__arm__) || defined(__ARM__)
  28. .align 2
  29. .globl _armFunc
  30. .globl _armFuncR0
  31. .globl _armFuncR0R1
  32. .globl _armFuncObjLast
  33. .globl _armFuncR0ObjLast
  34. _armFunc:
  35. stmdb sp!, {r4-r8, lr}
  36. mov r6, r0 // arg table
  37. movs r7, r1 // arg size (also set the condition code flags so that we detect if there are no arguments)
  38. mov r4, r2 // function address
  39. mov r8, #0
  40. beq nomoreargs
  41. // Load the first 4 arguments into r0-r3
  42. cmp r7, #4
  43. ldrge r0, [r6],#4
  44. cmp r7, #2*4
  45. ldrge r1, [r6],#4
  46. cmp r7, #3*4
  47. ldrge r2, [r6],#4
  48. cmp r7, #4*4
  49. ldrge r3, [r6],#4
  50. ble nomoreargs
  51. // Load the rest of the arguments onto the stack
  52. sub r7, r7, #4*4 // skip the 4 registers already loaded into r0-r3
  53. sub sp, sp, r7
  54. mov r8, r7
  55. stackargsloop:
  56. ldr r5, [r6], #4
  57. str r5, [sp], #4
  58. subs r7, r7, #4
  59. bne stackargsloop
  60. nomoreargs:
  61. sub sp, sp, r8
  62. blx r4
  63. add sp, sp, r8
  64. ldmia sp!, {r4-r8, pc}
  65. _armFuncObjLast:
  66. stmdb sp!, {r4-r8, lr}
  67. mov r6, r0 // arg table
  68. movs r7, r1 // arg size (also set the condition code flags so that we detect if there are no arguments)
  69. mov r4, r2 // function address
  70. mov r8, #0
  71. mov r0, r3 // objlast. might get overwritten
  72. str r3, [sp, #-4]! // objlast again.
  73. beq nomoreargsarmFuncObjLast
  74. // Load the first 4 arguments into r0-r3
  75. cmp r7, #4
  76. ldrge r0, [r6],#4
  77. cmp r7, #2*4
  78. ldrge r1, [r6],#4
  79. ldrlt r1, [sp]
  80. cmp r7, #3*4
  81. ldrge r2, [r6],#4
  82. ldrlt r2, [sp]
  83. cmp r7, #4*4
  84. ldrge r3, [r6],#4
  85. ldrlt r3, [sp]
  86. ble nomoreargsarmFuncObjLast
  87. // Load the rest of the arguments onto the stack
  88. sub r7, r7, #4*4 // skip the 4 registers already loaded into r0-r3
  89. sub sp, sp, r7
  90. mov r8, r7
  91. stackargslooparmFuncObjLast:
  92. ldr r5, [r6], #4
  93. str r5, [sp], #4
  94. subs r7, r7, #4
  95. bne stackargslooparmFuncObjLast
  96. nomoreargsarmFuncObjLast:
  97. sub sp, sp, r8
  98. blx r4
  99. add sp, sp, r8
  100. add sp, sp, #4
  101. ldmia sp!, {r4-r8, pc}
  102. _armFuncR0ObjLast:
  103. stmdb sp!, {r4-r8, lr}
  104. ldr r7, [sp,#6*4]
  105. str r7, [sp,#-4]!
  106. mov r6, r0 // arg table
  107. movs r7, r1 // arg size (also set the condition code flags so that we detect if there are no arguments)
  108. mov r4, r2 // function address
  109. mov r8, #0
  110. mov r0, r3 // r0 explicitly set
  111. ldr r1, [sp] // objlast. might get overwritten
  112. beq nomoreargsarmFuncR0ObjLast
  113. // Load the first 3 arguments into r1-r3
  114. cmp r7, #1*4
  115. ldrge r1, [r6],#4
  116. cmp r7, #2*4
  117. ldrge r2, [r6],#4
  118. ldrlt r2, [sp]
  119. cmp r7, #3*4
  120. ldrge r3, [r6],#4
  121. ldrlt r3, [sp]
  122. ble nomoreargsarmFuncR0ObjLast
  123. // Load the rest of the arguments onto the stack
  124. sub r7, r7, #3*4 // skip the 3 registers already loaded into r1-r3
  125. sub sp, sp, r7
  126. mov r8, r7
  127. stackargslooparmFuncR0ObjLast:
  128. ldr r5, [r6], #4
  129. str r5, [sp], #4
  130. subs r7, r7, #4
  131. bne stackargslooparmFuncR0ObjLast
  132. nomoreargsarmFuncR0ObjLast:
  133. sub sp, sp, r8
  134. blx r4
  135. add sp, sp, r8
  136. add sp, sp, #4
  137. ldmia sp!, {r4-r8, pc}
  138. _armFuncR0:
  139. stmdb sp!, {r4-r8, lr}
  140. mov r6, r0 // arg table
  141. movs r7, r1 // arg size (also set the condition code flags so that we detect if there are no arguments)
  142. mov r4, r2 // function address
  143. mov r8, #0
  144. mov r0, r3 // r0 explicitly set
  145. beq nomoreargsarmFuncR0
  146. // Load the first 3 arguments into r1-r3
  147. cmp r7, #1*4
  148. ldrge r1, [r6],#4
  149. cmp r7, #2*4
  150. ldrge r2, [r6],#4
  151. cmp r7, #3*4
  152. ldrge r3, [r6],#4
  153. ble nomoreargsarmFuncR0
  154. // Load the rest of the arguments onto the stack
  155. sub r7, r7, #3*4 // skip the 3 registers already loaded into r1-r3
  156. sub sp, sp, r7
  157. mov r8, r7
  158. stackargslooparmFuncR0:
  159. ldr r5, [r6], #4
  160. str r5, [sp], #4
  161. subs r7, r7, #4
  162. bne stackargslooparmFuncR0
  163. nomoreargsarmFuncR0:
  164. sub sp, sp, r8
  165. blx r4
  166. add sp, sp, r8
  167. ldmia sp!, {r4-r8, pc}
  168. _armFuncR0R1:
  169. stmdb sp!, {r4-r8, lr}
  170. mov r6, r0 // arg table
  171. movs r7, r1 // arg size (also set the condition code flags so that we detect if there are no arguments)
  172. mov r4, r2 // function address
  173. mov r8, #0
  174. mov r0, r3 // r0 explicitly set
  175. ldr r1, [sp, #6*4] // r1 explicitly set too
  176. beq nomoreargsarmFuncR0R1
  177. // Load the first 2 arguments into r2-r3
  178. cmp r7, #1*4
  179. ldrge r2, [r6],#4
  180. cmp r7, #2*4
  181. ldrge r3, [r6],#4
  182. ble nomoreargsarmFuncR0R1
  183. // Load the rest of the arguments onto the stack
  184. sub r7, r7, #2*4 // skip the 2 registers already loaded into r2-r3
  185. sub sp, sp, r7
  186. mov r8, r7
  187. stackargslooparmFuncR0R1:
  188. ldr r5, [r6], #4
  189. str r5, [sp], #4
  190. subs r7, r7, #4
  191. bne stackargslooparmFuncR0R1
  192. nomoreargsarmFuncR0R1:
  193. sub sp, sp, r8
  194. blx r4
  195. add sp, sp, r8
  196. ldmia sp!, {r4-r8, pc}
  197. #endif