Make panic a formatted print

This commit is contained in:
mintsuki 2020-05-10 00:48:58 +02:00
parent ed1fb65059
commit b52a6fd0dd
5 changed files with 19 additions and 10 deletions

View File

@ -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;
}

View File

@ -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");
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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);