as_callfunc_arm_xcode.S 6.6 KB

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