From 2838108c6ec2072258f10c75597318eb00c75a9c Mon Sep 17 00:00:00 2001 From: Tyler McGurrin Date: Thu, 5 Jun 2025 20:41:38 -0400 Subject: [PATCH] Memory Paging Stuff --- src/kernel/arch/i686/util.h | 8 ++++---- src/kernel/core/memory/page.c | 31 ++++++++++++++++++++++++++++++- src/kernel/core/memory/page.h | 4 +++- src/kernel/dri/cmos.c | 6 ++++++ src/kernel/dri/cmos.h | 1 + src/kernel/main.c | 18 ++++++------------ src/libs/version.h | 2 +- 7 files changed, 51 insertions(+), 19 deletions(-) diff --git a/src/kernel/arch/i686/util.h b/src/kernel/arch/i686/util.h index 80bd628..1d33184 100644 --- a/src/kernel/arch/i686/util.h +++ b/src/kernel/arch/i686/util.h @@ -8,7 +8,7 @@ #include void __attribute__((cdecl)) Reboot(); -void __attribute__((cdecl)) Read_CR0(); -void __attribute__((cdecl)) Write_CR0(uint8_t value); -void __attribute__((cdecl)) Read_CR3(); -void __attribute__((cdecl)) Write_CR3(uint8_t value); +unsigned long __attribute__((cdecl)) Read_CR0(); +void __attribute__((cdecl)) Write_CR0(unsigned long value); +unsigned long* __attribute__((cdecl)) Read_CR3(); +void __attribute__((cdecl)) Write_CR3(unsigned long* value); diff --git a/src/kernel/core/memory/page.c b/src/kernel/core/memory/page.c index 0fe01a0..7474d7c 100644 --- a/src/kernel/core/memory/page.c +++ b/src/kernel/core/memory/page.c @@ -5,5 +5,34 @@ \*----------------*/ #include "page.h" +#include +#include +#include +#include + +extern uint16_t DEBUG_COM_PORT; + unsigned long* Page_Directory = (unsigned long*) 0x9c000; -unsigned long* Page_Table = (unsigned long*) 0x9d000 +unsigned long* Page_Table = (unsigned long*) 0x9d000; + +void Memory_Page_Init() +{ + unsigned long address = 0; + unsigned int i; + + Serial_Printf(DEBUG_COM_PORT, "MEMORY:> Mapping First 4MB of Memory.\n"); + for(i=0; i<1024; i++) { + Page_Table[i] = address | 3; + address = address + 4096; // 4096 = 4kb + } + Serial_Printf(DEBUG_COM_PORT, "MEMORY:> Inititalizing Page Directory and Table.\n"); + + // fill the first entry of the page directory + // Page_Directory[0] = Page_Table; + Page_Directory[0] = Page_Directory[0] | 3; // attribute set to: supervisor level, read/write + for(i=1; i<1024; i++) { + Page_Directory[i] = 0 | 2; // attribute set to: supervisor level, read/write + } + Write_CR3(Page_Directory); + Write_CR0(Read_CR0() | 0x80000000); // set the paging bit in CR0 to 1 +} \ No newline at end of file diff --git a/src/kernel/core/memory/page.h b/src/kernel/core/memory/page.h index afc031f..736dabe 100644 --- a/src/kernel/core/memory/page.h +++ b/src/kernel/core/memory/page.h @@ -3,4 +3,6 @@ |Copyright (C) 2024| |Tyler McGurrin | \*----------------*/ -#pragma once \ No newline at end of file +#pragma once + +void Memory_Page_Init(); \ No newline at end of file diff --git a/src/kernel/dri/cmos.c b/src/kernel/dri/cmos.c index aa434b8..e237ea5 100644 --- a/src/kernel/dri/cmos.c +++ b/src/kernel/dri/cmos.c @@ -73,4 +73,10 @@ int Slave_FDD_Detect() i++; } return FDDType; +} + +int uptime; +void CPU_Timer() +{ + uptime++; } \ No newline at end of file diff --git a/src/kernel/dri/cmos.h b/src/kernel/dri/cmos.h index 2d7e89b..99ecc0c 100644 --- a/src/kernel/dri/cmos.h +++ b/src/kernel/dri/cmos.h @@ -8,6 +8,7 @@ #include void CMOS_RTC_Handler(); +void CPU_Timer(); int Master_FDD_Detect(); int Slave_FDD_Detect(); uint8_t Read_CMOS(uint8_t Register); diff --git a/src/kernel/main.c b/src/kernel/main.c index 336d8f9..7a9ba36 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -16,27 +16,17 @@ #include #include #include +#include #include #include #include "../libs/version.h" #include "../libs/boot/bootparams.h" -#define PS2_KEYBOARD_PORT 0x60 - extern uint8_t __bss_start; extern uint8_t __end; uint16_t DEBUG_COM_PORT = COM1_PORT; -int uptime; -void timer(Registers* regs) -{ - uptime++; - // printf("%d", uptime); - // movecursorpos(8,14); -} - - void __attribute__((section(".entry"))) start(BootParams* bootParams) { // print logo @@ -53,7 +43,7 @@ void __attribute__((section(".entry"))) start(BootParams* bootParams) { // Register IRQs printf("Registering IRQs..."); - IRQ_RegisterHandler(0, timer); + IRQ_RegisterHandler(0, CPU_Timer); IRQ_RegisterHandler(1, Keyboard_Handler); IRQ_RegisterHandler(4, COM1_Serial_Handler); IRQ_RegisterHandler(6, Floppy_Handler); @@ -67,6 +57,10 @@ void __attribute__((section(".entry"))) start(BootParams* bootParams) { // Floppy_Init(); // This should always be last; its slow as fuck printf("Done!\n"); + // unsure why this is not working, will look into it later... + printf("Initializing Memory Paging..."); + // Memory_Page_Init(); + printf("Done!\n"); diff --git a/src/libs/version.h b/src/libs/version.h index 4db63ec..89c7b44 100644 --- a/src/libs/version.h +++ b/src/libs/version.h @@ -6,5 +6,5 @@ #pragma once #define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n" -#define VERSION "RD-00035" +#define VERSION "RD-00036" #define BOOTLOGO " _ ______ ____ ____ ______\n / | / / __ )/ __ \\/ __ /_ __/\n / |/ / __ / / / / / / // / \n / /| / /_/ / /_/ / /_/ // / \n/_/ |_/_____/\\____/\\____//_/ \n"