3 Copyright (c) 2006 - 2007 Intel Corporation.
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 WinNt emulator of SEC phase. It's really a Posix application, but this is
18 Ok since all the other modules for NT32 are NOT Posix applications.
20 This program processes host environment variables and figures out
21 what the memory layout will be, how may FD's will be loaded and also
22 what the boot mode is.
24 The SEC registers a set of services with the SEC core. gPrivateDispatchTable
25 is a list of PPI's produced by the SEC that are availble for usage in PEI.
27 This code produces 128 K of temporary memory for the PEI stack by opening a
28 host file and mapping it directly to memory addresses.
30 The system.cmd script is used to set host environment variables that drive
31 the configuration opitons of the SEC.
37 #include <Ppi/UnixPeiLoadFile.h>
38 #include <Ppi/TemporaryRamSupport.h>
44 UNIX_PEI_LOAD_FILE_PPI mSecNtLoadFilePpi
= { SecWinNtPeiLoadFile
};
46 PEI_UNIX_AUTOSCAN_PPI mSecNtAutoScanPpi
= { SecWinNtPeiAutoScan
};
48 PEI_UNIX_THUNK_PPI mSecWinNtThunkPpi
= { SecWinNtWinNtThunkAddress
};
50 EFI_PEI_PROGRESS_CODE_PPI mSecStatusCodePpi
= { SecPeiReportStatusCode
};
52 UNIX_FWH_PPI mSecFwhInformationPpi
= { SecWinNtFdAddress
};
54 TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi
= {SecTemporaryRamSupport
};
56 EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable
[] = {
58 EFI_PEI_PPI_DESCRIPTOR_PPI
,
59 &gUnixPeiLoadFilePpiGuid
,
63 EFI_PEI_PPI_DESCRIPTOR_PPI
,
64 &gPeiUnixAutoScanPpiGuid
,
68 EFI_PEI_PPI_DESCRIPTOR_PPI
,
69 &gPeiUnixThunkPpiGuid
,
73 EFI_PEI_PPI_DESCRIPTOR_PPI
,
74 &gEfiPeiStatusCodePpiGuid
,
78 EFI_PEI_PPI_DESCRIPTOR_PPI
,
79 &gEfiTemporaryRamSupportPpiGuid
,
80 &mSecTemporaryRamSupportPpi
84 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
86 &mSecFwhInformationPpi
92 // Default information about where the FD is located.
93 // This array gets filled in with information from EFI_FIRMWARE_VOLUMES
94 // EFI_FIRMWARE_VOLUMES is a host environment variable set by system.cmd.
95 // The number of array elements is allocated base on parsing
96 // EFI_FIRMWARE_VOLUMES and the memory is never freed.
98 UINTN gFdInfoCount
= 0;
99 UNIX_FD_INFO
*gFdInfo
;
102 // Array that supports seperate memory rantes.
103 // The memory ranges are set in system.cmd via the EFI_MEMORY_SIZE variable.
104 // The number of array elements is allocated base on parsing
105 // EFI_MEMORY_SIZE and the memory is never freed.
107 UINTN gSystemMemoryCount
= 0;
108 UNIX_SYSTEM_MEMORY
*gSystemMemory
;
113 UINT32 TemporaryMemoryBase
,
114 UINT32 PermenentMemoryBase
117 EFI_PHYSICAL_ADDRESS
*
127 IN OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
132 SecNt32PeCoffRelocateImage (
133 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
147 Main entry point to SEC for WinNt. This is a unix program
150 Argc - Number of command line arguments
151 Argv - Array of command line argument strings
152 Envp - Array of environmemt variable strings
161 EFI_PHYSICAL_ADDRESS InitialStackMemory
;
162 UINT64 InitialStackMemorySize
;
170 CHAR16
*MemorySizeStr
;
171 CHAR16
*FirmwareVolumesStr
;
177 MemorySizeStr
= (CHAR16
*) FixedPcdGetPtr (PcdUnixMemorySizeForSecMain
);
178 FirmwareVolumesStr
= (CHAR16
*) FixedPcdGetPtr (PcdUnixFirmwareVolume
);
180 printf ("\nEDK SEC Main UNIX Emulation Environment from www.TianoCore.org\n");
183 // Allocate space for gSystemMemory Array
185 gSystemMemoryCount
= CountSeperatorsInString (MemorySizeStr
, '!') + 1;
186 gSystemMemory
= calloc (gSystemMemoryCount
, sizeof (UNIX_SYSTEM_MEMORY
));
187 if (gSystemMemory
== NULL
) {
188 printf ("ERROR : Can not allocate memory for system. Exiting.\n");
192 // Allocate space for gSystemMemory Array
194 gFdInfoCount
= CountSeperatorsInString (FirmwareVolumesStr
, '!') + 1;
195 gFdInfo
= calloc (gFdInfoCount
, sizeof (UNIX_FD_INFO
));
196 if (gFdInfo
== NULL
) {
197 printf ("ERROR : Can not allocate memory for fd info. Exiting.\n");
201 // Setup Boot Mode. If BootModeStr == "" then BootMode = 0 (BOOT_WITH_FULL_CONFIGURATION)
203 printf (" BootMode 0x%02x\n", FixedPcdGet32 (PcdUnixBootMode
));
206 // Open up a 128K file to emulate temp memory for PEI.
207 // on a real platform this would be SRAM, or using the cache as RAM.
208 // Set InitialStackMemory to zero so WinNtOpenFile will allocate a new mapping
210 InitialStackMemorySize
= STACK_SIZE
;
211 InitialStackMemory
= (UINTN
)MapMemory(0,
212 (UINT32
) InitialStackMemorySize
,
213 PROT_READ
| PROT_WRITE
,
214 MAP_ANONYMOUS
| MAP_PRIVATE
);
215 if (InitialStackMemory
== 0) {
216 printf ("ERROR : Can not open SecStack Exiting\n");
220 printf (" SEC passing in %u KB of temp RAM at 0x%08lx to PEI\n",
221 (UINTN
)(InitialStackMemorySize
/ 1024),
222 (unsigned long)InitialStackMemory
);
224 for (StackPointer
= (UINTN
*) (UINTN
) InitialStackMemory
;
225 StackPointer
< (UINTN
*) ((UINTN
) InitialStackMemory
+ (UINT64
) InitialStackMemorySize
);
227 *StackPointer
= 0x5AA55AA5;
231 // Open All the firmware volumes and remember the info in the gFdInfo global
233 FileName
= (CHAR8
*)malloc (StrLen (FirmwareVolumesStr
) + 1);
234 if (FileName
== NULL
) {
235 printf ("ERROR : Can not allocate memory for firmware volume string\n");
240 for (Done
= FALSE
, Index
= 0, PeiIndex
= 0, PeiCoreFile
= NULL
;
241 FirmwareVolumesStr
[Index2
] != 0;
243 for (Index1
= 0; (FirmwareVolumesStr
[Index2
] != '!') && (FirmwareVolumesStr
[Index2
] != 0); Index2
++)
244 FileName
[Index1
++] = FirmwareVolumesStr
[Index2
];
245 if (FirmwareVolumesStr
[Index2
] == '!')
247 FileName
[Index1
] = '\0';
250 // Open the FD and remmeber where it got mapped into our processes address space
254 &gFdInfo
[Index
].Address
,
257 if (EFI_ERROR (Status
)) {
258 printf ("ERROR : Can not open Firmware Device File %s (%x). Exiting.\n", FileName
, Status
);
262 printf (" FD loaded from %s at 0x%08lx",
263 FileName
, (unsigned long)gFdInfo
[Index
].Address
);
265 if (PeiCoreFile
== NULL
) {
267 // Assume the beginning of the FD is an FV and look for the PEI Core.
268 // Load the first one we find.
270 Status
= SecFfsFindPeiCore ((EFI_FIRMWARE_VOLUME_HEADER
*) (UINTN
) gFdInfo
[Index
].Address
, &PeiCoreFile
);
271 if (!EFI_ERROR (Status
)) {
273 printf (" contains SEC Core");
280 // Calculate memory regions and store the information in the gSystemMemory
281 // global for later use. The autosizing code will use this data to
282 // map this memory into the SEC process memory space.
289 // Save the size of the memory.
291 while (MemorySizeStr
[Index1
] >= '0' && MemorySizeStr
[Index1
] <= '9') {
292 val
= val
* 10 + MemorySizeStr
[Index1
] - '0';
295 gSystemMemory
[Index
++].Size
= val
* 0x100000;
296 if (MemorySizeStr
[Index1
] == 0)
304 // Hand off to PEI Core
306 SecLoadFromCore ((UINTN
) InitialStackMemory
, (UINTN
) InitialStackMemorySize
, (UINTN
) gFdInfo
[0].Address
, PeiCoreFile
);
309 // If we get here, then the PEI Core returned. This is an error as PEI should
310 // always hand off to DXE.
312 printf ("ERROR : PEI Core returned\n");
316 EFI_PHYSICAL_ADDRESS
*
323 STATIC UINTN base
= 0x40000000;
324 CONST UINTN align
= (1 << 24);
326 BOOLEAN isAligned
= 0;
329 // Try to get an aligned block somewhere in the address space of this
332 while((!isAligned
) && (base
!= 0)) {
333 res
= mmap ((void *)base
, length
, prot
, flags
, fd
, 0);
334 if (res
== MAP_FAILED
) {
337 if ((((UINTN
)res
) & ~(align
-1)) == (UINTN
)res
) {
351 IN OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
357 Opens and memory maps a file using WinNt services. If BaseAddress is non zero
358 the process will try and allocate the memory starting at BaseAddress.
361 FileName - The name of the file to open and map
362 MapSize - The amount of the file to map in bytes
363 CreationDisposition - The flags to pass to CreateFile(). Use to create new files for
364 memory emulation, and exiting files for firmware volume emulation
365 BaseAddress - The base address of the mapped file in the user address space.
366 If passed in as NULL the a new memory region is used.
367 If passed in as non NULL the request memory region is used for
368 the mapping of the file into the process space.
369 Length - The size of the mapped region in bytes
372 EFI_SUCCESS - The file was opened and mapped.
373 EFI_NOT_FOUND - FileName was not found in the current directory
374 EFI_DEVICE_ERROR - An error occured attempting to map the opened file
382 fd
= open (FileName
, O_RDONLY
);
384 return EFI_NOT_FOUND
;
385 FileSize
= lseek (fd
, 0, SEEK_END
);
390 /* Read entry address. */
391 lseek (fd
, FileSize
- 0x20, SEEK_SET
);
392 if (read (fd
, &EntryAddress
, 4) != 4)
395 return EFI_DEVICE_ERROR
;
400 res
= MapMemory(fd
, FileSize
, PROT_READ
| PROT_WRITE
| PROT_EXEC
, MAP_PRIVATE
);
404 if (res
== MAP_FAILED
)
405 return EFI_DEVICE_ERROR
;
407 *Length
= (UINT64
) FileSize
;
408 *BaseAddress
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) res
;
413 #define BYTES_PER_RECORD 512
417 SecPeiReportStatusCode (
418 IN EFI_PEI_SERVICES
**PeiServices
,
419 IN EFI_STATUS_CODE_TYPE CodeType
,
420 IN EFI_STATUS_CODE_VALUE Value
,
422 IN EFI_GUID
* CallerId
,
423 IN EFI_STATUS_CODE_DATA
* Data OPTIONAL
429 This routine produces the ReportStatusCode PEI service. It's passed
430 up to the PEI Core via a PPI. T
432 This code currently uses the UNIX clib printf. This does not work the same way
433 as the EFI Print (), as %t, %g, %s as Unicode are not supported.
436 (see EFI_PEI_REPORT_STATUS_CODE)
439 EFI_SUCCESS - Always return success
442 // TODO: PeiServices - add argument and description to function comment
443 // TODO: CodeType - add argument and description to function comment
444 // TODO: Value - add argument and description to function comment
445 // TODO: Instance - add argument and description to function comment
446 // TODO: CallerId - add argument and description to function comment
447 // TODO: Data - add argument and description to function comment
451 CHAR8 PrintBuffer
[BYTES_PER_RECORD
* 2];
459 } else if (ReportStatusCodeExtractAssertInfo (CodeType
, Value
, Data
, &Filename
, &Description
, &LineNumber
)) {
461 // Processes ASSERT ()
463 printf ("ASSERT %s(%d): %s\n", Filename
, LineNumber
, Description
);
465 } else if (ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
467 // Process DEBUG () macro
469 AsciiBSPrint (PrintBuffer
, BYTES_PER_RECORD
, Format
, Marker
);
470 printf (PrintBuffer
);
477 Transfers control to a function starting with a new stack.
479 Transfers control to the function specified by EntryPoint using the new stack
480 specified by NewStack and passing in the parameters specified by Context1 and
481 Context2. Context1 and Context2 are optional and may be NULL. The function
482 EntryPoint must never return.
484 If EntryPoint is NULL, then ASSERT().
485 If NewStack is NULL, then ASSERT().
487 @param EntryPoint A pointer to function to call with the new stack.
488 @param Context1 A pointer to the context to pass into the EntryPoint
490 @param Context2 A pointer to the context to pass into the EntryPoint
492 @param NewStack A pointer to the new stack to use for the EntryPoint
494 @param NewBsp A pointer to the new BSP for the EntryPoint on IPF. It's
495 Reserved on other architectures.
501 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
502 IN VOID
*Context1
, OPTIONAL
503 IN VOID
*Context2
, OPTIONAL
504 IN VOID
*Context3
, OPTIONAL
508 BASE_LIBRARY_JUMP_BUFFER JumpBuffer
;
510 ASSERT (EntryPoint
!= NULL
);
511 ASSERT (NewStack
!= NULL
);
514 // Stack should be aligned with CPU_STACK_ALIGNMENT
516 ASSERT (((UINTN
)NewStack
& (CPU_STACK_ALIGNMENT
- 1)) == 0);
518 JumpBuffer
.Eip
= (UINTN
)EntryPoint
;
519 JumpBuffer
.Esp
= (UINTN
)NewStack
- sizeof (VOID
*);
520 JumpBuffer
.Esp
-= sizeof (Context1
) + sizeof (Context2
) + sizeof(Context3
);
521 ((VOID
**)JumpBuffer
.Esp
)[1] = Context1
;
522 ((VOID
**)JumpBuffer
.Esp
)[2] = Context2
;
523 ((VOID
**)JumpBuffer
.Esp
)[3] = Context3
;
525 LongJump (&JumpBuffer
, (UINTN
)-1);
529 // InternalSwitchStack () will never return
536 IN UINTN LargestRegion
,
537 IN UINTN LargestRegionSize
,
538 IN UINTN BootFirmwareVolumeBase
,
539 IN VOID
*PeiCorePe32File
544 This is the service to load the PEI Core from the Firmware Volume
547 LargestRegion - Memory to use for PEI.
548 LargestRegionSize - Size of Memory to use for PEI
549 BootFirmwareVolumeBase - Start of the Boot FV
550 PeiCorePe32File - PEI Core PE32
553 Success means control is transfered and thus we should never return
558 EFI_PHYSICAL_ADDRESS TopOfMemory
;
561 EFI_PHYSICAL_ADDRESS PeiCoreEntryPoint
;
562 EFI_PHYSICAL_ADDRESS PeiImageAddress
;
563 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
567 // Compute Top Of Memory for Stack and PEI Core Allocations
569 TopOfMemory
= LargestRegion
+ LargestRegionSize
;
570 PeiStackSize
= (UINTN
)RShiftU64((UINT64
)STACK_SIZE
,1);
573 // |-----------| <---- TemporaryRamBase + TemporaryRamSize
576 // |-----------| <---- StackBase / PeiTemporaryMemoryBase
579 // |-----------| <---- TemporaryRamBase
581 TopOfStack
= (VOID
*)(LargestRegion
+ PeiStackSize
);
582 TopOfMemory
= LargestRegion
+ PeiStackSize
;
585 // Reservet space for storing PeiCore's parament in stack.
587 TopOfStack
= (VOID
*)((UINTN
)TopOfStack
- sizeof (EFI_SEC_PEI_HAND_OFF
) - CPU_STACK_ALIGNMENT
);
588 TopOfStack
= ALIGN_POINTER (TopOfStack
, CPU_STACK_ALIGNMENT
);
592 // Bind this information into the SEC hand-off state
594 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*)(UINTN
) TopOfStack
;
595 SecCoreData
->DataSize
= sizeof(EFI_SEC_PEI_HAND_OFF
);
596 SecCoreData
->BootFirmwareVolumeBase
= (VOID
*)BootFirmwareVolumeBase
;
597 SecCoreData
->BootFirmwareVolumeSize
= FixedPcdGet32(PcdUnixFirmwareFdSize
);
598 SecCoreData
->TemporaryRamBase
= (VOID
*)(UINTN
)LargestRegion
;
599 SecCoreData
->TemporaryRamSize
= STACK_SIZE
;
600 SecCoreData
->StackBase
= SecCoreData
->TemporaryRamBase
;
601 SecCoreData
->StackSize
= PeiStackSize
;
602 SecCoreData
->PeiTemporaryRamBase
= (VOID
*) ((UINTN
) SecCoreData
->TemporaryRamBase
+ PeiStackSize
);
603 SecCoreData
->PeiTemporaryRamSize
= STACK_SIZE
- PeiStackSize
;
606 // Load the PEI Core from a Firmware Volume
608 Status
= SecWinNtPeiLoadFile (
614 if (EFI_ERROR (Status
)) {
619 // Transfer control to the PEI Core
622 (SWITCH_STACK_ENTRY_POINT
) (UINTN
) PeiCoreEntryPoint
,
624 (VOID
*) (UINTN
) ((EFI_PEI_PPI_DESCRIPTOR
*) &gPrivateDispatchTable
),
629 // If we get here, then the PEI Core returned. This is an error
636 SecWinNtPeiAutoScan (
638 OUT EFI_PHYSICAL_ADDRESS
*MemoryBase
,
639 OUT UINT64
*MemorySize
644 This service is called from Index == 0 until it returns EFI_UNSUPPORTED.
645 It allows discontiguous memory regions to be supported by the emulator.
646 It uses gSystemMemory[] and gSystemMemoryCount that were created by
647 parsing the host environment variable EFI_MEMORY_SIZE.
648 The size comes from the varaible and the address comes from the call to
652 Index - Which memory region to use
653 MemoryBase - Return Base address of memory region
654 MemorySize - Return size in bytes of the memory region
657 EFI_SUCCESS - If memory region was mapped
658 EFI_UNSUPPORTED - If Index is not supported
664 if (Index
>= gSystemMemoryCount
) {
665 return EFI_UNSUPPORTED
;
669 res
= MapMemory(0, gSystemMemory
[Index
].Size
,
670 PROT_READ
| PROT_WRITE
| PROT_EXEC
,
671 MAP_PRIVATE
| MAP_ANONYMOUS
);
672 if (res
== MAP_FAILED
)
673 return EFI_DEVICE_ERROR
;
674 *MemorySize
= gSystemMemory
[Index
].Size
;
675 *MemoryBase
= (UINTN
)res
;
676 gSystemMemory
[Index
].Memory
= *MemoryBase
;
683 SecWinNtWinNtThunkAddress (
689 Since the SEC is the only Unix program in stack it must export
690 an interface to do Win API calls. That's what the WinNtThunk address
691 is for. gWinNt is initailized in WinNtThunk.c.
694 InterfaceSize - sizeof (EFI_WIN_NT_THUNK_PROTOCOL);
695 InterfaceBase - Address of the gWinNt global
698 EFI_SUCCESS - Data returned
708 SecWinNtPeiLoadFile (
710 IN EFI_PHYSICAL_ADDRESS
*ImageAddress
,
711 IN UINT64
*ImageSize
,
712 IN EFI_PHYSICAL_ADDRESS
*EntryPoint
717 Loads and relocates a PE/COFF image into memory.
720 Pe32Data - The base address of the PE/COFF file that is to be loaded and relocated
721 ImageAddress - The base address of the relocated PE/COFF image
722 ImageSize - The size of the relocated PE/COFF image
723 EntryPoint - The entry point of the relocated PE/COFF image
726 EFI_SUCCESS - The file was loaded and relocated
727 EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file
732 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
734 ZeroMem (&ImageContext
, sizeof (ImageContext
));
735 ImageContext
.Handle
= Pe32Data
;
737 ImageContext
.ImageRead
= (PE_COFF_LOADER_READ_FILE
) SecImageRead
;
739 Status
= PeCoffLoaderGetImageInfo (&ImageContext
);
740 if (EFI_ERROR (Status
)) {
744 // Allocate space in UNIX (not emulator) memory. Extra space is for alignment
746 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) malloc ((UINTN
) (ImageContext
.ImageSize
+ (ImageContext
.SectionAlignment
* 2)));
747 if (ImageContext
.ImageAddress
== 0) {
748 return EFI_OUT_OF_RESOURCES
;
751 // Align buffer on section boundry
753 ImageContext
.ImageAddress
+= ImageContext
.SectionAlignment
- 1;
754 ImageContext
.ImageAddress
&= ~(ImageContext
.SectionAlignment
- 1);
757 Status
= PeCoffLoaderLoadImage (&ImageContext
);
758 if (EFI_ERROR (Status
)) {
762 Status
= SecNt32PeCoffRelocateImage(&ImageContext
);
763 if (EFI_ERROR (Status
)) {
768 // BugBug: Flush Instruction Cache Here when CPU Lib is ready
771 *ImageAddress
= ImageContext
.ImageAddress
;
772 *ImageSize
= ImageContext
.ImageSize
;
773 *EntryPoint
= ImageContext
.EntryPoint
;
782 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
783 IN OUT UINT64
*FdSize
788 Return the FD Size and base address. Since the FD is loaded from a
789 file into host memory only the SEC will know it's address.
792 Index - Which FD, starts at zero.
793 FdSize - Size of the FD in bytes
794 FdBase - Start address of the FD. Assume it points to an FV Header
797 EFI_SUCCESS - Return the Base address and size of the FV
798 EFI_UNSUPPORTED - Index does nto map to an FD in the system
802 if (Index
>= gFdInfoCount
) {
803 return EFI_UNSUPPORTED
;
806 *FdBase
= gFdInfo
[Index
].Address
;
807 *FdSize
= gFdInfo
[Index
].Size
;
809 if (*FdBase
== 0 && *FdSize
== 0) {
810 return EFI_UNSUPPORTED
;
821 IN OUT UINTN
*ReadSize
,
827 Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file
830 FileHandle - The handle to the PE/COFF file
831 FileOffset - The offset, in bytes, into the file to read
832 ReadSize - The number of bytes to read from the file starting at FileOffset
833 Buffer - A pointer to the buffer to read the data into.
836 EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset
844 Destination8
= Buffer
;
845 Source8
= (CHAR8
*) ((UINTN
) FileHandle
+ FileOffset
);
848 *(Destination8
++) = *(Source8
++);
855 CountSeperatorsInString (
856 IN
const CHAR16
*String
,
862 Count the number of seperators in String
865 String - String to process
866 Seperator - Item to count
869 Number of Seperator in String
875 for (Count
= 0; *String
!= '\0'; String
++) {
876 if (*String
== Seperator
) {
895 SecNt32PeCoffRelocateImage (
896 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
905 Status
= PeCoffLoaderRelocateImage (ImageContext
);
907 "Loading %s 0x%08lx - entry point 0x%08lx\n",
908 ImageContext
->PdbPointer
,
909 (unsigned long)ImageContext
->ImageAddress
,
910 (unsigned long)ImageContext
->EntryPoint
);
912 Handle
= dlopen(ImageContext
->PdbPointer
, RTLD_NOW
);
915 Entry
= dlsym(Handle
, "_ModuleEntryPoint");
917 printf("%s\n", dlerror());
921 ImageContext
->EntryPoint
= Entry
;
922 printf("Change %s Entrypoint to :0x%08lx\n", ImageContext
->PdbPointer
, Entry
);
925 SecUnixLoaderBreak ();
933 SecNt32PeCoffUnloadimage (
934 IN PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
949 SecTemporaryRamSupport (
950 IN CONST EFI_PEI_SERVICES
**PeiServices
,
951 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
952 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
957 // Migrate the whole temporary memory to permenent memory.
960 (VOID
*)(UINTN
)PermanentMemoryBase
,
961 (VOID
*)(UINTN
)TemporaryMemoryBase
,
966 // SecSwitchStack function must be invoked after the memory migration
967 // immediatly, also we need fixup the stack change caused by new call into
971 (UINT32
) TemporaryMemoryBase
,
972 (UINT32
) PermanentMemoryBase
976 // We need *not* fix the return address because currently,
977 // The PeiCore is excuted in flash.
981 // Simulate to invalid temporary memory, terminate temporary memory
983 //ZeroMem ((VOID*)(UINTN)TemporaryMemoryBase, CopySize);