]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Use VirtualAlloc() to allocate enough memory space for Nt32 emulator in place of...
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 10 Oct 2007 02:13:43 +0000 (02:13 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 10 Oct 2007 02:13:43 +0000 (02:13 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4068 6f19259b-4bc3-4df7-8a09-765794883524

Nt32Pkg/Sec/SecMain.c
Nt32Pkg/Sec/SecMain.h
Nt32Pkg/Sec/SecMain.inf

index a1ab3f20ef818ba4625c1ecccfe8dc0f41ecc7b2..5b36dc6a3b6e625b5e856105a1daf9aabbedfa53 100644 (file)
@@ -17,18 +17,14 @@ Abstract:
   WinNt emulator of SEC phase. It's really a Win32 application, but this is\r
   Ok since all the other modules for NT32 are NOT Win32 applications.\r
 \r
-  This program processes Windows environment variables and figures out\r
-  what the memory layout will be, how may FD's will be loaded and also\r
-  what the boot mode is.\r
+  This program gets NT32 PCD setting and figures out what the memory layout \r
+  will be, how may FD's will be loaded and also what the boot mode is.\r
 \r
   The SEC registers a set of services with the SEC core. gPrivateDispatchTable\r
   is a list of PPI's produced by the SEC that are availble for usage in PEI.\r
 \r
-  This code produces 128 K of temporary memory for the PEI stack by opening a\r
-  Windows file and mapping it directly to memory addresses.\r
-\r
-  The system.cmd script is used to set windows environment variables that drive\r
-  the configuration opitons of the SEC.\r
+  This code produces 128 K of temporary memory for the PEI stack by directly\r
+  allocate memory space with ReadWrite and Execute attribute.\r
 \r
 --*/\r
 \r
@@ -99,19 +95,18 @@ EFI_PEI_PPI_DESCRIPTOR  gPrivateDispatchTable[] = {
 \r
 //\r
 // Default information about where the FD is located.\r
-//  This array gets filled in with information from EFI_FIRMWARE_VOLUMES\r
-//  EFI_FIRMWARE_VOLUMES is a Windows environment variable set by system.cmd.\r
+//  This array gets filled in with information from PcdWinNtFirmwareVolume\r
 //  The number of array elements is allocated base on parsing\r
-//  EFI_FIRMWARE_VOLUMES and the memory is never freed.\r
+//  PcdWinNtFirmwareVolume and the memory is never freed.\r
 //\r
 UINTN                                     gFdInfoCount = 0;\r
 NT_FD_INFO                                *gFdInfo;\r
 \r
 //\r
 // Array that supports seperate memory rantes.\r
-//  The memory ranges are set in system.cmd via the EFI_MEMORY_SIZE variable.\r
+//  The memory ranges are set by PcdWinNtMemorySizeForSecMain.\r
 //  The number of array elements is allocated base on parsing\r
-//  EFI_MEMORY_SIZE and the memory is never freed.\r
+//  PcdWinNtMemorySizeForSecMain value and the memory is never freed.\r
 //\r
 UINTN                                     gSystemMemoryCount = 0;\r
 NT_SYSTEM_MEMORY                          *gSystemMemory;\r
@@ -159,9 +154,9 @@ Returns:
   VOID                  *PeiCoreFile;\r
   CHAR16                *MemorySizeStr;\r
   CHAR16                *FirmwareVolumesStr;\r
-\r
-  MemorySizeStr      = (CHAR16 *)L"64!64";\r
-  FirmwareVolumesStr = (CHAR16 *)L"..\\Fv\\Fv_Recovery.fd";\r
+  \r
+  MemorySizeStr      = (CHAR16 *) FixedPcdGetPtr (PcdWinNtMemorySizeForSecMain);\r
+  FirmwareVolumesStr = (CHAR16 *) FixedPcdGetPtr (PcdWinNtFirmwareVolume);\r
 \r
   printf ("\nEDK SEC Main NT Emulation Environment from www.TianoCore.org\n");\r
 \r
@@ -196,21 +191,14 @@ Returns:
   printf ("  BootMode 0x%02x\n", FixedPcdGet32 (PcdWinNtBootMode));\r
 \r
   //\r
-  // Open up a 128K file to emulate temp memory for PEI.\r
+  //  Allocate 128K memory to emulate temp memory for PEI.\r
   //  on a real platform this would be SRAM, or using the cache as RAM.\r
   //  Set InitialStackMemory to zero so WinNtOpenFile will allocate a new mapping\r
   //\r
-  InitialStackMemory      = 0;\r
-  InitialStackMemorySize  = 0x20000;\r
-  Status = WinNtOpenFile (\r
-            L"SecStack",\r
-            (UINT32) InitialStackMemorySize,\r
-            OPEN_ALWAYS,\r
-            &InitialStackMemory,\r
-            &InitialStackMemorySize\r
-            );\r
-  if (EFI_ERROR (Status)) {\r
-    printf ("ERROR : Can not open SecStack Exiting\n");\r
+  InitialStackMemorySize  = STACK_SIZE;\r
+  InitialStackMemory = (EFI_PHYSICAL_ADDRESS) (UINTN) VirtualAlloc (NULL, (SIZE_T) (InitialStackMemorySize), MEM_COMMIT, PAGE_EXECUTE_READWRITE);\r
+  if (InitialStackMemory == 0) {\r
+    printf ("ERROR : Can not allocate enough space for SecStack\n");\r
     exit (1);\r
   }\r
 \r
@@ -286,7 +274,6 @@ Returns:
     // Save the size of the memory and make a Unicode filename SystemMemory00, ...\r
     //\r
     gSystemMemory[Index].Size = _wtoi (MemorySizeStr) * 0x100000;\r
-    _snwprintf (gSystemMemory[Index].FileName, NT_SYSTEM_MEMORY_FILENAME_SIZE, L"SystemMemory%02d", Index);\r
 \r
     //\r
     // Find the next region\r
@@ -646,9 +633,9 @@ Routine Description:
   This service is called from Index == 0 until it returns EFI_UNSUPPORTED.\r
   It allows discontiguous memory regions to be supported by the emulator.\r
   It uses gSystemMemory[] and gSystemMemoryCount that were created by\r
-  parsing the Windows environment variable EFI_MEMORY_SIZE.\r
-  The size comes from the varaible and the address comes from the call to\r
-  WinNtOpenFile.\r
+  parsing PcdWinNtMemorySizeForSecMain value.\r
+  The size comes from the Pcd value and the address comes from the memory space \r
+  with ReadWrite and Execute attributes allocated by VirtualAlloc() API.\r
 \r
 Arguments:\r
   Index      - Which memory region to use\r
@@ -661,24 +648,22 @@ Returns:
 \r
 --*/\r
 {\r
-  EFI_STATUS  Status;\r
-\r
   if (Index >= gSystemMemoryCount) {\r
     return EFI_UNSUPPORTED;\r
   }\r
+  \r
+  //\r
+  // Allocate enough memory space for emulator \r
+  //\r
+  gSystemMemory[Index].Memory = (EFI_PHYSICAL_ADDRESS) (UINTN) VirtualAlloc (NULL, (SIZE_T) (gSystemMemory[Index].Size), MEM_COMMIT, PAGE_EXECUTE_READWRITE);\r
+  if (gSystemMemory[Index].Memory == 0) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  \r
+  *MemoryBase = gSystemMemory[Index].Memory;\r
+  *MemorySize = gSystemMemory[Index].Size;\r
 \r
-  *MemoryBase = 0;\r
-  Status = WinNtOpenFile (\r
-            gSystemMemory[Index].FileName,\r
-            (UINT32) gSystemMemory[Index].Size,\r
-            OPEN_ALWAYS,\r
-            MemoryBase,\r
-            MemorySize\r
-            );\r
-\r
-  gSystemMemory[Index].Memory = *MemoryBase;\r
-\r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 VOID *\r
@@ -744,9 +729,10 @@ Returns:
     return Status;\r
   }\r
   //\r
-  // Allocate space in NT (not emulator) memory. Extra space is for alignment\r
+  // Allocate space in NT (not emulator) memory with ReadWrite and Execute attribue. \r
+  // Extra space is for alignment\r
   //\r
-  ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) malloc ((UINTN) (ImageContext.ImageSize + (ImageContext.SectionAlignment * 2)));\r
+  ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) VirtualAlloc (NULL, (SIZE_T) (ImageContext.ImageSize + (ImageContext.SectionAlignment * 2)), MEM_COMMIT, PAGE_EXECUTE_READWRITE);\r
   if (ImageContext.ImageAddress == 0) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
index a91467ae33a0ff5b4b781c8254cbe108585e9d4b..7102d5f5fa2defdb65095634858ce5506cd30260 100644 (file)
@@ -47,15 +47,11 @@ typedef struct {
   UINT64                Size;\r
 } NT_FD_INFO;\r
 \r
-#define NT_SYSTEM_MEMORY_FILENAME_SIZE  40\r
-\r
 typedef struct {\r
-  CHAR16                FileName[NT_SYSTEM_MEMORY_FILENAME_SIZE];\r
   EFI_PHYSICAL_ADDRESS  Memory;\r
   UINT64                Size;\r
 } NT_SYSTEM_MEMORY;\r
 \r
-\r
 #define MAX_PDB_NAME_TO_MOD_HANDLE_ARRAY_SIZE 0x100\r
 \r
 typedef struct {\r
index 66e9d757924dce92f56e007d8d40ba467cde1b90..6ee2164f303b8a9d88e30228fb192cd019afca2d 100644 (file)
@@ -63,6 +63,8 @@
 [FixedPcd.common]\r
   gEfiNt32PkgTokenSpaceGuid.PcdWinNtBootMode\r
   gEfiNt32PkgTokenSpaceGuid.PcdWinNtFirmwareFdSize\r
+  gEfiNt32PkgTokenSpaceGuid.PcdWinNtMemorySizeForSecMain\r
+  gEfiNt32PkgTokenSpaceGuid.PcdWinNtFirmwareVolume\r
   \r
 [BuildOptions.common]\r
   MSFT:DEBUG_*_IA32_DLINK_FLAGS = /out:"$(BIN_DIR)\SecMain.exe" /base:0x10000000 /pdb:"$(BIN_DIR)\SecMain.pdb" /LIBPATH:"$(VCINSTALLDIR)\Lib" /LIBPATH:"$(VCINSTALLDIR)\PlatformSdk\Lib" /NOLOGO /SUBSYSTEM:CONSOLE /NODEFAULTLIB /IGNORE:4086 /MAP /OPT:REF /DEBUG /MACHINE:I386 /LTCG Kernel32.lib MSVCRTD.lib Gdi32.lib User32.lib Winmm.lib\r