stos: Add kernel knotting impl
Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
@@ -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:
|
||||
@@ -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 <stdef.h>
|
||||
|
||||
/*
|
||||
* 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_ */
|
||||
@@ -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")
|
||||
|
||||
@@ -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 <drivers/bootvid/fbio.h>
|
||||
#include <ex/trace.h>
|
||||
#include <ke/knot.h>
|
||||
|
||||
#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));
|
||||
}
|
||||
Reference in New Issue
Block a user