diff options
| author | Ian Moffett <ian@osmora.org> | 2025-12-23 15:17:11 -0500 |
|---|---|---|
| committer | Ian Moffett <ian@osmora.org> | 2025-12-23 15:17:11 -0500 |
| commit | 7842d35829e0e07b73f426c4c9e29eba1018a75a (patch) | |
| tree | 5251dfad4a53c6af950207a7c64bceca98aae091 | |
| parent | 3b134c245f6fc8aebe77ae3c252629e6a67b6c89 (diff) | |
Signed-off-by: Ian Moffett <ian@osmora.org>
| -rw-r--r-- | mos/sys/inc/kern/panic.h | 18 | ||||
| -rw-r--r-- | mos/sys/kern/kern_panic.c | 29 |
2 files changed, 47 insertions, 0 deletions
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 <sdk/types.h> +#include <sdk/stdarg.h> + +/* + * 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 <sdk/string.h> +#include <kern/panic.h> +#include <kern/spinlock.h> +#include <kern/trace.h> +#include <mu/cpu.h> + +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(); + } +} |
