:: commit 5b960ec9b24433d95d207793a762d524604756c0

mintsuki <mintsuki@protonmail.com> — 2022-08-27 11:26

parents: e1cfd61ada

misc: Remove naked functions and bring up to par with trunk

diff --git a/common/efi_thunk.asm_uefi_ia32 b/common/efi_thunk.asm_uefi_ia32
new file mode 100644
index 00000000..4b36b934
--- /dev/null
+++ b/common/efi_thunk.asm_uefi_ia32
@@ -0,0 +1,6 @@
+global efi_main
+extern uefi_entry
+efi_main:
+    xor eax, eax
+    mov [esp], eax
+    jmp uefi_entry
diff --git a/common/efi_thunk.asm_uefi_x86_64 b/common/efi_thunk.asm_uefi_x86_64
new file mode 100644
index 00000000..88e7b64f
--- /dev/null
+++ b/common/efi_thunk.asm_uefi_x86_64
@@ -0,0 +1,6 @@
+global efi_main
+extern uefi_entry
+efi_main:
+    xor eax, eax
+    mov [rsp], rax
+    jmp uefi_entry
diff --git a/common/entry.s3.c b/common/entry.s3.c
index e350a391..4194e4dd 100644
--- a/common/entry.s3.c
+++ b/common/entry.s3.c
@@ -26,26 +26,6 @@
 void stage3_common(void);
 
 #if uefi == 1
-__attribute__((naked))
-EFI_STATUS efi_main(
-    __attribute__((unused)) EFI_HANDLE ImageHandle,
-    __attribute__((unused)) EFI_SYSTEM_TABLE *SystemTable) {
-    // Invalid return address of 0 to end stacktraces here
-#if defined (__x86_64__)
-    asm (
-        "xorl %eax, %eax\n\t"
-        "movq %rax, (%rsp)\n\t"
-        "jmp uefi_entry\n\t"
-    );
-#elif defined (__i386__)
-    asm (
-        "xorl %eax, %eax\n\t"
-        "movl %eax, (%esp)\n\t"
-        "jmp uefi_entry\n\t"
-    );
-#endif
-}
-
 extern symbol __image_base;
 
 noreturn void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
diff --git a/common/menu.c b/common/menu.c
index d7df7604..bb1eaf6d 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -537,52 +537,6 @@ static size_t print_tree(const char *shift, size_t level, size_t base_index, siz
     return max_entries;
 }
 
-#if defined (__x86_64__)
-__attribute__((used))
-static uintptr_t stack_at_first_entry = 0;
-#endif
-
-__attribute__((naked))
-noreturn void menu(__attribute__((unused)) bool timeout_enabled) {
-#if defined (__i386__)
-    asm volatile (
-        "pop %eax\n\t"
-        "call 1f\n\t"
-        "1:\n\t"
-        "pop %eax\n\t"
-        "add $(2f - 1b), %eax\n\t"
-        "cmpl $0, (%eax)\n\t"
-        "jne 1f\n\t"
-        "mov %esp, (%eax)\n\t"
-        "jmp 3f\n\t"
-        "1:\n\t"
-        "mov (%esp), %edi\n\t"
-        "mov (%eax), %esp\n\t"
-        "push %edi\n\t"
-        "jmp 3f\n\t"
-        "2:\n\t"
-        ".long 0\n\t"
-        "3:\n\t"
-        "push $0\n\t"
-        "jmp _menu"
-    );
-#elif defined (__x86_64__)
-    asm volatile (
-        "xor %eax, %eax\n\t"
-        "cmp %rax, stack_at_first_entry(%rip)\n\t"
-        "jne 1f\n\t"
-        "mov %rsp, stack_at_first_entry(%rip)\n\t"
-        "jmp 2f\n\t"
-        "1:\n\t"
-        "mov stack_at_first_entry(%rip), %rsp\n\t"
-        "2:\n\t"
-        "push $0\n\t"
-        "push $0\n\t"
-        "jmp _menu"
-    );
-#endif
-}
-
 static struct memmap_entry *rewound_memmap = NULL;
 static size_t rewound_memmap_entries = 0;
 static uint8_t *rewound_data;
@@ -597,8 +551,7 @@ extern symbol s2_data_begin;
 extern symbol s2_data_end;
 #endif
 
-__attribute__((used))
-static noreturn void _menu(bool timeout_enabled) {
+noreturn void _menu(bool timeout_enabled) {
     size_t data_size = (uintptr_t)data_end - (uintptr_t)data_begin;
 #if bios == 1
     size_t s2_data_size = (uintptr_t)s2_data_end - (uintptr_t)s2_data_begin;
diff --git a/common/menu_thunk.asm_ia32 b/common/menu_thunk.asm_ia32
new file mode 100644
index 00000000..54e160fa
--- /dev/null
+++ b/common/menu_thunk.asm_ia32
@@ -0,0 +1,26 @@
+global menu
+extern _menu
+menu:
+    pop eax
+    call .L1
+.L1:
+    pop eax
+    add eax, .L3 - .L1
+    cmp dword [eax], 0
+    jne .L2
+    mov [eax], esp
+    jmp .L4
+
+.L2:
+    mov edi, [esp]
+    mov esp, [eax]
+    push edi
+    jmp .L4
+
+.L3:
+    dq 0
+
+.L4:
+    push 0
+    jmp _menu
+
diff --git a/common/menu_thunk.asm_x86_64 b/common/menu_thunk.asm_x86_64
new file mode 100644
index 00000000..0e086fdc
--- /dev/null
+++ b/common/menu_thunk.asm_x86_64
@@ -0,0 +1,21 @@
+section .data
+
+stack_at_first_entry:
+    dq 0
+
+section .text
+
+global menu
+extern _menu
+menu:
+    xor eax, eax
+    cmp [rel stack_at_first_entry], rax
+    jne .L1
+    mov [rel stack_at_first_entry], rsp
+    jmp .L2
+.L1:
+    mov rsp, [rel stack_at_first_entry]
+.L2:
+    push 0
+    push 0
+    jmp _menu
tab: 248 wrap: offon