Introduce kernel virtual memory layout
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
* FILE: sdk/xtdk/mmtypes.h
|
||||
* DESCRIPTION: Memory management data structures
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
* Aiken Harris <harraiken91@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef __XTDK_MMTYPES_H
|
||||
@@ -51,6 +52,17 @@ typedef struct _MMCOLOR_TABLES
|
||||
ULONG_PTR Count;
|
||||
} MMCOLOR_TABLES, *PMMCOLOR_TABLES;
|
||||
|
||||
/* Memory layout structure definition */
|
||||
typedef struct _MMMEMORY_LAYOUT
|
||||
{
|
||||
PMMPFN PfnDatabaseAddress;
|
||||
PVOID SelfMapAddress;
|
||||
PVOID NonPagedPoolStart;
|
||||
PVOID NonPagedPoolEnd;
|
||||
PVOID PagedPoolStart;
|
||||
PVOID PagedPoolEnd;
|
||||
} MMMEMORY_LAYOUT, *PMMMEMORY_LAYOUT;
|
||||
|
||||
/* Page Frame Entry structure definition */
|
||||
typedef struct _MMPFNENTRY
|
||||
{
|
||||
|
||||
@@ -276,6 +276,7 @@ typedef struct _LOADER_INFORMATION_BLOCK LOADER_INFORMATION_BLOCK, *PLOADER_INFO
|
||||
typedef struct _LOADER_MEMORY_DESCRIPTOR LOADER_MEMORY_DESCRIPTOR, *PLOADER_MEMORY_DESCRIPTOR;
|
||||
typedef struct _M128 M128, *PM128;
|
||||
typedef struct _MMCOLOR_TABLES MMCOLOR_TABLES, *PMMCOLOR_TABLES;
|
||||
typedef struct _MMMEMORY_LAYOUT MMMEMORY_LAYOUT, *PMMMEMORY_LAYOUT;
|
||||
typedef struct _MMPFNENTRY MMPFNENTRY, *PMMPFNENTRY;
|
||||
typedef struct _MMPFNLIST MMPFNLIST, *PMMPFNLIST;
|
||||
typedef struct _PCAT_FIRMWARE_INFORMATION PCAT_FIRMWARE_INFORMATION, *PPCAT_FIRMWARE_INFORMATION;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtoskrnl/includes/mm/mmgr.hh
|
||||
* DESCRIPTION: Memory Manager
|
||||
* DESCRIPTION: Memory manager
|
||||
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
|
||||
*/
|
||||
|
||||
@@ -17,7 +17,12 @@ namespace MM
|
||||
{
|
||||
class Manager
|
||||
{
|
||||
private:
|
||||
STATIC MMMEMORY_LAYOUT MemoryLayout;
|
||||
|
||||
public:
|
||||
STATIC XTAPI PMMMEMORY_LAYOUT GetMemoryLayout(VOID);
|
||||
STATIC XTAPI VOID InitializeMemoryLayout(VOID);
|
||||
STATIC XTAPI VOID InitializeMemoryManager(VOID);
|
||||
STATIC XTAPI BOOLEAN VerifyMemoryTypeFree(LOADER_MEMORY_TYPE MemoryType);
|
||||
STATIC XTAPI BOOLEAN VerifyMemoryTypeInvisible(LOADER_MEMORY_TYPE MemoryType);
|
||||
|
||||
@@ -10,6 +10,64 @@
|
||||
#include <xtos.hh>
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves a pointer to the system's virtual memory layout structure.
|
||||
*
|
||||
* @return This routine returns a pointer to the memory layout structure.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
PMMMEMORY_LAYOUT
|
||||
MM::Manager::GetMemoryLayout(VOID)
|
||||
{
|
||||
/* Return a pointer to the global memory layout structure */
|
||||
return &MemoryLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the kernel's virtual memory layout.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
MM::Manager::InitializeMemoryLayout(VOID)
|
||||
{
|
||||
ULONG_PTR PagedPoolSize, PteCount;
|
||||
PFN_NUMBER PfnDatabaseSize;
|
||||
|
||||
/* Calculate size of paged pool (at least 32MiB) */
|
||||
PteCount = ((SIZE_TO_PAGES(33554432) + (MM_PTE_PER_PAGE - 1)) / MM_PTE_PER_PAGE);
|
||||
PagedPoolSize = PteCount * MM_PTE_PER_PAGE * MM_PAGE_SIZE;
|
||||
|
||||
/* Retrieve the PFN database size */
|
||||
PfnDatabaseSize = MM::Pfn::GetPfnDatabaseSize();
|
||||
|
||||
if(MM::Paging::GetXpaStatus())
|
||||
{
|
||||
MemoryLayout.PfnDatabaseAddress = (PMMPFN)0xFFFEFA8000000000ULL;
|
||||
MemoryLayout.SelfMapAddress = (PVOID)0xFFEDF6FB7DBEDF68ULL;
|
||||
|
||||
MemoryLayout.NonPagedPoolStart = (PVOID)((ULONG_PTR)MemoryLayout.PfnDatabaseAddress + PfnDatabaseSize * MM_PAGE_SIZE);
|
||||
MemoryLayout.NonPagedPoolEnd = (PVOID)0xFFFEFFFFFFBFFFFFULL;
|
||||
MemoryLayout.PagedPoolStart = (PVOID)0xFFFEF8A000000000ULL;
|
||||
MemoryLayout.PagedPoolEnd = (PVOID)(((ULONG_PTR)MemoryLayout.PagedPoolStart + PagedPoolSize) - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
MemoryLayout.PfnDatabaseAddress = (PMMPFN)0xFFFFFA8000000000ULL;
|
||||
MemoryLayout.SelfMapAddress = (PVOID)0xFFFFF6FB7DBEDF68ULL;
|
||||
|
||||
MemoryLayout.NonPagedPoolStart = (PVOID)((ULONG_PTR)MemoryLayout.PfnDatabaseAddress + PfnDatabaseSize * MM_PAGE_SIZE);
|
||||
MemoryLayout.NonPagedPoolEnd = (PVOID)0xFFFFFFFFFFBFFFFFULL;
|
||||
MemoryLayout.PagedPoolStart = (PVOID)0xFFFFF8A000000000ULL;
|
||||
MemoryLayout.PagedPoolEnd = (PVOID)(((ULONG_PTR)MemoryLayout.PagedPoolStart + PagedPoolSize) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs an early initialization of the XTOS Memory Manager.
|
||||
*
|
||||
@@ -34,6 +92,9 @@ MM::Manager::InitializeMemoryManager(VOID)
|
||||
|
||||
/* Compute allocation size for the PFN database */
|
||||
MM::Pfn::ComputePfnDatabaseSize();
|
||||
|
||||
/* Initialize memory layout */
|
||||
InitializeMemoryLayout();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user