Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions Kernel/Core/Kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
#include "../System/Gdt.h"
#include "../Process/UserMode.h"
#include "../Drivers/Io.h"
#include "../Drivers/Driver.h"
#include "Shell.h"
#include "Panic.h"

extern void KeyboardRegister(void);
int CurrentLine = 0;
int CurrentColumn = 0;
void ClearScreen(){
Expand Down Expand Up @@ -158,35 +155,41 @@ void PrintKernelAt(const char *str, int line, int col) {
}
}


void KernelKeeper(void) { // keep the thing alive or else...
while (1) {
for(volatile int i = 0; i < 100; i++); // Tiny loop
}
}
void KernelMain(uint32_t magic, uint32_t info) {

ClearScreen();
PrintKernel("[SUCCESS] VoidFrame Kernel - Version 0.0.1-alpha loaded\n");

// Initialize core systems
GdtInit();
IdtInstall();
SyscallInit();
PicInstall();
MemoryInit();
ProcessInit();
KeyboardRegister();
DriverInit();
PrintKernel("[SUCCESS] System modules loaded\n");
ClearScreen();
ShellInit();
CreateProcess(KernelKeeper);

// Create the security manager process (PID 1) - this is critical
uint32_t security_pid = CreateSecureProcess(SecureKernelIntegritySubsystem, PROC_PRIV_SYSTEM);
if (!security_pid) {
Panic("Cannot create SecureKernelIntegritySubsystem() - Critical security failure");
}

PrintKernel("[SUCCESS] Security manager created with PID: ");
PrintKernelInt(security_pid);
PrintKernel("\n");

PrintKernel("[SUCCESS] Core system modules loaded\n");

// Timer setup for scheduling
outb(0x43, 0x36); // Command: channel 0, lobyte/hibyte, rate generator
outb(0x40, 0x4B); // Low byte of divisor (299 = ~4000Hz)
outb(0x40, 0x01); // High byte of divisor
outb(0x21, inb(0x21) & ~0x03);

// Enable interrupts
asm volatile("sti");

PrintKernel("[SUCCESS] Kernel initialization complete - entering main loop\n");
while (1) {
ShellRun();
if (ShouldSchedule()) {
Schedule();
}
Expand Down
13 changes: 3 additions & 10 deletions Kernel/Core/Panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,27 @@ void __attribute__((noreturn)) KernelPanicHandler() {
PrintKernel("KernelPanicHandler() has encountered a fatal problem that it could not handled.");
while (1) {
asm volatile("hlt");
} // fun for now
}
}

void __attribute__((noreturn)) Panic(const char* message) {

asm volatile("cli");

ClearScreen();
CurrentLine = 0;
CurrentColumn = 0;
for(volatile int i = 0; i < 1000000000; i++);
PrintKernel("[FATAL] - [----KERNEL PANIC----]\n\n");
PrintKernel(message);
PrintKernel("\nSystem halted.\n\n");
PrintKernel("Calling KernelPanicHandler()...\n");
PrintKernel("\nCalling KernelPanicHandler()...\n");
KernelPanicHandler();
}

void __attribute__((noreturn)) PanicWithCode(const char* message, uint64_t error_code) {
asm volatile("cli");

ClearScreen();
CurrentLine = 0;
CurrentColumn = 0;
int i = 10000000;
while (i > 0) {
i--;
}
for(volatile int i = 0; i < 1000000000; i++);
PrintKernel("[FATAL] - [----KERNEL PANIC----]\n");
PrintKernel(message);
PrintKernel("\nError Code: ");
Expand Down
103 changes: 0 additions & 103 deletions Kernel/Core/Shell.c

This file was deleted.

7 changes: 0 additions & 7 deletions Kernel/Core/Shell.h

This file was deleted.

32 changes: 0 additions & 32 deletions Kernel/Drivers/Driver.c

This file was deleted.

30 changes: 0 additions & 30 deletions Kernel/Drivers/Driver.h

This file was deleted.

10 changes: 0 additions & 10 deletions Kernel/Drivers/Interrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "../Core/Kernel.h"
#include "Io.h"
#include "../Process/Process.h"
#include "Driver.h"

#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
Expand Down Expand Up @@ -67,15 +66,6 @@ static void FastDisplayTicks(uint64_t ticks) {

// The C-level interrupt handler
void InterruptHandler(struct Registers* regs) {
// Handle keyboard interrupt (IRQ1, remapped to 33)
if (regs->interrupt_number == 33) {
Driver* kbd = DriverGet(DRIVER_KEYBOARD);
if (kbd && kbd->handle_interrupt) {
kbd->handle_interrupt(1);
}
outb(0x20, 0x20); // EOI
return;
}

// Handle timer interrupt (IRQ0, remapped to 32)
if (likely(regs->interrupt_number == 32)) {
Expand Down
Loading