From 24a31cab26e498c37a80089ffc280ba9b27fd0bf Mon Sep 17 00:00:00 2001 From: Kaimakan71 Date: Sat, 5 Oct 2024 15:44:25 -0400 Subject: [PATCH] [BOOT] Execution contexts and more refactoring --- BOOT/ENVIRON/APP/BOOTMGR/EFI/efientry.c | 5 +- BOOT/ENVIRON/APP/BOOTMGR/bootmgr.c | 10 ++ BOOT/ENVIRON/INC/bootlib.h | 114 +++++++++++++------- BOOT/ENVIRON/INC/mm.h | 8 ++ BOOT/ENVIRON/LIB/EFI/eficon.c | 12 +++ BOOT/ENVIRON/LIB/EFI/efifw.c | 15 ++- BOOT/ENVIRON/LIB/EFI/efiinit.c | 12 +-- BOOT/ENVIRON/LIB/EFI/efimm.c | 83 +++++++++++---- BOOT/ENVIRON/LIB/MM/mm.c | 6 +- BOOT/ENVIRON/LIB/MM/mmmd.c | 132 ++++++++++++++++++------ BOOT/ENVIRON/LIB/MM/mmpa.c | 18 ++-- BOOT/ENVIRON/LIB/bootlib.c | 9 +- BOOT/ENVIRON/README.md | 11 +- 13 files changed, 317 insertions(+), 118 deletions(-) diff --git a/BOOT/ENVIRON/APP/BOOTMGR/EFI/efientry.c b/BOOT/ENVIRON/APP/BOOTMGR/EFI/efientry.c index 769ab76..a978d65 100644 --- a/BOOT/ENVIRON/APP/BOOTMGR/EFI/efientry.c +++ b/BOOT/ENVIRON/APP/BOOTMGR/EFI/efientry.c @@ -37,8 +37,9 @@ Arguments: Return Value: + EFI_SUCCESS if successful. EFI_INVALID_PARAMETER if EfiInitCreateInputParameters() fails. - Any status code returned by EfiGetEfiStatusCode(BmMain()). + Any other error code if BmMain() fails. --*/ @@ -54,7 +55,7 @@ Return Value: } // - // Transfer control to the firmware-independent boot manager. + // Transfer control to the firmware-independent boot manager code. // return EfiGetEfiStatusCode(BmMain(InputParameters)); } diff --git a/BOOT/ENVIRON/APP/BOOTMGR/bootmgr.c b/BOOT/ENVIRON/APP/BOOTMGR/bootmgr.c index 7510145..a5eafd2 100644 --- a/BOOT/ENVIRON/APP/BOOTMGR/bootmgr.c +++ b/BOOT/ENVIRON/APP/BOOTMGR/bootmgr.c @@ -60,6 +60,16 @@ Return Value: // (VOID)BmOpenDataStore(&DataStoreHandle); + // + // Stop here for now. + // Later this will be used to wait for input. + // + while (TRUE) { +#if defined(__x86_64__) || defined(__i386__) + asm volatile("hlt"); +#endif + } + Exit: BlDestroyLibrary(); return Status; diff --git a/BOOT/ENVIRON/INC/bootlib.h b/BOOT/ENVIRON/INC/bootlib.h index 2ff7501..d152ede 100644 --- a/BOOT/ENVIRON/INC/bootlib.h +++ b/BOOT/ENVIRON/INC/bootlib.h @@ -25,6 +25,12 @@ Abstract: #define PAGE_SHIFT EFI_PAGE_SHIFT #endif /* _EFI */ +// +// Address translation types. +// +#define TRANSLATION_TYPE_NONE 0 +#define TRANSLATION_TYPE_MAX 1 + // // Set machine type. // @@ -34,11 +40,48 @@ Abstract: #define BOOT_MACHINE_TYPE IMAGE_FILE_MACHINE_I386 #endif +#if defined(__i386__) || defined(__x86_64__) +typedef struct __attribute__((packed)) { + USHORT Limit; + ULONG_PTR Base; +} DESCRIPTOR_TABLE_REGISTER, *PDESCRIPTOR_TABLE_REGISTER; + +typedef struct __attribute__((packed)) { + DESCRIPTOR_TABLE_REGISTER Gdt; + DESCRIPTOR_TABLE_REGISTER Idt; + USHORT LdtSelector; + USHORT CS, DS, ES, FS, GS, SS; +} DESCRIPTOR_TABLE_CONTEXT, *PDESCRIPTOR_TABLE_CONTEXT; +#endif + // -// Address translation types. +// Firmware platform flags. // -#define TRANSLATION_TYPE_NONE 0 -#define TRANSLATION_TYPE_MAX 1 + +#define FIRMWARE_FLAG_EXECUTION_CONTEXT_SUPPORTED 0x00100000 + +// +// Execution contexts represent the current state +// of the processor/system. +// + +typedef enum { + ExecutionContextApplication, + ExecutionContextFirmware, + ExecutionContextMax +} EXECUTION_CONTEXT_TYPE; + +#define EXECUTION_CONTEXT_INTERRUPTS_ENABLED 0x02 +#define EXECUTION_CONTEXT_PAGING_ENABLED 0x04 + +typedef struct { + EXECUTION_CONTEXT_TYPE Type; +#if defined(__i386__) || defined(__x86_64__) + ULONG_PTR Cr3; +#endif + ULONG Flags; + DESCRIPTOR_TABLE_CONTEXT DescriptorTableContext; +} EXECUTION_CONTEXT, *PEXECUTION_CONTEXT; // // Application entry option. @@ -181,6 +224,11 @@ typedef struct { ULONG Reserved; EFI_HANDLE ImageHandle; EFI_SYSTEM_TABLE *SystemTable; + ULONG Reserved2; +#if defined(__i386__) || defined(__x86_64__) + ULONG_PTR Cr3; +#endif + DESCRIPTOR_TABLE_CONTEXT DescriptorTableContext; } BOOT_FIRMWARE_DATA, *PBOOT_FIRMWARE_DATA; #define BOOT_RETURN_DATA_VERSION 1 @@ -191,28 +239,6 @@ typedef struct { ULONG Flags; } BOOT_RETURN_DATA, *PBOOT_RETURN_DATA; -#if defined(__i386__) || defined(__x86_64__) -typedef struct __attribute__((packed)) { - USHORT Limit; - ULONG_PTR Base; -} DESCRIPTOR_TABLE_REGISTER, *PDESCRIPTOR_TABLE_REGISTER; - -typedef struct { - DESCRIPTOR_TABLE_REGISTER Gdt; - DESCRIPTOR_TABLE_REGISTER Idt; - USHORT LdtSelector; - USHORT CS, DS, ES, FS, GS, SS; -} DESCRIPTOR_TABLE_CONTEXT, *PDESCRIPTOR_TABLE_CONTEXT; -#endif - -typedef struct { - ULONG Reserved; -#if defined(__i386__) || defined(__x86_64__) - ULONG_PTR CR3; -#endif - DESCRIPTOR_TABLE_CONTEXT DescriptorTableContext; -} BOOT_PLATFORM_DATA, *PBOOT_PLATFORM_DATA; - // // Firmware-independent application parameters. // Passed to any boot application's entry point. @@ -376,17 +402,6 @@ typedef struct { BOOT_DEVICE Device; } BCDE_DEVICE, *PBCDE_DEVICE; -VOID -ConsolePrint ( - IN PWSTR String - ); - -VOID -ConsolePrintf ( - IN PWSTR Format, - ... - ); - // // Enable/disable debug printing. // @@ -398,11 +413,38 @@ ConsolePrintf ( #define DebugPrintf(Format, ...) #endif +extern PEXECUTION_CONTEXT CurrentExecutionContext; + +VOID +ConsolePrint ( + IN PWSTR String + ); + +VOID +ConsolePrintf ( + IN PWSTR Format, + ... + ); + VOID BlpArchGetDescriptorTableContext ( PDESCRIPTOR_TABLE_CONTEXT Context ); +BOOLEAN +BlArchIsFiveLevelPagingActive ( + ); + +VOID +BlpArchSwitchContext ( + IN EXECUTION_CONTEXT_TYPE Type + ); + +NTSTATUS +BlpArchInitialize ( + IN ULONG Stage + ); + NTSTATUS BlpFwInitialize ( IN ULONG Stage, diff --git a/BOOT/ENVIRON/INC/mm.h b/BOOT/ENVIRON/INC/mm.h index fea0b92..519b1c9 100644 --- a/BOOT/ENVIRON/INC/mm.h +++ b/BOOT/ENVIRON/INC/mm.h @@ -70,6 +70,14 @@ MmMdRemoveRegionFromMdlEx ( OUT PMEMORY_DESCRIPTOR_LIST Unused ); +NTSTATUS +MmMdRemoveRegionFromMdl ( + IN PMEMORY_DESCRIPTOR_LIST Mdl, + IN ULONGLONG RemoveStart, + IN ULONGLONG PageCount, + IN ULONG Flags + ); + NTSTATUS MmMdFreeDescriptor ( IN PMEMORY_DESCRIPTOR Descriptor diff --git a/BOOT/ENVIRON/LIB/EFI/eficon.c b/BOOT/ENVIRON/LIB/EFI/eficon.c index 440d8d2..c90305a 100644 --- a/BOOT/ENVIRON/LIB/EFI/eficon.c +++ b/BOOT/ENVIRON/LIB/EFI/eficon.c @@ -17,6 +17,7 @@ Abstract: #include #include "bootlib.h" +extern PEXECUTION_CONTEXT CurrentExecutionContext; extern SIMPLE_TEXT_OUTPUT_INTERFACE *EfiConOut; VOID @@ -41,7 +42,18 @@ Return Value: --*/ { + EXECUTION_CONTEXT_TYPE ContextType; + + ContextType = CurrentExecutionContext->Type; + if (ContextType != ExecutionContextFirmware) { + BlpArchSwitchContext(ExecutionContextFirmware); + } + EfiConOut->OutputString(EfiConOut, String); + + if (ContextType != ExecutionContextFirmware) { + BlpArchSwitchContext(ContextType); + } } VOID diff --git a/BOOT/ENVIRON/LIB/EFI/efifw.c b/BOOT/ENVIRON/LIB/EFI/efifw.c index 7b497b8..9dfc0df 100644 --- a/BOOT/ENVIRON/LIB/EFI/efifw.c +++ b/BOOT/ENVIRON/LIB/EFI/efifw.c @@ -13,9 +13,12 @@ Abstract: --*/ +#include #include "bootlib.h" #include "efi.h" +BOOT_FIRMWARE_DATA EfiFirmwareData; +PBOOT_FIRMWARE_DATA EfiFirmwareParameters; EFI_SYSTEM_TABLE *EfiST; EFI_BOOT_SERVICES *EfiBS; EFI_RUNTIME_SERVICES *EfiRT; @@ -36,7 +39,10 @@ Routine Description: Arguments: - Stage - 0 or 1. + Stage - Which stage of initialization to perform. + + Stage 0: Initialize global firmware-related data and pointers. + Once this stage is complete, ConsolePrint() and ConsolePrintf() can be used. FirmwareData - Pointer to BOOT_FIRMWARE_DATA. @@ -53,6 +59,9 @@ Return Value: } if (Stage == 0) { + RtlCopyMemory(&EfiFirmwareData, FirmwareData, sizeof(BOOT_FIRMWARE_DATA)); + EfiFirmwareParameters = &EfiFirmwareData; + EfiST = FirmwareData->SystemTable; EfiBS = EfiST->BootServices; EfiRT = EfiST->RuntimeServices; @@ -60,5 +69,9 @@ Return Value: EfiConIn = EfiST->ConIn; } + // + // TODO: Implement stage 1 initialization. + // + return STATUS_SUCCESS; } diff --git a/BOOT/ENVIRON/LIB/EFI/efiinit.c b/BOOT/ENVIRON/LIB/EFI/efiinit.c index 7cae2e6..cf9c506 100644 --- a/BOOT/ENVIRON/LIB/EFI/efiinit.c +++ b/BOOT/ENVIRON/LIB/EFI/efiinit.c @@ -615,7 +615,6 @@ Return Value: PMEMORY_DESCRIPTOR MemoryDescriptor; PBOOT_DEVICE BootDevice; PBOOT_FIRMWARE_DATA FirmwareData; - PBOOT_PLATFORM_DATA PlatformData; PBOOT_RETURN_DATA ReturnData; ScratchUsed = 0; @@ -697,19 +696,14 @@ Return Value: InputParameters->FirmwareDataOffset = ScratchUsed; FirmwareData = (PBOOT_FIRMWARE_DATA)(&EfiInitScratch[ScratchUsed]); ScratchUsed += sizeof(BOOT_FIRMWARE_DATA); + RtlZeroMemory(FirmwareData, sizeof(BOOT_FIRMWARE_DATA)); FirmwareData->Version = BOOT_FIRMWARE_DATA_VERSION; - FirmwareData->Reserved = 0; FirmwareData->ImageHandle = ImageHandle; FirmwareData->SystemTable = SystemTable; - - InputParameters->PlatformDataOffset = ScratchUsed; - PlatformData = (PBOOT_PLATFORM_DATA)(&EfiInitScratch[ScratchUsed]); - ScratchUsed += sizeof(BOOT_PLATFORM_DATA); - PlatformData->Reserved = 0; #if defined(__i386__) || defined(__x86_64__) - asm volatile("mov %%cr3, %0" :"=r"(PlatformData->CR3)); + asm volatile("mov %%cr3, %0" :"=r"(FirmwareData->Cr3)); #endif - BlpArchGetDescriptorTableContext(&PlatformData->DescriptorTableContext); + BlpArchGetDescriptorTableContext(&FirmwareData->DescriptorTableContext); InputParameters->ReturnDataOffset = ScratchUsed; ReturnData = (PBOOT_RETURN_DATA)(&EfiInitScratch[ScratchUsed]); diff --git a/BOOT/ENVIRON/LIB/EFI/efimm.c b/BOOT/ENVIRON/LIB/EFI/efimm.c index 3119480..ff6f86d 100644 --- a/BOOT/ENVIRON/LIB/EFI/efimm.c +++ b/BOOT/ENVIRON/LIB/EFI/efimm.c @@ -62,15 +62,32 @@ Return Value: --*/ { - return EfiGetNtStatusCode( - EfiBS->GetMemoryMap( - MemoryMapSize, - MemoryMap, - MapKey, - DescriptorSize, - DescriptorVersion - ) + EXECUTION_CONTEXT_TYPE ContextType; + EFI_STATUS EfiStatus; + + ContextType = CurrentExecutionContext->Type; + if (ContextType != ExecutionContextFirmware) { + // + // TODO: Translate addresses here. + // Need MmArchTranslateVirtualAddress(). + // + + BlpArchSwitchContext(ExecutionContextFirmware); + } + + EfiStatus = EfiBS->GetMemoryMap( + MemoryMapSize, + MemoryMap, + MapKey, + DescriptorSize, + DescriptorVersion ); + + if (ContextType != ExecutionContextFirmware) { + BlpArchSwitchContext(ContextType); + } + + return EfiGetNtStatusCode(EfiStatus); } NTSTATUS @@ -106,14 +123,26 @@ Return Value: --*/ { - return EfiGetNtStatusCode( - EfiBS->AllocatePages( - Type, - MemoryType, - Pages, - Memory - ) + EXECUTION_CONTEXT_TYPE ContextType; + EFI_STATUS EfiStatus; + + ContextType = CurrentExecutionContext->Type; + if (ContextType != ExecutionContextFirmware) { + BlpArchSwitchContext(ExecutionContextFirmware); + } + + EfiStatus = EfiBS->AllocatePages( + Type, + MemoryType, + Pages, + Memory ); + + if (ContextType != ExecutionContextFirmware) { + BlpArchSwitchContext(ContextType); + } + + return EfiGetNtStatusCode(EfiStatus); } NTSTATUS @@ -143,12 +172,24 @@ Return Value: --*/ { - return EfiGetNtStatusCode( - EfiBS->FreePages( - Memory, - Pages - ) + EXECUTION_CONTEXT_TYPE ContextType; + EFI_STATUS EfiStatus; + + ContextType = CurrentExecutionContext->Type; + if (ContextType != ExecutionContextFirmware) { + BlpArchSwitchContext(ExecutionContextFirmware); + } + + EfiStatus = EfiBS->FreePages( + Memory, + Pages ); + + if (ContextType != ExecutionContextFirmware) { + BlpArchSwitchContext(ContextType); + } + + return EfiGetNtStatusCode(EfiStatus); } MEMORY_TYPE @@ -616,7 +657,7 @@ Return Value: // // Remove the current descriptor. // - Status = MmMdRemoveRegionFromMdlEx(Mdl, NtStartPage, NtPageCount, MDL_OPERATION_FLAGS_PHYSICAL, NULL); + Status = MmMdRemoveRegionFromMdl(Mdl, NtStartPage, NtPageCount, MDL_OPERATION_FLAGS_PHYSICAL); if (!NT_SUCCESS(Status)) { MmMdFreeDescriptor(NtDescriptor); goto exit; diff --git a/BOOT/ENVIRON/LIB/MM/mm.c b/BOOT/ENVIRON/LIB/MM/mm.c index 0562ff6..2b8611c 100644 --- a/BOOT/ENVIRON/LIB/MM/mm.c +++ b/BOOT/ENVIRON/LIB/MM/mm.c @@ -79,8 +79,6 @@ Return Value: { NTSTATUS Status; - DebugPrint(L"Initializing memory manager...\r\n"); - // // Check TranslationType. // @@ -105,5 +103,9 @@ Return Value: return Status; } + // + // TODO: Finish this routine. + // + return STATUS_SUCCESS; } \ No newline at end of file diff --git a/BOOT/ENVIRON/LIB/MM/mmmd.c b/BOOT/ENVIRON/LIB/MM/mmmd.c index 438fcc9..2625fb5 100644 --- a/BOOT/ENVIRON/LIB/MM/mmmd.c +++ b/BOOT/ENVIRON/LIB/MM/mmmd.c @@ -27,6 +27,8 @@ ULONG MmGlobalMemoryDescriptorCount, MmGlobalMemoryDescriptorsUsed; PMEMORY_DESCRIPTOR MmDynamicMemoryDescriptors; ULONG MmDynamicMemoryDescriptorCount, MmDynamicMemoryDescriptorsUsed; +#define MAX_PRECEDENCE_INDEX sizeof(MmPlatformMemoryTypePrecedence) / sizeof(MmPlatformMemoryTypePrecedence[0]) + MEMORY_TYPE MmPlatformMemoryTypePrecedence[] = { MEMORY_TYPE_RESERVED, MEMORY_TYPE_UNUSABLE, @@ -44,6 +46,40 @@ MEMORY_TYPE MmPlatformMemoryTypePrecedence[] = { MEMORY_TYPE_FREE_ZEROED }; +ULONG +GetPrecedenceIndex ( + IN MEMORY_TYPE Type + ) + +/*++ + +Routine Description: + + Finds the index into MmPlatformMemoryTypePrecedence for Type. + +Arguments: + + Type - The memory type. + +Return Value: + + The precedence index if found. + MAX_PRECEDENCE_INDEX if not found. + +--*/ + +{ + for (ULONG Index = 0; + Index < MAX_PRECEDENCE_INDEX; + Index++) { + if (MmPlatformMemoryTypePrecedence[Index] == Type) { + return Index; + } + } + + return MAX_PRECEDENCE_INDEX; +} + BOOLEAN MmMdpHasPrecedence ( IN MEMORY_TYPE TypeA, @@ -58,9 +94,9 @@ Routine Description: Arguments: - TypeA - memory type A. + TypeA - Memory type A. - TypeB - memory type B. + TypeB - Memory type B. Return Value: @@ -71,7 +107,7 @@ Return Value: { ULONG ClassA, ClassB; - ULONG IndexA, IndexB; + ULONG PrecedenceIndexA, PrecedenceIndexB; if (TypeB == MEMORY_TYPE_FREE_ZEROED) { return TRUE; @@ -103,26 +139,17 @@ Return Value: return TRUE; } - for (IndexA = 0; - IndexA < sizeof(MmPlatformMemoryTypePrecedence) / sizeof(MmPlatformMemoryTypePrecedence[0]); - IndexA++) { - if (TypeA == MmPlatformMemoryTypePrecedence[IndexA]) { - goto CheckTypeBPrecedence; - } + PrecedenceIndexA = GetPrecedenceIndex(TypeA); + if (PrecedenceIndexA == MAX_PRECEDENCE_INDEX) { + return TRUE; } - return TRUE; - -CheckTypeBPrecedence: - for (IndexB = 0; - IndexB < sizeof(MmPlatformMemoryTypePrecedence) / sizeof(MmPlatformMemoryTypePrecedence[0]); - IndexB++) { - if (TypeB == MmPlatformMemoryTypePrecedence[IndexB]) { - return IndexA <= IndexB ? TRUE:FALSE; - } + PrecedenceIndexB = GetPrecedenceIndex(TypeB); + if (PrecedenceIndexB == MAX_PRECEDENCE_INDEX) { + return FALSE; } - return FALSE; + return PrecedenceIndexA <= PrecedenceIndexB ? TRUE:FALSE; } BOOLEAN @@ -690,6 +717,41 @@ Return Value: return Status; } +NTSTATUS +MmMdRemoveRegionFromMdl ( + IN PMEMORY_DESCRIPTOR_LIST Mdl, + IN ULONGLONG RemoveStart, + IN ULONGLONG PageCount, + IN ULONG Flags + ) + +/*++ + +Routine Description: + + Removes a region from a MDL. + Wrapper around MmMdRemoveRegionFromMdlEx(). + +Arguments: + + Same as MmMdRemoveRegionFromMdlEx(), except for Unused. + +Return Value: + + Any status code returned by MmMdRemoveRegionFromMdlEx(). + +--*/ + +{ + return MmMdRemoveRegionFromMdlEx( + Mdl, + RemoveStart, + PageCount, + Flags, + NULL + ); +} + NTSTATUS MmMdFreeDescriptor ( IN PMEMORY_DESCRIPTOR Descriptor @@ -732,10 +794,10 @@ Return Value: } // - // Free the descriptor from the heap. - // TODO: Use BlMmFreeHeap(). + // TODO: Free the descriptor from the heap. + // Need BlMmFreeHeap(). // - ConsolePrint(L"MmMdFreeDescriptor(): Heap not available\r\n"); + DebugPrint(L"MmMdFreeDescriptor(): Heap not available\r\n"); return STATUS_NOT_IMPLEMENTED; // return BlMmFreeHeap(Descriptor); } @@ -825,7 +887,7 @@ Return Value: VOID MmMdInitialize ( - IN ULONG Unused, + IN ULONG Stage, IN PBOOT_LIBRARY_PARAMETERS LibraryParameters ) @@ -837,9 +899,11 @@ Routine Description: Arguments: - Unused - Ignored. + Stage - Which stage of initialization to perform. - LibraryParameters - pointer to the library parameters structure. + Stage 0: Initializes the static memory descriptor pool. + + LibraryParameters - Pointer to the library parameters structure. Return Value: @@ -848,17 +912,19 @@ Return Value: --*/ { - (VOID)Unused; (VOID)LibraryParameters; - DebugPrint(L"Initializing memory descriptor manager...\r\n"); + if (Stage == 0) { + // + // Initialize static memory descriptor pool. + // + MmGlobalMemoryDescriptors = &MmStaticMemoryDescriptors[0]; + MmGlobalMemoryDescriptorCount = MAX_STATIC_DESCRIPTOR_COUNT; + MmGlobalMemoryDescriptorsUsed = 0; + RtlZeroMemory(MmGlobalMemoryDescriptors, MAX_STATIC_DESCRIPTOR_COUNT * sizeof(MEMORY_DESCRIPTOR)); + } // - // Initialize global memory descriptor list. + // TODO: Implement stage 1 initialization. // - MmGlobalMemoryDescriptors = &MmStaticMemoryDescriptors[0]; - MmGlobalMemoryDescriptorCount = MAX_STATIC_DESCRIPTOR_COUNT; - MmGlobalMemoryDescriptorsUsed = 0; - RtlZeroMemory(MmGlobalMemoryDescriptors, MAX_STATIC_DESCRIPTOR_COUNT * sizeof(MEMORY_DESCRIPTOR)); - DebugPrintf(L"Global memory descriptor count: %x\r\n", MmGlobalMemoryDescriptorCount); } diff --git a/BOOT/ENVIRON/LIB/MM/mmpa.c b/BOOT/ENVIRON/LIB/MM/mmpa.c index e132563..93a8cc5 100644 --- a/BOOT/ENVIRON/LIB/MM/mmpa.c +++ b/BOOT/ENVIRON/LIB/MM/mmpa.c @@ -88,14 +88,13 @@ Return Value: NTSTATUS Status; PMEMORY_DESCRIPTOR Descriptor, NewDescriptor; - (VOID)MemoryInfo; - - DebugPrint(L"Initializing page allocator...\r\n"); - PapMinimumAllocationCount = MinimumAllocation; PapMinimumPhysicalPage = 1; PapMaximumPhysicalPage = MAXULONGLONG >> PAGE_SHIFT; + // + // Initialize Memory Descriptor Lists + // InitializeMdl(&MmMdlFwAllocationTracker); InitializeMdl(&MmMdlBadMemory); InitializeMdl(&MmMdlTruncatedMemory); @@ -116,11 +115,18 @@ Return Value: // MDL the memory manager will use for allocation. // Descriptor = (PMEMORY_DESCRIPTOR)((PUCHAR)MemoryInfo + MemoryInfo->MdlOffset); - for (ULONG DescriptorCount = MemoryInfo->DescriptorCount; DescriptorCount > 0; DescriptorCount--) { + for (ULONG DescriptorCount = MemoryInfo->DescriptorCount; + DescriptorCount > 0; + DescriptorCount--) { // // Remove from the usable MDL. // - Status = MmMdRemoveRegionFromMdlEx(&MmMdlUnmappedUnallocated, Descriptor->FirstPage, Descriptor->PageCount, MDL_OPERATION_FLAGS_PHYSICAL, NULL); + Status = MmMdRemoveRegionFromMdl( + &MmMdlUnmappedUnallocated, + Descriptor->FirstPage, + Descriptor->PageCount, + MDL_OPERATION_FLAGS_PHYSICAL + ); if (!NT_SUCCESS(Status)) { return STATUS_INVALID_PARAMETER; } diff --git a/BOOT/ENVIRON/LIB/bootlib.c b/BOOT/ENVIRON/LIB/bootlib.c index ce7e6e8..f35c79b 100644 --- a/BOOT/ENVIRON/LIB/bootlib.c +++ b/BOOT/ENVIRON/LIB/bootlib.c @@ -24,6 +24,7 @@ Abstract: sizeof(BOOT_RETURN_DATA) \ ) +ULONG BlPlatformFlags = 0x002a0000 | FIRMWARE_FLAG_EXECUTION_CONTEXT_SUPPORTED; PBOOT_DEVICE BlpBootDevice; PBOOT_APPLICATION_PARAMETERS BlpApplicationParameters; BOOT_LIBRARY_PARAMETERS BlpLibraryParameters; @@ -59,8 +60,6 @@ Return Value: PBOOT_INIT_APPLICATION_ENTRY ApplicationEntry; PBOOT_FIRMWARE_DATA FirmwareData; - (VOID)LibraryParameters; - if (ApplicationParameters == NULL || ApplicationParameters->Signature != BOOT_APPLICATION_PARAMETERS_SIGNATURE || ApplicationParameters->Size < MIN_INPUT_PARAMETERS_SIZE) { @@ -84,7 +83,6 @@ Return Value: ConsolePrint(L"> Alcyone EFI Boot Manager\r\n"); ConsolePrintf(L"Image base: %x %x\r\nImage size: %x\r\n", HIDWORD((ULONG_PTR)ApplicationParameters->ImageBase), LODWORD((ULONG_PTR)ApplicationParameters->ImageBase), ApplicationParameters->ImageSize); - DebugPrint(L"Initializing boot library...\r\n"); if (ApplicationEntry->Signature != BOOT_INIT_APPLICATION_ENTRY_SIGNATURE) { DebugPrint(L"InitializeLibrary(): ApplicationEntry Signature is invalid\r\n"); @@ -104,6 +102,11 @@ Return Value: RtlCopyMemory(&BlpApplicationEntry.BcdIdentifier, &ApplicationEntry->BcdIdentifier, sizeof(GUID)); BlpApplicationEntry.Options = &ApplicationEntry->Options; + Status = BlpArchInitialize(0); + if (!NT_SUCCESS(Status)) { + return Status; + } + Status = BlpMmInitialize(MemoryInfo, ApplicationParameters->TranslationType, LibraryParameters); if (!NT_SUCCESS(Status)) { return Status; diff --git a/BOOT/ENVIRON/README.md b/BOOT/ENVIRON/README.md index 2a87229..5fe97bd 100644 --- a/BOOT/ENVIRON/README.md +++ b/BOOT/ENVIRON/README.md @@ -5,15 +5,16 @@ | File | Public Routines | |-|-| | APP/BOOTMGR/EFI/efientry.c | EfiMain() | -| APP/BOOTMGR/bootmgr.c | BmMain() | | APP/BOOTMGR/bcd.c | BmXXDataStore() | -| LIB/EFI/efifw.c | BlpFwXX() | -| LIB/EFI/efimm.c | MmFwXX() | -| LIB/EFI/efiinit.c | EfiInitXX() | +| APP/BOOTMGR/bootmgr.c | BmMain() | | LIB/EFI/eficon.c | ConsoleXX() | -| LIB/EFI/efilib.c | EfiGetEfiStatusCode() | +| LIB/EFI/efifw.c | BlpFwXX() | +| LIB/EFI/efiinit.c | EfiInitXX() | +| LIB/EFI/efilib.c | EfiGetXXStatusCode() | +| LIB/EFI/efimm.c | MmFwXX() | | LIB/MM/mm.c | BlpMmXX() | | LIB/MM/mmmd.c | MmMdXX() | | LIB/MM/mmpa.c | MmPaXX() | | LIB/bootlib.c | BlXXLibrary() | | LIB/bootopt.c | BlXXBootOptionXX() | +| LIB/XX/arch.c | BlpArchXX() |