efi_thunk/x86: Move to a custom stack inside .bss
diff --git a/common/efi_thunk.asm_uefi_ia32 b/common/efi_thunk.asm_uefi_ia32
index 3bcaee55..5a70081c 100644
--- a/common/efi_thunk.asm_uefi_ia32
+++ b/common/efi_thunk.asm_uefi_ia32
@@ -1,10 +1,33 @@
+extern _GLOBAL_OFFSET_TABLE_
+
+section .bss
+
+align 16
+stack:
+ resb 32768
+ .top:
+
section .text
global efi_main
extern uefi_entry
efi_main:
+ pop eax
+ pop ebx
+ pop ecx
+
+ call .get_got
+ .get_got:
+ pop eax
+ add eax, _GLOBAL_OFFSET_TABLE_ + $$ - .get_got wrt ..gotpc
+
+ lea eax, [eax + stack.top wrt ..gotoff]
+ mov esp, eax
+
+ push ecx
+ push ebx
xor eax, eax
- mov [esp], eax
+ push eax
jmp uefi_entry
section .note.GNU-stack noalloc noexec nowrite progbits
diff --git a/common/efi_thunk.asm_uefi_x86_64 b/common/efi_thunk.asm_uefi_x86_64
index dad16474..e13b0c4d 100644
--- a/common/efi_thunk.asm_uefi_x86_64
+++ b/common/efi_thunk.asm_uefi_x86_64
@@ -1,10 +1,20 @@
+section .bss
+
+align 16
+stack:
+ resb 32768
+ .top:
+
section .text
global efi_main
extern uefi_entry
efi_main:
+ lea rax, [rel stack.top]
+ sub rax, 8
+ mov rsp, rax
+
xor eax, eax
- mov [rsp], rax
jmp uefi_entry
section .note.GNU-stack noalloc noexec nowrite progbits
