From d2842bb6ec3e7fa691318c31e71e88b9a9eca545 Mon Sep 17 00:00:00 2001 From: "Ni, Ray" Date: Sat, 12 Nov 2022 12:00:40 +0800 Subject: EmulatorPkg/WinHost: pre-allocate "physical" RAM Move the "physical" RAM allocation from WinPeiAutoScan to main() entrypoint. This is to prepare the changes for "reset" support. Signed-off-by: Ray Ni Cc: Andrew Fish Reviewed-by: Zhiguang Liu --- EmulatorPkg/Win/Host/WinHost.c | 60 ++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 35 deletions(-) (limited to 'EmulatorPkg/Win') diff --git a/EmulatorPkg/Win/Host/WinHost.c b/EmulatorPkg/Win/Host/WinHost.c index 93247c5043..5b780ca8af 100644 --- a/EmulatorPkg/Win/Host/WinHost.c +++ b/EmulatorPkg/Win/Host/WinHost.c @@ -8,7 +8,7 @@ This code produces 128 K of temporary memory for the SEC stack by directly allocate memory space with ReadWrite and Execute attribute. -Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.
(C) Copyright 2016-2020 Hewlett Packard Enterprise Development LP
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -87,14 +87,6 @@ WinPeiAutoScan ( return EFI_UNSUPPORTED; } - // - // Allocate enough memory space for emulator - // - gSystemMemory[Index].Memory = (EFI_PHYSICAL_ADDRESS)(UINTN)VirtualAlloc (NULL, (SIZE_T)(gSystemMemory[Index].Size), MEM_COMMIT, PAGE_EXECUTE_READWRITE); - if (gSystemMemory[Index].Memory == 0) { - return EFI_OUT_OF_RESOURCES; - } - *MemoryBase = gSystemMemory[Index].Memory; *MemorySize = gSystemMemory[Index].Size; @@ -457,6 +449,30 @@ Returns: exit (1); } + // + // Allocate "physical" memory space for emulator. It will be reported out later throuth MemoryAutoScan() + // + for (Index = 0, Done = FALSE; !Done; Index++) { + ASSERT (Index < gSystemMemoryCount); + gSystemMemory[Index].Size = ((UINT64)_wtoi (MemorySizeStr)) * ((UINT64)SIZE_1MB); + gSystemMemory[Index].Memory = (EFI_PHYSICAL_ADDRESS)(UINTN)VirtualAlloc (NULL, (SIZE_T)(gSystemMemory[Index].Size), MEM_COMMIT, PAGE_EXECUTE_READWRITE); + if (gSystemMemory[Index].Memory == 0) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Find the next region + // + for (Index1 = 0; MemorySizeStr[Index1] != '!' && MemorySizeStr[Index1] != 0; Index1++) { + } + + if (MemorySizeStr[Index1] == 0) { + Done = TRUE; + } + + MemorySizeStr = MemorySizeStr + Index1 + 1; + } + // // Allocate space for gSystemMemory Array // @@ -575,32 +591,6 @@ Returns: SecPrint ("\n\r"); } - // - // Calculate memory regions and store the information in the gSystemMemory - // global for later use. The autosizing code will use this data to - // map this memory into the SEC process memory space. - // - for (Index = 0, Done = FALSE; !Done; Index++) { - // - // Save the size of the memory and make a Unicode filename SystemMemory00, ... - // - gSystemMemory[Index].Size = ((UINT64)_wtoi (MemorySizeStr)) * ((UINT64)SIZE_1MB); - - // - // Find the next region - // - for (Index1 = 0; MemorySizeStr[Index1] != '!' && MemorySizeStr[Index1] != 0; Index1++) { - } - - if (MemorySizeStr[Index1] == 0) { - Done = TRUE; - } - - MemorySizeStr = MemorySizeStr + Index1 + 1; - } - - SecPrint ("\n\r"); - // // Hand off to SEC Core // -- cgit v1.2.3