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
\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
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
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
// 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
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
\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
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