diff --git a/reactos/boot/environ/CMakeLists.txt b/reactos/boot/environ/CMakeLists.txt index a88f65cfcaf..bd42217b078 100644 --- a/reactos/boot/environ/CMakeLists.txt +++ b/reactos/boot/environ/CMakeLists.txt @@ -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 diff --git a/reactos/boot/environ/include/bl.h b/reactos/boot/environ/include/bl.h index bf61e0a8cdf..7d2c93ad93f 100644 --- a/reactos/boot/environ/include/bl.h +++ b/reactos/boot/environ/include/bl.h @@ -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; diff --git a/reactos/boot/environ/lib/bootlib.c b/reactos/boot/environ/lib/bootlib.c index da676ffb9a4..e0be4dca872 100644 --- a/reactos/boot/environ/lib/bootlib.c +++ b/reactos/boot/environ/lib/bootlib.c @@ -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; diff --git a/reactos/boot/environ/lib/mm/blkalloc.c b/reactos/boot/environ/lib/mm/blkalloc.c new file mode 100644 index 00000000000..c586979ce8a --- /dev/null +++ b/reactos/boot/environ/lib/mm/blkalloc.c @@ -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; +} diff --git a/reactos/boot/environ/lib/mm/descriptor.c b/reactos/boot/environ/lib/mm/descriptor.c new file mode 100644 index 00000000000..061606918f5 --- /dev/null +++ b/reactos/boot/environ/lib/mm/descriptor.c @@ -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; +} diff --git a/reactos/boot/environ/lib/mm/foo.c b/reactos/boot/environ/lib/mm/foo.c deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/reactos/boot/environ/lib/mm/heapalloc.c b/reactos/boot/environ/lib/mm/heapalloc.c new file mode 100644 index 00000000000..fe55cf7b61f --- /dev/null +++ b/reactos/boot/environ/lib/mm/heapalloc.c @@ -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; +} diff --git a/reactos/boot/environ/lib/mm/i386/mmx86.c b/reactos/boot/environ/lib/mm/i386/mmx86.c new file mode 100644 index 00000000000..9df43a8e8f4 --- /dev/null +++ b/reactos/boot/environ/lib/mm/i386/mmx86.c @@ -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; +} diff --git a/reactos/boot/environ/lib/mm/mm.c b/reactos/boot/environ/lib/mm/mm.c new file mode 100644 index 00000000000..0c475523c62 --- /dev/null +++ b/reactos/boot/environ/lib/mm/mm.c @@ -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; +} diff --git a/reactos/boot/environ/lib/mm/pagealloc.c b/reactos/boot/environ/lib/mm/pagealloc.c new file mode 100644 index 00000000000..e2f0cad8dbb --- /dev/null +++ b/reactos/boot/environ/lib/mm/pagealloc.c @@ -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; +}