invokeNative_em64.s 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. /* rdi - function ptr */
  16. /* rsi - argv */
  17. /* rdx - n_stacks */
  18. push %rbp
  19. mov %rsp, %rbp
  20. mov %rdx, %r10
  21. mov %rsp, %r11 /* Check that stack is aligned on */
  22. and $8, %r11 /* 16 bytes. This code may be removed */
  23. je check_stack_succ /* when we are sure that compiler always */
  24. int3 /* calls us with aligned stack */
  25. check_stack_succ:
  26. mov %r10, %r11 /* Align stack on 16 bytes before pushing */
  27. and $1, %r11 /* stack arguments in case we have an odd */
  28. shl $3, %r11 /* number of stack arguments */
  29. sub %r11, %rsp
  30. /* store memory args */
  31. movq %rdi, %r11 /* func ptr */
  32. movq %r10, %rcx /* counter */
  33. lea 64+48-8(%rsi,%rcx,8), %r10
  34. sub %rsp, %r10
  35. cmpq $0, %rcx
  36. je push_args_end
  37. push_args:
  38. push 0(%rsp,%r10)
  39. loop push_args
  40. push_args_end:
  41. /* fill all fp args */
  42. movq 0x00(%rsi), %xmm0
  43. movq 0x08(%rsi), %xmm1
  44. movq 0x10(%rsi), %xmm2
  45. movq 0x18(%rsi), %xmm3
  46. movq 0x20(%rsi), %xmm4
  47. movq 0x28(%rsi), %xmm5
  48. movq 0x30(%rsi), %xmm6
  49. movq 0x38(%rsi), %xmm7
  50. /* fill all int args */
  51. movq 0x40(%rsi), %rdi
  52. movq 0x50(%rsi), %rdx
  53. movq 0x58(%rsi), %rcx
  54. movq 0x60(%rsi), %r8
  55. movq 0x68(%rsi), %r9
  56. movq 0x48(%rsi), %rsi
  57. call *%r11
  58. leave
  59. ret