invokeNative_aarch64.s 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. .text
  6. .align 2
  7. #ifndef BH_PLATFORM_DARWIN
  8. .globl invokeNative
  9. .type invokeNative, function
  10. invokeNative:
  11. #else
  12. .globl _invokeNative
  13. _invokeNative:
  14. #endif /* end of BH_PLATFORM_DARWIN */
  15. /*
  16. * Arguments passed in:
  17. *
  18. * x0 function ptr
  19. * x1 argv
  20. * x2 nstacks
  21. */
  22. sub sp, sp, #0x30
  23. stp x19, x20, [sp, #0x20] /* save the registers */
  24. stp x21, x22, [sp, #0x10]
  25. stp x23, x24, [sp, #0x0]
  26. mov x19, x0 /* x19 = function ptr */
  27. mov x20, x1 /* x20 = argv */
  28. mov x21, x2 /* x21 = nstacks */
  29. mov x22, sp /* save the sp before call function */
  30. /* Fill in float-point registers */
  31. ldp d0, d1, [x20], #16 /* d0 = argv[0], d1 = argv[1] */
  32. ldp d2, d3, [x20], #16 /* d2 = argv[2], d3 = argv[3] */
  33. ldp d4, d5, [x20], #16 /* d4 = argv[4], d5 = argv[5] */
  34. ldp d6, d7, [x20], #16 /* d6 = argv[6], d7 = argv[7] */
  35. /* Fill integer registers */
  36. ldp x0, x1, [x20], #16 /* x0 = argv[8] = exec_env, x1 = argv[9] */
  37. ldp x2, x3, [x20], #16 /* x2 = argv[10], x3 = argv[11] */
  38. ldp x4, x5, [x20], #16 /* x4 = argv[12], x5 = argv[13] */
  39. ldp x6, x7, [x20], #16 /* x6 = argv[14], x7 = argv[15] */
  40. /* Now x20 points to stack args */
  41. /* Directly call the fucntion if no args in stack */
  42. cmp x21, #0
  43. beq call_func
  44. /* Fill all stack args: reserve stack space and fill one by one */
  45. mov x23, sp
  46. bic sp, x23, #15 /* Ensure stack is 16 bytes aligned */
  47. lsl x23, x21, #3 /* x23 = nstacks * 8 */
  48. add x23, x23, #15 /* x23 = (x23 + 15) & ~15 */
  49. bic x23, x23, #15
  50. sub sp, sp, x23 /* reserved stack space for stack arguments */
  51. mov x23, sp
  52. loop_stack_args: /* copy stack arguments to stack */
  53. cmp x21, #0
  54. beq call_func
  55. ldr x24, [x20], #8
  56. str x24, [x23], #8
  57. sub x21, x21, #1
  58. b loop_stack_args
  59. call_func:
  60. mov x20, x30 /* save x30(lr) */
  61. blr x19
  62. mov sp, x22 /* restore sp which is saved before calling fuction*/
  63. return:
  64. mov x30, x20 /* restore x30(lr) */
  65. ldp x19, x20, [sp, #0x20] /* restore the registers in stack */
  66. ldp x21, x22, [sp, #0x10]
  67. ldp x23, x24, [sp, #0x0]
  68. add sp, sp, #0x30 /* restore sp */
  69. ret