as_callfunc_arm_msvc.asm 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. ;
  2. ; AngelCode Scripting Library
  3. ; Copyright (c) 2003-2014 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. ; andreas@angelcode.com
  29. ;
  30. ; Assembly routines for the ARM call convention used for Windows CE
  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. ; Compile with Microsoft ARM assembler (armasm)
  35. ; http://msdn.microsoft.com/en-us/library/hh873190.aspx
  36. AREA |.rdata|, DATA, READONLY
  37. EXPORT armFunc
  38. EXPORT armFuncR0
  39. EXPORT armFuncR0R1
  40. EXPORT armFuncObjLast
  41. EXPORT armFuncR0ObjLast
  42. AREA |.text|, CODE, ARM, ALIGN=3
  43. ALIGN 8
  44. armFunc PROC
  45. stmdb sp!, {r4-r8, lr}
  46. mov r6, r0 ; arg table
  47. movs r7, r1 ; arg size (also set the condition code flags so that we detect if there are no arguments)
  48. mov r4, r2 ; function address
  49. mov r8, #0
  50. beq |nomoreargs|
  51. ; Load the first 4 arguments into r0-r3
  52. cmp r7, #4
  53. ldrge r0, [r6],#4
  54. cmp r7, #2*4
  55. ldrge r1, [r6],#4
  56. cmp r7, #3*4
  57. ldrge r2, [r6],#4
  58. cmp r7, #4*4
  59. ldrge r3, [r6],#4
  60. ble |nomoreargs|
  61. ; Load the rest of the arguments onto the stack
  62. sub r7, r7, #4*4 ; skip the 4 registers already loaded into r0-r3
  63. sub sp, sp, r7
  64. mov r8, r7
  65. |stackargsloop|
  66. ldr r5, [r6], #4
  67. str r5, [sp], #4
  68. subs r7, r7, #4
  69. bne |stackargsloop|
  70. |nomoreargs|
  71. sub sp, sp, r8
  72. blx r4
  73. add sp, sp, r8
  74. ldmia sp!, {r4-r8, pc}
  75. ENDP
  76. ALIGN 8
  77. armFuncObjLast PROC
  78. stmdb sp!, {r4-r8, lr}
  79. mov r6, r0 ; arg table
  80. movs r7, r1 ; arg size (also set the condition code flags so that we detect if there are no arguments)
  81. mov r4, r2 ; function address
  82. mov r8, #0
  83. mov r0, r3 ; objlast. might get overwritten
  84. str r3, [sp, #-4]! ; objlast again.
  85. beq |nomoreargs@armFuncObjLast|
  86. ; Load the first 4 arguments into r0-r3
  87. cmp r7, #4
  88. ldrge r0, [r6],#4
  89. cmp r7, #2*4
  90. ldrge r1, [r6],#4
  91. ldrlt r1, [sp]
  92. cmp r7, #3*4
  93. ldrge r2, [r6],#4
  94. ldrlt r2, [sp]
  95. cmp r7, #4*4
  96. ldrge r3, [r6],#4
  97. ldrlt r3, [sp]
  98. ble |nomoreargs@armFuncObjLast|
  99. ; Load the rest of the arguments onto the stack
  100. sub r7, r7, #4*4 ; skip the 4 registers already loaded into r0-r3
  101. sub sp, sp, r7
  102. mov r8, r7
  103. |stackargsloop@armFuncObjLast|
  104. ldr r5, [r6], #4
  105. str r5, [sp], #4
  106. subs r7, r7, #4
  107. bne |stackargsloop@armFuncObjLast|
  108. |nomoreargs@armFuncObjLast|
  109. sub sp, sp, r8
  110. blx r4
  111. add sp, sp, r8
  112. add sp, sp, #4
  113. ldmia sp!, {r4-r8, pc}
  114. ENDP
  115. ALIGN 8
  116. armFuncR0ObjLast PROC
  117. stmdb sp!, {r4-r8, lr}
  118. ldr r7, [sp,#6*4]
  119. str r7, [sp,#-4]!
  120. mov r6, r0 ; arg table
  121. movs r7, r1 ; arg size (also set the condition code flags so that we detect if there are no arguments)
  122. mov r4, r2 ; function address
  123. mov r8, #0
  124. mov r0, r3 ; r0 explicitly set
  125. ldr r1, [sp] ; objlast. might get overwritten
  126. beq |nomoreargs@armFuncR0ObjLast|
  127. ; Load the first 3 arguments into r1-r3
  128. cmp r7, #1*4
  129. ldrge r1, [r6],#4
  130. cmp r7, #2*4
  131. ldrge r2, [r6],#4
  132. ldrlt r2, [sp]
  133. cmp r7, #3*4
  134. ldrge r3, [r6],#4
  135. ldrlt r3, [sp]
  136. ble |nomoreargs@armFuncR0ObjLast|
  137. ; Load the rest of the arguments onto the stack
  138. sub r7, r7, #3*4 ; skip the 3 registers already loaded into r1-r3
  139. sub sp, sp, r7
  140. mov r8, r7
  141. |stackargsloop@armFuncR0ObjLast|
  142. ldr r5, [r6], #4
  143. str r5, [sp], #4
  144. subs r7, r7, #4
  145. bne |stackargsloop@armFuncR0ObjLast|
  146. |nomoreargs@armFuncR0ObjLast|
  147. sub sp, sp, r8
  148. blx r4
  149. add sp, sp, r8
  150. add sp, sp, #4
  151. ldmia sp!, {r4-r8, pc}
  152. ENDP
  153. ALIGN 8
  154. armFuncR0 PROC
  155. stmdb sp!, {r4-r8, lr}
  156. mov r6, r0 ; arg table
  157. movs r7, r1 ; arg size (also set the condition code flags so that we detect if there are no arguments)
  158. mov r4, r2 ; function address
  159. mov r8, #0
  160. mov r0, r3 ; r0 explicitly set
  161. beq |nomoreargs@armFuncR0|
  162. ; Load the first 3 arguments into r1-r3
  163. cmp r7, #1*4
  164. ldrge r1, [r6],#4
  165. cmp r7, #2*4
  166. ldrge r2, [r6],#4
  167. cmp r7, #3*4
  168. ldrge r3, [r6],#4
  169. ble |nomoreargs@armFuncR0|
  170. ; Load the rest of the arguments onto the stack
  171. sub r7, r7, #3*4 ; skip the 3 registers already loaded into r1-r3
  172. sub sp, sp, r7
  173. mov r8, r7
  174. |stackargsloop@armFuncR0|
  175. ldr r5, [r6], #4
  176. str r5, [sp], #4
  177. subs r7, r7, #4
  178. bne |stackargsloop@armFuncR0|
  179. |nomoreargs@armFuncR0|
  180. sub sp, sp, r8
  181. blx r4
  182. add sp, sp, r8
  183. ldmia sp!, {r4-r8, pc}
  184. ENDP
  185. ALIGN 8
  186. armFuncR0R1 PROC
  187. stmdb sp!, {r4-r8, lr}
  188. mov r6, r0 ; arg table
  189. movs r7, r1 ; arg size (also set the condition code flags so that we detect if there are no arguments)
  190. mov r4, r2 ; function address
  191. mov r8, #0
  192. mov r0, r3 ; r0 explicitly set
  193. ldr r1, [sp, #6*4] ; r1 explicitly set too
  194. beq |nomoreargs@armFuncR0R1|
  195. ; Load the first 2 arguments into r2-r3
  196. cmp r7, #1*4
  197. ldrge r2, [r6],#4
  198. cmp r7, #2*4
  199. ldrge r3, [r6],#4
  200. ble |nomoreargs@armFuncR0R1|
  201. ; Load the rest of the arguments onto the stack
  202. sub r7, r7, #2*4 ; skip the 2 registers already loaded into r2-r3
  203. sub sp, sp, r7
  204. mov r8, r7
  205. |stackargsloop@armFuncR0R1|
  206. ldr r5, [r6], #4
  207. str r5, [sp], #4
  208. subs r7, r7, #4
  209. bne |stackargsloop@armFuncR0R1|
  210. |nomoreargs@armFuncR0R1|
  211. sub sp, sp, r8
  212. blx r4
  213. add sp, sp, r8
  214. ldmia sp!, {r4-r8, pc}
  215. ENDP
  216. END