diff options
author | Ian Moffett <ian@osmora.org> | 2024-05-14 11:36:23 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-05-14 11:36:23 -0400 |
commit | 6bdd17edca2fa58263db47841e007cee5a01a26c (patch) | |
tree | 74aa0c5283b01cffddd341d46514ccf3c133006c /sys/arch | |
parent | 7a414a0c785ce4f12ac33a4e8a5061b21344bdf7 (diff) |
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 <ian@osmora.org>
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/amd64/amd64/machdep.c | 34 |
1 files changed, 33 insertions, 1 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 <sys/cdefs.h> #include <sys/panic.h> #include <sys/ksyms.h> +#include <sys/timer.h> #include <machine/trap.h> #include <machine/idt.h> #include <machine/io.h> @@ -40,6 +41,7 @@ #include <machine/lapic.h> #include <machine/tss.h> #include <machine/spectre.h> +#include <machine/isa/spkr.h> #include <machine/cpu.h> #include <machine/uart.h> #include <machine/cpuid.h> @@ -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) { |