summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-05-14 11:36:23 -0400
committerIan Moffett <ian@osmora.org>2024-05-14 11:36:23 -0400
commit6bdd17edca2fa58263db47841e007cee5a01a26c (patch)
tree74aa0c5283b01cffddd341d46514ccf3c133006c
parent7a414a0c785ce4f12ac33a4e8a5061b21344bdf7 (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>
-rw-r--r--sys/arch/amd64/amd64/machdep.c34
-rw-r--r--sys/include/sys/machdep.h2
-rw-r--r--sys/kern/kern_panic.c3
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 <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)
{
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();
}