From 6d351bb326fbaa7372c3b89e782fe8a8ed939602 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 27 Jan 2019 10:17:27 +0100 Subject: [PATCH] Kernel: Move RAM size detection to MemoryManager and use what we learn. --- Kernel/MemoryManager.cpp | 19 ++++++++++++++----- Kernel/MemoryManager.h | 4 ++++ Kernel/init.cpp | 7 ------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Kernel/MemoryManager.cpp b/Kernel/MemoryManager.cpp index d2a176ba69..f4314bf557 100644 --- a/Kernel/MemoryManager.cpp +++ b/Kernel/MemoryManager.cpp @@ -6,6 +6,7 @@ #include "StdLib.h" #include "Process.h" #include +#include "CMOS.h" //#define MM_DEBUG //#define PAGE_FAULT_DEBUG @@ -19,6 +20,16 @@ MemoryManager& MM MemoryManager::MemoryManager() { + // FIXME: This is not the best way to do memory map detection. + // Rewrite to use BIOS int 15,e820 once we have VM86 support. + word base_memory = (CMOS::read(0x16) << 8) | CMOS::read(0x15); + word ext_memory = (CMOS::read(0x18) << 8) | CMOS::read(0x17); + + kprintf("%u kB base memory\n", base_memory); + kprintf("%u kB extended memory\n", ext_memory); + + m_ram_size = ext_memory * 1024; + m_kernel_page_directory = PageDirectory::create_at_fixed_address(PhysicalAddress(0x4000)); m_page_table_zero = (dword*)0x6000; @@ -75,14 +86,12 @@ void MemoryManager::initialize_paging() // 1 MB -> 2 MB kmalloc_eternal() space. // 2 MB -> 3 MB kmalloc() space. // 3 MB -> 4 MB Supervisor physical pages (available for allocation!) - // 4 MB -> 32 MB Userspace physical pages (available for allocation!) + // 4 MB -> (max) MB Userspace physical pages (available for allocation!) for (size_t i = (2 * MB); i < (4 * MB); i += PAGE_SIZE) m_free_supervisor_physical_pages.append(adopt(*new PhysicalPage(PhysicalAddress(i), true))); -#ifdef MM_DEBUG - dbgprintf("MM: 4MB-32MB available for allocation\n"); -#endif - for (size_t i = (4 * MB); i < (32 * MB); i += PAGE_SIZE) + dbgprintf("MM: 4MB-%uMB available for allocation\n", m_ram_size / 1048576); + for (size_t i = (4 * MB); i < m_ram_size; i += PAGE_SIZE) m_free_physical_pages.append(adopt(*new PhysicalPage(PhysicalAddress(i), false))); m_quickmap_addr = LinearAddress(m_free_physical_pages.take_last().leakRef()->paddr().get()); #ifdef MM_DEBUG diff --git a/Kernel/MemoryManager.h b/Kernel/MemoryManager.h index 35ffbbc3f0..bd80937848 100644 --- a/Kernel/MemoryManager.h +++ b/Kernel/MemoryManager.h @@ -222,6 +222,8 @@ public: void remap_region(Process&, Region&); + size_t ram_size() const { return m_ram_size; } + private: MemoryManager(); ~MemoryManager(); @@ -347,6 +349,8 @@ private: HashTable m_vmos; HashTable m_regions; + + size_t m_ram_size { 0 }; }; struct ProcessPagingScope { diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 6f6ba198ae..46711f4c0b 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -6,7 +6,6 @@ #include "Process.h" #include "system.h" #include "PIC.h" -#include "CMOS.h" #include "IDEDiskDevice.h" #include "KSyms.h" #include @@ -165,12 +164,6 @@ void init() memset(&system, 0, sizeof(system)); - word base_memory = (CMOS::read(0x16) << 8) | CMOS::read(0x15); - word ext_memory = (CMOS::read(0x18) << 8) | CMOS::read(0x17); - - kprintf("%u kB base memory\n", base_memory); - kprintf("%u kB extended memory\n", ext_memory); - auto procfs = ProcFS::create(); procfs->initialize();