Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * thunks_32.S - assembly helpers for mixed-bitness code
0004  * Copyright (c) 2015 Denys Vlasenko
0005  *
0006  * These are little helpers that make it easier to switch bitness on
0007  * the fly.
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  /* USER32_CS */
0036     .code32; push $1f; .code64 /* hack: can't have X86_64_32S relocation in 32-bit ELF */
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