From 6bdd17edca2fa58263db47841e007cee5a01a26c Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 14 May 2024 11:36:23 -0400 Subject: kernel: machdep: Add machine_panic() + panic beep machine_panic() handles things like backtracing, beeping the speaker and halting the processor. Signed-off-by: Ian Moffett --- sys/arch/amd64/amd64/machdep.c | 34 +++++++++++++++++++++++++++++++++- sys/include/sys/machdep.h | 2 +- sys/kern/kern_panic.c | 3 +-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index f73d773..4476053 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -192,7 +194,7 @@ backtrace_addr_to_name(uintptr_t addr, off_t *off) return NULL; } -void +static void backtrace(void) { uintptr_t *rbp; @@ -218,6 +220,36 @@ backtrace(void) } } +/* + * Called last within panic() + */ +void +machine_panic(void) +{ + struct timer tmr = {0}; + bool has_timer = true; + + if (req_timer(TIMER_GP, &tmr) != TMRR_SUCCESS) + has_timer = false; + if (tmr.msleep == NULL) + has_timer = false; + + backtrace(); + + /* + * If we can use the timer, beep twice to + * alert the user. + */ + if (has_timer) { + for (int i = 0; i < 2; ++i) { + pcspkr_tone(1050, 200); + tmr.msleep(100); + } + } + + processor_halt(); +} + void cpu_halt_others(void) { diff --git a/sys/include/sys/machdep.h b/sys/include/sys/machdep.h index 99ebbac..31385ce 100644 --- a/sys/include/sys/machdep.h +++ b/sys/include/sys/machdep.h @@ -45,10 +45,10 @@ void processor_init(void); void processor_halt(void); void intr_mask(void); void intr_unmask(void); +void machine_panic(void); __weak void chips_init(void); __weak void pre_init(void); __weak void serial_dbgch(char c); -__weak void backtrace(void); __weak void cpu_halt_others(void); #endif /* defined(_KERNEL) */ diff --git a/sys/kern/kern_panic.c b/sys/kern/kern_panic.c index 5b90dc8..aec7be3 100644 --- a/sys/kern/kern_panic.c +++ b/sys/kern/kern_panic.c @@ -55,8 +55,7 @@ panic(const char *fmt, ...) kprintf("panic: "); vkprintf(fmt, &ap); - __TRY_CALL(backtrace); - processor_halt(); + machine_panic(); __builtin_unreachable(); } -- cgit v1.2.3