panic screen

This commit is contained in:
2026-01-29 09:02:15 +11:00
parent 34c9670ad3
commit 3f8e7fabd1
16 changed files with 64 additions and 3 deletions

View File

@@ -40,4 +40,23 @@ void BasicRenderer::Print(const char* str) {
chr++;
}
}
void BasicRenderer::Clear(uint32_t colour) {
uint64_t fbBase = (uint64_t)targetFramebuffer->BaseAddress;
uint64_t bytesPerScanline = targetFramebuffer->PixelsPerScanline * 4;
uint64_t fbHeight = targetFramebuffer->Height;
uint64_t fbSize = targetFramebuffer->BufferSize;
for (int verticalScanline = 0; verticalScanline < fbHeight; verticalScanline ++){
uint64_t pixPtrBase = fbBase + (bytesPerScanline * verticalScanline);
for (uint32_t* pixPtr = (uint32_t*)pixPtrBase; pixPtr < (uint32_t*)(pixPtrBase + bytesPerScanline); pixPtr ++){
*pixPtr = colour;
}
}
}
void BasicRenderer::Next() {
cursorPosition.x = 0;
cursorPosition.y += 16;
}

View File

@@ -2,6 +2,7 @@
#include "math.h"
#include "Framebuffer.h"
#include "PSF1Font.h"
#include <stdint.h>
class BasicRenderer {
public:
@@ -12,6 +13,8 @@ class BasicRenderer {
unsigned int Colour;
void Print(const char* str);
void PutChar(char chr, unsigned int xOff, unsigned int yOff);
void Clear(uint32_t colour);
void Next();
};
extern BasicRenderer* GlobalRenderer;

View File

@@ -1,6 +1,17 @@
#include "interrupts.h"
#include "../panic.h"
__attribute__((interrupt)) void PageFault_Handler(struct interrupt_frame* frame) {
GlobalRenderer->Print("Page fault caught!");
Panic("Page Fault");
while (true);
}
__attribute__((interrupt)) void DoubleFault_Handler(struct interrupt_frame* frame) {
Panic("Double Fault");
while (true);
}
__attribute__((interrupt)) void GPFault_Handler(struct interrupt_frame* frame) {
Panic("General Protection Fault");
while (true);
}

View File

@@ -3,4 +3,6 @@
struct interrupt_frame;
__attribute__((interrupt)) void PageFault_Handler(struct interrupt_frame* frame);
__attribute__((interrupt)) void PageFault_Handler(struct interrupt_frame* frame);
__attribute__((interrupt)) void DoubleFault_Handler(struct interrupt_frame* frame);
__attribute__((interrupt)) void GPFault_Handler(struct interrupt_frame* frame);

View File

@@ -4,8 +4,11 @@ extern "C" void _start(BootInfo* bootInfo) {
KernelInfo kernelInfo = InitializeKernel(bootInfo);
PageTableManager* pageTableManager = kernelInfo.pageTableManager;
GlobalRenderer->Clear(0xFF191919);
GlobalRenderer->Print("Kernel initialized successfully!");
GlobalRenderer->cursorPosition = {0, GlobalRenderer->cursorPosition.y + 18};
GlobalRenderer->Next();
asm("int $0x0e");
// make sure we never return from our OS
while (true);

View File

@@ -54,6 +54,16 @@ void PrepareInterrupts() {
int_PageFault->type_attr = IDT_TA_InterruptGate;
int_PageFault->selector = 0x08; // kernel code segment
IDTDescEntry* int_DoubleFault = (IDTDescEntry*)(idtr.Offset + 0x8 * sizeof(IDTDescEntry));
int_DoubleFault->SetOffset((uint64_t)DoubleFault_Handler);
int_DoubleFault->type_attr = IDT_TA_InterruptGate;
int_DoubleFault->selector = 0x08; // kernel code segment
IDTDescEntry* int_GPFault = (IDTDescEntry*)(idtr.Offset + 0xD * sizeof(IDTDescEntry));
int_GPFault->SetOffset((uint64_t)GPFault_Handler);
int_GPFault->type_attr = IDT_TA_InterruptGate;
int_GPFault->selector = 0x08; // kernel code segment
// load idt
asm("lidt %0" : : "m" (idtr));
}

10
kernel/src/panic.cpp Normal file
View File

@@ -0,0 +1,10 @@
#include "panic.h"
#include "BasicRenderer.h"
void Panic(const char* panicMessage) {
GlobalRenderer->Clear(0xFF000000);
GlobalRenderer->Colour = 0xFFFF0000;
GlobalRenderer->cursorPosition = {0,0};
GlobalRenderer->Print("PANIC!!! ");
GlobalRenderer->Print(panicMessage);
}

3
kernel/src/panic.h Normal file
View File

@@ -0,0 +1,3 @@
#pragma once
void Panic(const char* panicMessage);