feat: S3 sleep, PDF viewer graphics rendering, live user environment
This commit is contained in:
+77
-59
@@ -6,72 +6,52 @@
|
||||
#include "Panic.hpp"
|
||||
#include "../CppLib/BoxUI.hpp"
|
||||
|
||||
void Panic(const char *meditationString, System::PanicFrame* frame) {
|
||||
const int boxWidth = 72;
|
||||
static constexpr int BoxWidth = 72;
|
||||
|
||||
// Header
|
||||
kerr << BOXUI_ANSI_RED_BG << BOXUI_ANSI_WHITE_FG << BOXUI_ANSI_BOLD << "\n";
|
||||
kerr << BOXUI_TL;
|
||||
for (int i = 0; i < boxWidth - 2; ++i) kerr << BOXUI_H;
|
||||
kerr << BOXUI_TR << "\n";
|
||||
PrintBoxedLine(kerr, "!!! KERNEL PANIC !!!", boxWidth, true);
|
||||
PrintBoxedLine(kerr, "", boxWidth);
|
||||
PrintBoxedLine(kerr, "System halted. Please reboot.", boxWidth, true);
|
||||
PrintBoxedLine(kerr, "", boxWidth);
|
||||
PrintBoxedSeparator(kerr, boxWidth);
|
||||
PrintBoxedLine(kerr, "Meditation:", boxWidth, true);
|
||||
PrintBoxedLine(kerr, meditationString, boxWidth);
|
||||
PrintBoxedLine(kerr, "", boxWidth);
|
||||
static void PrintHorizontalEdge(const char* left, const char* right) {
|
||||
kerr << left;
|
||||
for (int i = 0; i < BoxWidth - 2; ++i) kerr << BOXUI_H;
|
||||
kerr << right << "\n";
|
||||
}
|
||||
|
||||
#if defined (__x86_64__)
|
||||
if (frame != nullptr) {
|
||||
PrintBoxedSeparator(kerr, boxWidth);
|
||||
PrintBoxedLine(kerr, "CPU State:", boxWidth, true);
|
||||
PrintBoxedHex(kerr, "Interrupt Vector", frame->InterruptVector, boxWidth);
|
||||
static void PrintPageFaultInfo(System::PanicFrame*& frame) {
|
||||
auto* pf = (System::PageFaultPanicFrame*)frame;
|
||||
frame = (System::PanicFrame*)&pf->IP;
|
||||
|
||||
if (frame->InterruptVector == 0xE) {
|
||||
auto pf_frame = (System::PageFaultPanicFrame*)frame;
|
||||
frame = (System::PanicFrame*)&pf_frame->IP;
|
||||
uint64_t cr2;
|
||||
asm volatile("mov %%cr2, %0" : "=r"(cr2));
|
||||
PrintBoxedHex(kerr, "Faulting Address (CR2)", cr2, BoxWidth);
|
||||
|
||||
// CR2 holds the faulting virtual address for page faults
|
||||
uint64_t cr2;
|
||||
asm volatile("mov %%cr2, %0" : "=r"(cr2));
|
||||
PrintBoxedHex(kerr, "Faulting Address (CR2)", cr2, boxWidth);
|
||||
PrintBoxedLine(kerr, "Page Fault Error:", BoxWidth, true);
|
||||
PrintBoxedDec(kerr, "Present", pf->PageFaultError.Present, BoxWidth);
|
||||
PrintBoxedDec(kerr, "Write", pf->PageFaultError.Write, BoxWidth);
|
||||
PrintBoxedDec(kerr, "User", pf->PageFaultError.User, BoxWidth);
|
||||
PrintBoxedDec(kerr, "Reserved Write", pf->PageFaultError.ReservedWrite, BoxWidth);
|
||||
PrintBoxedDec(kerr, "Instruction Fetch",pf->PageFaultError.InstructionFetch, BoxWidth);
|
||||
PrintBoxedDec(kerr, "Protection Key", pf->PageFaultError.ProtectionKey, BoxWidth);
|
||||
PrintBoxedDec(kerr, "Shadow Stack", pf->PageFaultError.ShadowStack, BoxWidth);
|
||||
PrintBoxedDec(kerr, "SGX", pf->PageFaultError.SGX, BoxWidth);
|
||||
}
|
||||
|
||||
PrintBoxedLine(kerr, "Page Fault Error:", boxWidth, true);
|
||||
PrintBoxedDec(kerr, "Present", pf_frame->PageFaultError.Present, boxWidth);
|
||||
PrintBoxedDec(kerr, "Write", pf_frame->PageFaultError.Write, boxWidth);
|
||||
PrintBoxedDec(kerr, "User", pf_frame->PageFaultError.User, boxWidth);
|
||||
PrintBoxedDec(kerr, "Reserved Write", pf_frame->PageFaultError.ReservedWrite, boxWidth);
|
||||
PrintBoxedDec(kerr, "Instruction Fetch", pf_frame->PageFaultError.InstructionFetch, boxWidth);
|
||||
PrintBoxedDec(kerr, "Protection Key", pf_frame->PageFaultError.ProtectionKey, boxWidth);
|
||||
PrintBoxedDec(kerr, "Shadow Stack", pf_frame->PageFaultError.ShadowStack, boxWidth);
|
||||
PrintBoxedDec(kerr, "SGX", pf_frame->PageFaultError.SGX, boxWidth);
|
||||
} else if (frame->InterruptVector == 0xD) {
|
||||
auto gpf_frame = (System::GPFPanicFrame*)frame;
|
||||
frame = (System::PanicFrame*)&frame->IP;
|
||||
PrintBoxedLine(kerr, "General Protection Fault:", boxWidth, true);
|
||||
PrintBoxedDec(kerr, "Error Code", gpf_frame->GeneralProtectionFaultError, boxWidth);
|
||||
}
|
||||
static void PrintGPFInfo(System::PanicFrame*& frame) {
|
||||
auto* gpf = (System::GPFPanicFrame*)frame;
|
||||
frame = (System::PanicFrame*)&gpf->IP;
|
||||
|
||||
PrintBoxedSeparator(kerr, boxWidth);
|
||||
PrintBoxedLine(kerr, "Registers:", boxWidth, true);
|
||||
PrintBoxedHex(kerr, "Instruction Pointer", frame->IP, boxWidth);
|
||||
PrintBoxedHex(kerr, "Code Segment", frame->CS, boxWidth);
|
||||
PrintBoxedHex(kerr, "Flags", frame->Flags, boxWidth);
|
||||
PrintBoxedHex(kerr, "Stack Pointer", frame->SP, boxWidth);
|
||||
PrintBoxedHex(kerr, "Stack Segment", frame->SS, boxWidth);
|
||||
}
|
||||
#endif
|
||||
PrintBoxedLine(kerr, "General Protection Fault:", BoxWidth, true);
|
||||
PrintBoxedDec(kerr, "Error Code", gpf->GeneralProtectionFaultError, BoxWidth);
|
||||
}
|
||||
|
||||
PrintBoxedLine(kerr, "", boxWidth);
|
||||
|
||||
// Footer
|
||||
kerr << BOXUI_BL;
|
||||
for (int i = 0; i < boxWidth - 2; ++i) kerr << BOXUI_H;
|
||||
kerr << BOXUI_BR << "\n";
|
||||
kerr << BOXUI_ANSI_RESET;
|
||||
static void PrintRegisters(System::PanicFrame* frame) {
|
||||
PrintBoxedSeparator(kerr, BoxWidth);
|
||||
PrintBoxedLine(kerr, "Registers:", BoxWidth, true);
|
||||
PrintBoxedHex(kerr, "Instruction Pointer", frame->IP, BoxWidth);
|
||||
PrintBoxedHex(kerr, "Code Segment", frame->CS, BoxWidth);
|
||||
PrintBoxedHex(kerr, "Flags", frame->Flags, BoxWidth);
|
||||
PrintBoxedHex(kerr, "Stack Pointer", frame->SP, BoxWidth);
|
||||
PrintBoxedHex(kerr, "Stack Segment", frame->SS, BoxWidth);
|
||||
}
|
||||
|
||||
[[noreturn]] static void Halt() {
|
||||
while (true) {
|
||||
#if defined (__x86_64__)
|
||||
asm ("cli");
|
||||
@@ -82,4 +62,42 @@ void Panic(const char *meditationString, System::PanicFrame* frame) {
|
||||
asm ("idle 0");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Panic(const char *meditationString, System::PanicFrame* frame) {
|
||||
// Header
|
||||
kerr << BOXUI_ANSI_RED_BG << BOXUI_ANSI_WHITE_FG << BOXUI_ANSI_BOLD << "\n";
|
||||
PrintHorizontalEdge(BOXUI_TL, BOXUI_TR);
|
||||
PrintBoxedLine(kerr, "!!! KERNEL PANIC !!!", BoxWidth, true);
|
||||
PrintBoxedLine(kerr, "", BoxWidth);
|
||||
PrintBoxedLine(kerr, "System halted. Please reboot.", BoxWidth, true);
|
||||
PrintBoxedLine(kerr, "", BoxWidth);
|
||||
|
||||
// Meditation string
|
||||
PrintBoxedSeparator(kerr, BoxWidth);
|
||||
PrintBoxedLine(kerr, meditationString, BoxWidth);
|
||||
PrintBoxedLine(kerr, "", BoxWidth);
|
||||
|
||||
// CPU state (x86_64 only)
|
||||
#if defined (__x86_64__)
|
||||
if (frame != nullptr) {
|
||||
PrintBoxedSeparator(kerr, BoxWidth);
|
||||
PrintBoxedLine(kerr, "CPU State:", BoxWidth, true);
|
||||
PrintBoxedHex(kerr, "Interrupt Vector", frame->InterruptVector, BoxWidth);
|
||||
|
||||
if (frame->InterruptVector == 0xE)
|
||||
PrintPageFaultInfo(frame);
|
||||
else if (frame->InterruptVector == 0xD)
|
||||
PrintGPFInfo(frame);
|
||||
|
||||
PrintRegisters(frame);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Footer
|
||||
PrintBoxedLine(kerr, "", BoxWidth);
|
||||
PrintHorizontalEdge(BOXUI_BL, BOXUI_BR);
|
||||
kerr << BOXUI_ANSI_RESET;
|
||||
|
||||
Halt();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user