invokeNative_aarch64.s 2.6 KB

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