From 74c38342d72a1acb5521f145b7f9ebf12eb39f0a Mon Sep 17 00:00:00 2001 From: Tom-on64 Date: Tue, 28 May 2024 17:43:07 +0200 Subject: [PATCH] Made memory/addresses.h more organised Also didn't need to add stdio.h to any files so that's good! --- include/c/stdio.h | 2 +- include/interrupt/pit.h | 3 +-- include/memory/addresses.h | 54 ++++++++++++++++++++----------------- include/memory/physical.h | 2 +- include/terminal/terminal.h | 2 +- src/kernel.c | 6 ++--- 6 files changed, 37 insertions(+), 32 deletions(-) diff --git a/include/c/stdio.h b/include/c/stdio.h index dab1684..8557dae 100644 --- a/include/c/stdio.h +++ b/include/c/stdio.h @@ -18,7 +18,7 @@ void putc(char c) { } char getc() { - char* character = (char*)0x3000; + char* character = (char*)0x2100; *character = '\0'; while (*character == '\0') { __asm__ volatile ("hlt"); } return *character; diff --git a/include/interrupt/pit.h b/include/interrupt/pit.h index 4c6f4dd..c59d49b 100644 --- a/include/interrupt/pit.h +++ b/include/interrupt/pit.h @@ -17,9 +17,8 @@ __attribute__ ((interrupt)) void timerHandler(intFrame_t* iframe) { static uint32_t cursorTicks = 0; cursorTicks++; - - if (terminal->showCursor) { + if (!terminal->hideCursor) { if (cursorTicks % 500 == 0) putcAt(127, terminal->x, terminal->y); else if (cursorTicks % 250 == 0) putcAt(' ', terminal->x, terminal->y); } diff --git a/include/memory/addresses.h b/include/memory/addresses.h index b143a28..11a4665 100644 --- a/include/memory/addresses.h +++ b/include/memory/addresses.h @@ -1,41 +1,47 @@ #ifndef ADDRESSES_H #define ADDRESSES_H -/* TODO: Follow this layout and/or change it to make more sense - * Memory layout - * 0x0000-0x0fff - Probably shouldn't mess with this? idk +/* + * Memory layout of addresses 0x0000 - 0xA000 + * 0x0000-0x0fff - Probably shouldn't mess with this? idk it feels wrong * 0x1000-0x17ff - Free * 0x1800-0x1fff - Global Variables - * 0x2000-0x2fff - Terminal area - * 0x3000-0x3fff - Keyboard area - * 0x4000-0x5fff - Filesytem area - * 0x6000-0x7fff - Font area - * 0x8000-0x8fff - Free + * 0x2000-0x2fff - Larger structs + * 0x3000-0x3fff - Filesystem area + * 0x4000-0x4fff - Font area + * 0x6000-0x84ff - Free + * 0x8500-0x8fff - SMAP Area * 0x9000-0x9fff - VBE info area */ -// Locations -#define KERNEL_LOC 0x100000 -#define DATETIME_LOC 0x2000 -#define TERMINAL_INFO_LOC 0x8000 -#define KEYBOARD_STATE_LOC 0x3000 -#define FILETABLE_LOC 0x4000 -#define MODE_INFO_BLOCK_LOC 0x9000 // 512 Bytes +// Global Variables +#define SLEEP_TIMER 0x1800 +#define CURRENT_PAGE_DIR_ADDR 0x1804 +#define PHYS_MEM_MAX_BLOCKS 0x1808 +#define PHYS_MEM_USED_BLOCKS 0x180C -// Variables -#define CURRENT_PAGE_DIR_ADDR 0x1800 -#define PHYS_MEM_MAX_BLOCKS 0x1804 -#define PHYS_MEM_USED_BLOCKS 0x1808 -#define SLEEP_TIMER 0x180C +// Some structs +#define TERMINAL_INFO_LOC 0x2000 +#define KEYBOARD_STATE_LOC 0x2100 +#define DATETIME_LOC 0x2200 -// Font -#define FONT_LOC 0x6000 +// Filesystem Area 0x3000 - 0x3fff +#define FILETABLE_LOC 0x3000 + +// Font area 0x4000 - 0x4fff +#define FONT_LOC 0x4000 #define FONT_WIDTH (FONT_LOC) #define FONT_HEIGHT (FONT_LOC + 1) -// Physical memory manager -#define MEMMAP_AREA 0x30000 +// Smap Area 0x8500 - 0x8fff #define SMAP_ENTRY_COUNT 0x8500 #define SMAP_ENTRIES 0x8504 +// VBE Info Area 0x9000 - 0x9fff +#define MODE_INFO_BLOCK_LOC 0x9000 // 512 Bytes + +// Other addresses +#define KERNEL_LOC 0x100000 +#define MEMMAP_AREA 0x30000 + #endif diff --git a/include/memory/physical.h b/include/memory/physical.h index 14c4bbf..38eb5af 100644 --- a/include/memory/physical.h +++ b/include/memory/physical.h @@ -1,12 +1,12 @@ #ifndef PHYSICAL_MEM_MANAGER_H #define PHYSICAL_MEM_MANAGER_H +#include #include #include #define BLOCK_SIZE 4096 // 4kB #define BLOCKS_PER_BYTE 8 -#define SMAP_ADDRESS 0x8500 typedef struct smapEntry_s { uint64_t baseAddress; diff --git a/include/terminal/terminal.h b/include/terminal/terminal.h index f07d637..3b01b69 100644 --- a/include/terminal/terminal.h +++ b/include/terminal/terminal.h @@ -14,7 +14,7 @@ typedef struct { uint32_t width; // Width in characters uint32_t height; // Height in characters char cursorChar; // Character to use as a cursor - bool showCursor; // Should we display the cursor + bool hideCursor; // Should we display the cursor } terminal_t; terminal_t* terminal = (terminal_t*)TERMINAL_INFO_LOC; diff --git a/src/kernel.c b/src/kernel.c index 068df87..e8893f4 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1,4 +1,3 @@ -#include // TODO: Add stdio.h to every header that needs it #include #include #include @@ -19,6 +18,7 @@ #include #include +#include #include #include #include @@ -368,8 +368,8 @@ void printFiletable(char* ft) { } void printPhysicalMemmap() { - uint32_t entryCount = *(uint32_t*)SMAP_ADDRESS; - smapEntry_t* smapEntry = (smapEntry_t*)(SMAP_ADDRESS+4); + uint32_t entryCount = *(uint32_t*)SMAP_ENTRY_COUNT; + smapEntry_t* smapEntry = (smapEntry_t*)SMAP_ENTRIES; for (uint32_t i = 0; i < entryCount; i++) { print("Region ");