sp1/amd64+knot: Add kernel knot() function
Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Mirocom Laboratories
|
||||
* All rights reserved.
|
||||
*
|
||||
* The following sources are CONFIDENTIAL and PROPRIETARY
|
||||
* property of Mirocom Laboratories. Unauthorized copying,
|
||||
* use, distribution or modification of this file, in whole
|
||||
* and in part, is strictly prohibited without the prior written
|
||||
* consent from Mirocom Laboratories.
|
||||
*/
|
||||
|
||||
.text
|
||||
.globl knot
|
||||
knot:
|
||||
cli // Ensure interrupts are disabled
|
||||
cld // Ensure the direction flag is clear
|
||||
|
||||
//
|
||||
// On a multi-processor system we really want to ensure that
|
||||
// only the current processor core gets to fuck and knot the
|
||||
// kernel. Atomically acquire the MP lock to lockout other cores
|
||||
// out.
|
||||
//
|
||||
mov $1, %rax // Obtain lock
|
||||
xchg %rax, __mp_lock // Swap it atomically
|
||||
or %rax, %rax // Are we another processor?
|
||||
jnz .lockout // Yes, enter lockout
|
||||
|
||||
//
|
||||
// Cumdrunk kernels cannot be trusted, we must update the stack
|
||||
// to a known address to avoid clobbering memory we don't wanna
|
||||
// touch. We also want to ensure that any partial memory transactions
|
||||
// that have not 100% finished to be finished before we enter the main
|
||||
// panic handler. This might not be fully needed but it is a precaution
|
||||
// to be taken.
|
||||
//
|
||||
lea stack_top(%rip), %rsp
|
||||
mfence
|
||||
jmp __knot
|
||||
.lockout:
|
||||
hlt
|
||||
jmp .lockout
|
||||
|
||||
.section .data
|
||||
__mp_lock: .quad 0
|
||||
|
||||
.section .bss
|
||||
stack_base: .skip 4096, 0
|
||||
stack_top:
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Mirocom Laboratories
|
||||
* All rights reserved.
|
||||
*
|
||||
* The following sources are CONFIDENTIAL and PROPRIETARY
|
||||
* property of Mirocom Laboratories. Unauthorized copying,
|
||||
* use, distribution or modification of this file, in whole
|
||||
* and in part, is strictly prohibited without the prior written
|
||||
* consent from Mirocom Laboratories.
|
||||
*/
|
||||
|
||||
#include <os/knot.h>
|
||||
#include <lib/printf.h>
|
||||
#include <mu/cpu.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/*
|
||||
* Even though we can assume that the stack is safe to use upon
|
||||
* entry of __knot(), we still want to avoid using it for stability
|
||||
* and security reasons. Globals go here.
|
||||
*/
|
||||
static char knotbuf[256];
|
||||
static va_list ap;
|
||||
|
||||
__no_return void
|
||||
__knot(const char *fmt, ...)
|
||||
{
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(knotbuf, sizeof(knotbuf), fmt, ap);
|
||||
|
||||
printf("\033[31;40m*******************************************\n");
|
||||
printf("ah!~ fuck, i've been knotted~ @.@\n");
|
||||
printf("knot: %s\n", knotbuf);
|
||||
|
||||
for (;;) {
|
||||
mu_cpu_intoff();
|
||||
mu_cpu_halt();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Mirocom Laboratories
|
||||
* All rights reserved.
|
||||
*
|
||||
* The following sources are CONFIDENTIAL and PROPRIETARY
|
||||
* property of Mirocom Laboratories. Unauthorized copying,
|
||||
* use, distribution or modification of this file, in whole
|
||||
* and in part, is strictly prohibited without the prior written
|
||||
* consent from Mirocom Laboratories.
|
||||
*/
|
||||
|
||||
#ifndef _OS_KNOT_H_
|
||||
#define _OS_KNOT_H_ 1
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/*
|
||||
* This routine knots and fucks the kernel so it doesn't
|
||||
* go anywhere and is halted. This is used during serious
|
||||
* errors that may occur.
|
||||
*
|
||||
* @fmt: Format specifier
|
||||
* @<...>: Vargs
|
||||
*/
|
||||
__no_return void knot(const char *fmt, ...);
|
||||
|
||||
/*
|
||||
* This routine is the main panic handler and should NOT be
|
||||
* called directly.
|
||||
*
|
||||
* @fmt: Format specifier
|
||||
* @<...>: Vargs
|
||||
*/
|
||||
__no_return void __knot(const char *fmt, ...);
|
||||
|
||||
#endif /* !_OS_KNOT_H_ */
|
||||
Reference in New Issue
Block a user