diff options
| -rw-r--r-- | mos/sys/inc/arch/x86_64/gdt.h | 42 | ||||
| -rw-r--r-- | mos/sys/inc/kern/panic.h | 18 | ||||
| -rw-r--r-- | mos/sys/kern/kern_panic.c | 29 |
3 files changed, 89 insertions, 0 deletions
diff --git a/mos/sys/inc/arch/x86_64/gdt.h b/mos/sys/inc/arch/x86_64/gdt.h new file mode 100644 index 0000000..35081b3 --- /dev/null +++ b/mos/sys/inc/arch/x86_64/gdt.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025, Ian Moffett. + * Provided under the BSD-3 clause. + */ + +#ifndef _MACHINE_GDT_H_ +#define _MACHINE_GDT_H_ 1 + +#ifndef __ASSEMBLER__ +#include <sdk/types.h> +#include <sdk/defs.h> +#endif /* __ASSEMBLER__ */ + +/* Kernel code/data */ +#define GDT_KCODE 0x08 +#define GDT_KDATA 0x10 + +/* User code/data */ +#define GDT_UCODE 0x18 +#define GDT_UDATA 0x20 + +/* Task state segment */ +#define GDT_TSS 0x28 +#define GDT_TSS_INDEX 0x05 + +#ifndef __ASSEMBLER__ +typedef struct { + USHORT limit; + USHORT base_low; + UBYTE base_mid; + UBYTE access; + UBYTE granularity; + UBYTE base_hi; +} PACKED GDT_ENTRY; + +typedef struct { + USHORT limit; + UPTR offset; +} PACKED GDTR; + +#endif /* !__ASSEMBLER__ */ +#endif /* !_MACHINE_GDT_H_ */ 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(); + } +} |
