UnixPkg: Enable gasket functions for all X64 toolchains

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10924 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jljusten
2010-10-13 07:06:42 +00:00
parent 124f761f02
commit 3ff2e32407
3 changed files with 427 additions and 419 deletions

View File

@@ -48,7 +48,7 @@ char *gGdbWorkingFileName = NULL;
//
// Globals
//
#ifdef __APPLE__
#if defined(__APPLE__) || defined(MDE_CPU_X64)
UNIX_PEI_LOAD_FILE_PPI mSecUnixLoadFilePpi = { GasketSecUnixPeiLoadFile };
PEI_UNIX_AUTOSCAN_PPI mSecUnixAutoScanPpi = { GasketSecUnixPeiAutoScan };
PEI_UNIX_THUNK_PPI mSecUnixThunkPpi = { GasketSecUnixUnixThunkAddress };
@@ -143,7 +143,7 @@ MapFile (
IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length
);
EFI_STATUS
EFIAPI
SecNt32PeCoffRelocateImage (
@@ -237,7 +237,7 @@ Returns:
// Set InitialStackMemory to zero so UnixOpenFile will allocate a new mapping
//
InitialStackMemorySize = STACK_SIZE;
InitialStackMemory = (UINTN)MapMemory(0,
InitialStackMemory = (UINTN)MapMemory(0,
(UINT32) InitialStackMemorySize,
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_ANONYMOUS | MAP_PRIVATE);
@@ -249,7 +249,7 @@ Returns:
printf (" SEC passing in %u KB of temp RAM at 0x%08lx to PEI\n",
(unsigned int)(InitialStackMemorySize / 1024),
(unsigned long)InitialStackMemory);
for (StackPointer = (UINTN*) (UINTN) InitialStackMemory;
StackPointer < (UINTN*)(UINTN)((UINTN) InitialStackMemory + (UINT64) InitialStackMemorySize);
StackPointer ++) {
@@ -422,12 +422,12 @@ Returns:
{
close (fd);
return EFI_DEVICE_ERROR;
}
}
}
#endif
res = MapMemory(fd, FileSize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
close (fd);
if (res == MAP_FAILED)
@@ -493,7 +493,7 @@ Returns:
} else if (ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
//
// Process DEBUG () macro
// Process DEBUG () macro
//
AsciiBSPrint (PrintBuffer, BYTES_PER_RECORD, Format, Marker);
printf ("%s", PrintBuffer);
@@ -560,17 +560,17 @@ Returns:
// | |
// | Stack |
// |-----------| <---- TemporaryRamBase
//
//
TopOfStack = (VOID *)(LargestRegion + PeiStackSize);
TopOfMemory = LargestRegion + PeiStackSize;
//
// Reservet space for storing PeiCore's parament in stack.
//
//
TopOfStack = (VOID *)((UINTN)TopOfStack - sizeof (EFI_SEC_PEI_HAND_OFF) - CPU_STACK_ALIGNMENT);
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
//
// Bind this information into the SEC hand-off state
//
@@ -578,7 +578,7 @@ Returns:
SecCoreData->DataSize = sizeof(EFI_SEC_PEI_HAND_OFF);
SecCoreData->BootFirmwareVolumeBase = (VOID*)BootFirmwareVolumeBase;
SecCoreData->BootFirmwareVolumeSize = PcdGet32 (PcdUnixFirmwareFdSize);
SecCoreData->TemporaryRamBase = (VOID*)(UINTN)LargestRegion;
SecCoreData->TemporaryRamBase = (VOID*)(UINTN)LargestRegion;
SecCoreData->TemporaryRamSize = STACK_SIZE;
SecCoreData->StackBase = SecCoreData->TemporaryRamBase;
SecCoreData->StackSize = PeiStackSize;
@@ -597,21 +597,21 @@ Returns:
if (EFI_ERROR (Status)) {
return ;
}
DispatchTableSize = sizeof (gPrivateDispatchTable);
DispatchTableSize += OverrideDispatchTableExtraSize ();
DispatchTable = malloc (DispatchTableSize);
if (DispatchTable == NULL) {
return;
}
//
// Allow an override for extra PPIs to be passed up to PEI
// This is an easy way to enable OS specific customizations
//
OverrideDispatchTable (&gPrivateDispatchTable[0], sizeof (gPrivateDispatchTable), DispatchTable, DispatchTableSize);
//
// Transfer control to the PEI Core
//
@@ -735,13 +735,13 @@ Returns:
if (EFI_ERROR (Status)) {
return Status;
}
//
// Allocate space in UNIX (not emulator) memory. Extra space is for alignment
//
ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) MapMemory (
0,
0,
(UINT32) (ImageContext.ImageSize + (ImageContext.SectionAlignment * 2)),
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_ANONYMOUS | MAP_PRIVATE
@@ -749,7 +749,7 @@ Returns:
if (ImageContext.ImageAddress == 0) {
return EFI_OUT_OF_RESOURCES;
}
//
// Align buffer on section boundry
//
@@ -761,12 +761,12 @@ Returns:
if (EFI_ERROR (Status)) {
return Status;
}
Status = PeCoffLoaderRelocateImage (&ImageContext);
if (EFI_ERROR (Status)) {
return Status;
}
SecPeCoffRelocateImageExtraAction (&ImageContext);
@@ -842,7 +842,7 @@ Returns:
if (Index == 0) {
//
// FD 0 has XIP code and well known PCD values
// FD 0 has XIP code and well known PCD values
// If the memory buffer could not be allocated at the FD build address
// the Fixup is the difference.
//
@@ -930,16 +930,16 @@ AddHandle (
Routine Description:
Store the ModHandle in an array indexed by the Pdb File name.
The ModHandle is needed to unload the image.
The ModHandle is needed to unload the image.
Arguments:
ImageContext - Input data returned from PE Laoder Library. Used to find the
ImageContext - Input data returned from PE Laoder Library. Used to find the
.PDB file name of the PE Image.
ModHandle - Returned from LoadLibraryEx() and stored for call to
ModHandle - Returned from LoadLibraryEx() and stored for call to
FreeLibrary().
Returns:
EFI_SUCCESS - ModHandle was stored.
EFI_SUCCESS - ModHandle was stored.
--*/
{
@@ -959,9 +959,9 @@ Returns:
return EFI_SUCCESS;
}
}
//
// No free space in mImageContextModHandleArray so grow it by
// No free space in mImageContextModHandleArray so grow it by
// IMAGE_CONTEXT_TO_MOD_HANDLE entires. realloc will
// copy the old values to the new locaiton. But it does
// not zero the new memory area.
@@ -974,9 +974,9 @@ Returns:
ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
memset (mImageContextModHandleArray + PreviousSize, 0, MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE * sizeof (IMAGE_CONTEXT_TO_MOD_HANDLE));
return AddHandle (ImageContext, ModHandle);
}
@@ -991,7 +991,7 @@ Routine Description:
Return the ModHandle and delete the entry in the array.
Arguments:
ImageContext - Input data returned from PE Laoder Library. Used to find the
ImageContext - Input data returned from PE Laoder Library. Used to find the
.PDB file name of the PE Image.
Returns:
@@ -1027,7 +1027,7 @@ Returns:
//
// Target for gdb breakpoint in a script that uses gGdbWorkingFileName to source a
// Target for gdb breakpoint in a script that uses gGdbWorkingFileName to source a
// add-symbol-file command. Hey what can you say scripting in gdb is not that great....
//
// Put .gdbinit in the CWD where you do gdb SecMain.dll for source level debug
@@ -1069,13 +1069,13 @@ IsPdbFile (
if ((Len < 5)|| (PdbFileName[Len - 4] != '.')) {
return FALSE;
}
if ((PdbFileName[Len - 3] == 'P' || PdbFileName[Len - 3] == 'p') &&
(PdbFileName[Len - 2] == 'D' || PdbFileName[Len - 2] == 'd') &&
(PdbFileName[Len - 1] == 'B' || PdbFileName[Len - 1] == 'b')) {
return TRUE;
}
return FALSE;
}
@@ -1090,14 +1090,14 @@ PrintLoadAddress (
if (ImageContext->PdbPointer == NULL) {
fprintf (stderr,
"0x%08lx Loading NO DEBUG with entry point 0x%08lx\n",
(unsigned long)(ImageContext->ImageAddress),
(unsigned long)(ImageContext->ImageAddress),
(unsigned long)ImageContext->EntryPoint
);
} else {
fprintf (stderr,
"0x%08lx Loading %s with entry point 0x%08lx\n",
(unsigned long)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders),
ImageContext->PdbPointer,
ImageContext->PdbPointer,
(unsigned long)ImageContext->EntryPoint
);
}
@@ -1112,7 +1112,7 @@ SecPeCoffRelocateImageExtraAction (
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
)
{
#ifdef __APPLE__
PrintLoadAddress (ImageContext);
@@ -1122,7 +1122,7 @@ SecPeCoffRelocateImageExtraAction (
// .dSYM files for the PE/COFF images that can be used by gdb for source level debugging.
//
FILE *GdbTempFile;
//
// In the Mach-O to PE/COFF conversion the size of the PE/COFF headers is not accounted for.
// Thus we need to skip over the PE/COFF header when giving load addresses for our symbol table.
@@ -1131,27 +1131,27 @@ SecPeCoffRelocateImageExtraAction (
//
// Now we have a database of the images that are currently loaded
//
//
// 'symbol-file' will clear out currnet symbol mappings in gdb.
// you can do a 'add-symbol-file filename address' for every image we loaded to get source
// level debug in gdb. Note Sec, being a true application will work differently.
// 'symbol-file' will clear out currnet symbol mappings in gdb.
// you can do a 'add-symbol-file filename address' for every image we loaded to get source
// level debug in gdb. Note Sec, being a true application will work differently.
//
// We add the PE/COFF header size into the image as the mach-O does not have a header in
// loaded into system memory.
//
// We add the PE/COFF header size into the image as the mach-O does not have a header in
// loaded into system memory.
//
// This gives us a data base of gdb commands and after something is unloaded that entry will be
// removed. We don't yet have the scheme of how to comunicate with gdb, but we have the
// removed. We don't yet have the scheme of how to comunicate with gdb, but we have the
// data base of info ready to roll.
//
// We could use qXfer:libraries:read, but OS X GDB does not currently support it.
// <library-list>
// We could use qXfer:libraries:read, but OS X GDB does not currently support it.
// <library-list>
// <library name="/lib/libc.so.6"> // ImageContext->PdbPointer
// <segment address="0x10000000"/> // ImageContext->ImageAddress + ImageContext->SizeOfHeaders
// </library>
// </library-list>
// </library>
// </library-list>
//
//
// Write the file we need for the gdb script
//
@@ -1159,37 +1159,45 @@ SecPeCoffRelocateImageExtraAction (
if (GdbTempFile != NULL) {
fprintf (GdbTempFile, "add-symbol-file %s 0x%08lx\n", ImageContext->PdbPointer, (long unsigned int)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders));
fclose (GdbTempFile);
//
// Target for gdb breakpoint in a script that uses gGdbWorkingFileName to set a breakpoint.
// Target for gdb breakpoint in a script that uses gGdbWorkingFileName to set a breakpoint.
// Hey what can you say scripting in gdb is not that great....
//
SecGdbScriptBreak ();
}
AddHandle (ImageContext, ImageContext->PdbPointer);
}
#else
void *Handle = NULL;
void *Entry = NULL;
fprintf (stderr,
if (ImageContext->PdbPointer == NULL) {
return;
}
if (!IsPdbFile (ImageContext->PdbPointer)) {
return;
}
fprintf (stderr,
"Loading %s 0x%08lx - entry point 0x%08lx\n",
ImageContext->PdbPointer,
(unsigned long)ImageContext->ImageAddress,
(unsigned long)ImageContext->EntryPoint);
Handle = dlopen (ImageContext->PdbPointer, RTLD_NOW);
if (Handle) {
Entry = dlsym (Handle, "_ModuleEntryPoint");
} else {
printf("%s\n", dlerror());
printf("%s\n", dlerror());
}
if (Entry != NULL) {
ImageContext->EntryPoint = (UINTN)Entry;
printf("Change %s Entrypoint to :0x%08lx\n", ImageContext->PdbPointer, (unsigned long)Entry);
@@ -1215,12 +1223,12 @@ SecPeCoffLoaderUnloadImageExtraAction (
#ifdef __APPLE__
FILE *GdbTempFile;
if (Handle != NULL) {
//
// Need to skip .PDB files created from VC++
//
if (!IsPdbFile (ImageContext->PdbPointer)) {
if (!IsPdbFile (ImageContext->PdbPointer)) {
//
// Write the file we need for the gdb script
//
@@ -1228,16 +1236,16 @@ SecPeCoffLoaderUnloadImageExtraAction (
if (GdbTempFile != NULL) {
fprintf (GdbTempFile, "remove-symbol-file %s\n", ImageContext->PdbPointer);
fclose (GdbTempFile);
//
// Target for gdb breakpoint in a script that uses gGdbWorkingFileName to set a breakpoint.
// Target for gdb breakpoint in a script that uses gGdbWorkingFileName to set a breakpoint.
// Hey what can you say scripting in gdb is not that great....
//
SecGdbScriptBreak ();
}
}
}
#else
//
// Don't want to confuse gdb with symbols for something that got unloaded
@@ -1268,32 +1276,32 @@ SecTemporaryRamSupport (
{
//
// Migrate the whole temporary memory to permenent memory.
//
//
CopyMem (
(VOID*)(UINTN)PermanentMemoryBase,
(VOID*)(UINTN)TemporaryMemoryBase,
(VOID*)(UINTN)PermanentMemoryBase,
(VOID*)(UINTN)TemporaryMemoryBase,
CopySize
);
//
// SecSwitchStack function must be invoked after the memory migration
// immediatly, also we need fixup the stack change caused by new call into
// immediatly, also we need fixup the stack change caused by new call into
// permenent memory.
//
//
SecSwitchStack (
(UINT32) TemporaryMemoryBase,
(UINT32) PermanentMemoryBase
);
//
// We need *not* fix the return address because currently,
// We need *not* fix the return address because currently,
// The PeiCore is excuted in flash.
//
//
// Simulate to invalid temporary memory, terminate temporary memory
//
//
//ZeroMem ((VOID*)(UINTN)TemporaryMemoryBase, CopySize);
return EFI_SUCCESS;
}