From 81d5f13a30406044e724e69be80707e418a15558 Mon Sep 17 00:00:00 2001 From: "Chloe M." Date: Tue, 23 Jun 2026 05:36:10 +0000 Subject: [PATCH] stos: Add kernel knotting impl Signed-off-by: Chloe M. --- paw/stos/arch/amd64/ke/knot.S | 51 +++++++++++++++++++++++++++++++++++ paw/stos/head/ke/knot.h | 34 +++++++++++++++++++++++ paw/stos/ke/Makefile | 3 ++- paw/stos/ke/knot.c | 49 +++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 paw/stos/arch/amd64/ke/knot.S create mode 100644 paw/stos/head/ke/knot.h create mode 100644 paw/stos/ke/knot.c diff --git a/paw/stos/arch/amd64/ke/knot.S b/paw/stos/arch/amd64/ke/knot.S new file mode 100644 index 0000000..6b6a087 --- /dev/null +++ b/paw/stos/arch/amd64/ke/knot.S @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Fucks and knots the kernel + * Author: Chloe M. + */ + + .text + .globl KeKnot +KeKnot: + /* + * When we are called here, the kernel is to be fucked with + * the most love and care we can put out before we knot it + * and fill it with warm cum... + */ + + cli /* Don't get interrupted */ + cld /* Just in case */ + + /* + * We don't want another processor to attempt to fuck the kernel + * while we are already knotting it to avoid it becoming too + * cumdrunk and misbehaving further. If another processor attempts + * to do so, knot and lock them hard, because that's what needy + * cores get :3 + */ + mov $1, %rax /* Prepare the lock */ + xchg %rax, MpLock /* Ah!~ Fuck~ @.@ */ + or %rax, %rax /* Are we another core? */ + jnz 1f + + /* + * The kernel is being extra needy and may or may not have + * kicked its paws into its stack. It's okay little kernel, + * we'll give you a new stack that's safe and cozy to lay in + * before the knotting begins! + */ + lea KnotStackTop(%rip), %rsp + + call KiKnot /* Enter the main knot handler */ +1: mfence /* Drain those caches~ */ +.Lock: + cli /* Don't get interrupted */ + hlt /* Get knotted >:3 */ + jmp .Lock + + .section .data +MpLock: .quad 0 +KnotStack: .fill 4096, 1, 0 +KnotStackTop: diff --git a/paw/stos/head/ke/knot.h b/paw/stos/head/ke/knot.h new file mode 100644 index 0000000..aa99eb4 --- /dev/null +++ b/paw/stos/head/ke/knot.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Fucks and knots the kernel + * Author: Chloe M. + */ + +#ifndef _KE_KNOT_H_ +#define _KE_KNOT_H_ 1 + +#include + +/* + * Valid knot reasons + * + * @KNOT_MISC: Misc. reason + * @KNOT_UNBOUND_RSRC: Unbounded resource + */ +typedef enum { + KNOT_MISC, + KNOT_UNBOUND_RSRC +} KNOT_REASON; + +/* + * Fuck and knot the kernel if it is misbehaving + * + * @Reason: Reason of knotting + * @Fmt: Format string + * @<...>: Variadic arguments + */ +VOID KeKnot(KNOT_REASON Reason, const char *Fmt, ...); + +#endif /* !_KE_KNOT_H_ */ diff --git a/paw/stos/ke/Makefile b/paw/stos/ke/Makefile index 3fc0cb7..2857632 100644 --- a/paw/stos/ke/Makefile +++ b/paw/stos/ke/Makefile @@ -9,7 +9,8 @@ .SILENT: include ../../mk/stos.mk -CFILES = $(shell find ../init -name "*.c") +CFILES = $(shell ls) +CFILES += $(shell find ../init -name "*.c") CFILES += $(shell find ../xt -name "*.c") CFILES += $(shell find ../lib -name "*.c") CFILES += $(shell find ../drivers -name "*.c") diff --git a/paw/stos/ke/knot.c b/paw/stos/ke/knot.c new file mode 100644 index 0000000..f5390f4 --- /dev/null +++ b/paw/stos/ke/knot.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Fucks and knots the kernel + * Author: Chloe M. + */ + +#include +#include +#include + +#define KNOT_REASON(Reason) \ + ((Reason) >= NELEM(ReasonTable)) \ + ? ReasonTable[0] \ + : ReasonTable[(Reason)] + +/* Reason lookup table */ +static const CHAR *ReasonTable[] = { + [KNOT_MISC] = "unspecified reason", + [KNOT_UNBOUND_RSRC] = "unbounded resource" +}; + +/* Globals */ +static CHAR KnotBuf[256]; +static va_list Ap; +static BOOTCONS_ATTR KnotAttr = { + .Background = 0x000080, + .Foreground = 0xFFFFFF +}; + +static CHAR KnotMessage[] = { + "SystemPaw DR has ran into a wittle issue and the kernel pilot kitty\n" + "has suspended the CPU to prevent damage to your machine.\n\n" + "Press and hold the power button until the screen blanks.\n\n" +}; + +VOID +KiKnot(KNOT_REASON Reason, const CHAR *Fmt, ...) +{ + va_start(Ap, Fmt); + FmtPrintf(KnotBuf, sizeof(KnotBuf), Fmt, Ap); + BootVidInitCons(&KnotAttr); + + TRACE("\033[H\033[2J"); + TRACE(KnotMessage); + TRACE("knot: %s", KnotBuf); + TRACE("reason: %s\n", KNOT_REASON(Reason)); +}