:: commit b52a6fd0dd8c40ce068660a2da3b32fd669d1aa1

mintsuki <mintsuki@protonmail.com> — 2020-05-09 22:48

parents: ed1fb65059

Make panic a formatted print

diff --git a/src/drivers/disk.c b/src/drivers/disk.c
index d3303090..296dd476 100644
--- a/src/drivers/disk.c
+++ b/src/drivers/disk.c
@@ -44,8 +44,7 @@ static int cache_block(int drive, uint64_t block) {
 
     if (r.eflags & EFLAGS_CF) {
         int ah = (r.eax >> 8) & 0xff;
-        print("Disk error %x. Drive %x, LBA %x.\n", ah, drive, dap.lba);
-        panic("");
+        panic("Disk error %x. Drive %x, LBA %x.\n", ah, drive, dap.lba);
         cached_block = CACHE_INVALID;
         return ah;
     }
diff --git a/src/lib/blib.c b/src/lib/blib.c
index ecda51f0..d0a30d83 100644
--- a/src/lib/blib.c
+++ b/src/lib/blib.c
@@ -50,10 +50,20 @@ int cpuid(uint32_t leaf, uint32_t subleaf,
     return 0;
 }
 
-__attribute__((noreturn)) void panic(const char *str) {
-    print("PANIC: %s", str);
+__attribute__((noreturn)) void panic(const char *fmt, ...) {
+    asm volatile ("cli");
+
+    va_list args;
+
+    va_start(args, fmt);
+
+    print("PANIC: ");
+    vprint(fmt, args);
+
+    va_end(args);
+
     for (;;) {
-        asm volatile ("cli; hlt");
+        asm volatile ("hlt");
     }
 }
 
diff --git a/src/lib/blib.h b/src/lib/blib.h
index 6e5ce6e5..32af4729 100644
--- a/src/lib/blib.h
+++ b/src/lib/blib.h
@@ -11,7 +11,7 @@ uint8_t bcd_to_int(uint8_t val);
 int cpuid(uint32_t leaf, uint32_t subleaf,
           uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
 
-__attribute__((noreturn)) void panic(const char *str);
+__attribute__((noreturn)) void panic(const char *fmt, ...);
 
 void pit_sleep(uint64_t pit_ticks);
 int pit_sleep_and_quit_on_keypress(uint32_t pit_ticks);
diff --git a/src/lib/config.c b/src/lib/config.c
index cf87d7e6..ef6103c0 100644
--- a/src/lib/config.c
+++ b/src/lib/config.c
@@ -19,7 +19,7 @@ int init_config(int drive, int part) {
     }
 
     if (f.size >= MAX_CONFIG_SIZE) {
-        panic("Config file is too big!\n");
+        panic("Config file is too big.");
     }
 
     config_addr = balloc(MAX_CONFIG_SIZE);
diff --git a/src/protos/stivale.c b/src/protos/stivale.c
index 1886f34e..ca3551cd 100644
--- a/src/protos/stivale.c
+++ b/src/protos/stivale.c
@@ -111,11 +111,11 @@ void stivale_load(char *cmdline, int boot_drive) {
 
     switch (ret) {
         case 1:
-            panic("stivale: File is not a valid ELF.\n");
+            panic("stivale: File is not a valid ELF.");
         case 2:
-            panic("stivale: Section .stivalehdr not found.\n");
+            panic("stivale: Section .stivalehdr not found.");
         case 3:
-            panic("stivale: Section .stivalehdr exceeds the size of the struct.\n");
+            panic("stivale: Section .stivalehdr exceeds the size of the struct.");
     }
 
     print("stivale: Requested stack at %X\n", stivale_hdr.stack);
tab: 248 wrap: offon