:: commit b5ab7d57b34a13b41cb3fd41a7a1b68a79a26233

mintsuki <mintsuki@protonmail.com> — 2022-08-09 12:20

parents: 655d376a09

stivale(2): Remove returns added for autodetection

diff --git a/common/protos/stivale.c b/common/protos/stivale.c
index 4ac669bb..aa251f12 100644
--- a/common/protos/stivale.c
+++ b/common/protos/stivale.c
@@ -57,7 +57,7 @@ bool stivale_load_by_anchor(void **_anchor, const char *magic,
     return true;
 }
 
-bool stivale_load(char *config, char *cmdline) {
+noreturn void stivale_load(char *config, char *cmdline) {
     struct stivale_struct *stivale_struct = ext_mem_alloc(sizeof(struct stivale_struct));
 
     // BIOS or UEFI?
@@ -99,7 +99,7 @@ bool stivale_load(char *config, char *cmdline) {
     if (bits == -1) {
         struct stivale_anchor *anchor;
         if (!stivale_load_by_anchor((void **)&anchor, "STIVALE1 ANCHOR", kernel, kernel_file_size)) {
-            goto fail;
+            panic(true, "stivale: Failed to load kernel by anchor");
         }
 
         bits = anchor->bits;
@@ -113,13 +113,13 @@ bool stivale_load(char *config, char *cmdline) {
             case 64:
                 if (elf64_load_section(kernel, &stivale_hdr, ".stivalehdr",
                                        sizeof(struct stivale_header), slide)) {
-                    goto fail;
+                    panic(true, "stivale: Failed to load .stivalehdr section");
                 }
                 break;
             case 32:
                 if (elf32_load_section(kernel, &stivale_hdr, ".stivalehdr",
                                        sizeof(struct stivale_header))) {
-                    goto fail;
+                    panic(true, "stivale: Failed to load .stivalehdr section");
                 }
                 break;
         }
@@ -373,13 +373,6 @@ bool stivale_load(char *config, char *cmdline) {
     stivale_spinup(bits, want_5lv, &pagemap,
                    entry_point, REPORTED_ADDR((uint64_t)(uintptr_t)stivale_struct),
                    stivale_hdr.stack, false, false, (uintptr_t)local_gdt);
-
-    __builtin_unreachable();
-
-fail:
-    pmm_free(kernel, kernel_file_size);
-    pmm_free(stivale_struct, sizeof(struct stivale_struct));
-    return false;
 }
 
 pagemap_t stivale_build_pagemap(bool level5pg, bool unmap_null, struct elf_range *ranges, size_t ranges_count,
diff --git a/common/protos/stivale.h b/common/protos/stivale.h
index 83c99d53..ae8e5aa7 100644
--- a/common/protos/stivale.h
+++ b/common/protos/stivale.h
@@ -7,7 +7,7 @@
 #include <mm/vmm.h>
 #include <lib/elf.h>
 
-bool stivale_load(char *config, char *cmdline);
+noreturn void stivale_load(char *config, char *cmdline);
 
 bool stivale_load_by_anchor(void **_anchor, const char *magic,
                             uint8_t *file, uint64_t filesize);
diff --git a/common/protos/stivale2.c b/common/protos/stivale2.c
index 31516421..2941317c 100644
--- a/common/protos/stivale2.c
+++ b/common/protos/stivale2.c
@@ -78,7 +78,7 @@ uint64_t stivale2_term_write_ptr = 0;
 void stivale2_term_callback(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
 #endif
 
-bool stivale2_load(char *config, char *cmdline) {
+noreturn void stivale2_load(char *config, char *cmdline) {
     struct stivale2_struct *stivale2_struct = ext_mem_alloc(sizeof(struct stivale2_struct));
 
     struct file_handle *kernel_file;
@@ -117,7 +117,7 @@ bool stivale2_load(char *config, char *cmdline) {
     if (bits == -1) {
         struct stivale2_anchor *anchor;
         if (!stivale_load_by_anchor((void **)&anchor, "STIVALE2 ANCHOR", kernel, kernel_file_size)) {
-            goto fail;
+            panic(true, "stivale2: Failed to load kernel by anchor");
         }
 
         bits = anchor->bits;
@@ -131,13 +131,13 @@ bool stivale2_load(char *config, char *cmdline) {
             case 64:
                 if (elf64_load_section(kernel, &stivale2_hdr, ".stivale2hdr",
                                        sizeof(struct stivale2_header), slide)) {
-                    goto fail;
+                    panic(true, "stivale2: Failed to load .stivale2hdr section");
                 }
                 break;
             case 32:
                 if (elf32_load_section(kernel, &stivale2_hdr, ".stivale2hdr",
                                        sizeof(struct stivale2_header))) {
-                    goto fail;
+                    panic(true, "stivale2: Failed to load .stivale2hdr section");
                 }
                 break;
         }
@@ -846,11 +846,4 @@ have_tm_tag:;
     stivale_spinup(bits, want_5lv, &pagemap, entry_point,
                    REPORTED_ADDR((uint64_t)(uintptr_t)stivale2_struct),
                    stivale2_hdr.stack, want_pmrs, want_pmrs, (uintptr_t)local_gdt);
-
-    __builtin_unreachable();
-
-fail:
-    pmm_free(kernel, kernel_file_size);
-    pmm_free(stivale2_struct, sizeof(struct stivale2_struct));
-    return false;
 }
diff --git a/common/protos/stivale2.h b/common/protos/stivale2.h
index 9674fcff..b037e34b 100644
--- a/common/protos/stivale2.h
+++ b/common/protos/stivale2.h
@@ -1,8 +1,8 @@
 #ifndef __PROTOS__STIVALE2_H__
 #define __PROTOS__STIVALE2_H__
 
-#include <stdbool.h>
+#include <stdnoreturn.h>
 
-bool stivale2_load(char *config, char *cmdline);
+noreturn void stivale2_load(char *config, char *cmdline);
 
 #endif
tab: 248 wrap: offon