[BOOTMGFW]

- Begin carving out the rough edges of the memory manager. This will be the hardest part.

svn path=/trunk/; revision=69044
This commit is contained in:
Alex Ionescu 2015-09-06 03:24:30 +00:00
parent 6073e89f6b
commit 110b26a50d
10 changed files with 338 additions and 11 deletions

View file

@ -12,7 +12,12 @@ list(APPEND BOOTLIB_SOURCE
lib/bootlib.c
lib/misc/bcd.c
lib/misc/util.c
lib/firmware/efi/firmware.c)
lib/firmware/efi/firmware.c
lib/mm/mm.c
lib/mm/pagealloc.c
lib/mm/heapalloc.c
lib/mm/blkalloc.c
lib/mm/descriptor.c)
if(ARCH STREQUAL "i386")
list(APPEND BOOTLIB_ASM_SOURCE
@ -20,6 +25,7 @@ if(ARCH STREQUAL "i386")
)
list(APPEND BOOTLIB_SOURCE
lib/arch/i386/arch.c
lib/mm/i386/mmx86.c
)
elseif(ARCH STREQUAL "amd64")
list(APPEND BOOTLIB_ASM_SOURCE

View file

@ -1,9 +1,9 @@
/*
* COPYRIGHT: See COPYING.ARM in the top level directory
* PROJECT: ReactOS UEFI Boot Library
* FILE: boot/environ/include/bl.h
* PURPOSE: Main Boot Library Header
* PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
* COPYRIGHT: See COPYING.ARM in the top level directory
* PROJECT: ReactOS UEFI Boot Library
* FILE: boot/environ/include/bl.h
* PURPOSE: Main Boot Library Header
* PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
*/
#ifndef _BL_H
@ -401,6 +401,13 @@ BlpFwInitialize (
_In_ PBL_FIRMWARE_DESCRIPTOR FirmwareParameters
);
NTSTATUS
BlpMmInitialize (
_In_ PBL_MEMORY_DATA MemoryData,
_In_ BL_TRANSLATION_TYPE TranslationType,
_In_ PBL_LIBRARY_PARAMETERS LibraryParameters
);
/* UTILITY ROUTINES **********************************************************/
EFI_STATUS
@ -427,6 +434,39 @@ BlpArchSwitchContext (
_In_ BL_ARCH_MODE NewMode
);
/* MEMORY MANAGER ROUTINES ***************************************************/
NTSTATUS
MmBaInitialize (
VOID
);
NTSTATUS
MmPaInitialize (
_In_ PBL_MEMORY_DATA MemoryData,
_In_ ULONG MinimumPages
);
NTSTATUS
MmArchInitialize (
_In_ ULONG Phase,
_In_ PBL_MEMORY_DATA MemoryData,
_In_ BL_TRANSLATION_TYPE TranslationType,
_In_ BL_TRANSLATION_TYPE LibraryTranslationType
);
NTSTATUS
MmHaInitialize (
_In_ ULONG HeapSize,
_In_ ULONG HeapAttributes
);
NTSTATUS
MmMdInitialize (
_In_ ULONG Phase,
_In_ PBL_LIBRARY_PARAMETERS LibraryParameters
);
extern ULONG BlpApplicationFlags;
extern BL_LIBRARY_PARAMETERS BlpLibraryParameters;
extern BL_TRANSLATION_TYPE MmTranslationType;

View file

@ -19,9 +19,6 @@ PBOOT_APPLICATION_PARAMETER_BLOCK BlpApplicationParameters;
BL_APPLICATION_ENTRY BlpApplicationEntry;
BOOLEAN BlpLibraryParametersInitialized;
/* temp */
BL_TRANSLATION_TYPE MmTranslationType;
/* FUNCTIONS *****************************************************************/
/* HACKKKYYY */
@ -68,7 +65,7 @@ InitializeLibrary (
)
{
NTSTATUS Status;
//PBL_MEMORY_DATA MemoryData;
PBL_MEMORY_DATA MemoryData;
PBL_APPLICATION_ENTRY AppEntry;
PBL_FIRMWARE_DESCRIPTOR FirmwareDescriptor;
ULONG_PTR ParamPointer = (ULONG_PTR)BootAppParameters;
@ -84,7 +81,7 @@ InitializeLibrary (
}
/* Get sub-structures */
//MemoryData = (PBL_MEMORY_DATA)(ParamPointer + BootAppParameters->MemoryDataOffset);
MemoryData = (PBL_MEMORY_DATA)(ParamPointer + BootAppParameters->MemoryDataOffset);
FirmwareDescriptor = (PBL_FIRMWARE_DESCRIPTOR)(ParamPointer + BootAppParameters->FirmwareParametersOffset);
AppEntry = (PBL_APPLICATION_ENTRY)(ParamPointer + BootAppParameters->AppEntryOffset);
BlpBootDevice = (PBL_DEVICE_DESCRIPTOR)(ParamPointer + BootAppParameters->BootDeviceOffset);
@ -125,6 +122,16 @@ InitializeLibrary (
goto Quickie;
}
/* Initialize the memory manager */
Status = BlpMmInitialize(MemoryData,
BootAppParameters->MemoryTranslationType,
LibraryParameters);
if (!NT_SUCCESS(Status))
{
EarlyPrint(L"MM init failed!\n");
goto Quickie;
}
EarlyPrint(L"TODO!\n");
Status = STATUS_NOT_IMPLEMENTED;

View file

@ -0,0 +1,24 @@
/*
* COPYRIGHT: See COPYING.ARM in the top level directory
* PROJECT: ReactOS UEFI Boot Library
* FILE: boot/environ/lib/mm/blkalloc.c
* PURPOSE: Boot Library Memory Manager Block Allocator
* PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include "bl.h"
/* DATA VARIABLES ************************************************************/
/* FUNCTIONS *****************************************************************/
NTSTATUS
MmBaInitialize (
VOID
)
{
return STATUS_NOT_IMPLEMENTED;
}

View file

@ -0,0 +1,26 @@
/*
* COPYRIGHT: See COPYING.ARM in the top level directory
* PROJECT: ReactOS UEFI Boot Library
* FILE: boot/environ/lib/mm/descriptor.c
* PURPOSE: Boot Library Memory Manager Descriptor Manager
* PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include "bl.h"
/* DATA VARIABLES ************************************************************/
/* FUNCTIONS *****************************************************************/
NTSTATUS
MmMdInitialize (
_In_ ULONG Phase,
_In_ PBL_LIBRARY_PARAMETERS LibraryParameters
)
{
EarlyPrint(L"Md init\n");
return STATUS_NOT_IMPLEMENTED;
}

View file

@ -0,0 +1,25 @@
/*
* COPYRIGHT: See COPYING.ARM in the top level directory
* PROJECT: ReactOS UEFI Boot Library
* FILE: boot/environ/lib/mm/heapalloc.c
* PURPOSE: Boot Library Memory Manager Heap Allocator
* PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include "bl.h"
/* DATA VARIABLES ************************************************************/
/* FUNCTIONS *****************************************************************/
NTSTATUS
MmHaInitialize (
_In_ ULONG HeapSize,
_In_ ULONG HeapAttributes
)
{
return STATUS_NOT_IMPLEMENTED;
}

View file

@ -0,0 +1,26 @@
/*
* COPYRIGHT: See COPYING.ARM in the top level directory
* PROJECT: ReactOS UEFI Boot Library
* FILE: boot/environ/lib/mm/i386/mmx86.c
* PURPOSE: Boot Library Memory Manager x86-Specific Code
* PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include "bl.h"
/* DATA VARIABLES ************************************************************/
/* FUNCTIONS *****************************************************************/
NTSTATUS
MmArchInitialize (
_In_ ULONG Phase,
_In_ PBL_MEMORY_DATA MemoryData,
_In_ BL_TRANSLATION_TYPE TranslationType,
_In_ BL_TRANSLATION_TYPE LibraryTranslationType
)
{
return STATUS_NOT_IMPLEMENTED;
}

View file

@ -0,0 +1,148 @@
/*
* COPYRIGHT: See COPYING.ARM in the top level directory
* PROJECT: ReactOS UEFI Boot Library
* FILE: boot/environ/lib/mm/mm.c
* PURPOSE: Boot Library Memory Manager Core
* PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include "bl.h"
/* DATA VARIABLES ************************************************************/
BL_TRANSLATION_TYPE MmTranslationType, MmOriginalTranslationType;
ULONG MmDescriptorCallTreeCount;
/* FUNCTIONS *****************************************************************/
NTSTATUS
MmTrInitialize (
VOID
)
{
return STATUS_NOT_IMPLEMENTED;
}
NTSTATUS
BlMmRemoveBadMemory (
VOID
)
{
return STATUS_NOT_IMPLEMENTED;
}
NTSTATUS
BlpMmInitialize (
_In_ PBL_MEMORY_DATA MemoryData,
_In_ BL_TRANSLATION_TYPE TranslationType,
_In_ PBL_LIBRARY_PARAMETERS LibraryParameters
)
{
NTSTATUS Status;
/* Take a reference */
MmDescriptorCallTreeCount = 1;
/* Only support valid translation types */
if ((TranslationType > BlPae) || (LibraryParameters->TranslationType > BlPae))
{
/* Bail out */
EarlyPrint(L"Invalid translation types present\n");
Status = STATUS_INVALID_PARAMETER;
goto Quickie;
}
/* Initialize memory descriptors */
MmMdInitialize(0, LibraryParameters);
/* Remember the page type we came in with */
MmOriginalTranslationType = TranslationType;
/* Initialize the physical page allocator */
Status = MmPaInitialize(MemoryData,
LibraryParameters->MinimumAllocationCount);
if (!NT_SUCCESS(Status))
{
goto Quickie;
}
/* Initialize the memory tracker */
Status = MmTrInitialize();
if (!NT_SUCCESS(Status))
{
//MmArchDestroy();
//MmPaDestroy(1);
goto Quickie;
}
/* Initialize paging, large pages, self-mapping, PAE, if needed */
Status = MmArchInitialize(1,
MemoryData,
TranslationType,
LibraryParameters->TranslationType);
if (NT_SUCCESS(Status))
{
/* Save the newly active transation type */
MmTranslationType = LibraryParameters->TranslationType;
/* Initialize the heap allocator now */
Status = MmHaInitialize(LibraryParameters->MinimumHeapSize,
LibraryParameters->HeapAllocationAttributes);
}
/* If Phase 1 init failed, bail out */
if (!NT_SUCCESS(Status))
{
/* Kill everything set setup so far */
//MmPaDestroy(0);
//MmTrDestroy();
//MmArchDestroy();
//MmPaDestroy(1);
goto Quickie;
}
/* Do we have too many descriptors? */
if (LibraryParameters->DescriptorCount > 512)
{
/* Switch to using a dynamic buffer instead */
//MmMdpSwitchToDynamicDescriptors(LibraryParameters->DescriptorCount);
}
/* Remove memory that the BCD says is bad */
BlMmRemoveBadMemory();
/* Now map all the memory regions as needed */
Status = MmArchInitialize(2,
MemoryData,
TranslationType,
LibraryParameters->TranslationType);
if (NT_SUCCESS(Status))
{
/* Initialize the block allocator */
Status = MmBaInitialize();
}
/* Check if anything in phase 2 failed */
if (!NT_SUCCESS(Status))
{
/* Go back to static descriptors and kill the heap */
//MmMdpSwitchToStaticDescriptors();
//HapInitializationStatus = 0;
++MmDescriptorCallTreeCount;
/* Destroy the Phase 1 initialization */
//MmPaDestroy(0);
//MmTrDestroy();
//MmArchDestroy();
//MmPaDestroy(1);
}
Quickie:
/* Free the memory descriptors and return the initialization state */
//MmMdFreeGlobalDescriptors();
--MmDescriptorCallTreeCount;
return Status;
}

View file

@ -0,0 +1,25 @@
/*
* COPYRIGHT: See COPYING.ARM in the top level directory
* PROJECT: ReactOS UEFI Boot Library
* FILE: boot/environ/lib/mm/pagealloc.c
* PURPOSE: Boot Library Memory Manager Page Allocator
* PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include "bl.h"
/* DATA VARIABLES ************************************************************/
/* FUNCTIONS *****************************************************************/
NTSTATUS
MmPaInitialize (
_In_ PBL_MEMORY_DATA MemoryData,
_In_ ULONG MinimumPages
)
{
return STATUS_NOT_IMPLEMENTED;
}