From 7842d35829e0e07b73f426c4c9e29eba1018a75a Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 23 Dec 2025 15:17:11 -0500 Subject: mos: kern: Add panic function Signed-off-by: Ian Moffett --- mos/sys/inc/kern/panic.h | 18 ++++++++++++++++++ mos/sys/kern/kern_panic.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 mos/sys/inc/kern/panic.h create mode 100644 mos/sys/kern/kern_panic.c diff --git a/mos/sys/inc/kern/panic.h b/mos/sys/inc/kern/panic.h new file mode 100644 index 0000000..a7aac0e --- /dev/null +++ b/mos/sys/inc/kern/panic.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025, Ian Moffett. + * Provided under the BSD-3 clause. + */ + +#ifndef _KERN_PANIC_H_ +#define _KERN_PANIC_H_ 1 + +#include +#include + +/* + * Signal to the operator that a severe error has + * occurred and the system has been halted. + */ +void panic(const char *fmt, ...); + +#endif /* !_KERN_PANIC_H_ */ diff --git a/mos/sys/kern/kern_panic.c b/mos/sys/kern/kern_panic.c new file mode 100644 index 0000000..8f03e6a --- /dev/null +++ b/mos/sys/kern/kern_panic.c @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025, Ian Moffett. + * Provided under the BSD-3 clause. + */ + +#include +#include +#include +#include +#include + +static SPINLOCK panic_sync; +static char panic_buf[256]; +static va_list ap; + +void +panic(const char *fmt, ...) +{ + spinlock_acquire(&panic_sync, SPINLOCK_IRQMUT); + va_start(ap, fmt); + + vsnprintf(panic_buf, sizeof(panic_buf), fmt, ap); + trace("panic: "); + trace(panic_buf); + + for (;;) { + mu_cpu_halt(); + } +} -- cgit v1.2.3