From 65566d68683ecbfc2a10b4fb544d5e6f362ae230 Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Mon, 28 Jun 2021 18:43:18 +0200 Subject: [PATCH] Kernel: Make and use KERNEL_BASE This is to make the 0xc0000000 less a magic number, and will make it easier in the future to move the Kernel around --- Kernel/KSyms.cpp | 2 +- Kernel/Process.cpp | 2 +- Kernel/Sections.h | 2 ++ Kernel/VM/MemoryManager.cpp | 2 +- Kernel/VM/MemoryManager.h | 6 +++--- Kernel/VM/PageDirectory.cpp | 4 ++-- Kernel/VM/Region.h | 3 ++- 7 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Kernel/KSyms.cpp b/Kernel/KSyms.cpp index 6e138f6b04..b9c56c1a91 100644 --- a/Kernel/KSyms.cpp +++ b/Kernel/KSyms.cpp @@ -115,7 +115,7 @@ NEVER_INLINE static void dump_backtrace_impl(FlatPtr base_pointer, bool use_ksym if (use_ksyms) { FlatPtr copied_stack_ptr[2]; for (FlatPtr* stack_ptr = (FlatPtr*)base_pointer; stack_ptr && recognized_symbol_count < max_recognized_symbol_count; stack_ptr = (FlatPtr*)copied_stack_ptr[0]) { - if ((FlatPtr)stack_ptr < 0xc0000000) + if ((FlatPtr)stack_ptr < KERNEL_BASE) break; void* fault_at; diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index c49b83cb11..7aaa1e911d 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -340,7 +340,7 @@ void Process::crash(int signal, FlatPtr ip, bool out_of_memory) if (out_of_memory) { dbgln("\033[31;1mOut of memory\033[m, killing: {}", *this); } else { - if (ip >= 0xc0000000 && g_kernel_symbols_available) { + if (ip >= KERNEL_BASE && g_kernel_symbols_available) { auto* symbol = symbolicate_kernel_address(ip); dbgln("\033[31;1m{:p} {} +{}\033[0m\n", ip, (symbol ? demangle(symbol->name) : "(k?)"), (symbol ? ip - symbol->address : 0)); } else { diff --git a/Kernel/Sections.h b/Kernel/Sections.h index 5cd82429eb..b90ec8ffeb 100644 --- a/Kernel/Sections.h +++ b/Kernel/Sections.h @@ -10,3 +10,5 @@ #define READONLY_AFTER_INIT __attribute__((section(".ro_after_init"))) #define UNMAP_AFTER_INIT NEVER_INLINE __attribute__((section(".unmap_after_init"))) + +#define KERNEL_BASE 0xC000'0000 diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index 58b337a9b5..9a26833cd7 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -717,7 +717,7 @@ RefPtr MemoryManager::allocate_supervisor_physical_page() return {}; } - fast_u32_fill((u32*)page->paddr().offset(0xc0000000).as_ptr(), 0, PAGE_SIZE / sizeof(u32)); + fast_u32_fill((u32*)page->paddr().offset(KERNEL_BASE).as_ptr(), 0, PAGE_SIZE / sizeof(u32)); ++m_super_physical_pages_used; return page; } diff --git a/Kernel/VM/MemoryManager.h b/Kernel/VM/MemoryManager.h index 6dd68d5ce7..95ad451d2c 100644 --- a/Kernel/VM/MemoryManager.h +++ b/Kernel/VM/MemoryManager.h @@ -40,12 +40,12 @@ constexpr FlatPtr page_round_down(FlatPtr x) inline FlatPtr low_physical_to_virtual(FlatPtr physical) { - return physical + 0xc0000000; + return physical + KERNEL_BASE; } inline FlatPtr virtual_to_low_physical(FlatPtr virtual_) { - return virtual_ - 0xc0000000; + return virtual_ - KERNEL_BASE; } enum class UsedMemoryRangeType { @@ -260,7 +260,7 @@ void VMObject::for_each_region(Callback callback) inline bool is_user_address(VirtualAddress vaddr) { - return vaddr.get() < 0xc0000000; + return vaddr.get() < KERNEL_BASE; } inline bool is_user_range(VirtualAddress vaddr, size_t size) diff --git a/Kernel/VM/PageDirectory.cpp b/Kernel/VM/PageDirectory.cpp index f584b6ab10..e4b8cd5d45 100644 --- a/Kernel/VM/PageDirectory.cpp +++ b/Kernel/VM/PageDirectory.cpp @@ -37,7 +37,7 @@ extern "C" PageDirectoryEntry boot_pd3[1024]; UNMAP_AFTER_INIT PageDirectory::PageDirectory() { - m_range_allocator.initialize_with_range(VirtualAddress(0xc2000000), 0x2f000000); + m_range_allocator.initialize_with_range(VirtualAddress(KERNEL_BASE + 0x02000000), 0x2f000000); m_identity_range_allocator.initialize_with_range(VirtualAddress(FlatPtr(0x00000000)), 0x00200000); // Adopt the page tables already set up by boot.S @@ -89,7 +89,7 @@ PageDirectory::PageDirectory(const RangeAllocator* parent_range_allocator) m_directory_pages[2] = MM.allocate_user_physical_page(); if (!m_directory_pages[2]) return; - // Share the top 1 GiB of kernel-only mappings (>=3GiB or >=0xc0000000) + // Share the top 1 GiB of kernel-only mappings (>=3GiB or >=KERNEL_BASE) m_directory_pages[3] = MM.kernel_page_directory().m_directory_pages[3]; #if ARCH(X86_64) diff --git a/Kernel/VM/Region.h b/Kernel/VM/Region.h index 2522742f5c..7fe7612a10 100644 --- a/Kernel/VM/Region.h +++ b/Kernel/VM/Region.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -87,7 +88,7 @@ public: void set_mmap(bool mmap) { m_mmap = mmap; } bool is_user() const { return !is_kernel(); } - bool is_kernel() const { return vaddr().get() < 0x00800000 || vaddr().get() >= 0xc0000000; } + bool is_kernel() const { return vaddr().get() < 0x00800000 || vaddr().get() >= KERNEL_BASE; } PageFaultResponse handle_fault(const PageFault&, ScopedSpinLock&);