thunks_32.S 882 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * thunks_32.S - assembly helpers for mixed-bitness code
  4. * Copyright (c) 2015 Denys Vlasenko
  5. *
  6. * These are little helpers that make it easier to switch bitness on
  7. * the fly.
  8. */
  9. .text
  10. .code32
  11. .global call64_from_32
  12. .type call32_from_64, @function
  13. // 4(%esp): function to call
  14. call64_from_32:
  15. // Fetch function address
  16. mov 4(%esp), %eax
  17. // Save registers which are callee-clobbered by 64-bit ABI
  18. push %ecx
  19. push %edx
  20. push %esi
  21. push %edi
  22. // Switch to long mode
  23. jmp $0x33,$1f
  24. 1: .code64
  25. // Call the function
  26. call *%rax
  27. // Switch to compatibility mode
  28. push $0x23 /* USER32_CS */
  29. .code32; push $1f; .code64 /* hack: can't have X86_64_32S relocation in 32-bit ELF */
  30. lretq
  31. 1: .code32
  32. pop %edi
  33. pop %esi
  34. pop %edx
  35. pop %ecx
  36. ret
  37. .size call64_from_32, .-call64_from_32
  38. .section .note.GNU-stack,"",%progbits