From 50816a3b6d25930e086a2850a5d3de879a3e7d56 Mon Sep 17 00:00:00 2001 From: Nathan Giddings Date: Sun, 2 Aug 2020 15:03:35 -0500 Subject: [PATCH] Added key systems to kernel state --- src/kernelstate.hpp | 17 +++++++++++++---- src/mmap.hpp | 4 ++-- src/startup.cpp | 19 ++++++++++++++++--- src/x86/linker.ld | 9 ++++++++- src/x86/mmap.cpp | 9 +++++---- 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/kernelstate.hpp b/src/kernelstate.hpp index 7133f9c..b7ea052 100644 --- a/src/kernelstate.hpp +++ b/src/kernelstate.hpp @@ -1,9 +1,10 @@ #ifndef KERNELSTATE_H #define KERNELSTATE_H -#include - -#include "process.hpp" +#include "pageallocator.hpp" +#include "allocator.hpp" +#include "interrupts.hpp" +#include "scheduler.hpp" namespace kernel { @@ -12,7 +13,15 @@ class State { public: - static const size_t MAX_PROCESSES = 2048; + static const unsigned int MAX_PROCESSES = 2048; + + static BuddyAllocator pageAllocator; + + static Allocator allocator; + + static Interrupts interrupts; + + static ProcessQueue processQueue; }; diff --git a/src/mmap.hpp b/src/mmap.hpp index 3169629..8550153 100644 --- a/src/mmap.hpp +++ b/src/mmap.hpp @@ -10,9 +10,9 @@ namespace kernel { -int mmap(PageAllocator& allocator, void* start, size_t length, int flags); +int mmap(void* start, size_t length, int flags); -int munmap(PageAllocator& allocator, void* start, size_t length); +int munmap(void* start, size_t length); bool isMapped(void* addr); diff --git a/src/startup.cpp b/src/startup.cpp index abefa11..fa6da1c 100755 --- a/src/startup.cpp +++ b/src/startup.cpp @@ -6,28 +6,41 @@ #include "mmgr.hpp" #include "tty.hpp" #include "util.hpp" +#include "kernelstate.hpp" #include "config.h" using namespace kernel; +BuddyAllocator State::pageAllocator; +Allocator State::allocator; +Interrupts State::interrupts; +ProcessQueue State::processQueue; + +extern int _pageMapLocation; +extern int _heapLocation; +extern int _heapSize; + extern SystemInfo system_info; extern MemoryMap::Region memory_map; void main(char* cmdline) { + MemoryMap memmap(&memory_map, 16); + State::pageAllocator = BuddyAllocator(memmap, (char*) &_pageMapLocation, system_info.getHighMemory() / 4 + 256, 6); + mmap((void*) &_heapLocation, 0x100000, MMAP_RW); + State::allocator = Allocator((void*) 0xFFB00000, 0x100000, 256); + TTY tty((char*) 0xFF8B8000); tty << PACKAGE_STRING << "\n\n"; tty << "Low memory: \t" << (int) system_info.getLowMemory() << " KiB\n"; tty << "High memory:\t" << (int) system_info.getHighMemory() << " KiB\n"; tty << "Type\t\tLocation\t\tSize\n"; - MemoryMap memmap(&memory_map, 16); for(size_t i = 0; i < memmap.size() && memmap[i].getSize() > 0; i++) { tty << (int) memmap[i].getType() << "\t\t\t"; tty << (void*) memmap[i].getLocation() << "\t\t"; tty << (int) memmap[i].getSize() << "\n"; } - BuddyAllocator alloc(memmap, (char*) 0xFF800000, system_info.getHighMemory() / 4 + 256, 6); - mmap(alloc, (void*) 0, 4096, MMAP_RW); + mmap((void*) 0, 4096, MMAP_RW); tty << "Nothing left to do. Hanging.\n"; } diff --git a/src/x86/linker.ld b/src/x86/linker.ld index cfe1db2..55d5651 100755 --- a/src/x86/linker.ld +++ b/src/x86/linker.ld @@ -1,7 +1,8 @@ ENTRY(_start) - + SECTIONS { + . = 0xFF900000; VIRTUAL_BASE = .; PHYSICAL_BASE = 0x100000; @@ -33,4 +34,10 @@ SECTIONS LOAD_END = ADDR(.data) + SIZEOF(.data) - (VIRTUAL_BASE - PHYSICAL_BASE); BSS_END = ADDR(.bss) + SIZEOF(.bss) - (VIRTUAL_BASE - PHYSICAL_BASE); IMAGE_SIZE = ((BSS_END - LOAD_START) + (4096 - ((BSS_END - LOAD_START) % 4096))) / 4096; + + _pageMapLocation = 0xFF800000; + _heapLocation = 0xFFB00000; + _heapSize = 0x100000; + _kernelStart = VIRTUAL_BASE; + _kernelEnd = VIRTUAL_BASE + (4096 * IMAGE_SIZE); } diff --git a/src/x86/mmap.cpp b/src/x86/mmap.cpp index 1a8f530..87c7907 100644 --- a/src/x86/mmap.cpp +++ b/src/x86/mmap.cpp @@ -1,4 +1,5 @@ #include "../mmap.hpp" +#include "../kernelstate.hpp" class PageTableEntry { public: @@ -149,7 +150,7 @@ private: uint32_t physicalAddress : 20; }; -int kernel::mmap(PageAllocator& allocator, void* start, size_t length, int flags) +int kernel::mmap(void* start, size_t length, int flags) { if((size_t) start % 4096 != 0) return -1; @@ -161,7 +162,7 @@ int kernel::mmap(PageAllocator& allocator, void* start, size_t length, int flags size_t directoryIndex = tableIndex / 1024; if(!pageDirectory[directoryIndex].getPresent()) { - physaddr_t newPT = allocator.allocate(4096); + physaddr_t newPT = State::pageAllocator.allocate(4096); if(newPT == 0) return -1; pageDirectory[directoryIndex] = newPT; @@ -171,7 +172,7 @@ int kernel::mmap(PageAllocator& allocator, void* start, size_t length, int flags } if(!pageTables[tableIndex].getPresent()) { - physaddr_t page = allocator.allocate(4096); + physaddr_t page = State::pageAllocator.allocate(4096); pageTables[tableIndex] = page; pageTables[tableIndex].setPresent(true); pageTables[tableIndex].setUsermode(false); @@ -184,7 +185,7 @@ int kernel::mmap(PageAllocator& allocator, void* start, size_t length, int flags return 0; } -int kernel::munmap(PageAllocator& allocator, void* start, size_t length) +int kernel::munmap(void* start, size_t length) { if((size_t) start % 4096 != 0) return -1;