diff options
author | Ian Moffett <ian@osmora.org> | 2025-03-19 20:27:01 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-03-19 20:27:01 -0400 |
commit | 3afce9621a4db3a677c6764c2845f674c0985617 (patch) | |
tree | 5856f4e15935e8f126fe0ce4c22cad4e26c3fd2d /sys | |
parent | beeb9ff5f6e389ec7041721fdc4adaf6603b529a (diff) |
kernel: panic: Add hcf() and bas()
hcf(): Halt and catch fire (used for debugging mostly)
bas(): Burn and sizzle - internal usage
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r-- | sys/include/sys/panic.h | 5 | ||||
-rw-r--r-- | sys/kern/kern_panic.c | 52 |
2 files changed, 50 insertions, 7 deletions
diff --git a/sys/include/sys/panic.h b/sys/include/sys/panic.h index 93f9ab5..53cc923 100644 --- a/sys/include/sys/panic.h +++ b/sys/include/sys/panic.h @@ -30,9 +30,12 @@ #ifndef _SYS_PANIC_H_ #define _SYS_PANIC_H_ +#include <sys/cdefs.h> + #if defined(_KERNEL) -void panic(const char *fmt, ...); +__dead_cold void panic(const char *fmt, ...); +__dead_cold void hcf(const char *fmt, ...); void md_backtrace(void); #endif /* _KERNEL */ diff --git a/sys/kern/kern_panic.c b/sys/kern/kern_panic.c index 8aa7594..950ea8f 100644 --- a/sys/kern/kern_panic.c +++ b/sys/kern/kern_panic.c @@ -33,6 +33,29 @@ #include <sys/reboot.h> /* + * Burn and sizzle - the core logic that really ends + * things ::) + * + * @do_trace: If true, a backtrace will be printed + * @reboot_type: REBOOT_* defines + */ +static void +bas(bool do_trace, int reboot_type) +{ + static struct spinlock lock = {0}; + + spinlock_acquire(&lock); /* Never released */ + + if (do_trace) { + kprintf(OMIT_TIMESTAMP "** backtrace\n"); + md_backtrace(); + } + + cpu_reboot(reboot_type); + __builtin_unreachable(); +} + +/* * Tells the user something terribly wrong happened then * halting the system as soon as possible. * @@ -45,17 +68,34 @@ void panic(const char *fmt, ...) { va_list ap; - static struct spinlock lock = {0}; - spinlock_acquire(&lock); /* Never released */ va_start(ap, fmt); - kprintf(OMIT_TIMESTAMP "panic: "); vkprintf(fmt, &ap); + bas(true, REBOOT_HALT); + + __builtin_unreachable(); +} + +/* + * Halt and catch fire - immediately ceases all system activity + * with an optional message. + * + * @fmt: printf() format string, NULL to not + * specify any message (not recommended) + */ +void +hcf(const char *fmt, ...) +{ + va_list ap; + - kprintf(OMIT_TIMESTAMP "** backtrace\n"); - md_backtrace(); + if (fmt != NULL) { + va_start(ap, fmt); + kprintf(OMIT_TIMESTAMP); + vkprintf(fmt, &ap); + } - cpu_reboot(REBOOT_HALT); + bas(true, REBOOT_HALT); __builtin_unreachable(); } |