:: commit b373ba0a8f9fa9b48cf012160e1049f12deaf08c

mintsuki <mintsuki@protonmail.com> — 2022-07-13 05:40

parents: f592fdeb9c

protos: Remove pointless returns added for autodetection

diff --git a/common/lib/panic.s2.c b/common/lib/panic.s2.c
index 605c14c5..489ffff0 100644
--- a/common/lib/panic.s2.c
+++ b/common/lib/panic.s2.c
@@ -69,7 +69,6 @@ nested:
         getchar();
 
         menu(false);
-        __builtin_unreachable();
 /*
         fb_clear(&fbinfo);
 
diff --git a/common/menu.c b/common/menu.c
index 3387ffdb..1de13838 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -939,6 +939,4 @@ noreturn void boot(char *config) {
     }
 
     panic(true, "Incorrect protocol specified for kernel.");
-
-    __builtin_unreachable();
 }
diff --git a/common/protos/chainload.c b/common/protos/chainload.c
index 64e0b2a5..eee0f681 100644
--- a/common/protos/chainload.c
+++ b/common/protos/chainload.c
@@ -1,5 +1,6 @@
 #include <stddef.h>
 #include <stdint.h>
+#include <stdnoreturn.h>
 #include <protos/chainload.h>
 #include <lib/part.h>
 #include <lib/config.h>
@@ -20,7 +21,7 @@
 #if bios == 1
 
 __attribute__((noinline, section(".realmode")))
-static void spinup(uint8_t drive) {
+noreturn static void spinup(uint8_t drive) {
     struct idtr real_mode_idt;
     real_mode_idt.limit = 0x3ff;
     real_mode_idt.ptr   = 0;
@@ -67,9 +68,11 @@ static void spinup(uint8_t drive) {
         : "a" (&real_mode_idt), "d" (drive)
         : "memory"
     );
+
+    __builtin_unreachable();
 }
 
-void chainload(char *config) {
+noreturn void chainload(char *config) {
     uint64_t val;
 
     int part; {
@@ -186,7 +189,7 @@ void bios_chainload_volume(struct volume *p) {
 
 #elif uefi == 1
 
-void chainload(char *config) {
+noreturn void chainload(char *config) {
     char *image_path = config_get_value(config, 0, "IMAGE_PATH");
     if (image_path == NULL)
         panic(true, "chainload: IMAGE_PATH not specified");
@@ -198,7 +201,7 @@ void chainload(char *config) {
     efi_chainload_file(config, image);
 }
 
-void efi_chainload_file(char *config, struct file_handle *image) {
+noreturn void efi_chainload_file(char *config, struct file_handle *image) {
     EFI_STATUS status;
 
     EFI_HANDLE efi_part_handle = image->efi_part_handle;
diff --git a/common/protos/chainload.h b/common/protos/chainload.h
index c58defe1..aa4beac1 100644
--- a/common/protos/chainload.h
+++ b/common/protos/chainload.h
@@ -1,11 +1,13 @@
 #ifndef __PROTOS__CHAINLOAD_H__
 #define __PROTOS__CHAINLOAD_H__
 
-void chainload(char *config);
+#include <stdnoreturn.h>
+
+noreturn void chainload(char *config);
 
 #if uefi == 1
 #include <fs/file.h>
-void efi_chainload_file(char *config, struct file_handle *image);
+noreturn void efi_chainload_file(char *config, struct file_handle *image);
 #endif
 
 #if bios == 1
diff --git a/common/protos/chainload_next.c b/common/protos/chainload_next.c
index bf1559c7..37a4315d 100644
--- a/common/protos/chainload_next.c
+++ b/common/protos/chainload_next.c
@@ -1,5 +1,6 @@
 #include <stddef.h>
 #include <stdint.h>
+#include <stdnoreturn.h>
 #include <protos/chainload_next.h>
 #include <protos/chainload.h>
 #include <lib/blib.h>
@@ -30,7 +31,7 @@ static void try(char *config, struct volume *v) {
 }
 #endif
 
-void chainload_next(char *config) {
+noreturn void chainload_next(char *config) {
     bool wrap = false;
     for (int i = boot_volume->is_optical ? 0 : (wrap = true, boot_volume->index + 1);
          boot_volume->is_optical ? true : i != boot_volume->index; i++) {
@@ -64,6 +65,4 @@ void chainload_next(char *config) {
     }
 
     panic(true, "chainload_next: No other bootable device");
-
-    __builtin_unreachable();
 }
diff --git a/common/protos/chainload_next.h b/common/protos/chainload_next.h
index 226a8d97..61d2be0f 100644
--- a/common/protos/chainload_next.h
+++ b/common/protos/chainload_next.h
@@ -1,6 +1,8 @@
 #ifndef __PROTOS__CHAINLOAD_NEXT_H__
 #define __PROTOS__CHAINLOAD_NEXT_H__
 
-void chainload_next(char *config);
+#include <stdnoreturn.h>
+
+noreturn void chainload_next(char *config);
 
 #endif
diff --git a/common/protos/limine.c b/common/protos/limine.c
index b91ff1c0..74261a03 100644
--- a/common/protos/limine.c
+++ b/common/protos/limine.c
@@ -1,6 +1,7 @@
 #include <stdint.h>
 #include <stddef.h>
 #include <stdbool.h>
+#include <stdnoreturn.h>
 #include <config.h>
 #include <protos/stivale.h>
 #include <protos/stivale2.h>
@@ -121,7 +122,7 @@ static void term_write_shim(uint64_t context, uint64_t buf, uint64_t count) {
     term_write(buf, count);
 }
 
-bool limine_load(char *config, char *cmdline) {
+noreturn void limine_load(char *config, char *cmdline) {
     uint32_t eax, ebx, ecx, edx;
 
     char *kernel_path = config_get_value(config, 0, "KERNEL_PATH");
@@ -142,8 +143,7 @@ bool limine_load(char *config, char *cmdline) {
     int bits = elf_bits(kernel);
 
     if (bits == -1 || bits == 32) {
-        printv("limine: Kernel in unrecognised format");
-        return false;
+        panic(true, "limine: Kernel in unrecognised format");
     }
 
     // ELF loading
@@ -159,7 +159,7 @@ bool limine_load(char *config, char *cmdline) {
                    &ranges, &ranges_count,
                    true, &physical_base, &virtual_base, &image_size,
                    &is_reloc)) {
-        return false;
+        panic(true, "limine: ELF64 load failure");
     }
 
     kaslr = kaslr && is_reloc;
@@ -201,10 +201,6 @@ bool limine_load(char *config, char *cmdline) {
         }
     }
 
-    if (requests_count == 0) {
-        return false;
-    }
-
     // Check if 64 bit CPU
     if (!cpuid(0x80000001, 0, &eax, &ebx, &ecx, &edx) || !(edx & (1 << 29))) {
         panic(true, "limine: This CPU does not support 64-bit mode.");
@@ -741,6 +737,4 @@ FEAT_END
 
     stivale_spinup(64, want_5lv, &pagemap, entry_point, 0,
                    reported_addr(stack), true, true, (uintptr_t)local_gdt);
-
-    __builtin_unreachable();
 }
diff --git a/common/protos/limine.h b/common/protos/limine.h
index 64bcdbae..82783473 100644
--- a/common/protos/limine.h
+++ b/common/protos/limine.h
@@ -1,8 +1,8 @@
 #ifndef __PROTOS__LIMINE_H__
 #define __PROTOS__LIMINE_H__
 
-#include <stdbool.h>
+#include <stdnoreturn.h>
 
-bool limine_load(char *config, char *cmdline);
+noreturn void limine_load(char *config, char *cmdline);
 
 #endif
diff --git a/common/protos/linux.c b/common/protos/linux.c
index 7419751b..204edf6d 100644
--- a/common/protos/linux.c
+++ b/common/protos/linux.c
@@ -348,7 +348,7 @@ struct boot_params {
 
 // End of Linux code
 
-bool linux_load(char *config, char *cmdline) {
+noreturn void linux_load(char *config, char *cmdline) {
     struct file_handle *kernel_file;
 
     char *kernel_path = config_get_value(config, 0, "KERNEL_PATH");
@@ -363,8 +363,7 @@ bool linux_load(char *config, char *cmdline) {
 
     // validate signature
     if (signature != 0x53726448) {
-        fclose(kernel_file);
-        return false;
+        panic(true, "linux: Invalid kernel signature");
     }
 
     size_t setup_code_size = 0;
@@ -626,5 +625,6 @@ set_textmode:;
 
     irq_flush_type = IRQ_PIC_ONLY_FLUSH;
 
-    common_spinup(linux_spinup, 2, (void *)kernel_load_addr, boot_params);
+    common_spinup(linux_spinup, 2, (uint32_t)kernel_load_addr,
+                                   (uint32_t)(uintptr_t)boot_params);
 }
diff --git a/common/protos/linux.h b/common/protos/linux.h
index fadd321e..4c8ef103 100644
--- a/common/protos/linux.h
+++ b/common/protos/linux.h
@@ -1,8 +1,8 @@
 #ifndef __PROTOS__LINUX_H__
 #define __PROTOS__LINUX_H__
 
-#include <stdbool.h>
+#include <stdnoreturn.h>
 
-bool linux_load(char *config, char *cmdline);
+noreturn void linux_load(char *config, char *cmdline);
 
 #endif
diff --git a/common/protos/multiboot1.c b/common/protos/multiboot1.c
index 98642580..528021da 100644
--- a/common/protos/multiboot1.c
+++ b/common/protos/multiboot1.c
@@ -1,5 +1,6 @@
 #include <stdint.h>
 #include <stddef.h>
+#include <stdnoreturn.h>
 #include <protos/multiboot1.h>
 #include <protos/multiboot.h>
 #include <config.h>
@@ -43,7 +44,7 @@ static void *mb1_info_alloc(void **mb1_info_raw, size_t size) {
     return ret;
 }
 
-bool multiboot1_load(char *config, char *cmdline) {
+noreturn void multiboot1_load(char *config, char *cmdline) {
     struct file_handle *kernel_file;
 
     char *kernel_path = config_get_value(config, 0, "KERNEL_PATH");
@@ -72,8 +73,7 @@ bool multiboot1_load(char *config, char *cmdline) {
     }
 
     if (header.magic != MULTIBOOT1_HEADER_MAGIC) {
-        pmm_free(kernel_file, kernel_file_size);
-        return false;
+        panic(true, "multiboot1: Invalid magic");
     }
 
     print("multiboot1: Loading kernel `%s`...\n", kernel_path);
diff --git a/common/protos/multiboot1.h b/common/protos/multiboot1.h
index e282f9d1..b35fb33b 100644
--- a/common/protos/multiboot1.h
+++ b/common/protos/multiboot1.h
@@ -3,7 +3,7 @@
 
 #include <stdint.h>
 #include <stddef.h>
-#include <stdbool.h>
+#include <stdnoreturn.h>
 
 #define MULTIBOOT1_HEADER_MAGIC 0x1BADB002
 
@@ -94,6 +94,6 @@ struct multiboot1_mmap_entry {
     uint32_t type;
 } __attribute__((packed));
 
-bool multiboot1_load(char *config, char *cmdline);
+noreturn void multiboot1_load(char *config, char *cmdline);
 
 #endif
diff --git a/common/protos/multiboot2.c b/common/protos/multiboot2.c
index 8122475b..7b89a117 100644
--- a/common/protos/multiboot2.c
+++ b/common/protos/multiboot2.c
@@ -1,5 +1,6 @@
 #include <stdint.h>
 #include <stddef.h>
+#include <stdnoreturn.h>
 #include <protos/multiboot2.h>
 #include <protos/multiboot.h>
 #include <config.h>
@@ -58,7 +59,7 @@ static size_t get_multiboot2_info_size(
 
 #define append_tag(P, TAG) ({ (P) += ALIGN_UP((TAG)->size, MULTIBOOT_TAG_ALIGN); })
 
-bool multiboot2_load(char *config, char* cmdline) {
+noreturn void multiboot2_load(char *config, char* cmdline) {
     struct file_handle *kernel_file;
 
     char *kernel_path = config_get_value(config, 0, "KERNEL_PATH");
@@ -85,8 +86,7 @@ bool multiboot2_load(char *config, char* cmdline) {
     }
 
     if (header->magic != MULTIBOOT2_HEADER_MAGIC) {
-        pmm_free(kernel_file, kernel_file_size);
-        return false;
+        panic(true, "multiboot2: Invalid magic");
     }
 
     print("multiboot2: Loading kernel `%s`...\n", kernel_path);
diff --git a/common/protos/multiboot2.h b/common/protos/multiboot2.h
index a0be2015..87b6e9f9 100644
--- a/common/protos/multiboot2.h
+++ b/common/protos/multiboot2.h
@@ -23,9 +23,9 @@
 #define __PROTOS__MULTIBOOT2_H__
 
 #include <stdint.h>
-#include <stdbool.h>
+#include <stdnoreturn.h>
 
-bool multiboot2_load(char *config, char *cmdline);
+noreturn void multiboot2_load(char *config, char *cmdline);
 
 /*  How many bytes from the start of the file we search for the header. */
 #define MULTIBOOT_SEARCH                        32768
tab: 248 wrap: offon