From c4798a69b14c78285d013ff45a39c6fa007614ce Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 30 Apr 2023 21:38:20 +0300 Subject: [PATCH] Update code --- Architecture/amd64/linker.ld | 7 ++++--- Architecture/i386/linker.ld | 7 ++++--- Core/Memory/PhysicalMemoryManager.cpp | 8 +++++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Architecture/amd64/linker.ld b/Architecture/amd64/linker.ld index 39ce7db..04aeafe 100644 --- a/Architecture/amd64/linker.ld +++ b/Architecture/amd64/linker.ld @@ -33,11 +33,12 @@ SECTIONS *(.multiboot2) *(.bootstrap .bootstrap.*) } - _bootstrap_end = .; + . += CONSTANT(MAXPAGESIZE); + _bootstrap_end = ALIGN(CONSTANT(MAXPAGESIZE)); . += KERNEL_VMA; - - _kernel_start = .; + . += CONSTANT(MAXPAGESIZE); + _kernel_start = ALIGN(CONSTANT(MAXPAGESIZE)); .text : AT(ADDR(.text) - KERNEL_VMA) { *(.text .text.*) diff --git a/Architecture/i386/linker.ld b/Architecture/i386/linker.ld index 576b36a..2e427dd 100644 --- a/Architecture/i386/linker.ld +++ b/Architecture/i386/linker.ld @@ -33,11 +33,12 @@ SECTIONS *(.multiboot2) *(.bootstrap .bootstrap.*) } - _bootstrap_end = .; + . += CONSTANT(MAXPAGESIZE); + _bootstrap_end = ALIGN(CONSTANT(MAXPAGESIZE)); . += KERNEL_VMA; - - _kernel_start = .; + . += CONSTANT(MAXPAGESIZE); + _kernel_start = ALIGN(CONSTANT(MAXPAGESIZE)); .text : AT(ADDR(.text) - KERNEL_VMA) { *(.text .text.*) diff --git a/Core/Memory/PhysicalMemoryManager.cpp b/Core/Memory/PhysicalMemoryManager.cpp index 1f4704e..15b3d93 100644 --- a/Core/Memory/PhysicalMemoryManager.cpp +++ b/Core/Memory/PhysicalMemoryManager.cpp @@ -24,6 +24,8 @@ #include "../../kernel.h" +extern "C" char BootPageTable[]; // 0x10000 in length + namespace Memory { uint64_t Physical::GetTotalMemory() @@ -450,7 +452,7 @@ namespace Memory for (uint64_t i = 0; i < Info->Memory.Entries; i++) { - if (Info->Memory.Entry[i].Type == Usable) + if (Info->Memory.Entry[i].Type == Usable && Info->Memory.Entry[i].BaseAddress != 0x0) this->UnreservePages(Info->Memory.Entry[i].BaseAddress, TO_PAGES(Info->Memory.Entry[i].Length)); } @@ -460,6 +462,10 @@ namespace Memory debug("Reserving bitmap pages..."); this->ReservePages(PageBitmap.Buffer, TO_PAGES(PageBitmap.Size)); + debug("Reserving kernel..."); + this->ReservePages(BootPageTable, TO_PAGES(0x10000)); + this->ReservePages(&_bootstrap_start, TO_PAGES((uintptr_t)&_bootstrap_end - (uintptr_t)&_bootstrap_start)); + this->ReservePages(&_kernel_start, TO_PAGES((uintptr_t)&_kernel_end - (uintptr_t)&_kernel_start)); } Physical::Physical() {}