summaryrefslogtreecommitdiff
path: root/src/cpu/x86/64bit/prot2long.inc
diff options
context:
space:
mode:
authorPatrick Rudolph <patrick.rudolph@9elements.com>2023-12-28 07:45:19 +0100
committerFelix Held <felix-coreboot@felixheld.de>2024-01-05 14:33:22 +0000
commit3052e9e6421cd5926b2b668c96a4d9cc040fcbf9 (patch)
tree6332ebd4f20f7ce0c36fd7d0267a019dbb0e799f /src/cpu/x86/64bit/prot2long.inc
parent8e7251c6257aa59fc73ae1f64c278341bfde4c95 (diff)
cpu/x86/64bit/mode_switch2: The reverse function to mode_switch
Add another mode_switch assembly function to call x86_64 code from x86_32 code. This is particullary useful for BLOBs like mrc.bin or FSP that calls back into coreboot. The user must first wrap all functions that are to be called from x86_32 using the macro prot2lm_wrapper. Instead of using the original function the wrapped functions must be passed to the x86_32 BLOBs. The assembly code assume that 0-3 32bit arguments are passed to the wrapped function. Tested: - Called x86_64 code from x86_32 code in qemu. - Booted Lenovo X220 using x86_32 MRC using x86_64 console. Change-Id: Ib625233e5f673eae9f3dcb2d03004c06bb07b149 Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/79753 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Diffstat (limited to 'src/cpu/x86/64bit/prot2long.inc')
-rw-r--r--src/cpu/x86/64bit/prot2long.inc27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/cpu/x86/64bit/prot2long.inc b/src/cpu/x86/64bit/prot2long.inc
new file mode 100644
index 0000000000..96c44a86f5
--- /dev/null
+++ b/src/cpu/x86/64bit/prot2long.inc
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+.text
+.code32
+/*
+ * Macro to wrap a x86_64 function to be called from x86_32 code.
+ * This assumes that 0-3 32bit arguments are passed to the
+ * calling function.
+ *
+ * In order to preserve ESP without setting up a stack frame
+ * pass the function to call in EAX. The macro prepends "__prot2lm_"
+ * to the wrapped function name.
+ */
+.macro prot2lm_wrapper func2call:req
+ .global __prot2lm_\func2call
+__prot2lm_\func2call :
+ /* Get function to call */
+ mov $\func2call, %eax
+
+ /*
+ * Jump to function instead of call.
+ * It will return directly to caller.
+ */
+ jmp long_mode_call_3arg
+
+ /* Not reachable */
+.endm