invokeNative_aarch64_simd.s 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2020 Intel Corporation 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. ld1 {v0.2D, v1.2D, v2.2D, v3.2D}, [x20], #64 /* v0 = argv[0], v1 = argv[1], v2 = argv[2], v3 = argv[3]*/
  32. ld1 {v4.2D, v5.2D, v6.2D, v7.2D}, [x20], #64 /* v4 = argv[4], v5 = argv[5], v6 = argv[6], v7 = argv[7]*/
  33. /* Fill inteter registers */
  34. ldp x0, x1, [x20], #16 /* x0 = argv[8] = exec_env, x1 = argv[9] */
  35. ldp x2, x3, [x20], #16 /* x2 = argv[10], x3 = argv[11] */
  36. ldp x4, x5, [x20], #16 /* x4 = argv[12], x5 = argv[13] */
  37. ldp x6, x7, [x20], #16 /* x6 = argv[14], x7 = argv[15] */
  38. /* Now x20 points to stack args */
  39. /* Directly call the function if no args in stack */
  40. cmp x21, #0
  41. beq call_func
  42. /* Fill all stack args: reserve stack space and fill one by one */
  43. mov x23, sp
  44. bic sp, x23, #15 /* Ensure stack is 16 bytes aligned */
  45. lsl x23, x21, #3 /* x23 = nstacks * 8 */
  46. add x23, x23, #15 /* x23 = (x23 + 15) & ~15 */
  47. bic x23, x23, #15
  48. sub sp, sp, x23 /* reserved stack space for stack arguments */
  49. mov x23, sp
  50. loop_stack_args: /* copy stack arguments to stack */
  51. cmp x21, #0
  52. beq call_func
  53. ldr x24, [x20], #8
  54. str x24, [x23], #8
  55. sub x21, x21, #1
  56. b loop_stack_args
  57. call_func:
  58. mov x20, x30 /* save x30(lr) */
  59. blr x19
  60. mov sp, x22 /* restore sp which is saved before calling function*/
  61. return:
  62. mov x30, x20 /* restore x30(lr) */
  63. ldp x19, x20, [sp, #0x20] /* restore the registers in stack */
  64. ldp x21, x22, [sp, #0x10]
  65. ldp x23, x24, [sp, #0x0]
  66. add sp, sp, #0x30 /* restore sp */
  67. ret
  68. #if defined(__linux__) && defined(__ELF__)
  69. .section .note.GNU-stack,"",%progbits
  70. #endif