From ccd55824e79865a04b1c872bda4af0f1de1f50be Mon Sep 17 00:00:00 2001 From: qhuang8 Date: Tue, 25 Aug 2009 07:29:13 +0000 Subject: Integrate patch from Andrew Fish to make it run on OS X. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9194 6f19259b-4bc3-4df7-8a09-765794883524 --- UnixPkg/CpuRuntimeDxe/Cpu.c | 17 +- UnixPkg/CpuRuntimeDxe/Cpu.inf | 4 +- UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c | 32 +- UnixPkg/FvbServicesRuntimeDxe/FvbInfo.c | 4 +- UnixPkg/FvbServicesRuntimeDxe/FwBlockService.h | 16 +- UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf | 2 +- UnixPkg/Include/Common/UnixInclude.h | 30 +- UnixPkg/Include/Ppi/UnixAutoScan.h | 2 +- UnixPkg/Include/Ppi/UnixFwh.h | 2 +- UnixPkg/Include/Ppi/UnixPeiLoadFile.h | 2 +- UnixPkg/Include/Ppi/UnixThunk.h | 2 +- UnixPkg/Include/Protocol/UnixIo.h | 20 +- UnixPkg/Include/Protocol/UnixThunk.h | 55 ++- UnixPkg/Include/UnixDxe.h | 2 +- .../DxeUnixPeCoffExtraActionLib.c | 39 +- .../DxeUnixPeCoffExtraActionLib.inf | 4 +- .../PeCoffGetEntryPoint.c | 39 +- .../PeiUnixPeCoffExtraActionLib.c | 36 +- .../PeiUnixPeCoffExtraActionLib.inf | 4 +- UnixPkg/Library/UnixBdsLib/PlatformBds.inf | 2 +- UnixPkg/Library/UnixBdsLib/PlatformData.c | 40 +- .../MiscSubClassPlatformDxe/MiscSubClassDriver.inf | 2 +- UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.c | 2 +- UnixPkg/ResetRuntimeDxe/Reset.c | 30 +- UnixPkg/Sec/Ia32/Stack.S | 95 +++++ UnixPkg/Sec/SecMain.c | 425 ++++++++++++++++++--- UnixPkg/Sec/SecMain.h | 61 ++- UnixPkg/Sec/SecMain.inf | 15 +- UnixPkg/Sec/UgaX11.c | 61 ++- UnixPkg/Sec/UnixThunk.c | 138 ++++++- UnixPkg/TimerDxe/Timer.c | 36 +- UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c | 2 +- UnixPkg/UnixBlockIoDxe/UnixBlockIo.c | 3 +- UnixPkg/UnixBlockIoDxe/UnixBlockIo.h | 2 +- UnixPkg/UnixConsoleDxe/Console.h | 8 +- UnixPkg/UnixConsoleDxe/ConsoleIn.c | 20 +- UnixPkg/UnixConsoleDxe/ConsoleOut.c | 96 ++--- UnixPkg/UnixConsoleDxe/UnixConsole.inf | 4 +- UnixPkg/UnixSerialIoDxe/UnixSerialIo.c | 14 +- UnixPkg/UnixSerialIoDxe/UnixSerialIo.h | 8 +- .../UnixSimpleFileSystemDxe/UnixSimpleFileSystem.c | 11 +- .../UnixSimpleFileSystemDxe/UnixSimpleFileSystem.h | 6 +- UnixPkg/UnixThunkDxe/UnixThunk.c | 2 +- UnixPkg/UnixThunkDxe/UnixThunk.inf | 4 +- 44 files changed, 1039 insertions(+), 360 deletions(-) create mode 100644 UnixPkg/Sec/Ia32/Stack.S (limited to 'UnixPkg') diff --git a/UnixPkg/CpuRuntimeDxe/Cpu.c b/UnixPkg/CpuRuntimeDxe/Cpu.c index dc25d4d812..a151aafc07 100644 --- a/UnixPkg/CpuRuntimeDxe/Cpu.c +++ b/UnixPkg/CpuRuntimeDxe/Cpu.c @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2006, Intel Corporation +Copyright (c) 2006 - 2009, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -58,12 +58,15 @@ CPU_ARCH_PROTOCOL_PRIVATE mCpuTemplate = { 4 }, { - CpuMemoryServiceRead, - CpuMemoryServiceWrite, - CpuIoServiceRead, - CpuIoServiceWrite + { + CpuMemoryServiceRead, + CpuMemoryServiceWrite + }, + { + CpuIoServiceRead, + CpuIoServiceWrite + } }, - 0, TRUE }; @@ -430,7 +433,7 @@ Returns: // // Locate DataHub protocol. // - Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, &DataHub); + Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID **)&DataHub); if (EFI_ERROR (Status)) { return; } diff --git a/UnixPkg/CpuRuntimeDxe/Cpu.inf b/UnixPkg/CpuRuntimeDxe/Cpu.inf index edab145b61..a0f66b6713 100644 --- a/UnixPkg/CpuRuntimeDxe/Cpu.inf +++ b/UnixPkg/CpuRuntimeDxe/Cpu.inf @@ -42,7 +42,7 @@ IntelFrameworkPkg/IntelFrameworkPkg.dec IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec UnixPkg/UnixPkg.dec - MdePkg/MdePkg.dec + MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec @@ -70,4 +70,4 @@ [Depex] - gEfiDataHubProtocolGuid + gEfiDataHubProtocolGuid diff --git a/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c b/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c index 132442b6b9..30723c5d72 100644 --- a/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c +++ b/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2006 - 2008, Intel Corporation +Copyright (c) 2006 - 2009, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -33,8 +33,8 @@ Revision History #include #include #include -#include -#include +#include +#include #include "FwBlockService.h" @@ -210,7 +210,7 @@ Returns: --*/ { - EFI_FW_VOL_INSTANCE *FwhInstance; + EFI_FW_VOL_INSTANCE *FwhInstance = NULL; EFI_STATUS Status; // @@ -250,7 +250,7 @@ Returns: --*/ { - EFI_FW_VOL_INSTANCE *FwhInstance; + EFI_FW_VOL_INSTANCE *FwhInstance = NULL; EFI_STATUS Status; // @@ -303,7 +303,7 @@ Returns: UINTN Offset; EFI_LBA StartLba; EFI_LBA NextLba; - EFI_FW_VOL_INSTANCE *FwhInstance; + EFI_FW_VOL_INSTANCE *FwhInstance = NULL; EFI_FV_BLOCK_MAP_ENTRY *BlockMap; EFI_STATUS Status; @@ -626,7 +626,7 @@ Returns: --*/ { - EFI_FW_VOL_INSTANCE *FwhInstance; + EFI_FW_VOL_INSTANCE *FwhInstance = NULL; EFI_FVB_ATTRIBUTES_2 OldAttributes; EFI_FVB_ATTRIBUTES_2 *AttribPtr; UINT32 Capabilities; @@ -733,7 +733,7 @@ Returns: EFI_STATUS EFIAPI FvbProtocolGetPhysicalAddress ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, OUT EFI_PHYSICAL_ADDRESS *Address ) /*++ @@ -764,7 +764,7 @@ Returns: EFI_STATUS EFIAPI FvbProtocolGetBlockSize ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN EFI_LBA Lba, OUT UINTN *BlockSize, OUT UINTN *NumOfBlocks @@ -808,7 +808,7 @@ Returns: EFI_STATUS EFIAPI FvbProtocolGetAttributes ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, OUT EFI_FVB_ATTRIBUTES_2 *Attributes ) /*++ @@ -835,7 +835,7 @@ Returns: EFI_STATUS EFIAPI FvbProtocolSetAttributes ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes ) /*++ @@ -862,7 +862,7 @@ Returns: EFI_STATUS EFIAPI FvbProtocolEraseBlocks ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, ... ) /*++ @@ -891,7 +891,7 @@ Returns: --*/ { EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; - EFI_FW_VOL_INSTANCE *FwhInstance; + EFI_FW_VOL_INSTANCE *FwhInstance = NULL; UINTN NumOfBlocks; VA_LIST args; EFI_LBA StartingLba; @@ -960,7 +960,7 @@ Returns: EFI_STATUS EFIAPI FvbProtocolWrite ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN EFI_LBA Lba, IN UINTN Offset, IN OUT UINTN *NumBytes, @@ -1008,7 +1008,7 @@ Returns: EFI_STATUS EFIAPI FvbProtocolRead ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN EFI_LBA Lba, IN UINTN Offset, IN OUT UINTN *NumBytes, @@ -1124,7 +1124,7 @@ Returns: --*/ { EFI_STATUS Status; - EFI_FW_VOL_INSTANCE *FwhInstance; + EFI_FW_VOL_INSTANCE *FwhInstance = NULL; EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; EFI_DXE_SERVICES *DxeServices; EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor; diff --git a/UnixPkg/FvbServicesRuntimeDxe/FvbInfo.c b/UnixPkg/FvbServicesRuntimeDxe/FvbInfo.c index 0e7580cb36..b8399edf99 100644 --- a/UnixPkg/FvbServicesRuntimeDxe/FvbInfo.c +++ b/UnixPkg/FvbServicesRuntimeDxe/FvbInfo.c @@ -34,8 +34,8 @@ Abstract: #include #include #include -#include -#include +#include +#include #include #include diff --git a/UnixPkg/FvbServicesRuntimeDxe/FwBlockService.h b/UnixPkg/FvbServicesRuntimeDxe/FwBlockService.h index 5ed8107745..b87192dfde 100644 --- a/UnixPkg/FvbServicesRuntimeDxe/FwBlockService.h +++ b/UnixPkg/FvbServicesRuntimeDxe/FwBlockService.h @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2006, Intel Corporation +Copyright (c) 2006 - 2009, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -161,7 +161,7 @@ FvbGetLbaAddress ( EFI_STATUS EFIAPI FvbProtocolGetAttributes ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, OUT EFI_FVB_ATTRIBUTES_2 *Attributes ) ; @@ -169,7 +169,7 @@ FvbProtocolGetAttributes ( EFI_STATUS EFIAPI FvbProtocolSetAttributes ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes ) ; @@ -177,7 +177,7 @@ FvbProtocolSetAttributes ( EFI_STATUS EFIAPI FvbProtocolGetPhysicalAddress ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, OUT EFI_PHYSICAL_ADDRESS *Address ) ; @@ -185,7 +185,7 @@ FvbProtocolGetPhysicalAddress ( EFI_STATUS EFIAPI FvbProtocolGetBlockSize ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN EFI_LBA Lba, OUT UINTN *BlockSize, OUT UINTN *NumOfBlocks @@ -195,7 +195,7 @@ FvbProtocolGetBlockSize ( EFI_STATUS EFIAPI FvbProtocolRead ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN EFI_LBA Lba, IN UINTN Offset, IN OUT UINTN *NumBytes, @@ -206,7 +206,7 @@ FvbProtocolRead ( EFI_STATUS EFIAPI FvbProtocolWrite ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN EFI_LBA Lba, IN UINTN Offset, IN OUT UINTN *NumBytes, @@ -217,7 +217,7 @@ FvbProtocolWrite ( EFI_STATUS EFIAPI FvbProtocolEraseBlocks ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, ... ) ; diff --git a/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf b/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf index 05fc427091..0f3817f028 100644 --- a/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf +++ b/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf @@ -53,7 +53,7 @@ DxeServicesTableLib BaseLib UefiDriverEntryPoint - UefiLib + UefiLib DevicePathLib diff --git a/UnixPkg/Include/Common/UnixInclude.h b/UnixPkg/Include/Common/UnixInclude.h index 922964672c..487386f9cb 100644 --- a/UnixPkg/Include/Common/UnixInclude.h +++ b/UnixPkg/Include/Common/UnixInclude.h @@ -1,6 +1,7 @@ /*++ -Copyright (c) 2006, Intel Corporation +Copyright (c) 2006 - 2009, Intel Corporation +Portions copyright (c) 2008-2009 Apple Inc. All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -19,14 +20,21 @@ Abstract: #ifndef __UNIX_INCLUDE_H__ #define __UNIX_INCLUDE_H__ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include + +#ifdef __APPLE__ +#include +#include +#else +#include +#endif + +#include +#include +#include +#include +#include +#include +#include #endif diff --git a/UnixPkg/Include/Ppi/UnixAutoScan.h b/UnixPkg/Include/Ppi/UnixAutoScan.h index 0c04d8202e..9660796eff 100644 --- a/UnixPkg/Include/Ppi/UnixAutoScan.h +++ b/UnixPkg/Include/Ppi/UnixAutoScan.h @@ -26,7 +26,7 @@ Unix Autoscan PPI #define PEI_UNIX_AUTOSCAN_PPI_GUID \ { \ - 0xf2ed3d14, 0x8985, 0x11db, {0xb0, 0x57, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ + 0xf2ed3d14, 0x8985, 0x11db, {0xb0, 0x57, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ } typedef diff --git a/UnixPkg/Include/Ppi/UnixFwh.h b/UnixPkg/Include/Ppi/UnixFwh.h index a9885a57bf..1deed11454 100644 --- a/UnixPkg/Include/Ppi/UnixFwh.h +++ b/UnixPkg/Include/Ppi/UnixFwh.h @@ -26,7 +26,7 @@ Abstract: #define UNIX_FWH_PPI_GUID \ { \ - 0xf2f0dc30, 0x8985, 0x11db, {0xa1, 0x5b, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ + 0xf2f0dc30, 0x8985, 0x11db, {0xa1, 0x5b, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ } typedef diff --git a/UnixPkg/Include/Ppi/UnixPeiLoadFile.h b/UnixPkg/Include/Ppi/UnixPeiLoadFile.h index b91c630b5a..cfd58fdb35 100644 --- a/UnixPkg/Include/Ppi/UnixPeiLoadFile.h +++ b/UnixPkg/Include/Ppi/UnixPeiLoadFile.h @@ -28,7 +28,7 @@ Abstract: #define UNIX_PEI_LOAD_FILE_GUID \ { \ - 0xf2f48768, 0x8985, 0x11db, {0xb8, 0xda, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ + 0xf2f48768, 0x8985, 0x11db, {0xb8, 0xda, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ } typedef diff --git a/UnixPkg/Include/Ppi/UnixThunk.h b/UnixPkg/Include/Ppi/UnixThunk.h index 866bd61398..ba4d413131 100644 --- a/UnixPkg/Include/Ppi/UnixThunk.h +++ b/UnixPkg/Include/Ppi/UnixThunk.h @@ -26,7 +26,7 @@ Abstract: #define PEI_UNIX_THUNK_PPI_GUID \ { \ - 0xf2f830f2, 0x8985, 0x11db, {0x80, 0x6b, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ + 0xf2f830f2, 0x8985, 0x11db, {0x80, 0x6b, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ } typedef diff --git a/UnixPkg/Include/Protocol/UnixIo.h b/UnixPkg/Include/Protocol/UnixIo.h index 1758ecb7c4..c25b06f071 100644 --- a/UnixPkg/Include/Protocol/UnixIo.h +++ b/UnixPkg/Include/Protocol/UnixIo.h @@ -22,7 +22,7 @@ Abstract: #define EFI_UNIX_IO_PROTOCOL_GUID \ { \ - 0xf2e23f54, 0x8985, 0x11db, {0xac, 0x79, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ + 0xf2e23f54, 0x8985, 0x11db, {0xac, 0x79, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ } typedef struct { @@ -44,7 +44,7 @@ extern EFI_GUID gEfiUnixIoProtocolGuid; // #define EFI_UNIX_VIRTUAL_DISKS_GUID \ { \ - 0xf2ba331a, 0x8985, 0x11db, {0xa4, 0x06, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ + 0xf2ba331a, 0x8985, 0x11db, {0xa4, 0x06, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ } extern EFI_GUID gEfiUnixVirtualDisksGuid; @@ -54,7 +54,7 @@ extern EFI_GUID gEfiUnixVirtualDisksGuid; // #define EFI_UNIX_PHYSICAL_DISKS_GUID \ { \ - 0xf2bdcc96, 0x8985, 0x11db, {0x87, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ + 0xf2bdcc96, 0x8985, 0x11db, {0x87, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ } extern EFI_GUID gEfiUnixPhysicalDisksGuid; @@ -64,7 +64,7 @@ extern EFI_GUID gEfiUnixPhysicalDisksGuid; // #define EFI_UNIX_FILE_SYSTEM_GUID \ { \ - 0xf2c16b9e, 0x8985, 0x11db, {0x92, 0xc8, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ + 0xf2c16b9e, 0x8985, 0x11db, {0x92, 0xc8, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ } extern EFI_GUID gEfiUnixFileSystemGuid; @@ -84,7 +84,7 @@ extern EFI_GUID gEfiUnixSerialPortGuid; // #define EFI_UNIX_UGA_GUID \ { \ - 0xf2c8b80e, 0x8985, 0x11db, {0x93, 0xf1, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ + 0xf2c8b80e, 0x8985, 0x11db, {0x93, 0xf1, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ } extern EFI_GUID gEfiUnixUgaGuid; @@ -94,7 +94,7 @@ extern EFI_GUID gEfiUnixUgaGuid; // #define EFI_UNIX_GOP_GUID \ { \ - 0xbace07c2, 0x8987, 0x11db, {0xa5, 0x9a, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ + 0xbace07c2, 0x8987, 0x11db, {0xa5, 0x9a, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ } extern EFI_GUID gEfiUnixGopGuid; @@ -104,7 +104,7 @@ extern EFI_GUID gEfiUnixGopGuid; // #define EFI_UNIX_CONSOLE_GUID \ { \ - 0xf2cc5d06, 0x8985, 0x11db, {0xbb, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ + 0xf2cc5d06, 0x8985, 0x11db, {0xbb, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ } extern EFI_GUID gEfiUnixConsoleGuid; @@ -114,7 +114,7 @@ extern EFI_GUID gEfiUnixConsoleGuid; // #define EFI_UNIX_MEMORY_GUID \ { \ - 0xf2d006cc, 0x8985, 0x11db, {0xa4, 0x72, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ + 0xf2d006cc, 0x8985, 0x11db, {0xa4, 0x72, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ } extern EFI_GUID gEfiUnixMemoryGuid; @@ -124,7 +124,7 @@ extern EFI_GUID gEfiUnixMemoryGuid; // #define EFI_UNIX_CPU_MODEL_GUID \ { \ - 0xf2d3b330, 0x8985, 0x11db, {0x8a, 0xa3, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ + 0xf2d3b330, 0x8985, 0x11db, {0x8a, 0xa3, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ } extern EFI_GUID gEfiUnixCPUModelGuid; @@ -134,7 +134,7 @@ extern EFI_GUID gEfiUnixCPUModelGuid; // #define EFI_UNIX_CPU_SPEED_GUID \ { \ - 0xf2d74e5a, 0x8985, 0x11db, {0x97, 0x05, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ + 0xf2d74e5a, 0x8985, 0x11db, {0x97, 0x05, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ } extern EFI_GUID gEfiUnixCPUSpeedGuid; diff --git a/UnixPkg/Include/Protocol/UnixThunk.h b/UnixPkg/Include/Protocol/UnixThunk.h index ba325bff87..29a9791292 100644 --- a/UnixPkg/Include/Protocol/UnixThunk.h +++ b/UnixPkg/Include/Protocol/UnixThunk.h @@ -1,6 +1,7 @@ /*++ -Copyright (c) 2004, Intel Corporation +Copyright (c) 2004 - 2009, Intel Corporation +Portions copyright (c) 2008-2009 Apple Inc.
All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -31,7 +32,13 @@ Abstract: #include #include #include + +#if __CYGWIN__ +#include +#else #include +#endif + #include #include #include @@ -42,12 +49,24 @@ Abstract: #include #include #include -#include #include + +#ifdef __APPLE__ +#include +#include +#define _XOPEN_SOURCE +#else +#include #include +#endif + #include #include +#include +#include + + #define EFI_UNIX_THUNK_PROTOCOL_GUID \ { \ 0xf2e98868, 0x8985, 0x11db, {0x9a, 0x59, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \ @@ -167,7 +186,11 @@ void typedef int +#if __CYGWIN__ +(*UnixIoCtl) (int fd, int __request, ...); +#else (*UnixIoCtl) (int fd, unsigned long int __request, ...); +#endif typedef int @@ -204,8 +227,29 @@ VOID * // +// Work functions to enable source level debug in the emulator // -// + +typedef +RETURN_STATUS +(EFIAPI *UnixPeCoffGetEntryPoint) ( + IN VOID *Pe32Data, + IN OUT VOID **EntryPoint + ); + +typedef +VOID +(EFIAPI *UnixPeCoffRelocateImageExtraAction) ( + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext + ); + +typedef +VOID +(EFIAPI *UnixPeCoffLoaderUnloadImageExtraAction) ( + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext + ); + + #define EFI_UNIX_THUNK_PROTOCOL_SIGNATURE SIGNATURE_32 ('L', 'N', 'X', 'T') @@ -254,6 +298,11 @@ typedef struct _EFI_UNIX_THUNK_PROTOCOL { UnixDlopen Dlopen; UnixDlerror Dlerror; UnixDlsym Dlsym; + UnixPeCoffGetEntryPoint PeCoffGetEntryPoint; + UnixPeCoffRelocateImageExtraAction PeCoffRelocateImageExtraAction; + UnixPeCoffLoaderUnloadImageExtraAction PeCoffUnloadImageExtraAction; + + } EFI_UNIX_THUNK_PROTOCOL; extern EFI_GUID gEfiUnixThunkProtocolGuid; diff --git a/UnixPkg/Include/UnixDxe.h b/UnixPkg/Include/UnixDxe.h index 29a0c16e0f..7ab91b900d 100644 --- a/UnixPkg/Include/UnixDxe.h +++ b/UnixPkg/Include/UnixDxe.h @@ -29,7 +29,7 @@ Abstract: // UnixIo.h depends on UnixThunk.h // -#include +#include #include #include diff --git a/UnixPkg/Library/DxeUnixPeCoffExtraActionLib/DxeUnixPeCoffExtraActionLib.c b/UnixPkg/Library/DxeUnixPeCoffExtraActionLib/DxeUnixPeCoffExtraActionLib.c index 014390cf4f..b700975fc8 100644 --- a/UnixPkg/Library/DxeUnixPeCoffExtraActionLib/DxeUnixPeCoffExtraActionLib.c +++ b/UnixPkg/Library/DxeUnixPeCoffExtraActionLib/DxeUnixPeCoffExtraActionLib.c @@ -1,6 +1,7 @@ /**@file Copyright (c) 2006 - 2009, Intel Corporation +Portions copyright (c) 2008-2009 Apple Inc. All rights reserved. All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -22,12 +23,10 @@ Abstract: **/ -#include -#include +#include #include #include - #include #include #include @@ -35,9 +34,12 @@ Abstract: #include // + // Cache of UnixThunk protocol + // -EFI_UNIX_THUNK_PROTOCOL *mUnix; + +EFI_UNIX_THUNK_PROTOCOL *mUnix = NULL; /** @@ -82,35 +84,10 @@ PeCoffLoaderRelocateImageExtraAction ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { - VOID * Handle; - VOID * Entry; - - ASSERT (ImageContext != NULL); - - Handle = NULL; - Entry = NULL; - - DEBUG ((EFI_D_ERROR, "Loading %a 0x%08lx - entry point 0x%08lx\n", - ImageContext->PdbPointer, - (UINTN)ImageContext->ImageAddress, - (UINTN)ImageContext->EntryPoint)); - - Handle = mUnix->Dlopen(ImageContext->PdbPointer, RTLD_NOW); - - if (Handle) { - Entry = mUnix->Dlsym(Handle, "_ModuleEntryPoint"); - } else { - DEBUG ((EFI_D_ERROR, "%a\n", mUnix->Dlerror())); - } - - if (Entry != NULL) { - ImageContext->EntryPoint = Entry; - DEBUG ((EFI_D_ERROR, "Change %a Entrypoint to :0x%08lx\n", ImageContext->PdbPointer, Entry)); + mUnix->PeCoffRelocateImageExtraAction (ImageContext); } - return; - } /** Performs additional actions just before a PE/COFF image is unloaded. Any resources @@ -128,5 +105,5 @@ PeCoffLoaderUnloadImageExtraAction ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { - ASSERT (ImageContext != NULL); + mUnix->PeCoffUnloadImageExtraAction (ImageContext); } diff --git a/UnixPkg/Library/DxeUnixPeCoffExtraActionLib/DxeUnixPeCoffExtraActionLib.inf b/UnixPkg/Library/DxeUnixPeCoffExtraActionLib/DxeUnixPeCoffExtraActionLib.inf index 93c514692c..83d6963982 100644 --- a/UnixPkg/Library/DxeUnixPeCoffExtraActionLib/DxeUnixPeCoffExtraActionLib.inf +++ b/UnixPkg/Library/DxeUnixPeCoffExtraActionLib/DxeUnixPeCoffExtraActionLib.inf @@ -2,7 +2,7 @@ # PeCoff extra action libary for DXE phase that run Unix emulator. # # Lib to provide memory journal status code reporting Routines -# Copyright (c) 2007, Intel Corporation +# Copyright (c) 2007 - 2009, Intel Corporation # All rights reserved. This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -39,8 +39,6 @@ [Packages] UnixPkg/UnixPkg.dec MdePkg/MdePkg.dec - IntelFrameworkPkg/IntelFrameworkPkg.dec - IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec [LibraryClasses] DebugLib diff --git a/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c b/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c index be9cba831c..ef0d6c17cb 100644 --- a/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c +++ b/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c @@ -1,6 +1,7 @@ /*++ -Copyright (c) 2006 - 2008, Intel Corporation +Copyright (c) 2006 - 2009, Intel Corporation +Portions copyright (c) 2008-2009 Apple Inc. All rights reserved. All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -54,38 +55,24 @@ Returns: --*/ { + PEI_UNIX_THUNK_PPI *UnixThunkPpi; EFI_STATUS Status; - EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor; - UNIX_PEI_LOAD_FILE_PPI *PeiUnixService; - EFI_PHYSICAL_ADDRESS ImageAddress; - UINT64 ImageSize; - EFI_PHYSICAL_ADDRESS ImageEntryPoint; - - ASSERT (Pe32Data != NULL); - ASSERT (EntryPoint != NULL); + EFI_UNIX_THUNK_PROTOCOL *Unix; + // + // Locate Unix ThunkPpi for retrieving standard output handle + // Status = PeiServicesLocatePpi ( - &gUnixPeiLoadFilePpiGuid, + &gPeiUnixThunkPpiGuid, 0, - &PpiDescriptor, - (void **)&PeiUnixService + NULL, + (VOID **) &UnixThunkPpi ); - ASSERT_EFI_ERROR (Status); - Status = PeiUnixService->PeiLoadFileService ( - Pe32Data, - &ImageAddress, - &ImageSize, - &ImageEntryPoint - ); - - if (EFI_ERROR (Status)) { - return Status; - } + Unix = (EFI_UNIX_THUNK_PROTOCOL *)UnixThunkPpi->UnixThunk (); - *EntryPoint = (VOID*)(UINTN)ImageEntryPoint; - return Status; + return Unix->PeCoffGetEntryPoint (Pe32Data, EntryPoint); } /** @@ -255,6 +242,8 @@ PeCoffLoaderGetPdbPointer ( return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY)); case CODEVIEW_SIGNATURE_RSDS: return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY)); + case CODEVIEW_SIGNATURE_MTOC: + return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY)); default: break; } diff --git a/UnixPkg/Library/PeiUnixPeCoffExtraActionLib/PeiUnixPeCoffExtraActionLib.c b/UnixPkg/Library/PeiUnixPeCoffExtraActionLib/PeiUnixPeCoffExtraActionLib.c index 3b2af0301b..dea03fb142 100644 --- a/UnixPkg/Library/PeiUnixPeCoffExtraActionLib/PeiUnixPeCoffExtraActionLib.c +++ b/UnixPkg/Library/PeiUnixPeCoffExtraActionLib/PeiUnixPeCoffExtraActionLib.c @@ -1,6 +1,7 @@ /**@file Copyright (c) 2006 - 2009, Intel Corporation +Portions copyright (c) 2008-2009 Apple Inc. All rights reserved. All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -36,7 +37,7 @@ Abstract: EFI_UNIX_THUNK_PROTOCOL *mUnix = NULL; /** - The function caches the pointer of the WinNT thunk functions + The function caches the pointer of the Unix thunk functions It will ASSERT() if Unix thunk ppi is not installed. @retval EFI_SUCCESS WinNT thunk protocol is found and cached. @@ -83,38 +84,12 @@ PeCoffLoaderRelocateImageExtraAction ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { - VOID * Handle; - VOID * Entry; - - ASSERT (ImageContext != NULL); - - Handle = NULL; - Entry = NULL; - if (mUnix == NULL) { UnixPeCoffGetUnixThunkStucture (); } - DEBUG ((EFI_D_ERROR, "Loading %a 0x%08lx - entry point 0x%08lx\n", - ImageContext->PdbPointer, - (UINTN)ImageContext->ImageAddress, - (UINTN)ImageContext->EntryPoint)); - - Handle = mUnix->Dlopen (ImageContext->PdbPointer, RTLD_NOW); - - if (Handle) { - Entry = mUnix->Dlsym(Handle, "_ModuleEntryPoint"); - } else { - DEBUG ((EFI_D_ERROR, "%a\n", mUnix->Dlerror())); + mUnix->PeCoffRelocateImageExtraAction (ImageContext); } - - if (Entry != NULL) { - ImageContext->EntryPoint = Entry; - DEBUG ((EFI_D_ERROR, "Change %a Entrypoint to :0x%08lx\n", ImageContext->PdbPointer, Entry)); - } - - return; - } /** Performs additional actions just before a PE/COFF image is unloaded. Any resources @@ -132,5 +107,8 @@ PeCoffLoaderUnloadImageExtraAction ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { - ASSERT (ImageContext != NULL); + if (mUnix == NULL) { + UnixPeCoffGetUnixThunkStucture (); + } + mUnix->PeCoffUnloadImageExtraAction (ImageContext); } diff --git a/UnixPkg/Library/PeiUnixPeCoffExtraActionLib/PeiUnixPeCoffExtraActionLib.inf b/UnixPkg/Library/PeiUnixPeCoffExtraActionLib/PeiUnixPeCoffExtraActionLib.inf index 1ecdd29681..722d586e17 100644 --- a/UnixPkg/Library/PeiUnixPeCoffExtraActionLib/PeiUnixPeCoffExtraActionLib.inf +++ b/UnixPkg/Library/PeiUnixPeCoffExtraActionLib/PeiUnixPeCoffExtraActionLib.inf @@ -2,7 +2,7 @@ # PeCoff extra action libary for Pei phase that run UNIX emulator. # # Lib to provide memory journal status code reporting Routines -# Copyright (c) 2007, Intel Corporation +# Copyright (c) 2007 - 2009, Intel Corporation # All rights reserved. This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -37,8 +37,6 @@ [Packages] MdePkg/MdePkg.dec UnixPkg/UnixPkg.dec - IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec - IntelFrameworkPkg/IntelFrameworkPkg.dec [LibraryClasses] BaseLib diff --git a/UnixPkg/Library/UnixBdsLib/PlatformBds.inf b/UnixPkg/Library/UnixBdsLib/PlatformBds.inf index 1a5604d8f2..834b5c6897 100644 --- a/UnixPkg/Library/UnixBdsLib/PlatformBds.inf +++ b/UnixPkg/Library/UnixBdsLib/PlatformBds.inf @@ -50,7 +50,7 @@ BaseMemoryLib DebugLib PcdLib - GenericBdsLib + GenericBdsLib DevicePathLib diff --git a/UnixPkg/Library/UnixBdsLib/PlatformData.c b/UnixPkg/Library/UnixBdsLib/PlatformData.c index 9051dbf33f..df60c1c96c 100644 --- a/UnixPkg/Library/UnixBdsLib/PlatformData.c +++ b/UnixPkg/Library/UnixBdsLib/PlatformData.c @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2006, Intel Corporation +Copyright (c) 2006 - 2009, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -32,22 +32,22 @@ UINT16 gPlatformBootTimeOutDefault = 10; // UNIX_PLATFORM_UGA_DEVICE_PATH gUgaDevicePath0 = { - { + { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, - { + { (UINT8) (sizeof (VENDOR_DEVICE_PATH)), - (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8), - }, + (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) + }, EFI_UNIX_THUNK_PROTOCOL_GUID }, { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, - { + { (UINT8) (sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)), - (UINT8) ((sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)) >> 8), - }, + (UINT8) ((sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)) >> 8) + }, EFI_UNIX_UGA_GUID, 0 }, @@ -58,19 +58,19 @@ UNIX_PLATFORM_UGA_DEVICE_PATH gUgaDevicePath1 = { { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, - { + { (UINT8) (sizeof (VENDOR_DEVICE_PATH)), - (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8), - }, + (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) + }, EFI_UNIX_THUNK_PROTOCOL_GUID }, { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, - { + { (UINT8) (sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)), - (UINT8) ((sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)) >> 8), - }, + (UINT8) ((sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)) >> 8) + }, EFI_UNIX_UGA_GUID, 1 }, @@ -80,20 +80,20 @@ UNIX_PLATFORM_UGA_DEVICE_PATH gUgaDevicePath1 = { UNIX_CONSOLE_DEVICE_PATH gUnixConsoleDevicePath = { { HARDWARE_DEVICE_PATH, - HW_VENDOR_DP, + HW_VENDOR_DP, { (UINT8) (sizeof (VENDOR_DEVICE_PATH)), - (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8), - }, + (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) + }, EFI_UNIX_THUNK_PROTOCOL_GUID }, { HARDWARE_DEVICE_PATH, - HW_VENDOR_DP, + HW_VENDOR_DP, { (UINT8) (sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)), - (UINT8) ((sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)) >> 8), - }, + (UINT8) ((sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)) >> 8) + }, EFI_UNIX_CONSOLE_GUID, 0 }, diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf b/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf index 9a3e16e792..8623e91036 100644 --- a/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf +++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf @@ -64,7 +64,7 @@ [Packages] - MdePkg/MdePkg.dec + MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec IntelFrameworkPkg/IntelFrameworkPkg.dec IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec diff --git a/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.c b/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.c index b94e1f1776..d34f6eeaa6 100644 --- a/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.c +++ b/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.c @@ -89,7 +89,7 @@ Returns: } - gUnix->GetLocalTime (Time); + gUnix->GetLocalTime (Time); if (Capabilities != NULL) { Capabilities->Resolution = 1; diff --git a/UnixPkg/ResetRuntimeDxe/Reset.c b/UnixPkg/ResetRuntimeDxe/Reset.c index f583b649eb..329ca0a89d 100644 --- a/UnixPkg/ResetRuntimeDxe/Reset.c +++ b/UnixPkg/ResetRuntimeDxe/Reset.c @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2004 - 2008, Intel Corporation +Copyright (c) 2004 - 2009, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -113,9 +113,30 @@ Returns: --*/ { + EFI_STATUS Status; + UINTN HandleCount; + EFI_HANDLE *HandleBuffer; + UINTN Index; + // - // BUGBUG Need to kill all console windows later + // Disconnect all // + Status = gBS->LocateHandleBuffer ( + AllHandles, + NULL, + NULL, + &HandleCount, + &HandleBuffer + ); + if (!EFI_ERROR (Status)) { + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->DisconnectController (HandleBuffer[Index], NULL, NULL); + } + + gBS->FreePool (HandleBuffer); + } + + // // Discard ResetType, always return 0 as exit code // @@ -124,6 +145,7 @@ Returns: // // Should never go here // - while (1) - ; + ASSERT (FALSE); + + return; } diff --git a/UnixPkg/Sec/Ia32/Stack.S b/UnixPkg/Sec/Ia32/Stack.S new file mode 100644 index 0000000000..4716af9a9f --- /dev/null +++ b/UnixPkg/Sec/Ia32/Stack.S @@ -0,0 +1,95 @@ +#------------------------------------------------------------------------------ +# +# Copyright (c) 2008 - 2009, Intel Corporation +# Portions copyright (c) 2008-2009 Apple Inc. +# All rights reserved. This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# Module Name: +# +# Stack.asm +# +# Abstract: +# +# Switch the stack from temporary memory to permenent memory. +# +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# VOID +# EFIAPI +# SecSwitchStack ( +# UINT32 TemporaryMemoryBase, +# UINT32 PermenentMemoryBase +# ); +#------------------------------------------------------------------------------ + +#include + +ASM_GLOBAL ASM_PFX(SecSwitchStack) +ASM_PFX(SecSwitchStack): +# +# Save three register: eax, ebx, ecx +# + push %eax + push %ebx + push %ecx + push %edx + +# +# !!CAUTION!! this function address's is pushed into stack after +# migration of whole temporary memory, so need save it to permenent +# memory at first! +# + + movl 20(%esp), %ebx # Save the first parameter + movl 24(%esp), %ecx # Save the second parameter + +# +# Save this function's return address into permenent memory at first. +# Then, Fixup the esp point to permenent memory +# + + movl %esp, %eax + subl %ebx, %eax + addl %ecx, %eax + movl (%esp), %edx # copy pushed register's value to permenent memory + movl %edx, (%eax) + movl 4(%esp), %edx + movl %edx, 4(%eax) + movl 8(%esp), %edx + movl %edx, 8(%eax) + movl 12(%esp), %edx + movl %edx, 12(%eax) + movl 16(%esp), %edx + movl %edx, 16(%eax) + movl %eax, %esp # From now, esp is pointed to permenent memory + +# +# Fixup the ebp point to permenent memory +# +#ifndef __APPLE__ + movl %ebp, %eax + subl %ebx, %eax + addl %ecx, %eax + movl %eax, %ebp # From now, ebp is pointed to permenent memory + +# +# Fixup callee's ebp point for PeiDispatch +# + movl (%ebp), %eax + subl %ebx, %eax + addl %ecx, %eax + movl %eax, (%ebp) # From now, Temporary's PPI caller's stack is in permenent memory +#endif + + pop %edx + pop %ecx + pop %ebx + pop %eax + ret diff --git a/UnixPkg/Sec/SecMain.c b/UnixPkg/Sec/SecMain.c index 4e09ddc3e1..b1490aef56 100644 --- a/UnixPkg/Sec/SecMain.c +++ b/UnixPkg/Sec/SecMain.c @@ -1,6 +1,7 @@ /*++ -Copyright (c) 2006 - 2007 Intel Corporation. +Copyright (c) 2006 - 2009 Intel Corporation. +Portions copyright (c) 2008-2009 Apple Inc. All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -14,7 +15,7 @@ Module Name: SecMain.c Abstract: - WinNt emulator of SEC phase. It's really a Posix application, but this is + Unix emulator of SEC phase. It's really a Posix application, but this is Ok since all the other modules for NT32 are NOT Posix applications. This program processes host environment variables and figures out @@ -35,21 +36,29 @@ Abstract: #include "SecMain.h" #include #include +#include #include #include + +#ifdef __APPLE__ +#define MAP_ANONYMOUS MAP_ANON +char *gGdbWorkingFileName = NULL; +#endif + + // // Globals // -UNIX_PEI_LOAD_FILE_PPI mSecNtLoadFilePpi = { SecWinNtPeiLoadFile }; +UNIX_PEI_LOAD_FILE_PPI mSecUnixLoadFilePpi = { SecUnixPeiLoadFile }; -PEI_UNIX_AUTOSCAN_PPI mSecNtAutoScanPpi = { SecWinNtPeiAutoScan }; +PEI_UNIX_AUTOSCAN_PPI mSecUnixAutoScanPpi = { SecUnixPeiAutoScan }; -PEI_UNIX_THUNK_PPI mSecWinNtThunkPpi = { SecWinNtWinNtThunkAddress }; +PEI_UNIX_THUNK_PPI mSecUnixThunkPpi = { SecUnixUnixThunkAddress }; EFI_PEI_PROGRESS_CODE_PPI mSecStatusCodePpi = { SecPeiReportStatusCode }; -UNIX_FWH_PPI mSecFwhInformationPpi = { SecWinNtFdAddress }; +UNIX_FWH_PPI mSecFwhInformationPpi = { SecUnixFdAddress }; TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = {SecTemporaryRamSupport}; @@ -57,17 +66,17 @@ EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable[] = { { EFI_PEI_PPI_DESCRIPTOR_PPI, &gUnixPeiLoadFilePpiGuid, - &mSecNtLoadFilePpi + &mSecUnixLoadFilePpi }, { EFI_PEI_PPI_DESCRIPTOR_PPI, &gPeiUnixAutoScanPpiGuid, - &mSecNtAutoScanPpi + &mSecUnixAutoScanPpi }, { EFI_PEI_PPI_DESCRIPTOR_PPI, &gPeiUnixThunkPpiGuid, - &mSecWinNtThunkPpi + &mSecUnixThunkPpi }, { EFI_PEI_PPI_DESCRIPTOR_PPI, @@ -107,6 +116,12 @@ UNIX_FD_INFO *gFdInfo; UINTN gSystemMemoryCount = 0; UNIX_SYSTEM_MEMORY *gSystemMemory; + + +UINTN mImageContextModHandleArraySize = 0; +IMAGE_CONTEXT_TO_MOD_HANDLE *mImageContextModHandleArray = NULL; + + VOID EFIAPI SecSwitchStack ( @@ -134,17 +149,16 @@ SecNt32PeCoffRelocateImage ( ); -INTN -EFIAPI +int main ( - IN INTN Argc, - IN CHAR8 **Argv, - IN CHAR8 **Envp + IN int Argc, + IN char **Argv, + IN char **Envp ) /*++ Routine Description: - Main entry point to SEC for WinNt. This is a unix program + Main entry point to SEC for Unix. This is a unix program Arguments: Argc - Number of command line arguments @@ -179,6 +193,19 @@ Returns: printf ("\nEDK SEC Main UNIX Emulation Environment from www.TianoCore.org\n"); +#ifdef __APPLE__ + // + // We can't use dlopen on OS X, so we need a scheme to get symboles into gdb + // We need to create a temp file that contains gdb commands so we can load + // symbols when we load every PE/COFF image. + // + Index = strlen (*Argv); + gGdbWorkingFileName = malloc (Index + strlen(".gdb")); + strcpy (gGdbWorkingFileName, *Argv); + strcat (gGdbWorkingFileName, ".gdb"); +#endif + + // // Allocate space for gSystemMemory Array // @@ -200,12 +227,12 @@ Returns: // // Setup Boot Mode. If BootModeStr == "" then BootMode = 0 (BOOT_WITH_FULL_CONFIGURATION) // - printf (" BootMode 0x%02x\n", FixedPcdGet32 (PcdUnixBootMode)); + printf (" BootMode 0x%02x\n", (unsigned int)FixedPcdGet32 (PcdUnixBootMode)); // // Open up a 128K file to emulate temp memory for PEI. // on a real platform this would be SRAM, or using the cache as RAM. - // Set InitialStackMemory to zero so WinNtOpenFile will allocate a new mapping + // Set InitialStackMemory to zero so UnixOpenFile will allocate a new mapping // InitialStackMemorySize = STACK_SIZE; InitialStackMemory = (UINTN)MapMemory(0, @@ -218,11 +245,11 @@ Returns: } printf (" SEC passing in %u KB of temp RAM at 0x%08lx to PEI\n", - (UINTN)(InitialStackMemorySize / 1024), + (unsigned int)(InitialStackMemorySize / 1024), (unsigned long)InitialStackMemory); for (StackPointer = (UINTN*) (UINTN) InitialStackMemory; - StackPointer < (UINTN*) ((UINTN) InitialStackMemory + (UINT64) InitialStackMemorySize); + StackPointer < (UINTN*)(UINTN)((UINTN) InitialStackMemory + (UINT64) InitialStackMemorySize); StackPointer ++) { *StackPointer = 0x5AA55AA5; } @@ -255,7 +282,7 @@ Returns: &gFdInfo[Index].Size ); if (EFI_ERROR (Status)) { - printf ("ERROR : Can not open Firmware Device File %s (%x). Exiting.\n", FileName, Status); + printf ("ERROR : Can not open Firmware Device File %s (%x). Exiting.\n", FileName, (unsigned int)Status); exit (1); } @@ -354,7 +381,7 @@ MapFile ( /*++ Routine Description: - Opens and memory maps a file using WinNt services. If BaseAddress is non zero + Opens and memory maps a file using Unix services. If BaseAddress is non zero the process will try and allocate the memory starting at BaseAddress. Arguments: @@ -415,12 +442,12 @@ Returns: EFI_STATUS EFIAPI SecPeiReportStatusCode ( - IN EFI_PEI_SERVICES **PeiServices, + IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_STATUS_CODE_TYPE CodeType, IN EFI_STATUS_CODE_VALUE Value, IN UINT32 Instance, - IN EFI_GUID * CallerId, - IN EFI_STATUS_CODE_DATA * Data OPTIONAL + IN CONST EFI_GUID *CallerId, + IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL ) /*++ @@ -460,7 +487,7 @@ Returns: // // Processes ASSERT () // - printf ("ASSERT %s(%d): %s\n", Filename, LineNumber, Description); + printf ("ASSERT %s(%d): %s\n", Filename, (int)LineNumber, Description); } else if (ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) { // @@ -605,7 +632,7 @@ Returns: // // Load the PEI Core from a Firmware Volume // - Status = SecWinNtPeiLoadFile ( + Status = SecUnixPeiLoadFile ( PeiCorePe32File, &PeiImageAddress, &PeiCoreSize, @@ -633,7 +660,7 @@ Returns: EFI_STATUS EFIAPI -SecWinNtPeiAutoScan ( +SecUnixPeiAutoScan ( IN UINTN Index, OUT EFI_PHYSICAL_ADDRESS *MemoryBase, OUT UINT64 *MemorySize @@ -646,7 +673,7 @@ Routine Description: It uses gSystemMemory[] and gSystemMemoryCount that were created by parsing the host environment variable EFI_MEMORY_SIZE. The size comes from the varaible and the address comes from the call to - WinNtOpenFile. + UnixOpenFile. Arguments: Index - Which memory region to use @@ -680,19 +707,18 @@ Returns: VOID * EFIAPI -SecWinNtWinNtThunkAddress ( +SecUnixUnixThunkAddress ( VOID ) /*++ Routine Description: Since the SEC is the only Unix program in stack it must export - an interface to do Win API calls. That's what the WinNtThunk address - is for. gWinNt is initailized in WinNtThunk.c. + an interface to do POSIX calls. gUnix is initailized in UnixThunk.c. Arguments: InterfaceSize - sizeof (EFI_WIN_NT_THUNK_PROTOCOL); - InterfaceBase - Address of the gWinNt global + InterfaceBase - Address of the gUnix global Returns: EFI_SUCCESS - Data returned @@ -704,12 +730,11 @@ Returns: EFI_STATUS -EFIAPI -SecWinNtPeiLoadFile ( +SecUnixPeiLoadFile ( IN VOID *Pe32Data, - IN EFI_PHYSICAL_ADDRESS *ImageAddress, - IN UINT64 *ImageSize, - IN EFI_PHYSICAL_ADDRESS *EntryPoint + OUT EFI_PHYSICAL_ADDRESS *ImageAddress, + OUT UINT64 *ImageSize, + OUT EFI_PHYSICAL_ADDRESS *EntryPoint ) /*++ @@ -759,10 +784,7 @@ Returns: return Status; } - Status = SecNt32PeCoffRelocateImage(&ImageContext); - if (EFI_ERROR (Status)) { - return Status; - } + SecPeCoffRelocateImageExtraAction (&ImageContext); // // BugBug: Flush Instruction Cache Here when CPU Lib is ready @@ -775,9 +797,30 @@ Returns: return EFI_SUCCESS; } + +RETURN_STATUS +EFIAPI +SecPeCoffGetEntryPoint ( + IN VOID *Pe32Data, + IN OUT VOID **EntryPoint + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS ImageAddress; + UINT64 ImageSize; + EFI_PHYSICAL_ADDRESS PhysEntryPoint; + + Status = SecUnixPeiLoadFile (Pe32Data, &ImageAddress, &ImageSize, &PhysEntryPoint); + + *EntryPoint = (VOID *)(UINTN)PhysEntryPoint; + return Status; +} + + + EFI_STATUS EFIAPI -SecWinNtFdAddress ( +SecUnixFdAddress ( IN UINTN Index, IN OUT EFI_PHYSICAL_ADDRESS *FdBase, IN OUT UINT64 *FdSize @@ -882,6 +925,131 @@ Returns: } +EFI_STATUS +AddHandle ( + IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + IN VOID *ModHandle + ) +/*++ + +Routine Description: + Store the ModHandle in an array indexed by the Pdb File name. + The ModHandle is needed to unload the image. + +Arguments: + 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 + FreeLibrary(). + +Returns: + EFI_SUCCESS - ModHandle was stored. + +--*/ +{ + UINTN Index; + IMAGE_CONTEXT_TO_MOD_HANDLE *Array; + UINTN PreviousSize; + + + Array = mImageContextModHandleArray; + for (Index = 0; Index < mImageContextModHandleArraySize; Index++, Array++) { + if (Array->ImageContext == NULL) { + // + // Make a copy of the stirng and store the ModHandle + // + Array->ImageContext = ImageContext; + Array->ModHandle = ModHandle; + return EFI_SUCCESS; + } + } + + // + // 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. + // + PreviousSize = mImageContextModHandleArraySize * sizeof (IMAGE_CONTEXT_TO_MOD_HANDLE); + mImageContextModHandleArraySize += MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE; + + mImageContextModHandleArray = realloc (mImageContextModHandleArray, mImageContextModHandleArraySize * sizeof (IMAGE_CONTEXT_TO_MOD_HANDLE)); + if (mImageContextModHandleArray == NULL) { + 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); +} + + +VOID * +RemoveHandle ( + IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext + ) +/*++ + +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 + .PDB file name of the PE Image. + +Returns: + ModHandle - ModHandle assoicated with ImageContext is returned + NULL - No ModHandle associated with ImageContext + +--*/ +{ + UINTN Index; + IMAGE_CONTEXT_TO_MOD_HANDLE *Array; + + if (ImageContext->PdbPointer == NULL) { + // + // If no PDB pointer there is no ModHandle so return NULL + // + return NULL; + } + + Array = mImageContextModHandleArray; + for (Index = 0; Index < mImageContextModHandleArraySize; Index++, Array++) { + if ((Array->ImageContext == ImageContext)) { + // + // If you find a match return it and delete the entry + // + Array->ImageContext = NULL; + return Array->ModHandle; + } + } + + return NULL; +} + + + +// +// 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 +// +// cat .gdbinit +// b SecGdbScriptBreak +// command +// silent +// source SecMain.dll.gdb +// c +// end +// +VOID +SecGdbScriptBreak ( + VOID + ) +{ +} VOID SecUnixLoaderBreak ( @@ -890,19 +1058,128 @@ SecUnixLoaderBreak ( { } -EFI_STATUS +BOOLEAN +IsPdbFile ( + IN CHAR8 *PdbFileName + ) +{ + UINTN Len; + + if (PdbFileName == NULL) { + return FALSE; + } + + Len = strlen (PdbFileName); + 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; +} + + +#define MAX_SPRINT_BUFFER_SIZE 0x200 + +void +PrintLoadAddress ( + IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext + ) +{ + fprintf (stderr, + "0x%08lx Loading %s with entry point 0x%08lx\n", + (unsigned long)ImageContext->ImageAddress + ImageContext->SizeOfHeaders, + ImageContext->PdbPointer, + (unsigned long)ImageContext->EntryPoint + ); + + // Keep output synced up + fflush (stderr); +} + + +VOID EFIAPI -SecNt32PeCoffRelocateImage ( +SecPeCoffRelocateImageExtraAction ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { - void * Handle; - void * Entry; EFI_STATUS Status; - Handle = NULL; - Entry = NULL; Status = PeCoffLoaderRelocateImage (ImageContext); + if (EFI_ERROR (Status)) { + PrintLoadAddress (ImageContext); + return; + } + +#ifdef __APPLE__ + PrintLoadAddress (ImageContext); + + // + // In mach-o (OS X executable) dlopen() can only load files in the MH_DYLIB of MH_BUNDLE format. + // To convert to PE/COFF we need to construct a mach-o with the MH_PRELOAD format. We create + // .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. + // + if (ImageContext->PdbPointer != NULL && !IsPdbFile (ImageContext->PdbPointer)) { + // + // 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. + // + // 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 + // data base of info ready to roll. + // + // We could use qXfer:libraries:read, but OS X GDB does not currently support it. + // + // // ImageContext->PdbPointer + // // ImageContext->ImageAddress + ImageContext->SizeOfHeaders + // + // + // + + // + // Write the file we need for the gdb script + // + GdbTempFile = fopen (gGdbWorkingFileName, "w"); + if (GdbTempFile != NULL) { + fprintf (GdbTempFile, "add-symbol-file %s 0x%x\n", ImageContext->PdbPointer, (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)); + fclose (GdbTempFile); + + // + // 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, "Loading %s 0x%08lx - entry point 0x%08lx\n", ImageContext->PdbPointer, @@ -918,23 +1195,63 @@ SecNt32PeCoffRelocateImage ( } if (Entry != NULL) { - ImageContext->EntryPoint = Entry; - printf("Change %s Entrypoint to :0x%08lx\n", ImageContext->PdbPointer, Entry); + ImageContext->EntryPoint = (UINTN)Entry; + printf("Change %s Entrypoint to :0x%08lx\n", ImageContext->PdbPointer, (unsigned long)Entry); } SecUnixLoaderBreak (); - return Status; +#endif + + return; } -EFI_STATUS +VOID EFIAPI -SecNt32PeCoffUnloadimage ( +SecPeCoffLoaderUnloadImageExtraAction ( IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { - return EFI_SUCCESS; + VOID *Handle; + + Handle = RemoveHandle (ImageContext); + +#ifdef __APPLE__ + FILE *GdbTempFile; + + if (Handle != NULL) { + // + // Need to skip .PDB files created from VC++ + // + if (!IsPdbFile (ImageContext->PdbPointer)) { + // + // Write the file we need for the gdb script + // + GdbTempFile = fopen (gGdbWorkingFileName, "w"); + 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. + // 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 + // + if (Handle != NULL) { + dlclose (Handle); + } + +#endif + return; } VOID diff --git a/UnixPkg/Sec/SecMain.h b/UnixPkg/Sec/SecMain.h index 236a50ee43..c7a72c93a6 100644 --- a/UnixPkg/Sec/SecMain.h +++ b/UnixPkg/Sec/SecMain.h @@ -1,6 +1,7 @@ /*++ -Copyright (c) 2006 - 2008, Intel Corporation +Copyright (c) 2006 - 2009, Intel Corporation +Portions copyright (c) 2008-2009 Apple Inc. All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -28,6 +29,7 @@ Abstract: #include #include #include +#include #define STACK_SIZE 0x20000 @@ -42,10 +44,17 @@ typedef struct { } UNIX_SYSTEM_MEMORY; +#define MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE 0x100 + +typedef struct { + PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext; + VOID *ModHandle; +} IMAGE_CONTEXT_TO_MOD_HANDLE; + EFI_STATUS EFIAPI -SecWinNtPeiLoadFile ( +SecUnixPeiLoadFile ( VOID *Pe32Data, // TODO: add IN/OUT modifier to Pe32Data EFI_PHYSICAL_ADDRESS *ImageAddress, // TODO: add IN/OUT modifier to ImageAddress UINT64 *ImageSize, // TODO: add IN/OUT modifier to ImageSize @@ -73,7 +82,7 @@ Returns: EFI_STATUS EFIAPI -SecWinNtPeiAutoScan ( +SecUnixPeiAutoScan ( IN UINTN Index, OUT EFI_PHYSICAL_ADDRESS *MemoryBase, OUT UINT64 *MemorySize @@ -99,7 +108,7 @@ Returns: VOID * EFIAPI -SecWinNtWinNtThunkAddress ( +SecUnixUnixThunkAddress ( VOID ) /*++ @@ -122,7 +131,7 @@ Returns: EFI_STATUS EFIAPI -SecWinNtWinNtFwhAddress ( +SecUnixUnixFwhAddress ( IN OUT UINT64 *FwhSize, IN OUT EFI_PHYSICAL_ADDRESS *FwhBase ) @@ -147,12 +156,12 @@ Returns: EFI_STATUS EFIAPI SecPeiReportStatusCode ( - IN EFI_PEI_SERVICES **PeiServices, + IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_STATUS_CODE_TYPE CodeType, IN EFI_STATUS_CODE_VALUE Value, IN UINT32 Instance, - IN EFI_GUID * CallerId, - IN EFI_STATUS_CODE_DATA * Data OPTIONAL + IN CONST EFI_GUID *CallerId, + IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL ) /*++ @@ -176,12 +185,11 @@ Returns: --*/ ; -INTN -EFIAPI +int main ( - IN INTN Argc, - IN CHAR8 **Argv, - IN CHAR8 **Envp + IN int Argc, + IN char **Argv, + IN char **Envp ) /*++ @@ -331,7 +339,7 @@ Returns: EFI_STATUS EFIAPI -SecWinNtPeCoffLoaderLoadAsDll ( +SecUnixPeCoffLoaderLoadAsDll ( IN CHAR8 *PdbFileName, IN VOID **ImageEntryPoint, OUT VOID **ModHandle @@ -357,7 +365,7 @@ Returns: EFI_STATUS EFIAPI -SecWinNtPeCoffLoaderFreeLibrary ( +SecUnixPeCoffLoaderFreeLibrary ( OUT VOID *ModHandle ) /*++ @@ -379,7 +387,7 @@ Returns: EFI_STATUS EFIAPI -SecWinNtFdAddress ( +SecUnixFdAddress ( IN UINTN Index, IN OUT EFI_PHYSICAL_ADDRESS *FdBase, IN OUT UINT64 *FdSize @@ -509,4 +517,25 @@ SecTemporaryRamSupport ( IN UINTN CopySize ); + +RETURN_STATUS +EFIAPI +SecPeCoffGetEntryPoint ( + IN VOID *Pe32Data, + IN OUT VOID **EntryPoint + ); + +VOID +EFIAPI +SecPeCoffRelocateImageExtraAction ( + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext + ); + +VOID +EFIAPI +SecPeCoffLoaderUnloadImageExtraAction ( + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext + ); + + extern EFI_UNIX_THUNK_PROTOCOL *gUnix; diff --git a/UnixPkg/Sec/SecMain.inf b/UnixPkg/Sec/SecMain.inf index a0c92687a9..c7a9b40df7 100644 --- a/UnixPkg/Sec/SecMain.inf +++ b/UnixPkg/Sec/SecMain.inf @@ -2,7 +2,8 @@ # Entry Point of Unix Emulator # # Main executable file of Unix Emulator that loads PEI core after initialization finished. -# Copyright (c) 2008, Intel Corporation +# Copyright (c) 2008 - 2009, Intel Corporation +# Portions copyright (c) 2008-2009 Apple Inc. # # All rights reserved. This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -35,7 +36,10 @@ UnixThunk.c FwVol.c SecMain.c - Stack.S + +[Sources.Ia32] + Ia32/Gasket.S + Ia32/Stack.S [Packages] MdePkg/MdePkg.dec @@ -74,3 +78,10 @@ GCC:*_*_IA32_CC_FLAGS == -m32 -g -fshort-wchar -fno-strict-aliasing -Wall -malign-double -idirafter/usr/include -c -include $(DEST_DIR_DEBUG)/AutoGen.h -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings GCC:*_*_IA32_PP_FLAGS == -m32 -E -x assembler-with-cpp -include $(DEST_DIR_DEBUG)/AutoGen.h GCC:*_*_IA32_ASM_FLAGS == -c -x assembler -imacros $(DEST_DIR_DEBUG)/AutoGen.h + +# +# Need to do this link via gcc and not ld as the pathing to libraries changes from OS version to OS version +# + XCODE:*_*_IA32_DLINK_PATH == gcc + XCODE:*_*_IA32_DLINK_FLAGS == -arch i386 -L/usr/X11R6/lib -lXext -lX11 -lIOKit -framework Carbon + XCODE:*_*_IA32_ASM_FLAGS == -arch i386 -g diff --git a/UnixPkg/Sec/UgaX11.c b/UnixPkg/Sec/UgaX11.c index 1c68b328d3..386e0bc145 100644 --- a/UnixPkg/Sec/UgaX11.c +++ b/UnixPkg/Sec/UgaX11.c @@ -1,6 +1,19 @@ +/*++ + +Copyright (c) 2004 - 2009, Intel Corporation +Portions copyright (c) 2008-2009 Apple Inc. All rights reserved. +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +--*/ + #include #include -#include #include #include @@ -123,8 +136,15 @@ TryCreateShmImage(UGA_IO_PRIVATE *drv) XDestroyImage(drv->image); return 0; } + +#ifndef __APPLE__ + // + // This closes shared memory in real time on OS X. Only closes after folks quit using + // it on Linux. + // /* Can this fail ? */ shmctl (drv->xshm_info.shmid, IPC_RMID, NULL); +#endif drv->xshm_info.shmaddr = (char*)drv->image_data; drv->image->data = (char*)drv->image_data; @@ -157,6 +177,12 @@ UgaClose (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo) } XDestroyWindow(drv->display, drv->win); XCloseDisplay(drv->display); + +#ifdef __APPLE__ + // Free up the shared memory + shmctl (drv->xshm_info.shmid, IPC_RMID, NULL); +#endif + free(drv); return EFI_SUCCESS; } @@ -534,16 +560,45 @@ UgaCreate (EFI_UNIX_UGA_IO_PROTOCOL **Uga, CONST CHAR16 *Title) char *display_name = NULL; int title_len; - drv = (UGA_IO_PRIVATE *) - calloc (1, sizeof (UGA_IO_PRIVATE)); + drv = (UGA_IO_PRIVATE *)calloc (1, sizeof (UGA_IO_PRIVATE)); if (drv == NULL) return EFI_OUT_OF_RESOURCES; +#ifdef __APPLE__ +// +// +// +EFI_STATUS EFIAPI GasketUgaClose (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo); +EFI_STATUS EFIAPI GasketUgaSize (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, UINT32 Width, UINT32 Height); +EFI_STATUS EFIAPI GasketUgaCheckKey (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo); +EFI_STATUS EFIAPI GasketUgaGetKey (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, EFI_INPUT_KEY *key); +EFI_STATUS EFIAPI GasketUgaBlt ( + EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, + IN EFI_UGA_PIXEL *BltBuffer OPTIONAL, + IN EFI_UGA_BLT_OPERATION BltOperation, + IN UINTN SourceX, + IN UINTN SourceY, + IN UINTN DestinationX, + IN UINTN DestinationY, + IN UINTN Width, + IN UINTN Height, + IN UINTN Delta OPTIONAL + ); + + drv->UgaIo.UgaClose = GasketUgaClose; + drv->UgaIo.UgaSize = GasketUgaSize; + drv->UgaIo.UgaCheckKey = GasketUgaCheckKey; + drv->UgaIo.UgaGetKey = GasketUgaGetKey; + drv->UgaIo.UgaBlt = GasketUgaBlt; +#else drv->UgaIo.UgaClose = UgaClose; drv->UgaIo.UgaSize = UgaSize; drv->UgaIo.UgaCheckKey = UgaCheckKey; drv->UgaIo.UgaGetKey = UgaGetKey; drv->UgaIo.UgaBlt = UgaBlt; +#endif + + drv->key_count = 0; drv->key_rd = 0; diff --git a/UnixPkg/Sec/UnixThunk.c b/UnixPkg/Sec/UnixThunk.c index 8cf64b9d2e..5dfba7a734 100644 --- a/UnixPkg/Sec/UnixThunk.c +++ b/UnixPkg/Sec/UnixThunk.c @@ -1,6 +1,7 @@ /*++ -Copyright (c) 2004 - 2006, Intel Corporation +Copyright (c) 2004 - 2009, Intel Corporation +Portions copyright (c) 2008-2009 Apple Inc. All rights reserved. All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -149,11 +150,136 @@ GetErrno(void) return errno; } +#if __APPLE__ +void GasketmsSleep (unsigned long Milliseconds); +void Gasketexit (int status); +void GasketSetTimer (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs)); +void GasketGetLocalTime (EFI_TIME *Time); +struct tm *Gasketgmtime (const time_t *clock); +long GasketGetTimeZone (void); +int GasketGetDayLight (void); +int Gasketpoll (struct pollfd *pfd, int nfds, int timeout); +int Gasketread (int fd, void *buf, int count); +int Gasketwrite (int fd, const void *buf, int count); +char *Gasketgetenv (const char *name); +int Gasketopen (const char *name, int flags, int mode); +off_t Gasketlseek (int fd, off_t off, int whence); +int Gasketftruncate (int fd, long int len); +int Gasketclose (int fd); +int Gasketmkdir (const char *pathname, mode_t mode); +int Gasketrmdir (const char *pathname); +int Gasketunlink (const char *pathname); +int GasketGetErrno (void); +DIR *Gasketopendir (const char *pathname); +void *Gasketrewinddir (DIR *dir); +struct dirent *Gasketreaddir (DIR *dir); +int Gasketclosedir (DIR *dir); +int Gasketstat (const char *path, struct stat *buf); +int Gasketstatfs (const char *path, struct statfs *buf); +int Gasketrename (const char *oldpath, const char *newpath); +time_t Gasketmktime (struct tm *tm); +int Gasketfsync (int fd); +int Gasketchmod (const char *path, mode_t mode); +int Gasketutime (const char *filename, const struct utimbuf *buf); +int Gaskettcflush (int fildes, int queue_selector); +EFI_STATUS GasketUgaCreate(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo, CONST CHAR16 *Title); +void Gasketperror (__const char *__s); + +// +// ... is always an int or pointer to device specific data structure +// +int Gasketioctl (int fd, unsigned long int __request, ...); +int Gasketfcntl (int __fd, int __cmd, ...); + +int Gasketcfsetispeed (struct termios *__termios_p, speed_t __speed); +int Gasketcfsetospeed (struct termios *__termios_p, speed_t __speed); +int Gaskettcgetattr (int __fd, struct termios *__termios_p); +int Gaskettcsetattr (int __fd, int __optional_actions, __const struct termios *__termios_p); +int Gasketsigaction (int sig, const struct sigaction *act, struct sigaction *oact); +int Gasketsetcontext (const ucontext_t *ucp); +int Gasketgetcontext (ucontext_t *ucp); +int Gasketsigemptyset (sigset_t *set); +int Gasketsigaltstack (const stack_t *ss, stack_t *oss); + +RETURN_STATUS +GasketUnixPeCoffGetEntryPoint ( + IN VOID *Pe32Data, + IN OUT VOID **EntryPoint + ); + +VOID +GasketUnixPeCoffRelocateImageExtraAction ( + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext + ); + +VOID +GasketPeCoffLoaderUnloadImageExtraAction ( + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext + ); + +#endif + extern EFI_STATUS UgaCreate(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo, CONST CHAR16 *Title); EFI_UNIX_THUNK_PROTOCOL mUnixThunkTable = { EFI_UNIX_THUNK_PROTOCOL_SIGNATURE, +#ifdef __APPLE__ +// +// Mac OS X requires the stack to be 16-byte aligned for IA-32. So on an OS X build +// we add an assembly wrapper that makes sure the stack ges aligned. +// This has the nice benfit of being able to run EFI ABI code, like the EFI shell +// that is checked in to source control in the OS X version of the emulator +// + GasketmsSleep, /* Sleep */ + Gasketexit, /* Exit */ + GasketSetTimer, + GasketGetLocalTime, + Gasketgmtime, + GasketGetTimeZone, + GasketGetDayLight, + (UnixPoll)Gasketpoll, + (UnixRead)Gasketread, + (UnixWrite)Gasketwrite, + Gasketgetenv, + (UnixOpen)Gasketopen, + (UnixSeek)Gasketlseek, + (UnixFtruncate)Gasketftruncate, + Gasketclose, + Gasketmkdir, + Gasketrmdir, + Gasketunlink, + GasketGetErrno, + Gasketopendir, + (UnixRewindDir)Gasketrewinddir, + Gasketreaddir, + Gasketclosedir, + Gasketstat, + Gasketstatfs, + Gasketrename, + Gasketmktime, + Gasketfsync, + Gasketchmod, + Gasketutime, + Gaskettcflush, + GasketUgaCreate, + Gasketperror, + Gasketioctl, + Gasketfcntl, + Gasketcfsetispeed, + Gasketcfsetospeed, + Gaskettcgetattr, + Gaskettcsetattr, + + dlopen, // Update me with a gasket + dlerror, // Update me with a gasket + dlsym, // Update me with a gasket + + SecPeCoffGetEntryPoint, // Update me with a gasket + SecPeCoffRelocateImageExtraAction, // Update me with a gasket + SecPeCoffLoaderUnloadImageExtraAction // Update me with a gasket + +#else msSleep, /* Sleep */ exit, /* Exit */ SetTimer, @@ -166,8 +292,8 @@ EFI_UNIX_THUNK_PROTOCOL mUnixThunkTable = { (UnixWrite)write, getenv, (UnixOpen)open, - lseek, - ftruncate, + (UnixSeek)lseek, + (UnixFtruncate)ftruncate, close, mkdir, rmdir, @@ -195,7 +321,11 @@ EFI_UNIX_THUNK_PROTOCOL mUnixThunkTable = { tcsetattr, dlopen, dlerror, - dlsym + dlsym, + SecPeCoffGetEntryPoint, + SecPeCoffRelocateImageExtraAction, + SecPeCoffLoaderUnloadImageExtraAction +#endif }; diff --git a/UnixPkg/TimerDxe/Timer.c b/UnixPkg/TimerDxe/Timer.c index 53b5656f7c..7f43a368e2 100644 --- a/UnixPkg/TimerDxe/Timer.c +++ b/UnixPkg/TimerDxe/Timer.c @@ -62,7 +62,7 @@ UINT64 mTimerPeriodMs; VOID -TimerCallback (UINT64 DeltaMs) +TimerCallback (UINT64 DeltaMs) /*++ Routine Description: @@ -84,12 +84,12 @@ Returns: --*/ { EFI_TPL OriginalTPL; - EFI_TIMER_NOTIFY CallbackFunction; - + EFI_TIMER_NOTIFY CallbackFunction; + OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL); - if (OriginalTPL < TPL_HIGH_LEVEL) { + if (OriginalTPL < TPL_HIGH_LEVEL) { CallbackFunction = mTimerNotifyFunction; // @@ -99,7 +99,7 @@ Returns: if (CallbackFunction != NULL) { CallbackFunction ((UINT64) (DeltaMs * 10000)); } - } + } gBS->RestoreTPL (OriginalTPL); @@ -164,13 +164,13 @@ Returns: return EFI_ALREADY_STARTED; } - if (NotifyFunction == NULL) { - /* Disable timer. */ - gUnix->SetTimer (0, TimerCallback); - } else if (mTimerNotifyFunction == NULL) { - /* Enable Timer. */ - gUnix->SetTimer (mTimerPeriodMs, TimerCallback); - } + if (NotifyFunction == NULL) { + /* Disable timer. */ + gUnix->SetTimer (0, TimerCallback); + } else if (mTimerNotifyFunction == NULL) { + /* Enable Timer. */ + gUnix->SetTimer (mTimerPeriodMs, TimerCallback); + } mTimerNotifyFunction = NotifyFunction; return EFI_SUCCESS; @@ -224,13 +224,13 @@ Returns: // If TimerPeriod is 0, then the timer thread should be canceled // If the TimerPeriod is valid, then create and/or adjust the period of the timer thread // - if (TimerPeriod == 0 - || ((TimerPeriod > TIMER_MINIMUM_VALUE) + if (TimerPeriod == 0 + || ((TimerPeriod > TIMER_MINIMUM_VALUE) && (TimerPeriod < TIMER_MAXIMUM_VALUE))) { mTimerPeriodMs = DivU64x32 (TimerPeriod + 5000, 10000); - - gUnix->SetTimer (mTimerPeriodMs, TimerCallback); - } + + gUnix->SetTimer (mTimerPeriodMs, TimerCallback); + } return EFI_SUCCESS; } @@ -369,6 +369,6 @@ Returns: if (EFI_ERROR (Status)) { return Status; } - + return EFI_SUCCESS; } diff --git a/UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c b/UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c index 0e9a32c66a..e4c5df99c4 100644 --- a/UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c +++ b/UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c @@ -148,7 +148,7 @@ UnixBlockIoDriverDiagnosticsRunDiagnostics ( if (DiagnosticType != EfiDriverDiagnosticTypeStandard) { *ErrorType = &gEfiBlockIoProtocolGuid; *BufferSize = 0x60; - gBS->AllocatePool (EfiBootServicesData, (UINTN) (*BufferSize), + gBS->AllocatePool (EfiBootServicesData, (UINTN) (*BufferSize), (void *)Buffer); CopyMem (*Buffer, L"Unix Block I/O Driver Diagnostics Failed\n", *BufferSize); return EFI_DEVICE_ERROR; diff --git a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.c b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.c index a483a876dc..c3bd3d38c6 100644 --- a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.c +++ b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.c @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2004 - 2007, Intel Corporation +Copyright (c) 2004 - 2009, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -1276,6 +1276,7 @@ This function extends the capability of SetFilePointer to accept 64 bit paramete EFI_STATUS Status; off_t res; + Status = EFI_SUCCESS; res = Private->UnixThunk->Lseek(Private->fd, DistanceToMove, MoveMethod); if (res == -1) { Status = EFI_INVALID_PARAMETER; diff --git a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.h b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.h index 70ab77ef36..693f20e55c 100644 --- a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.h +++ b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.h @@ -56,7 +56,7 @@ typedef struct { UINTN ReadMode; UINTN Mode; - int fd; + int fd; UINT64 LastBlock; UINTN BlockSize; diff --git a/UnixPkg/UnixConsoleDxe/Console.h b/UnixPkg/UnixConsoleDxe/Console.h index 7a3c7da8b9..a3ab0e173e 100644 --- a/UnixPkg/UnixConsoleDxe/Console.h +++ b/UnixPkg/UnixConsoleDxe/Console.h @@ -94,7 +94,7 @@ typedef struct { UINTN RowsY; } UNIX_SIMPLE_TEXT_OUT_MODE; -#if 0 +#if 0 // // Simple Text Out protocol member functions // @@ -319,7 +319,7 @@ Returns: --*/ ; -#endif +#endif // // Simple Text Out constructor and destructor. // @@ -365,7 +365,7 @@ Returns: --*/ ; -#if 0 +#if 0 // // Simple Text In protocol member functions. // @@ -441,7 +441,7 @@ Returns: --*/ ; -#endif +#endif // // Simple Text In constructor // diff --git a/UnixPkg/UnixConsoleDxe/ConsoleIn.c b/UnixPkg/UnixConsoleDxe/ConsoleIn.c index 821ff2c805..6ab68956e9 100644 --- a/UnixPkg/UnixConsoleDxe/ConsoleIn.c +++ b/UnixPkg/UnixConsoleDxe/ConsoleIn.c @@ -27,7 +27,7 @@ Abstract: --*/ #include "Console.h" -#include +#include // // Private worker functions @@ -68,7 +68,7 @@ Returns: EFI_STATUS UnixConvertInputRecordToEfiKey ( - IN char c, + IN char c, OUT EFI_INPUT_KEY *Key ) /*++ @@ -92,8 +92,8 @@ Returns: --*/ { Key->ScanCode = 0; - if (c == '\n') - c = '\r'; + if (c == '\n') + c = '\r'; Key->UnicodeChar = c; return EFI_SUCCESS; } @@ -124,7 +124,7 @@ Returns: { EFI_STATUS Status; UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private; - char c; + char c; Private = UNIX_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This); @@ -133,7 +133,7 @@ Returns: return Status; } - if (Private->UnixThunk->Read (0, &c, 1) != 1) + if (Private->UnixThunk->Read (0, &c, 1) != 1) return EFI_NOT_READY; Status = UnixConvertInputRecordToEfiKey (c, Key); @@ -193,11 +193,11 @@ Returns: --*/ { - struct pollfd pfd; + struct pollfd pfd; - pfd.fd = 0; - pfd.events = POLLIN; - if (Private->UnixThunk->Poll (&pfd, 1, 0) <= 0) { + pfd.fd = 0; + pfd.events = POLLIN; + if (Private->UnixThunk->Poll (&pfd, 1, 0) <= 0) { return EFI_NOT_READY; } return EFI_SUCCESS; diff --git a/UnixPkg/UnixConsoleDxe/ConsoleOut.c b/UnixPkg/UnixConsoleDxe/ConsoleOut.c index 693cf60d01..93ace4d80b 100644 --- a/UnixPkg/UnixConsoleDxe/ConsoleOut.c +++ b/UnixPkg/UnixConsoleDxe/ConsoleOut.c @@ -26,13 +26,13 @@ Abstract: // Private worker functions. // -#if 0 +#if 0 VOID UnixSimpleTextOutScrollScreen ( IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console ); -#endif +#endif VOID UnixSimpleTextOutPutChar ( IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console, @@ -51,7 +51,7 @@ UnixSimpleTextOutSetMode ( IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN UINTN ModeNumber ); - + // // Modeule Global for Simple Text Out Mode. // @@ -60,12 +60,12 @@ UnixSimpleTextOutSetMode ( UNIX_SIMPLE_TEXT_OUT_MODE mUnixSimpleTextOutSupportedModes[] = { { 80, 25 }, -#if 0 +#if 0 { 80, 50 }, { 80, 43 }, { 100, 100 }, { 100, 999 } -#endif +#endif }; EFI_STATUS @@ -131,7 +131,7 @@ Returns: for (Str = String; *Str != '\0'; Str++) { switch (*Str) { -#if 0 +#if 0 case '\n': if (Private->Position.Y == (Private->MaxScreenSize.Y - 1)) { UnixSimpleTextOutScrollScreen (Private); @@ -155,7 +155,7 @@ Returns: } break; -#endif +#endif default: UnixSimpleTextOutPutChar (Private, *Str); } @@ -186,11 +186,11 @@ Returns: --*/ { - char c = Char; - Console->UnixThunk->Write (1, &c, 1); + char c = Char; + Console->UnixThunk->Write (1, &c, 1); } -#if 0 +#if 0 VOID UnixSimpleTextOutScrollScreen ( IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console @@ -212,8 +212,8 @@ Returns: --*/ { } -#endif - +#endif + EFI_STATUS EFIAPI @@ -358,9 +358,9 @@ Returns: Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This); -#if 0 +#if 0 Private->Attribute = (WORD) Attribute; -#endif +#endif This->Mode->Attribute = (INT32) Attribute; return EFI_SUCCESS; @@ -393,10 +393,10 @@ Returns: Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This); This->SetCursorPosition (This, 0, 0); - Private->UnixThunk->Write (1, "\e[2J", 4); - + Private->UnixThunk->Write (1, "\e[2J", 4); -#if 0 + +#if 0 Private->UnixThunk->FillConsoleOutputCharacter ( Private->NtOutHandle, ' ', @@ -411,7 +411,7 @@ Returns: Private->Possition, &ConsoleWindow ); -#endif +#endif return EFI_SUCCESS; } @@ -441,36 +441,36 @@ Returns: --*/ { - char buf[12]; + char buf[12]; UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private; Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This); -#if 0 +#if 0 Private->Position.X = (WORD) Column; -#endif +#endif This->Mode->CursorColumn = (INT32) Column; -#if 0 +#if 0 Private->Position.Y = (WORD) Row; -#endif +#endif This->Mode->CursorRow = (INT32) Row; -#if 0 +#if 0 Private->UnixThunk->SetConsoleCursorPosition (Private->NtOutHandle, Private->Possition); -#endif - - buf[0] = '\e'; - buf[1] = '['; - buf[2] = '0' + ((Row / 100) % 10); - buf[3] = '0' + ((Row / 10) % 10); - buf[4] = '0' + ((Row / 1) % 10); - buf[5] = ';'; - buf[6] = '0' + ((Column / 100) % 10); - buf[7] = '0' + ((Column / 10) % 10); - buf[8] = '0' + ((Column / 1) % 10); - buf[9] = 'H'; - Private->UnixThunk->Write (1, buf, 10); - +#endif + + buf[0] = '\e'; + buf[1] = '['; + buf[2] = '0' + ((Row / 100) % 10); + buf[3] = '0' + ((Row / 10) % 10); + buf[4] = '0' + ((Row / 1) % 10); + buf[5] = ';'; + buf[6] = '0' + ((Column / 100) % 10); + buf[7] = '0' + ((Column / 10) % 10); + buf[8] = '0' + ((Column / 1) % 10); + buf[9] = 'H'; + Private->UnixThunk->Write (1, buf, 10); + return EFI_SUCCESS; } @@ -498,19 +498,19 @@ Returns: --*/ { UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private; -#if 0 +#if 0 CONSOLE_CURSOR_INFO Info; -#endif +#endif Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This); Private->CursorEnable = Enable; This->Mode->CursorVisible = Enable; -#if 0 +#if 0 Private->UnixThunk->GetConsoleCursorInfo (Private->NtOutHandle, &Info); Info.bVisible = Enable; Private->UnixThunk->SetConsoleCursorInfo (Private->NtOutHandle, &Info); -#endif +#endif return EFI_SUCCESS; } @@ -539,13 +539,13 @@ Returns: CHAR16 *WindowName; //WindowName = Private->UnixIo->EnvString; -#if 0 +#if 0 Private->Attribute = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY; if (*WindowName == '?') { Private->Attribute = BACKGROUND_RED | FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN; WindowName = L"EFI Emulator Error Console"; } -#endif +#endif WindowName = L"EFI Emulator Error Console"; AddUnicodeString ( @@ -576,7 +576,7 @@ Returns: SimpleTextOut->Mode->MaxMode = MAX_SIMPLE_TEXT_OUT_MODE; SimpleTextOut->Mode->Attribute = 0; //FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY; -#if 0 +#if 0 // // Open the window an initialize it! // @@ -588,7 +588,7 @@ Returns: NULL ); Private->UnixThunk->SetConsoleTitle (WindowName); -#endif +#endif return SimpleTextOut->SetMode (SimpleTextOut, 0); } @@ -613,8 +613,8 @@ Returns: --*/ { -#if 0 +#if 0 Console->UnixThunk->CloseHandle (Console->NtOutHandle); -#endif +#endif return EFI_SUCCESS; } diff --git a/UnixPkg/UnixConsoleDxe/UnixConsole.inf b/UnixPkg/UnixConsoleDxe/UnixConsole.inf index 636a6cb880..6a9748a323 100644 --- a/UnixPkg/UnixConsoleDxe/UnixConsole.inf +++ b/UnixPkg/UnixConsoleDxe/UnixConsole.inf @@ -62,6 +62,6 @@ gEfiSimpleTextInProtocolGuid # PROTOCOL BY_START gEfiSimpleTextOutProtocolGuid # PROTOCOL BY_START gEfiUnixIoProtocolGuid # PROTOCOL TO_START - -[Guids] + +[Guids] gEfiUnixConsoleGuid diff --git a/UnixPkg/UnixSerialIoDxe/UnixSerialIo.c b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.c index fa4e3aad36..edbfd0ad13 100644 --- a/UnixPkg/UnixSerialIoDxe/UnixSerialIo.c +++ b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.c @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2006 - 2007, Intel Corporation +Copyright (c) 2006 - 2009, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -46,7 +46,6 @@ Abstract: --*/ #include "UnixSerialIo.h" -#include EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding = { UnixSerialIoDriverBindingSupported, @@ -454,7 +453,7 @@ Returns: UnixHandle = UnixIo->UnixThunk->Open (AsciiDevName, O_RDWR | O_NOCTTY, 0); if (UnixHandle == -1) { - DEBUG ((EFI_D_INFO, "Faile to open serial device, %s!\r\n", UnixIo->EnvString )); + DEBUG ((EFI_D_INFO, "Failed to open serial device, %s!\r\n", UnixIo->EnvString )); UnixIo->UnixThunk->Perror (AsciiDevName); Status = EFI_DEVICE_ERROR; goto Error; @@ -1125,6 +1124,7 @@ Returns: return EFI_DEVICE_ERROR; } + Bits = 0; if ((Status & TIOCM_CTS) == TIOCM_CTS) { Bits |= EFI_SERIAL_CLEAR_TO_SEND; } @@ -1206,6 +1206,7 @@ Returns: --*/ { UNIX_SERIAL_IO_PRIVATE_DATA *Private; + EFI_STATUS Status; UINT8 *ByteBuffer; UINT32 TotalBytesWritten; UINT32 BytesToGo; @@ -1219,6 +1220,7 @@ Returns: Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This); ByteBuffer = (UINT8 *) Buffer; + Status = EFI_SUCCESS; TotalBytesWritten = 0; if (Private->SoftwareLoopbackEnable || Private->HardwareLoopbackEnable) { @@ -1250,6 +1252,10 @@ Returns: &ByteBuffer[TotalBytesWritten], BytesToGo ); + if (BytesWritten == -1) { + Status = EFI_DEVICE_ERROR; + break; + } if (Private->HardwareFlowControl) { // @@ -1269,7 +1275,7 @@ Returns: gBS->RestoreTPL (Tpl); - return EFI_SUCCESS; + return Status; } EFI_STATUS diff --git a/UnixPkg/UnixSerialIoDxe/UnixSerialIo.h b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.h index 3a6c11ac37..bcd8018e4c 100644 --- a/UnixPkg/UnixSerialIoDxe/UnixSerialIo.h +++ b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.h @@ -1,6 +1,7 @@ /*++ -Copyright (c) 2006 - 2008, Intel Corporation +Copyright (c) 2006 - 2009, Intel Corporation +Portions copyright (c) 2008-2009 Apple Inc. All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -23,8 +24,13 @@ Abstract: #include #include #include + +#ifdef __APPLE__ +#else #include #include +#endif + #include #include diff --git a/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.c b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.c index 9d9325c105..d01fd4e751 100644 --- a/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.c +++ b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.c @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2006 - 2007, Intel Corporation +Copyright (c) 2006 - 2009, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -566,6 +566,8 @@ Done: gBS->FreePool (PrivateFile); } + + *Root = NULL; } gBS->RestoreTPL (OldTpl); @@ -1262,7 +1264,12 @@ Returns: CHAR8 *FullFileName; EFI_TPL OldTpl; - if (This == NULL || BufferSize == NULL || Buffer == NULL) { + if (This == NULL || BufferSize == NULL) { + return EFI_INVALID_PARAMETER; + } + + if ((*BufferSize != 0) && (Buffer == NULL)) { + // Buffer can be NULL if *BufferSize is zero return EFI_INVALID_PARAMETER; } diff --git a/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.h b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.h index 59fe085b70..1b6395540d 100644 --- a/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.h +++ b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.h @@ -68,13 +68,13 @@ typedef struct { EFI_UNIX_THUNK_PROTOCOL *UnixThunk; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem; EFI_FILE EfiFile; - INTN fd; - DIR *Dir; + INTN fd; + DIR *Dir; BOOLEAN IsRootDirectory; BOOLEAN IsDirectoryPath; BOOLEAN IsOpenedByRead; char *FileName; - struct dirent *Dirent; + struct dirent *Dirent; } UNIX_EFI_FILE_PRIVATE; #define UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS(a) \ diff --git a/UnixPkg/UnixThunkDxe/UnixThunk.c b/UnixPkg/UnixThunkDxe/UnixThunk.c index 16990a4978..3baa974818 100644 --- a/UnixPkg/UnixThunkDxe/UnixThunk.c +++ b/UnixPkg/UnixThunkDxe/UnixThunk.c @@ -35,7 +35,7 @@ Abstract: #include #include #include -#include +#include #include // diff --git a/UnixPkg/UnixThunkDxe/UnixThunk.inf b/UnixPkg/UnixThunkDxe/UnixThunk.inf index fd803b1b13..0b424afaf8 100644 --- a/UnixPkg/UnixThunkDxe/UnixThunk.inf +++ b/UnixPkg/UnixThunkDxe/UnixThunk.inf @@ -47,8 +47,8 @@ UnixLib UefiDriverEntryPoint UefiLib - DebugLib - DevicePathLib + DebugLib + DevicePathLib -- cgit v1.2.3