invokeNative_ia32.s 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. push %ebp
  16. movl %esp, %ebp
  17. movl 16(%ebp), %ecx /* ecx = argc */
  18. leal 2(%ecx), %edx /* edx = ecx + 2 (count return address and saved ebp) */
  19. andl $3, %edx /* edx = edx % 4 */
  20. jz stack_aligned /* if edx == 0, stack is already 16 bytes aligned */
  21. leal -16(%esp, %edx, 4), %esp /* esp = esp - 16 + edx * 4 */
  22. stack_aligned:
  23. test %ecx, %ecx
  24. jz skip_push_args /* if ecx == 0, skip pushing arguments */
  25. movl 12(%ebp), %edx /* edx = argv */
  26. leal -4(%edx,%ecx,4), %edx /* edx = edx + ecx * 4 - 4 */
  27. subl %esp, %edx /* edx = edx - esp */
  28. 1:
  29. push 0(%esp,%edx)
  30. loop 1b /* loop ecx counts */
  31. skip_push_args:
  32. movl 8(%ebp), %edx /* edx = func_ptr */
  33. call *%edx
  34. leave
  35. ret