diff --git a/xtoskrnl/includes/mm/mmgr.hh b/xtoskrnl/includes/mm/mmgr.hh index 97209a9..589dec3 100644 --- a/xtoskrnl/includes/mm/mmgr.hh +++ b/xtoskrnl/includes/mm/mmgr.hh @@ -29,6 +29,7 @@ namespace MM STATIC XTAPI PPHYSICAL_MEMORY_DESCRIPTOR GetPhysicalMemoryBlock(VOID); STATIC XTAPI VOID InitializeMemoryLayout(VOID); STATIC XTAPI VOID InitializeMemoryManager(VOID); + STATIC XTAPI XTSTATUS MapKernelSharedData(VOID); STATIC XTAPI BOOLEAN VerifyMemoryTypeFree(IN LOADER_MEMORY_TYPE MemoryType); STATIC XTAPI BOOLEAN VerifyMemoryTypeInvisible(IN LOADER_MEMORY_TYPE MemoryType); diff --git a/xtoskrnl/ke/amd64/krnlinit.cc b/xtoskrnl/ke/amd64/krnlinit.cc index a245232..e0ad0ff 100644 --- a/xtoskrnl/ke/amd64/krnlinit.cc +++ b/xtoskrnl/ke/amd64/krnlinit.cc @@ -50,11 +50,14 @@ KE::KernelInit::InitializeMachine(VOID) /* Initialize frame buffer */ HL::FrameBuffer::InitializeFrameBuffer(); - /* Initialize processor */ - HL::Cpu::InitializeProcessor(); - /* Initialize page map support */ MM::Paging::InitializePageMapSupport(); + + /* Map Kernel Shared Data (KSD) */ + MM::Manager::MapKernelSharedData(); + + /* Initialize processor */ + HL::Cpu::InitializeProcessor(); } /** diff --git a/xtoskrnl/ke/i686/krnlinit.cc b/xtoskrnl/ke/i686/krnlinit.cc index ad2ba24..ccf7bdd 100644 --- a/xtoskrnl/ke/i686/krnlinit.cc +++ b/xtoskrnl/ke/i686/krnlinit.cc @@ -50,11 +50,14 @@ KE::KernelInit::InitializeMachine(VOID) /* Initialize frame buffer */ HL::FrameBuffer::InitializeFrameBuffer(); - /* Initialize processor */ - HL::Cpu::InitializeProcessor(); - /* Initialize page map support */ MM::Paging::InitializePageMapSupport(); + + /* Map Kernel Shared Data (KSD) */ + MM::Manager::MapKernelSharedData(); + + /* Initialize processor */ + HL::Cpu::InitializeProcessor(); } /** diff --git a/xtoskrnl/mm/mmgr.cc b/xtoskrnl/mm/mmgr.cc index b1bf9eb..4f75947 100644 --- a/xtoskrnl/mm/mmgr.cc +++ b/xtoskrnl/mm/mmgr.cc @@ -282,6 +282,45 @@ MM::Manager::InitializeMemoryManager(VOID) AR::CpuFunc::FlushTlb(); } +/** + * Allocates and maps the Kernel Shared Data page to its hardcoded virtual address. + * + * @return This routine returns status code. + * + * @since XT 1.0 + */ +XTAPI +XTSTATUS +MM::Manager::MapKernelSharedData(VOID) +{ + PHYSICAL_ADDRESS PhysAddr; + PMMPTE PtePointer; + XTSTATUS Status; + + /* Allocate one physical page from the hardware pool for the shared data */ + Status = MM::HardwarePool::AllocateHardwareMemory(1, FALSE, &PhysAddr); + if(Status != STATUS_SUCCESS) + { + /* Memory allocation failed, return error code */ + return Status; + } + + /* Retrieve the Page Table Entry (PTE) corresponding to the KSD virtual address */ + PtePointer = MM::Paging::GetPteAddress((PVOID)MM_KERNEL_SHARED_DATA_ADDRESS); + + /* Manually map the corresponding PTE */ + MM::Paging::SetPte(PtePointer, (PFN_NUMBER)(PhysAddr.QuadPart >> MM_PAGE_SHIFT), MM_PTE_READWRITE); + + /* Flush the Translation Lookaside Buffer (TLB) */ + MM::Paging::FlushTlb(); + + /* Zero the page content */ + RTL::Memory::ZeroMemory((PVOID)MM_KERNEL_SHARED_DATA_ADDRESS, MM_PAGE_SIZE); + + /* Return success */ + return STATUS_SUCCESS; +} + /** * Checks whether the specified memory type should be considered as free. *