invokeNative_armasm64.asm 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ; Copyright (C) 2019 Intel Corporation. All rights reserved.
  2. ; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. AREA |.text|, CODE, READONLY, ALIGN=2
  4. EXPORT invokeNative
  5. ; ------------------------ direct call path ------------------------
  6. call_func
  7. mov x20, x30 ; save x30(lr)
  8. blr x19
  9. mov sp, x22 ; restore sp saved before function call
  10. return_label
  11. mov x30, x20 ; restore x30(lr)
  12. ldp x19, x20, [sp, #0x20]
  13. ldp x21, x22, [sp, #0x10]
  14. ldp x23, x24, [sp, #0x0]
  15. add sp, sp, #0x30
  16. ret
  17. ; ------------------------ stack-args path ------------------------
  18. handle_stack
  19. ; Reserve aligned stack space for stack arguments and copy them
  20. mov x23, sp
  21. bic sp, x23, #15 ; Ensure 16-byte alignment
  22. lsl x23, x21, #3 ; x23 = nstacks * 8
  23. add x23, x23, #15
  24. bic x23, x23, #15
  25. sub sp, sp, x23
  26. mov x23, sp
  27. copy_loop
  28. cmp x21, #0
  29. b.eq call_func ; when done, branch back to call path
  30. ldr x24, [x20], #8
  31. str x24, [x23], #8
  32. sub x21, x21, #1
  33. b copy_loop
  34. ; ------------------------ function entry ------------------------
  35. invokeNative
  36. sub sp, sp, #0x30
  37. stp x19, x20, [sp, #0x20] ; save the registers
  38. stp x21, x22, [sp, #0x10]
  39. stp x23, x24, [sp, #0x0]
  40. mov x19, x0 ; x19 = function ptr
  41. mov x20, x1 ; x20 = argv
  42. mov x21, x2 ; x21 = nstacks
  43. mov x22, sp ; save the sp before call function
  44. ; Fill in floating-point registers
  45. ldp d0, d1, [x20], #16
  46. ldp d2, d3, [x20], #16
  47. ldp d4, d5, [x20], #16
  48. ldp d6, d7, [x20], #16
  49. ; Fill integer registers
  50. ldp x0, x1, [x20], #16 ; x0 = argv[8] = exec_env, x1 = argv[9]
  51. ldp x2, x3, [x20], #16
  52. ldp x4, x5, [x20], #16
  53. ldp x6, x7, [x20], #16
  54. ; Now x20 points to stack args
  55. cmp x21, #0
  56. b.ne handle_stack ; backward: there are stack args
  57. b call_func ; backward: no stack args
  58. END