aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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();
}