arm_JavascriptFunctionA.S 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. // -------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. // -------------------------------------------------------------------------------------------------------
  5. #include "unixasmmacros.inc"
  6. .syntax unified
  7. .thumb
  8. // .thumb
  9. .global C_FUNC(_ZN2Js18JavascriptFunction24DeferredDeserializeThunkEPNS_16RecyclableObjectENS_8CallInfoEz)
  10. .global C_FUNC(_ZN2Js18JavascriptFunction20DeferredParsingThunkEPNS_16RecyclableObjectENS_8CallInfoEz)
  11. // .arm
  12. .global C_FUNC(arm_CallFunction)
  13. .global C_FUNC(arm_CallEhFrame)
  14. .global C_FUNC(arm_CallCatch)
  15. NESTED_ENTRY _ZN2Js18JavascriptFunction24DeferredDeserializeThunkEPNS_16RecyclableObjectENS_8CallInfoEz, _TEXT, NoHandler
  16. push_nonvol_reg {r0-r3}
  17. push_nonvol_reg {r11}
  18. push_nonvol_reg {lr}
  19. bl _ZN2Js18JavascriptFunction19DeferredDeserializeEPNS_14ScriptFunctionE
  20. mov r12,r0 // back up entryPoint in R12
  21. pop_nonvol_reg {lr}
  22. pop_nonvol_reg {r11}
  23. pop_nonvol_reg {r0-r3}
  24. bx r12 // jump (tail call) to new entryPoint
  25. NESTED_END _ZN2Js18JavascriptFunction24DeferredDeserializeThunkEPNS_16RecyclableObjectENS_8CallInfoEz, _TEXT
  26. NESTED_ENTRY _ZN2Js18JavascriptFunction20DeferredParsingThunkEPNS_16RecyclableObjectENS_8CallInfoEz, _TEXT, NoHandler
  27. push_nonvol_reg {r0-r3}
  28. push_nonvol_reg {r11}
  29. push_nonvol_reg {lr}
  30. mov r0, sp // Pass the address of the function at the saved r0 in case it need to be boxed
  31. bl _ZN2Js18JavascriptFunction13DeferredParseEPPNS_14ScriptFunctionE
  32. mov r12,r0 // back up entryPoint in R12
  33. pop_nonvol_reg {lr}
  34. pop_nonvol_reg {r11}
  35. pop_nonvol_reg {r0-r3}
  36. bx r12 // jump (tail call) to new entryPoint
  37. NESTED_END _ZN2Js18JavascriptFunction20DeferredParsingThunkEPNS_16RecyclableObjectENS_8CallInfoEz, _TEXT
  38. .arm
  39. NESTED_ENTRY arm_CallFunction, _TEXT, NoHandler
  40. // IMPORTANT: the number of pushed registers (even vs odd) must be consistent with 8-bytes align check below.
  41. PROLOG_PUSH {r4-r7} // r6 is saved for stack alignment, this does: add r11,sp,#10 as well
  42. PROLOG_PUSH {r11}
  43. PROLOG_PUSH {lr}
  44. #if defined(_CONTROL_FLOW_GUARD)
  45. PROLOG_PUSH {r8-r9} // extra register to save info across icall check, and one register to maintain alignment
  46. #endif
  47. PROLOG_STACK_SAVE r7 // mov r7,sp -- save stack frame for restoring at the epilog.
  48. // All but two values go onto the stack ... calculate the number of values on the stack.
  49. mov r4,r1 // r4 = callInfo.
  50. bfc r4,#24,#8 // clear high order 8 bits of r6 -- clean callInfo.Flags which shares same word as callInfo.Count.
  51. sub r4,r4,#2 // subtract 2 == number of values that we can pass via registers.
  52. mov r5,r4,lsl #2 // r5 = space needed on the stack for values.
  53. // Adjust sp to meet ABI requirement: stack must be 8-bytes aligned at any function boundary.
  54. // Each reg is 4 bytes, so as we push 4 (even) regs above, r1 == odd number of regs breaks 8-byte alignment, even is OK.
  55. asrs r12,r4,#1 // r-shift r1 into carry - set carry flag if r4 is odd. Note: the value in r12 is not used.
  56. addcs r4, r4, #1 // if carry is set, add space for one more argument on stack to guarantee 8-byte alignment.
  57. // offset stack by the amount of space we'll need.
  58. sub sp,sp,r4
  59. mov r4,r3 // copy entryPoint to r4 so we can use r3 as a scratch variable
  60. add r2,r2,#8 // add 8 to r2 (so it is the address of the first value to be placed on the stack).
  61. mov r12,#0 // offset for getting values/storing on stack.
  62. LOCAL_LABEL(argN):
  63. cmp r5,r12
  64. beq LOCAL_LABEL(arg2) // if r5 == r12, no more values need to go onto the stack.
  65. ldr r3,[r2,r12] // r3 = *(r2 + r12)
  66. str r3,[sp,r12] // *(sp + r12) = r3
  67. add r12,r12,#4 // offset increases by 4.
  68. b LOCAL_LABEL(argN) // goto argN
  69. LOCAL_LABEL(arg2):
  70. // Verify that the call target is valid, and process last two arguments
  71. #if defined(_CONTROL_FLOW_GUARD)
  72. mov r5, r0 // save argument registers
  73. mov r6, r1
  74. mov r8, r2
  75. mov r0, r4 // the target address to check
  76. mov32 r12, __guard_check_icall_fptr
  77. ldr r12, [r12]
  78. blx r12
  79. mov r0, r5 // restore argument registers
  80. mov r1, r6
  81. mov r2, r8
  82. #endif
  83. // Push values[1] into r3
  84. ldr r3,[r2,#-4] // r3 = *(r2-4) = values[1]
  85. // Push values[0] into r2
  86. ldr r2,[r2,#-8] // r2 = *(r2-8) = values[0]
  87. blx r4 // call r4 (== entry point)
  88. EPILOG_STACK_RESTORE r7
  89. #if defined(_CONTROL_FLOW_GUARD)
  90. EPILOG_POP {r8-r9}
  91. #endif
  92. EPILOG_POP {pc}
  93. EPILOG_POP {r11}
  94. EPILOG_POP {r4-r7}
  95. NESTED_END arm_CallFunction, _TEXT
  96. NESTED_ENTRY arm_CallEhFrame, _TEXT, NoHandler
  97. // Params:
  98. // r0 -- thunk target
  99. // r1 -- frame pointer
  100. // r2 -- locals pointer
  101. // r3 -- size of stack args area
  102. // Home params and save registers
  103. // Push r11 to create the equivalent of the stack nested function list (doesn't matter what is stored there)
  104. // Push r12 to create the equivalent of the arguments object slot (doesn't matter what is stored there)
  105. PROLOG_PUSH {r0-r3}
  106. PROLOG_PUSH {r11}
  107. PROLOG_PUSH {lr}
  108. PROLOG_PUSH {r4-r12}
  109. PROLOG_VPUSH {d8-d15}
  110. // Save a pointer to the saved registers
  111. PROLOG_STACK_SAVE r4
  112. PROLOG_PUSH {r4}
  113. // Set up the frame pointer and locals pointer
  114. mov r7,r2
  115. mov r11,r1
  116. // Allocate the arg out area, calling chkstk if necessary
  117. cmp r3,4096
  118. bge LOCAL_LABEL(chkstk_call)
  119. sub sp,r3
  120. // Verify that the call target is valid
  121. #if 0 && defined(_CONTROL_FLOW_GUARD)
  122. // we have used the r1-r3 info to set up the fake frame
  123. // they aren't needed by the jitted code that we're going to thunk to
  124. // so we don't preserve them across the __guard_check_icall_fptr call
  125. mov r5, r0
  126. mov32 r12, __guard_check_icall_fptr
  127. ldr r12, [r12]
  128. blx r12
  129. mov r0, r5
  130. #endif
  131. // Thunk to the jitted code (and don't return)
  132. bx r0
  133. LOCAL_LABEL(chkstk_call):
  134. // Call chkstk, passing a DWORD count in r4
  135. lsr r4,r3,#2
  136. // bl |__chkstk|
  137. // r4 is now the byte count to be allocated
  138. sub sp,r4
  139. // Thunk to the jitted code (and don't return)
  140. bx r0
  141. NESTED_END arm_CallEhFrame, _TEXT
  142. NESTED_ENTRY arm_CallCatch, _TEXT, NoHandler
  143. // Params:
  144. // r0 -- thunk target
  145. // r1 -- frame pointer
  146. // r2 -- locals pointer
  147. // r3 -- size of stack args area
  148. // [sp] -- exception object
  149. // Home params and save registers
  150. // Push r11 to create the equivalent of the stack nested function list (doesn't matter what is stored there)
  151. // Push r12 to create the equivalent of the arguments object slot (doesn't matter what is stored there)
  152. PROLOG_PUSH {r0-r3}
  153. PROLOG_PUSH {r11}
  154. PROLOG_PUSH {lr}
  155. PROLOG_PUSH {r4-r12}
  156. PROLOG_VPUSH {d8-d15}
  157. // Save a pointer to the saved registers
  158. PROLOG_STACK_SAVE r4
  159. PROLOG_PUSH {r4}
  160. // Set up the frame pointer and locals pointer
  161. mov r7,r2
  162. mov r11,r1
  163. // Load the exception object from [sp, 16 (homed params) + 44 (saved registers) + 64 (double registers) + 4 (saved SP) == 128]
  164. ldr r1,[sp,#128]
  165. // Allocate the arg out area, calling chkstk if necessary
  166. cmp r3,4096
  167. bge LOCAL_LABEL(chkstk_call_catch)
  168. sub sp,r3
  169. // Verify that the call target is valid
  170. #if 0 && defined(_CONTROL_FLOW_GUARD)
  171. // we have used the r1-r3 info to set up the fake frame
  172. // they aren't needed by the jitted code that we're going to thunk to
  173. // so we don't preserve them across the __guard_check_icall_fptr call
  174. mov r5, r0
  175. mov32 r12, __guard_check_icall_fptr
  176. ldr r12, [r12]
  177. blx r12
  178. mov r0, r5
  179. #endif
  180. // Thunk to the jitted code (and don't return)
  181. bx r0
  182. LOCAL_LABEL(chkstk_call_catch):
  183. // Call chkstk, passing a DWORD count in r4
  184. lsr r4,r3,#2
  185. // bl |__chkstk|
  186. // r4 is now the byte count to be allocated
  187. sub sp,r4
  188. // Thunk to the jitted code (and don't return)
  189. bx r0
  190. NESTED_END arm_CallCatch, _TEXT