as_callfunc_arm_msvc.asm 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. ;
  2. ; AngelCode Scripting Library
  3. ; Copyright (c) 2003-2009 Andreas Jonsson
  4. ;
  5. ; This software is provided 'as-is', without any express or implied
  6. ; warranty. In no event will the authors be held liable for any
  7. ; damages arising from the use of this software.
  8. ;
  9. ; Permission is granted to anyone to use this software for any
  10. ; purpose, including commercial applications, and to alter it and
  11. ; redistribute it freely, subject to the following restrictions:
  12. ;
  13. ; 1. The origin of this software must not be misrepresented; you
  14. ; must not claim that you wrote the original software. If you use
  15. ; this software in a product, an acknowledgment in the product
  16. ; documentation would be appreciated but is not required.
  17. ;
  18. ; 2. Altered source versions must be plainly marked as such, and
  19. ; must not be misrepresented as being the original software.
  20. ;
  21. ; 3. This notice may not be removed or altered from any source
  22. ; distribution.
  23. ;
  24. ; The original version of this library can be located at:
  25. ; http://www.angelcode.com/angelscript/
  26. ;
  27. ; Andreas Jonsson
  28. ; [email protected]
  29. ;
  30. ; Assembly routines for the ARM call convention
  31. ; Written by Fredrik Ehnbom in June 2009
  32. ; MSVC currently doesn't support inline assembly for the ARM platform
  33. ; so this separate file is needed.
  34. AREA |.rdata|, DATA, READONLY
  35. EXPORT |armFunc|
  36. EXPORT armFuncR0
  37. EXPORT armFuncR0R1
  38. EXPORT armFuncObjLast
  39. EXPORT armFuncR0ObjLast
  40. AREA |.text|, CODE, ARM
  41. |armFunc| PROC
  42. stmdb sp!, {r4-r8, lr}
  43. mov r6, r0 ; arg table
  44. movs r7, r1 ; arg size (also set the condition code flags so that we detect if there are no arguments)
  45. mov r4, r2 ; function address
  46. mov r8, #0
  47. beq |nomoreargs|
  48. ; Load the first 4 arguments into r0-r3
  49. cmp r7, #4
  50. ldrge r0, [r6],#4
  51. cmp r7, #2*4
  52. ldrge r1, [r6],#4
  53. cmp r7, #3*4
  54. ldrge r2, [r6],#4
  55. cmp r7, #4*4
  56. ldrge r3, [r6],#4
  57. ble |nomoreargs|
  58. ; Load the rest of the arguments onto the stack
  59. sub r7, r7, #4*4 ; skip the 4 registers already loaded into r0-r3
  60. sub sp, sp, r7
  61. mov r8, r7
  62. |stackargsloop|
  63. ldr r5, [r6], #4
  64. str r5, [sp], #4
  65. subs r7, r7, #4
  66. bne |stackargsloop|
  67. |nomoreargs|
  68. sub sp, sp, r8
  69. blx r4
  70. add sp, sp, r8
  71. ldmia sp!, {r4-r8, pc}
  72. ENDP
  73. armFuncObjLast PROC
  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. str r3, [sp, #-4]! ; objlast again.
  81. beq |nomoreargs@armFuncObjLast|
  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. ldrlt r1, [sp]
  88. cmp r7, #3*4
  89. ldrge r2, [r6],#4
  90. ldrlt r2, [sp]
  91. cmp r7, #4*4
  92. ldrge r3, [r6],#4
  93. ldrlt r3, [sp]
  94. ble |nomoreargs@armFuncObjLast|
  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. sub sp, sp, r7
  98. mov r8, r7
  99. |stackargsloop@armFuncObjLast|
  100. ldr r5, [r6], #4
  101. str r5, [sp], #4
  102. subs r7, r7, #4
  103. bne |stackargsloop@armFuncObjLast|
  104. |nomoreargs@armFuncObjLast|
  105. sub sp, sp, r8
  106. blx r4
  107. add sp, sp, r8
  108. add sp, sp, #4
  109. ldmia sp!, {r4-r8, pc}
  110. ENDP
  111. armFuncR0ObjLast PROC
  112. stmdb sp!, {r4-r8, lr}
  113. ldr r7, [sp,#6*4]
  114. str r7, [sp,#-4]!
  115. mov r6, r0 ; arg table
  116. movs r7, r1 ; arg size (also set the condition code flags so that we detect if there are no arguments)
  117. mov r4, r2 ; function address
  118. mov r8, #0
  119. mov r0, r3 ; r0 explicitly set
  120. ldr r1, [sp] ; objlast. might get overwritten
  121. beq |nomoreargs@armFuncR0ObjLast|
  122. ; Load the first 3 arguments into r1-r3
  123. cmp r7, #1*4
  124. ldrge r1, [r6],#4
  125. cmp r7, #2*4
  126. ldrge r2, [r6],#4
  127. ldrlt r2, [sp]
  128. cmp r7, #3*4
  129. ldrge r3, [r6],#4
  130. ldrlt r3, [sp]
  131. ble |nomoreargs@armFuncR0ObjLast|
  132. ; Load the rest of the arguments onto the stack
  133. sub r7, r7, #3*4 ; skip the 3 registers already loaded into r1-r3
  134. sub sp, sp, r7
  135. mov r8, r7
  136. |stackargsloop@armFuncR0ObjLast|
  137. ldr r5, [r6], #4
  138. str r5, [sp], #4
  139. subs r7, r7, #4
  140. bne |stackargsloop@armFuncR0ObjLast|
  141. |nomoreargs@armFuncR0ObjLast|
  142. sub sp, sp, r8
  143. blx r4
  144. add sp, sp, r8
  145. add sp, sp, #4
  146. ldmia sp!, {r4-r8, pc}
  147. ENDP
  148. armFuncR0 PROC
  149. stmdb sp!, {r4-r8, lr}
  150. mov r6, r0 ; arg table
  151. movs r7, r1 ; arg size (also set the condition code flags so that we detect if there are no arguments)
  152. mov r4, r2 ; function address
  153. mov r8, #0
  154. mov r0, r3 ; r0 explicitly set
  155. beq |nomoreargs@armFuncR0|
  156. ; Load the first 3 arguments into r1-r3
  157. cmp r7, #1*4
  158. ldrge r1, [r6],#4
  159. cmp r7, #2*4
  160. ldrge r2, [r6],#4
  161. cmp r7, #3*4
  162. ldrge r3, [r6],#4
  163. ble |nomoreargs@armFuncR0|
  164. ; Load the rest of the arguments onto the stack
  165. sub r7, r7, #3*4 ; skip the 3 registers already loaded into r1-r3
  166. sub sp, sp, r7
  167. mov r8, r7
  168. |stackargsloop@armFuncR0|
  169. ldr r5, [r6], #4
  170. str r5, [sp], #4
  171. subs r7, r7, #4
  172. bne |stackargsloop@armFuncR0|
  173. |nomoreargs@armFuncR0|
  174. sub sp, sp, r8
  175. blx r4
  176. add sp, sp, r8
  177. ldmia sp!, {r4-r8, pc}
  178. ENDP
  179. armFuncR0R1 PROC
  180. stmdb sp!, {r4-r8, lr}
  181. mov r6, r0 ; arg table
  182. movs r7, r1 ; arg size (also set the condition code flags so that we detect if there are no arguments)
  183. mov r4, r2 ; function address
  184. mov r8, #0
  185. mov r0, r3 ; r0 explicitly set
  186. ldr r1, [sp, #6*4] ; r1 explicitly set too
  187. beq |nomoreargs@armFuncR0R1|
  188. ; Load the first 2 arguments into r2-r3
  189. cmp r7, #1*4
  190. ldrge r2, [r6],#4
  191. cmp r7, #2*4
  192. ldrge r3, [r6],#4
  193. ble |nomoreargs@armFuncR0R1|
  194. ; Load the rest of the arguments onto the stack
  195. sub r7, r7, #2*4 ; skip the 2 registers already loaded into r2-r3
  196. sub sp, sp, r7
  197. mov r8, r7
  198. |stackargsloop@armFuncR0R1|
  199. ldr r5, [r6], #4
  200. str r5, [sp], #4
  201. subs r7, r7, #4
  202. bne |stackargsloop@armFuncR0R1|
  203. |nomoreargs@armFuncR0R1|
  204. sub sp, sp, r8
  205. blx r4
  206. add sp, sp, r8
  207. ldmia sp!, {r4-r8, pc}
  208. ENDP
  209. END