0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 .text
0011 .code32
0012
0013 .global call64_from_32
0014 .type call32_from_64, @function
0015
0016 // 4(%esp): function to call
0017 call64_from_32:
0018 // Fetch function address
0019 mov 4(%esp), %eax
0020
0021 // Save registers which are callee-clobbered by 64-bit ABI
0022 push %ecx
0023 push %edx
0024 push %esi
0025 push %edi
0026
0027 // Switch to long mode
0028 jmp $0x33,$1f
0029 1: .code64
0030
0031 // Call the function
0032 call *%rax
0033
0034 // Switch to compatibility mode
0035 push $0x23
0036 .code32; push $1f; .code64
0037 lretq
0038 1: .code32
0039
0040 pop %edi
0041 pop %esi
0042 pop %edx
0043 pop %ecx
0044
0045 ret
0046
0047 .size call64_from_32, .-call64_from_32
0048
0049 .section .note.GNU-stack,"",%progbits