| 1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 |
/* |
| 3 |
* Calls a x86_64 function from x86_32 context. |
| 4 |
* Must not be directly invoked from C code! |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <cpu/x86/64bit/entry64.inc> |
| 8 |
|
| 9 |
.text |
| 10 |
.code32 |
| 11 |
.section ".text.long_mode_call_3arg", "ax", @progbits |
| 12 |
.global long_mode_call_3arg |
| 13 |
long_mode_call_3arg: |
| 14 |
|
| 15 |
/* Function to call is passed in EAX. */ |
| 16 |
|
| 17 |
/* Backup registers */ |
| 18 |
pushal |
| 19 |
|
| 20 |
/* Backup stack pointer */ |
| 21 |
mov %esp, %ebp |
| 22 |
|
| 23 |
/* Enter long mode, preserves ebx */ |
| 24 |
setup_longmode $PML4E |
| 25 |
|
| 26 |
/* Align stack */ |
| 27 |
movabs $0xfffffffffffffff0, %rax |
| 28 |
andq %rax, %rsp |
| 29 |
|
| 30 |
movl 28(%rbp), %ebx /* Function to call */ |
| 31 |
movl 36(%rbp), %edi /* 1st arg */ |
| 32 |
movl 40(%rbp), %esi /* 2nd arg */ |
| 33 |
movl 44(%rbp), %edx /* 3rd arg */ |
| 34 |
|
| 35 |
call *%rbx |
| 36 |
|
| 37 |
/* Store return value on stack. popal will fetch it. */ |
| 38 |
mov %eax, 28(%rbp) |
| 39 |
shr $32, %rax |
| 40 |
movl %eax, 24(%rbp) |
| 41 |
|
| 42 |
#include <cpu/x86/64bit/exit32.inc> |
| 43 |
|
| 44 |
/* Restore stack pointer */ |
| 45 |
mov %ebp, %esp |
| 46 |
|
| 47 |
/* Restore registers */ |
| 48 |
popal |
| 49 |
|
| 50 |
ret |