third_party/efistub: init
Adds the EFI stub from systemd-boot, built using our new EFI toolchain.
This allows us to bundle kernels, command lines and other data into
single EFI payloads and also sign them later.
A rules to build these unified EFI payloads is coming later.
Change-Id: I789e893ff88541f3dc9e7400ccd2565ae414e554
Reviewed-on: https://review.monogon.dev/c/monogon/+/335
Reviewed-by: Sergiusz Bazanski <serge@monogon.tech>
diff --git a/third_party/efistub/patches/use-sysv-for-kernel.patch b/third_party/efistub/patches/use-sysv-for-kernel.patch
new file mode 100644
index 0000000..4a69bbe
--- /dev/null
+++ b/third_party/efistub/patches/use-sysv-for-kernel.patch
@@ -0,0 +1,35 @@
+From d725d3cd472434c52e3c4bebbd7b242329d7a1b4 Mon Sep 17 00:00:00 2001
+From: Lorenz Brun <lorenz@monogon.tech>
+Date: Tue, 28 Sep 2021 05:21:10 +0200
+Subject: [PATCH] Use the SysV ABI calling into the kernel
+
+The original code expected to be compiled into a PE binary but
+internally still using the SysV ABI. Lots of trampolines are used to
+make that work as everything outside is using the MSVC ABI.
+The kernel also exposes the MSVC ABI using trampolines, but only for
+direct PE entrypoints. The EFI handover jump target does not do ABI
+conversion and thus matches the kernel's internal ABI, which is SysV.
+
+This means this call needs to be annotated as otherwise we'd call into
+the Kernel's EFI code using the MSVC ABI which is expecting SysV.
+Sigh.
+---
+ src/boot/efi/linux.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/boot/efi/linux.c b/src/boot/efi/linux.c
+index 5232a3ba40..0d58f39ff6 100644
+--- a/src/boot/efi/linux.c
++++ b/src/boot/efi/linux.c
+@@ -12,7 +12,7 @@
+ #define __regparm0__
+ #endif
+
+-typedef VOID(*handover_f)(VOID *image, EFI_SYSTEM_TABLE *table, struct boot_params *params) __regparm0__;
++typedef __attribute__((sysv_abi)) VOID(*handover_f)(VOID *image, EFI_SYSTEM_TABLE *table, struct boot_params *params) __regparm0__;
+
+ static VOID linux_efi_handover(EFI_HANDLE image, struct boot_params *params) {
+ handover_f handover;
+--
+2.25.1
+