diff options
Diffstat (limited to 'UnixPkg/Sec')
-rw-r--r-- | UnixPkg/Sec/FwVol.c | 314 | ||||
-rw-r--r-- | UnixPkg/Sec/Gasket.c | 456 | ||||
-rw-r--r-- | UnixPkg/Sec/Gasket.h | 594 | ||||
-rw-r--r-- | UnixPkg/Sec/Ia32/Gasket.S | 344 | ||||
-rw-r--r-- | UnixPkg/Sec/Ia32/Stack.S | 95 | ||||
-rw-r--r-- | UnixPkg/Sec/Ia32/SwitchStack.c | 98 | ||||
-rw-r--r-- | UnixPkg/Sec/SecMain.c | 1340 | ||||
-rw-r--r-- | UnixPkg/Sec/SecMain.h | 601 | ||||
-rw-r--r-- | UnixPkg/Sec/SecMain.inf | 106 | ||||
-rw-r--r-- | UnixPkg/Sec/UgaX11.c | 865 | ||||
-rw-r--r-- | UnixPkg/Sec/UnixThunk.c | 343 | ||||
-rw-r--r-- | UnixPkg/Sec/X64/MangleGasket.S | 1294 | ||||
-rw-r--r-- | UnixPkg/Sec/X64/NameManglingFix.c | 44 | ||||
-rw-r--r-- | UnixPkg/Sec/X64/SwitchStack.S | 120 |
14 files changed, 0 insertions, 6614 deletions
diff --git a/UnixPkg/Sec/FwVol.c b/UnixPkg/Sec/FwVol.c deleted file mode 100644 index 6723148bdc..0000000000 --- a/UnixPkg/Sec/FwVol.c +++ /dev/null @@ -1,314 +0,0 @@ -/*++
-
-Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
-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:
- FwVol.c
-
-Abstract:
- A simple FV stack so the SEC can extract the SEC Core from an
- FV.
-
---*/
-
-#include "SecMain.h"
-
-#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \
- (ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1))
-
-EFI_FFS_FILE_STATE
-GetFileState (
- IN UINT8 ErasePolarity,
- IN EFI_FFS_FILE_HEADER *FfsHeader
- )
-/*++
-
-Routine Description:
- Returns the highest bit set of the State field
-
-Arguments:
- ErasePolarity - Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY
- in the Attributes field.
- FfsHeader - Pointer to FFS File Header.
-
-Returns:
- Returns the highest bit in the State field
-
---*/
-{
- EFI_FFS_FILE_STATE FileState;
- EFI_FFS_FILE_STATE HighestBit;
-
- FileState = FfsHeader->State;
-
- if (ErasePolarity != 0) {
- FileState = (EFI_FFS_FILE_STATE)~FileState;
- }
-
- HighestBit = 0x80;
- while (HighestBit != 0 && (HighestBit & FileState) == 0) {
- HighestBit >>= 1;
- }
-
- return HighestBit;
-}
-
-UINT8
-CalculateHeaderChecksum (
- IN EFI_FFS_FILE_HEADER *FileHeader
- )
-/*++
-
-Routine Description:
- Calculates the checksum of the header of a file.
-
-Arguments:
- FileHeader - Pointer to FFS File Header.
-
-Returns:
- Checksum of the header.
-
---*/
-{
- UINT8 *ptr;
- UINTN Index;
- UINT8 Sum;
-
- Sum = 0;
- ptr = (UINT8 *) FileHeader;
-
- for (Index = 0; Index < sizeof (EFI_FFS_FILE_HEADER) - 3; Index += 4) {
- Sum = (UINT8) (Sum + ptr[Index]);
- Sum = (UINT8) (Sum + ptr[Index + 1]);
- Sum = (UINT8) (Sum + ptr[Index + 2]);
- Sum = (UINT8) (Sum + ptr[Index + 3]);
- }
-
- for (; Index < sizeof (EFI_FFS_FILE_HEADER); Index++) {
- Sum = (UINT8) (Sum + ptr[Index]);
- }
- //
- // State field (since this indicates the different state of file).
- //
- Sum = (UINT8) (Sum - FileHeader->State);
- //
- // Checksum field of the file is not part of the header checksum.
- //
- Sum = (UINT8) (Sum - FileHeader->IntegrityCheck.Checksum.File);
-
- return Sum;
-}
-
-EFI_STATUS
-SecFfsFindNextFile (
- IN EFI_FV_FILETYPE SearchType,
- IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
- IN OUT EFI_FFS_FILE_HEADER **FileHeader
- )
-/*++
-
-Routine Description:
- Given the input file pointer, search for the next matching file in the
- FFS volume as defined by SearchType. The search starts from FileHeader inside
- the Firmware Volume defined by FwVolHeader.
-
-Arguments:
- SearchType - Filter to find only files of this type.
- Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
- FwVolHeader - Pointer to the FV header of the volume to search.
- This parameter must point to a valid FFS volume.
- FileHeader - Pointer to the current file from which to begin searching.
- This pointer will be updated upon return to reflect the file
- found.
-
-Returns:
- EFI_NOT_FOUND - No files matching the search criteria were found
- EFI_SUCCESS
-
---*/
-{
- EFI_FFS_FILE_HEADER *FfsFileHeader;
- UINT32 FileLength;
- UINT32 FileOccupiedSize;
- UINT32 FileOffset;
- UINT64 FvLength;
- UINT8 ErasePolarity;
- UINT8 FileState;
-
- FvLength = FwVolHeader->FvLength;
- if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) {
- ErasePolarity = 1;
- } else {
- ErasePolarity = 0;
- }
- //
- // If FileHeader is not specified (NULL) start with the first file in the
- // firmware volume. Otherwise, start from the FileHeader.
- //
- if (*FileHeader == NULL) {
- FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FwVolHeader + FwVolHeader->HeaderLength);
- } else {
- //
- // Length is 24 bits wide so mask upper 8 bits
- // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.
- //
- FileLength = *(UINT32 *) (*FileHeader)->Size & 0x00FFFFFF;
- FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
- FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) *FileHeader + FileOccupiedSize);
- }
-
- FileOffset = (UINT32) ((UINT8 *) FfsFileHeader - (UINT8 *) FwVolHeader);
-
- while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) {
- //
- // Get FileState which is the highest bit of the State
- //
- FileState = GetFileState (ErasePolarity, FfsFileHeader);
-
- switch (FileState) {
-
- case EFI_FILE_HEADER_INVALID:
- FileOffset += sizeof (EFI_FFS_FILE_HEADER);
- FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER));
- break;
-
- case EFI_FILE_DATA_VALID:
- case EFI_FILE_MARKED_FOR_UPDATE:
- if (CalculateHeaderChecksum (FfsFileHeader) == 0) {
- FileLength = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;
- FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
-
- if ((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) {
-
- *FileHeader = FfsFileHeader;
-
- return EFI_SUCCESS;
- }
-
- FileOffset += FileOccupiedSize;
- FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize);
- } else {
- return EFI_NOT_FOUND;
- }
- break;
-
- case EFI_FILE_DELETED:
- FileLength = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;
- FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
- FileOffset += FileOccupiedSize;
- FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize);
- break;
-
- default:
- return EFI_NOT_FOUND;
-
- }
- }
-
- return EFI_NOT_FOUND;
-}
-
-EFI_STATUS
-SecFfsFindSectionData (
- IN EFI_SECTION_TYPE SectionType,
- IN EFI_FFS_FILE_HEADER *FfsFileHeader,
- IN OUT VOID **SectionData
- )
-/*++
-
-Routine Description:
- Given the input file pointer, search for the next matching section in the
- FFS volume.
-
-Arguments:
- SearchType - Filter to find only sections of this type.
- FfsFileHeader - Pointer to the current file to search.
- SectionData - Pointer to the Section matching SectionType in FfsFileHeader.
- NULL if section not found
-
-Returns:
- EFI_NOT_FOUND - No files matching the search criteria were found
- EFI_SUCCESS
-
---*/
-{
- UINT32 FileSize;
- EFI_COMMON_SECTION_HEADER *Section;
- UINT32 SectionLength;
- UINT32 ParsedLength;
-
- //
- // Size is 24 bits wide so mask upper 8 bits.
- // Does not include FfsFileHeader header size
- // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.
- //
- Section = (EFI_COMMON_SECTION_HEADER *) (FfsFileHeader + 1);
- FileSize = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;
- FileSize -= sizeof (EFI_FFS_FILE_HEADER);
-
- *SectionData = NULL;
- ParsedLength = 0;
- while (ParsedLength < FileSize) {
- if (Section->Type == SectionType) {
- *SectionData = (VOID *) (Section + 1);
- return EFI_SUCCESS;
- }
- //
- // Size is 24 bits wide so mask upper 8 bits.
- // SectionLength is adjusted it is 4 byte aligned.
- // Go to the next section
- //
- SectionLength = *(UINT32 *) Section->Size & 0x00FFFFFF;
- SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);
-
- ParsedLength += SectionLength;
- Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) Section + SectionLength);
- }
-
- return EFI_NOT_FOUND;
-}
-
-EFI_STATUS
-SecFfsFindPeiCore (
- IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
- OUT VOID **Pe32Data
- )
-/*++
-
-Routine Description:
- Given the pointer to the Firmware Volume Header find the SEC
- core and return it's PE32 image.
-
-Arguments:
- FwVolHeader - Pointer to memory mapped FV
- Pe32Data - Pointer to SEC PE32 iamge.
-
-Returns:
- EFI_SUCCESS - Pe32Data is valid
- other - Failure
-
---*/
-{
- EFI_STATUS Status;
- EFI_FFS_FILE_HEADER *FileHeader;
- EFI_FV_FILETYPE SearchType;
-
- SearchType = EFI_FV_FILETYPE_PEI_CORE;
- FileHeader = NULL;
- do {
- Status = SecFfsFindNextFile (SearchType, FwVolHeader, &FileHeader);
- if (!EFI_ERROR (Status)) {
- Status = SecFfsFindSectionData (EFI_SECTION_PE32, FileHeader, Pe32Data);
- return Status;
- }
- } while (!EFI_ERROR (Status));
-
- return Status;
-}
diff --git a/UnixPkg/Sec/Gasket.c b/UnixPkg/Sec/Gasket.c deleted file mode 100644 index 04c65f1a8d..0000000000 --- a/UnixPkg/Sec/Gasket.c +++ /dev/null @@ -1,456 +0,0 @@ -/** @file
-
- Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-
- 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.
-
-**/
-
-#ifdef __APPLE__
-
-#include "SecMain.h"
-#include "Gasket.h"
-
-//
-// Gasket functions for EFI_UNIX_THUNK_PROTOCOL
-//
-
-void
-GasketmsSleep (unsigned long Milliseconds)
-{
- GasketUintn (msSleep, Milliseconds);
- return;
-}
-
-void
-Gasketexit (int status)
-{
- GasketUintn (exit, status);
- return;
-}
-
-
-void
-GasketSetTimer (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs))
-{
- GasketUint64Uintn (SetTimer, PeriodMs, (UINTN)CallBack);
- return;
-}
-
-
-void
-GasketGetLocalTime (EFI_TIME *Time)
-{
- GasketUintn (GetLocalTime, (UINTN)Time);
- return;
-}
-
-
-struct tm *
-Gasketgmtime (const time_t *clock)
-{
- return (struct tm *)(UINTN)GasketUintn (localtime, (UINTN)clock);
-}
-
-
-long
-GasketGetTimeZone (void)
-{
- return GasketVoid (GetTimeZone);
-}
-
-
-int
-GasketGetDayLight (void)
-{
- return GasketVoid (GetDayLight);
-}
-
-
-int
-Gasketpoll (struct pollfd *pfd, unsigned int nfds, int timeout)
-{
- return GasketUintnUintnUintn (poll, (UINTN)pfd, nfds, timeout);
-}
-
-
-long
-Gasketread (int fd, void *buf, int count)
-{
- return GasketUintnUintnUintn (read, fd, (UINTN)buf, count);
-}
-
-
-long
-Gasketwrite (int fd, const void *buf, int count)
-{
- return GasketUintnUintnUintn (write, fd, (UINTN)buf, count);
-}
-
-
-char *
-Gasketgetenv (const char *name)
-{
- return (char *)(UINTN)GasketUintn (getenv, (UINTN)name);
-}
-
-
-int
-Gasketopen (const char *name, int flags, int mode)
-{
- return GasketUintnUintnUintn (open, (UINTN)name, flags, mode);
-}
-
-
-off_t
-Gasketlseek (int fd, off_t off, int whence)
-{
- if (sizeof off == 8) {
- return GasketUintnUint64Uintn (lseek, fd, off, whence);
- } else if (sizeof off == 4) {
- return GasketUintnUintnUintn (lseek, fd, off, whence);
- }
-}
-
-
-int
-Gasketftruncate (int fd, long int len)
-{
- return GasketUintnUintn (ftruncate, fd, len);
-}
-
-
-int
-Gasketclose (int fd)
-{
- return GasketUintn (close, fd);
-}
-
-
-int
-Gasketmkdir (const char *pathname, mode_t mode)
-{
- return GasketUintnUint16 (mkdir, (UINTN)pathname, mode);
-}
-
-
-int
-Gasketrmdir (const char *pathname)
-{
- return GasketUintn (rmdir, (UINTN)pathname);
-}
-
-
-int
-Gasketunlink (const char *pathname)
-{
- return GasketUintn (unlink, (UINTN)pathname);
-}
-
-
-int
-GasketGetErrno (void)
-{
- return GasketVoid (GetErrno);
-}
-
-
-DIR *
-Gasketopendir (const char *pathname)
-{
- return (DIR *)(UINTN)GasketUintn (opendir, (UINTN)pathname);
-}
-
-
-void
-Gasketrewinddir (DIR *dir)
-{
- GasketUintn (rewinddir, (UINTN)dir);
- return;
-}
-
-
-struct dirent *
-Gasketreaddir (DIR *dir)
-{
- return (struct dirent *)(UINTN)GasketUintn (readdir, (UINTN)dir);
-}
-
-
-int
-Gasketclosedir (DIR *dir)
-{
- return GasketUintn (closedir, (UINTN)dir);
-}
-
-
-int
-Gasketstat (const char *path, STAT_FIX *buf)
-{
- return GasketUintnUintn (stat, (UINTN)path, (UINTN)buf);
-}
-
-
-int
-Gasketstatfs (const char *path, struct statfs *buf)
-{
- return GasketUintnUintn (statfs, (UINTN)path, (UINTN)buf);
-}
-
-
-int
-Gasketrename (const char *oldpath, const char *newpath)
-{
- return GasketUintnUintn (rename, (UINTN)oldpath, (UINTN)newpath);
-}
-
-
-time_t
-Gasketmktime (struct tm *tm)
-{
- return GasketUintn (mktime, (UINTN)tm);
-}
-
-
-int
-Gasketfsync (int fd)
-{
- return GasketUintn (fsync, fd);
-}
-
-
-int
-Gasketchmod (const char *path, mode_t mode)
-{
- return GasketUintnUint16 (chmod, (UINTN)path, mode);
-}
-
-
-int
-Gasketutime (const char *filename, const struct utimbuf *buf)
-{
- return GasketUintnUintn (utime, (UINTN)filename, (UINTN)buf);
-}
-
-
-int
-Gaskettcflush (int fildes, int queue_selector)
-{
- return GasketUintnUintn (tcflush, fildes, queue_selector);
-}
-
-
-EFI_STATUS
-GasketUgaCreate (struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo, CONST CHAR16 *Title)
-{
- return GasketUintnUintn (UgaCreate, (UINTN)UgaIo, (UINTN)Title);
-}
-
-
-void
-Gasketperror (__const char *__s)
-{
- GasketUintn (perror, (UINTN)__s);
- return;
-}
-
-
-
-//
-// ... is always an int or pointer to device specific data structure
-//
-int
-Gasketioctl (int fd, unsigned long int __request, void *Arg)
-{
- return GasketUintnUintnUintn (ioctl, fd, __request, (UINTN)Arg);
-}
-
-
-int
-Gasketfcntl (int __fd, int __cmd, void *Arg)
-{
- return GasketUintnUintnUintn (fcntl, __fd, __cmd, (UINTN)Arg);
-}
-
-
-
-int
-Gasketcfsetispeed (struct termios *__termios_p, speed_t __speed)
-{
- return GasketUintnUintn (cfsetispeed, (UINTN)__termios_p, __speed);
-}
-
-
-int
-Gasketcfsetospeed (struct termios *__termios_p, speed_t __speed)
-{
- return GasketUintnUintn (cfsetospeed, (UINTN)__termios_p, __speed);
-}
-
-
-int
-Gaskettcgetattr (int __fd, struct termios *__termios_p)
-{
- return GasketUintnUintn (tcgetattr, __fd, (UINTN)__termios_p);
-}
-
-
-int
-Gaskettcsetattr (int __fd, int __optional_actions, __const struct termios *__termios_p)
-{
- return GasketUintnUintnUintn (tcsetattr, __fd, __optional_actions, (UINTN)__termios_p);
-}
-
-
-
-
-RETURN_STATUS
-GasketUnixPeCoffGetEntryPoint (
- IN VOID *Pe32Data,
- IN OUT VOID **EntryPoint
- )
-{
- return GasketUintnUintn (SecPeCoffGetEntryPoint, (UINTN)Pe32Data, (UINTN)EntryPoint);
-}
-
-
-
-VOID
-GasketUnixPeCoffRelocateImageExtraAction (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- GasketUintn (SecPeCoffRelocateImageExtraAction, (UINTN)ImageContext);
- return;
-}
-
-
-
-VOID
-GasketUnixPeCoffUnloadImageExtraAction (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- GasketUintn (SecPeCoffLoaderUnloadImageExtraAction, (UINTN)ImageContext);
- return;
-}
-
-
-//
-// Gasket functions for EFI_UNIX_UGA_IO_PROTOCOL
-//
-
-EFI_STATUS
-EFIAPI
-GasketUgaClose (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo)
-{
- return GasketUintn (UgaClose, (UINTN)UgaIo);
-}
-
-EFI_STATUS
-EFIAPI
-GasketUgaSize (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, UINT32 Width, UINT32 Height)
-{
- return GasketUintnUintnUintn (UgaSize, (UINTN)UgaIo, Width, Height);
-}
-
-EFI_STATUS
-EFIAPI
-GasketUgaCheckKey (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo)
-{
- return GasketUintn (UgaCheckKey, (UINTN)UgaIo);
-}
-
-EFI_STATUS
-EFIAPI
-GasketUgaKeySetState (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, EFI_KEY_TOGGLE_STATE *KeyToggleState)
-{
- return GasketUintnUintn (UgaGetKey, (UINTN)UgaIo, (UINTN)KeyToggleState);
-}
-
-EFI_STATUS
-EFIAPI
-GasketUgaGetKey (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, EFI_KEY_DATA *key)
-{
- return GasketUintnUintn (UgaGetKey, (UINTN)UgaIo, (UINTN)key);
-}
-
-EFI_STATUS
-EFIAPI
-GasketUgaRegisterKeyNotify (
- IN EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
- IN UGA_REGISTER_KEY_NOTIFY_CALLBACK CallBack,
- IN VOID *Context
- )
-{
- return GasketUintnUintnUintn (UgaRegisterKeyNotify, (UINTN)UgaIo, (UINTN)CallBack, (UINTN)Context);
-}
-
-EFI_STATUS
-EFIAPI
-GasketUgaBlt (
- EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
- IN EFI_UGA_PIXEL *BltBuffer OPTIONAL,
- IN EFI_UGA_BLT_OPERATION BltOperation,
- IN UGA_BLT_ARGS *Args
- )
-{
- return GasketUintnUintnUintnUintn (UgaBlt, (UINTN)UgaIo, (UINTN)BltBuffer, (UINTN)BltOperation, (UINTN)Args);
-}
-
-EFI_STATUS
-EFIAPI
-GasketUgaCheckPointer (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo)
-{
- return GasketUintn (UgaCheckPointer, (UINTN)UgaIo);
-}
-
-EFI_STATUS
-EFIAPI
-GasketUgaGetPointerState (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, EFI_SIMPLE_POINTER_STATE *state)
-{
- return GasketUintnUintn (UgaGetPointerState, (UINTN)UgaIo, (UINTN)state);
-}
-
-void
-GasketUnixEnableInterrupt (void)
-{
- GasketVoid (UnixEnableInterrupt);
-}
-
-void
-GasketUnixDisableInterrupt (void)
-{
- GasketVoid (UnixDisableInterrupt);
-}
-
-
-int
-Gasketgetifaddrs (struct ifaddrs **ifap)
-{
- return( GasketUintn( getifaddrs, ( UINTN ) ifap ) );
-}
-
-
-void
-Gasketfreeifaddrs (struct ifaddrs *ifap)
-{
- GasketUintn( freeifaddrs, ( UINTN ) ifap );
-}
-
-
-int
-Gasketsocket (int domain, int type, int protocol )
-{
- return( GasketUintnUintnUintn( socket, domain, type, protocol ) );
-}
-
-
-#endif
-
diff --git a/UnixPkg/Sec/Gasket.h b/UnixPkg/Sec/Gasket.h deleted file mode 100644 index 4c75d8abcc..0000000000 --- a/UnixPkg/Sec/Gasket.h +++ /dev/null @@ -1,594 +0,0 @@ -/** @file
-
- Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-
- 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.
-
-**/
-
-#ifndef _GASKET_H_
-#define _GASKET_H_
-
-#include <Library/PeCoffLib.h>
-
-#include <Protocol/UgaDraw.h>
-#include <Protocol/SimpleTextIn.h>
-#include <Protocol/SimpleTextInEx.h>
-#include <Protocol/UnixUgaIo.h>
-
-
-//
-// Gasket functions for EFI_UNIX_THUNK_PROTOCOL
-//
-
-void
-EFIAPI
-GasketmsSleep (unsigned long Milliseconds);
-
-void
-EFIAPI
-Gasketexit (
- int status
- );
-
-void
-EFIAPI
-GasketSetTimer (
- UINT64 PeriodMs,
- VOID (*CallBack)(UINT64 DeltaMs)
- );
-
-void
-EFIAPI
-GasketGetLocalTime (
- EFI_TIME *Time
- );
-
-struct tm *
-EFIAPI
-Gasketgmtime (
- const time_t *clock
- );
-
-long
-EFIAPI
-GasketGetTimeZone (
- void
- );
-
-int
-EFIAPI
-GasketGetDayLight (
- void
- );
-
-
-int
-EFIAPI
-Gasketpoll (
- struct pollfd *pfd,
- unsigned int nfds,
- int timeout
- );
-
-long
-EFIAPI
-Gasketread (
- int fd,
- void *buf,
- int count);
-
-long
-EFIAPI
-Gasketwrite (
- int fd,
- const void *buf,
- int count
- );
-
-char *
-EFIAPI
-Gasketgetenv (
- const char *name
- );
-
-int
-EFIAPI
-Gasketopen (
- const char *name,
- int flags,
- int mode
- );
-
-off_t
-EFIAPI
-Gasketlseek (
- int fd,
- off_t off,
- int whence
- );
-
-int
-EFIAPI
-Gasketftruncate (
- int fd,
- long int len
- );
-
-int
-EFIAPI
-Gasketclose (
- int fd
- );
-
-int
-EFIAPI
-Gasketmkdir (
- const char *pathname,
- mode_t mode
- );
-
-int
-EFIAPI
-Gasketrmdir (
- const char *pathname
- );
-
-int
-EFIAPI
-Gasketunlink (
- const char *pathname
- );
-
-int
-EFIAPI
-GasketGetErrno (
- void
- );
-
-DIR *
-EFIAPI
-Gasketopendir (
- const char *pathname
- );
-
-void
-EFIAPI
-Gasketrewinddir (
- DIR *dir
- );
-
-struct dirent *
-EFIAPI
-Gasketreaddir (
- DIR *dir
- );
-
-int
-EFIAPI
-Gasketclosedir (
- DIR *dir
- );
-
-int
-EFIAPI
-Gasketstat (
- const char *path,
- STAT_FIX *buf)
- ;
-
-int
-EFIAPI
-Gasketstatfs (
- const char *path,
- struct statfs *buf
- );
-
-int
-EFIAPI
-Gasketrename (
- const char *oldpath,
- const char *newpath
- );
-
-time_t
-EFIAPI
-Gasketmktime (
- struct tm *tm
- );
-
-int
-EFIAPI
-Gasketfsync (
- int fd
- );
-
-int
-EFIAPI
-Gasketchmod (
- const char *path,
- mode_t mode
- );
-
-int
-EFIAPI
-Gasketutime (
- const char *filename,
- const struct utimbuf *buf
- );
-
-int
-EFIAPI
-Gaskettcflush (
- int fildes,
- int queue_selector
- );
-
-EFI_STATUS
-EFIAPI
-GasketUgaCreate (
- struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo,
- CONST CHAR16 *Title
- );
-
-void
-EFIAPI
-Gasketperror (
- __const char *__s
- );
-
-//
-// ... is always an int or pointer to device specific data structure
-//
-
-int
-EFIAPI
-Gasketioctl (
- int fd,
- unsigned long int __request,
- void *Arg
- );
-
-int
-EFIAPI
-Gasketfcntl (
- int __fd,
- int __cmd,
- void *Arg
- );
-
-int
-EFIAPI
-Gasketcfsetispeed (
- struct termios *__termios_p,
- speed_t __speed
- );
-
-int
-EFIAPI
-Gasketcfsetospeed (
- struct termios *__termios_p,
- speed_t __speed
- );
-
-int
-EFIAPI
-Gaskettcgetattr (
- int __fd,
- struct termios *__termios_p
- );
-
-int
-EFIAPI
-Gaskettcsetattr (
- int __fd,
- int __optional_actions,
- __const struct termios *__termios_p
- );
-
-int
-EFIAPI
-Gasketsigaction (
- int sig,
- const struct sigaction *act,
- struct sigaction *oact
- );
-
-int
-EFIAPI
-Gasketgetifaddrs (
- struct ifaddrs **ifap
- );
-
-void
-EFIAPI
-Gasketfreeifaddrs (
- struct ifaddrs *ifap
- );
-
-int
-EFIAPI
-Gasketsocket (
- int domain,
- int type,
- int protocol
- );
-
-void
-EFIAPI
-GasketUnixEnableInterrupt (void);
-
-void
-EFIAPI
-GasketUnixDisableInterrupt (void);
-
-RETURN_STATUS
-EFIAPI
-GasketUnixPeCoffGetEntryPoint (
- IN VOID *Pe32Data,
- IN OUT VOID **EntryPoint
- );
-
-VOID
-EFIAPI
-GasketUnixPeCoffRelocateImageExtraAction (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- );
-
-VOID
-EFIAPI
-GasketUnixPeCoffUnloadImageExtraAction (
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- );
-
-
-
-UINTN
-EFIAPI
-GasketVoid (
- void *api
- );
-
-UINTN
-EFIAPI
-GasketUintn (
- void *api,
- UINTN a
- );
-
-UINTN
-EFIAPI
-GasketUintnUintn (
- void *api,
- UINTN a,
- UINTN b
- );
-
-UINTN
-EFIAPI
-GasketUintnUintnUintn (
- void *api,
- UINTN a,
- UINTN b,
- UINTN c
- );
-
-UINTN
-EFIAPI
-GasketUintnUintnUintnUintn (
- void *api,
- UINTN a,
- UINTN b,
- UINTN c,
- UINTN d
- );
-
-UINTN
-EFIAPI
-GasketUintn10Args (
- void *api,
- UINTN a,
- UINTN b,
- UINTN c,
- UINTN d,
- UINTN e,
- UINTN f,
- UINTN g,
- UINTN h,
- UINTN i,
- UINTN j
- );
-
-UINTN
-EFIAPI
-GasketUint64Uintn (
- void *api,
- UINT64 a,
- UINTN b);
-
-UINT64
-EFIAPI
-GasketUintnUint64Uintn (
- void *api,
- UINTN a,
- UINT64 b,
- UINTN c
- );
-
-UINTN
-EFIAPI
-GasketUintnUint16 (
- void *api,
- UINTN a,
- UINT16 b
- );
-
-typedef
-void
-(*CALL_BACK) (
- UINT64 Delta
- );
-
-UINTN
-ReverseGasketUint64 (
- CALL_BACK CallBack,
- UINT64 a
- );
-
-UINTN
-ReverseGasketUint64Uint64 (
- VOID *CallBack,
- VOID *Context,
- VOID *Key
- );
-
-//
-// Gasket functions for EFI_UNIX_UGA_IO_PROTOCOL
-//
-
-
-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_KEY_DATA *key
- );
-
-EFI_STATUS
-EFIAPI
-GasketUgaKeySetState (
- EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
- EFI_KEY_TOGGLE_STATE *KeyToggleState
- );
-
-EFI_STATUS
-EFIAPI
-GasketUgaRegisterKeyNotify (
- IN EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
- IN UGA_REGISTER_KEY_NOTIFY_CALLBACK CallBack,
- IN VOID *Context
- );
-
-EFI_STATUS
-EFIAPI
-GasketUgaBlt (
- IN EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
- IN EFI_UGA_PIXEL *BltBuffer OPTIONAL,
- IN EFI_UGA_BLT_OPERATION BltOperation,
- IN UGA_BLT_ARGS *Args
- );
-
-EFI_STATUS
-EFIAPI
-GasketUgaCheckPointer (
- EFI_UNIX_UGA_IO_PROTOCOL *UgaIo
- );
-
-EFI_STATUS
-EFIAPI
-GasketUgaGetPointerState (
- EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
- EFI_SIMPLE_POINTER_STATE *state
- );
-
-
-//
-// Gasket functions for EFI_UNIX_UGA_IO_PROTOCOL C calls
-//
-
-
-EFI_STATUS
-EFIAPI
-UgaCreate (
- EFI_UNIX_UGA_IO_PROTOCOL **Uga,
- CONST CHAR16 *Title
- );
-
-EFI_STATUS
-EFIAPI
-UgaClose (
- EFI_UNIX_UGA_IO_PROTOCOL *UgaIo
- );
-
-EFI_STATUS
-EFIAPI
-UgaSize(
- EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
- UINT32 Width,
- UINT32 Height
- );
-
-EFI_STATUS
-EFIAPI
-UgaCheckKey(
- EFI_UNIX_UGA_IO_PROTOCOL *UgaIo
- );
-
-EFI_STATUS
-EFIAPI
-UgaGetKey (
- EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
- EFI_KEY_DATA *key
- );
-
-EFI_STATUS
-EFIAPI
-UgaRegisterKeyNotify (
- IN EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
- IN UGA_REGISTER_KEY_NOTIFY_CALLBACK CallBack,
- IN VOID *Context
- );
-
-
-EFI_STATUS
-EFIAPI
-UgaBlt (
- IN EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
- IN EFI_UGA_PIXEL *BltBuffer OPTIONAL,
- IN EFI_UGA_BLT_OPERATION BltOperation,
- IN UGA_BLT_ARGS *Args
- );
-
-EFI_STATUS
-EFIAPI
-UgaCheckPointer (
- IN EFI_UNIX_UGA_IO_PROTOCOL *UgaIo
- );
-
-EFI_STATUS
-EFIAPI
-UgaGetPointerState (
- IN EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
- IN EFI_SIMPLE_POINTER_STATE *State
- );
-
-
-#endif
-
-
diff --git a/UnixPkg/Sec/Ia32/Gasket.S b/UnixPkg/Sec/Ia32/Gasket.S deleted file mode 100644 index 5f762a3782..0000000000 --- a/UnixPkg/Sec/Ia32/Gasket.S +++ /dev/null @@ -1,344 +0,0 @@ -#------------------------------------------------------------------------------
-#
-# OS X Application requires 16 byte stack alignment. The problem is these
-# APIs are exposed to code that does not have this requirement via
-# EFI_UNIX_THUNK_PROTOCOL. So these are wrapper functions that make sure
-# the stack is aligned. This code should also work if the stack is already
-# aligned. Extra stack padding is really the same as local varaibles so
-# it gets freed by the leave instruction
-#
-# I basically used the compiler, added extra 16 bytes to the local stack and
-# made sure %esp ended in 0 before the call (16 byte algined)
-#
-# The EFI_UNIX_THUNK_PROTOCOL member functions call a C API that then calls
-# one of these generic assembly routines. We do it that way to work around
-# some magic name changing that happens in C. For example stat() is _stat()
-# on Leopard and _stat$INDOE64 on Snow Leopard. That is why we pass stat()
-# into one of these gaskets from C code.
-#
-# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-# 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.
-#
-#------------------------------------------------------------------------------
-
-#ifdef __APPLE__
-
- .text
-
-#------------------------------------------------------------------------------
-# int GasketVoid (void *api)
-#------------------------------------------------------------------------------
-.globl _GasketVoid
-_GasketVoid:
- pushl %ebp
- movl %esp, %ebp
- subl $34, %esp # sub extra 0x10 from the stack for the AND
- and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
- movl 8(%ebp), %eax
- movl %eax, -12(%ebp)
- movl -12(%ebp), %eax
- call *%eax
- leave
- ret
-
-#------------------------------------------------------------------------------
-#------------------------------------------------------------------------------
-.globl _GasketUintn
-_GasketUintn:
- pushl %ebp
- movl %esp, %ebp
- subl $50, %esp # sub extra 0x10 from the stack for the AND
- and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
- movl 8(%ebp), %eax
- movl %eax, -12(%ebp)
- movl 12(%ebp), %eax
- movl %eax, (%esp)
- movl -12(%ebp), %eax
- call *%eax
- leave
- ret
-
-#------------------------------------------------------------------------------
-#------------------------------------------------------------------------------
-.globl _GasketUintnUintn
-_GasketUintnUintn:
- pushl %ebp
- movl %esp, %ebp
- subl $50, %esp # sub extra 0x10 from the stack for the AND
- and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
- movl 8(%ebp), %eax
- movl %eax, -12(%ebp)
- movl 16(%ebp), %eax
- movl %eax, 4(%esp)
- movl 12(%ebp), %eax
- movl %eax, (%esp)
- movl -12(%ebp), %eax
- call *%eax
- leave
- ret
-
-#------------------------------------------------------------------------------
-#------------------------------------------------------------------------------
-.globl _GasketUintnUintnUintn
-_GasketUintnUintnUintn:
- pushl %ebp
- movl %esp, %ebp
- subl $50, %esp # sub extra 0x10 from the stack for the AND
- and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
- movl 8(%ebp), %eax
- movl %eax, -12(%ebp)
- movl 20(%ebp), %eax
- movl %eax, 8(%esp)
- movl 16(%ebp), %eax
- movl %eax, 4(%esp)
- movl 12(%ebp), %eax
- movl %eax, (%esp)
- movl -12(%ebp), %eax
- call *%eax
- leave
- ret
-
-#------------------------------------------------------------------------------
-#------------------------------------------------------------------------------
-.globl _GasketUintnUintnUintnUintn
-_GasketUintnUintnUintnUintn:
- pushl %ebp
- movl %esp, %ebp
- subl $50, %esp # sub extra 0x10 from the stack for the AND
- and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
- movl 8(%ebp), %eax
- movl %eax, -12(%ebp)
- movl 24(%ebp), %eax
- movl %eax, 12(%esp)
- movl 20(%ebp), %eax
- movl %eax, 8(%esp)
- movl 16(%ebp), %eax
- movl %eax, 4(%esp)
- movl 12(%ebp), %eax
- movl %eax, (%esp)
- movl -12(%ebp), %eax
- call *%eax
- leave
- ret
-
-#------------------------------------------------------------------------------
-#------------------------------------------------------------------------------
-.globl _GasketUintnUintnUintnUintnUintn
-_GasketUintnUintnUintnUintnUintn:
- pushl %ebp
- movl %esp, %ebp
- subl $50, %esp # sub extra 0x10 from the stack for the AND
- and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
- movl 8(%ebp), %eax
- movl %eax, -12(%ebp)
- movl 28(%ebp), %eax
- movl %eax, 16(%esp)
- movl 24(%ebp), %eax
- movl %eax, 12(%esp)
- movl 20(%ebp), %eax
- movl %eax, 8(%esp)
- movl 16(%ebp), %eax
- movl %eax, 4(%esp)
- movl 12(%ebp), %eax
- movl %eax, (%esp)
- movl -12(%ebp), %eax
- call *%eax
- leave
- ret
-
-#------------------------------------------------------------------------------
-#------------------------------------------------------------------------------
-.globl _GasketUintn10Args
-_GasketUintn10Args:
- pushl %ebp
- movl %esp, %ebp
- subl $82, %esp # sub extra 0x10 from the stack for the AND
- and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
- movl 8(%ebp), %eax
- movl %eax, -12(%ebp)
- movl 48(%ebp), %eax
- movl %eax, 36(%esp)
- movl 44(%ebp), %eax
- movl %eax, 32(%esp)
- movl 40(%ebp), %eax
- movl %eax, 28(%esp)
- movl 36(%ebp), %eax
- movl %eax, 24(%esp)
- movl 32(%ebp), %eax
- movl %eax, 20(%esp)
- movl 28(%ebp), %eax
- movl %eax, 16(%esp)
- movl 24(%ebp), %eax
- movl %eax, 12(%esp)
- movl 20(%ebp), %eax
- movl %eax, 8(%esp)
- movl 16(%ebp), %eax
- movl %eax, 4(%esp)
- movl 12(%ebp), %eax
- movl %eax, (%esp)
- movl -12(%ebp), %eax
- call *%eax
- leave
- ret
-
-
-#------------------------------------------------------------------------------
-#------------------------------------------------------------------------------
-.globl _GasketUint64Uintn
-_GasketUint64Uintn:
- pushl %ebp
- movl %esp, %ebp
- subl $66, %esp # sub extra 0x10 from the stack for the AND
- and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
- movl 12(%ebp), %eax
- movl %eax, -32(%ebp)
- movl 16(%ebp), %eax
- movl %eax, -28(%ebp)
- movl 8(%ebp), %eax
- movl %eax, -12(%ebp)
- movl 20(%ebp), %eax
- movl %eax, 8(%esp)
- movl -32(%ebp), %eax
- movl -28(%ebp), %edx
- movl %eax, (%esp)
- movl %edx, 4(%esp)
- movl -12(%ebp), %eax
- call *%eax
- leave
- ret
-
-#------------------------------------------------------------------------------
-#------------------------------------------------------------------------------
-.globl _GasketUintnUint64Uintn
-_GasketUintnUint64Uintn:
- pushl %ebp
- movl %esp, %ebp
- subl $66, %esp # sub extra 0x10 from the stack for the AND
- and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
- movl 16(%ebp), %eax
- movl %eax, -32(%ebp)
- movl 20(%ebp), %eax
- movl %eax, -28(%ebp)
- movl 8(%ebp), %eax
- movl %eax, -12(%ebp)
- movl 24(%ebp), %eax
- movl %eax, 12(%esp)
- movl -32(%ebp), %eax
- movl -28(%ebp), %edx
- movl %eax, 4(%esp)
- movl %edx, 8(%esp)
- movl 12(%ebp), %eax
- movl %eax, (%esp)
- movl -12(%ebp), %eax
- call *%eax
- leave
- ret
-
-#------------------------------------------------------------------------------
-#------------------------------------------------------------------------------
-.globl _GasketUintnUint16
-_GasketUintnUint16:
- pushl %ebp
- movl %esp, %ebp
- subl $66, %esp # sub extra 0x10 from the stack for the AND
- and $-16, %esp # stack needs to end in 0xFFFFFFF0 before call
- movl 16(%ebp), %eax
- movw %ax, -28(%ebp)
- movl 8(%ebp), %eax
- movl %eax, -12(%ebp)
- movzwl -28(%ebp), %eax
- movl %eax, 4(%esp)
- movl 12(%ebp), %eax
- movl %eax, (%esp)
- movl -12(%ebp), %eax
- call *%eax
- leave
- ret
-
-
-.globl _ReverseGasketUint64
-_ReverseGasketUint64:
- pushl %ebp
- movl %esp, %ebp
- subl $40, %esp
- movl 12(%ebp), %eax
- movl %eax, -16(%ebp)
- movl 16(%ebp), %eax
- movl %eax, -12(%ebp)
- movl -16(%ebp), %eax
- movl -12(%ebp), %edx
- movl %eax, (%esp)
- movl %edx, 4(%esp)
- movl 8(%ebp), %eax
- call *%eax
- leave
- ret
-
-
-.globl _ReverseGasketUint64Uint64
-_ReverseGasketUint64Uint64:
- pushl %ebp
- movl %esp, %ebp
- subl $56, %esp
- movl 12(%ebp), %eax
- movl %eax, -32(%ebp)
- movl 16(%ebp), %eax
- movl %eax, -28(%ebp)
- movl 20(%ebp), %eax
- movl %eax, -40(%ebp)
- movl 24(%ebp), %eax
- movl %eax, -36(%ebp)
- movl 8(%ebp), %eax
- movl %eax, -12(%ebp)
- movl -40(%ebp), %eax
- movl -36(%ebp), %edx
- movl %eax, 8(%esp)
- movl %edx, 12(%esp)
- movl -32(%ebp), %eax
- movl -28(%ebp), %edx
- movl %eax, (%esp)
- movl %edx, 4(%esp)
- movl -12(%ebp), %eax
- call *%eax
- leave
- ret
-
-
-// Sec PPI Callbacks
-
-.globl _GasketSecUnixPeiLoadFile
-_GasketSecUnixPeiLoadFile:
- jmp _SecUnixPeiLoadFile
-
-
-.globl _GasketSecUnixPeiAutoScan
-_GasketSecUnixPeiAutoScan:
- jmp _SecUnixPeiAutoScan
-
-
-.globl _GasketSecUnixUnixThunkAddress
-_GasketSecUnixUnixThunkAddress:
- jmp _SecUnixUnixThunkAddress
-
-
-.globl _GasketSecPeiReportStatusCode
-_GasketSecPeiReportStatusCode:
- jmp _SecPeiReportStatusCode
-
-
-.globl _GasketSecUnixFdAddress
-_GasketSecUnixFdAddress:
- jmp _SecUnixFdAddress
-
-
-.globl _GasketSecTemporaryRamSupport
-_GasketSecTemporaryRamSupport:
- jmp _SecTemporaryRamSupport
-
- #endif
diff --git a/UnixPkg/Sec/Ia32/Stack.S b/UnixPkg/Sec/Ia32/Stack.S deleted file mode 100644 index ff5a77f8ba..0000000000 --- a/UnixPkg/Sec/Ia32/Stack.S +++ /dev/null @@ -1,95 +0,0 @@ -#------------------------------------------------------------------------------
-#
-# Copyright (c) 2008 - 2009, Intel Corporation. All rights reserved.<BR>
-# Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-# 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 <ProcessorBind.h>
-
-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/Ia32/SwitchStack.c b/UnixPkg/Sec/Ia32/SwitchStack.c deleted file mode 100644 index cf5f364d0d..0000000000 --- a/UnixPkg/Sec/Ia32/SwitchStack.c +++ /dev/null @@ -1,98 +0,0 @@ -/*++ - -Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> -Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> -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: - - SecMain.c - -Abstract: - 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 - what the memory layout will be, how may FD's will be loaded and also - what the boot mode is. - - The SEC registers a set of services with the SEC core. gPrivateDispatchTable - is a list of PPI's produced by the SEC that are availble for usage in PEI. - - This code produces 128 K of temporary memory for the PEI stack by opening a - host file and mapping it directly to memory addresses. - - The system.cmd script is used to set host environment variables that drive - the configuration opitons of the SEC. - ---*/ - -#include "SecMain.h" - - -/** - Transfers control to a function starting with a new stack. - - Transfers control to the function specified by EntryPoint using the new stack - specified by NewStack and passing in the parameters specified by Context1 and - Context2. Context1 and Context2 are optional and may be NULL. The function - EntryPoint must never return. - - If EntryPoint is NULL, then ASSERT(). - If NewStack is NULL, then ASSERT(). - - @param EntryPoint A pointer to function to call with the new stack. - @param Context1 A pointer to the context to pass into the EntryPoint - function. - @param Context2 A pointer to the context to pass into the EntryPoint - function. - @param NewStack A pointer to the new stack to use for the EntryPoint - function. - @param NewBsp A pointer to the new BSP for the EntryPoint on IPF. It's - Reserved on other architectures. - -**/ -VOID -EFIAPI -PeiSwitchStacks ( - IN SWITCH_STACK_ENTRY_POINT EntryPoint, - IN VOID *Context1, OPTIONAL - IN VOID *Context2, OPTIONAL - IN VOID *Context3, OPTIONAL - IN VOID *NewStack - ) -{ - BASE_LIBRARY_JUMP_BUFFER JumpBuffer; - - ASSERT (EntryPoint != NULL); - ASSERT (NewStack != NULL); - - // - // Stack should be aligned with CPU_STACK_ALIGNMENT - // - ASSERT (((UINTN)NewStack & (CPU_STACK_ALIGNMENT - 1)) == 0); - - JumpBuffer.Eip = (UINTN)EntryPoint; - JumpBuffer.Esp = (UINTN)NewStack - sizeof (VOID*); - JumpBuffer.Esp -= sizeof (Context1) + sizeof (Context2) + sizeof(Context3); - ((VOID**)JumpBuffer.Esp)[1] = Context1; - ((VOID**)JumpBuffer.Esp)[2] = Context2; - ((VOID**)JumpBuffer.Esp)[3] = Context3; - - LongJump (&JumpBuffer, (UINTN)-1); - - - // - // InternalSwitchStack () will never return - // - ASSERT (FALSE); -} - - - diff --git a/UnixPkg/Sec/SecMain.c b/UnixPkg/Sec/SecMain.c deleted file mode 100644 index f0627be39a..0000000000 --- a/UnixPkg/Sec/SecMain.c +++ /dev/null @@ -1,1340 +0,0 @@ -/*++ - -Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> -Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR> -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: - - SecMain.c - -Abstract: - 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 - what the memory layout will be, how may FD's will be loaded and also - what the boot mode is. - - The SEC registers a set of services with the SEC core. gPrivateDispatchTable - is a list of PPI's produced by the SEC that are availble for usage in PEI. - - This code produces 128 K of temporary memory for the PEI stack by opening a - host file and mapping it directly to memory addresses. - - The system.cmd script is used to set host environment variables that drive - the configuration opitons of the SEC. - ---*/ - -#include "SecMain.h" -#include <sys/mman.h> -#include <Ppi/UnixPeiLoadFile.h> -#include <Ppi/TemporaryRamSupport.h> -#include <dlfcn.h> - -#ifdef __APPLE__ -#define MAP_ANONYMOUS MAP_ANON -char *gGdbWorkingFileName = NULL; -#endif - - -// -// Globals -// -#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 }; -EFI_PEI_PROGRESS_CODE_PPI mSecStatusCodePpi = { GasketSecPeiReportStatusCode }; -UNIX_FWH_PPI mSecFwhInformationPpi = { GasketSecUnixFdAddress }; -EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = { GasketSecTemporaryRamSupport }; -#else -UNIX_PEI_LOAD_FILE_PPI mSecUnixLoadFilePpi = { SecUnixPeiLoadFile }; -PEI_UNIX_AUTOSCAN_PPI mSecUnixAutoScanPpi = { SecUnixPeiAutoScan }; -PEI_UNIX_THUNK_PPI mSecUnixThunkPpi = { SecUnixUnixThunkAddress }; -EFI_PEI_PROGRESS_CODE_PPI mSecStatusCodePpi = { SecPeiReportStatusCode }; -UNIX_FWH_PPI mSecFwhInformationPpi = { SecUnixFdAddress }; -EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = { SecTemporaryRamSupport }; -#endif - -EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable[] = { - { - EFI_PEI_PPI_DESCRIPTOR_PPI, - &gUnixPeiLoadFilePpiGuid, - &mSecUnixLoadFilePpi - }, - { - EFI_PEI_PPI_DESCRIPTOR_PPI, - &gPeiUnixAutoScanPpiGuid, - &mSecUnixAutoScanPpi - }, - { - EFI_PEI_PPI_DESCRIPTOR_PPI, - &gPeiUnixThunkPpiGuid, - &mSecUnixThunkPpi - }, - { - EFI_PEI_PPI_DESCRIPTOR_PPI, - &gEfiPeiStatusCodePpiGuid, - &mSecStatusCodePpi - }, - { - EFI_PEI_PPI_DESCRIPTOR_PPI, - &gEfiTemporaryRamSupportPpiGuid, - &mSecTemporaryRamSupportPpi - }, - { - EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, - &gUnixFwhPpiGuid, - &mSecFwhInformationPpi - } -}; - - -// -// Default information about where the FD is located. -// This array gets filled in with information from EFI_FIRMWARE_VOLUMES -// EFI_FIRMWARE_VOLUMES is a host environment variable set by system.cmd. -// The number of array elements is allocated base on parsing -// EFI_FIRMWARE_VOLUMES and the memory is never freed. -// -UINTN gFdInfoCount = 0; -UNIX_FD_INFO *gFdInfo; - -// -// Array that supports seperate memory rantes. -// The memory ranges are set in system.cmd via the EFI_MEMORY_SIZE variable. -// The number of array elements is allocated base on parsing -// EFI_MEMORY_SIZE and the memory is never freed. -// -UINTN gSystemMemoryCount = 0; -UNIX_SYSTEM_MEMORY *gSystemMemory; - - - -UINTN mImageContextModHandleArraySize = 0; -IMAGE_CONTEXT_TO_MOD_HANDLE *mImageContextModHandleArray = NULL; - - -VOID -EFIAPI -SecSwitchStack ( - UINT32 TemporaryMemoryBase, - UINT32 PermenentMemoryBase - ); - -EFI_PHYSICAL_ADDRESS * -MapMemory ( - INTN fd, - UINT64 length, - INTN prot, - INTN flags); - -EFI_STATUS -MapFile ( - IN CHAR8 *FileName, - IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress, - OUT UINT64 *Length - ); - -EFI_STATUS -EFIAPI -SecNt32PeCoffRelocateImage ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext - ); - - -int -main ( - IN int Argc, - IN char **Argv, - IN char **Envp - ) -/*++ - -Routine Description: - Main entry point to SEC for Unix. This is a unix program - -Arguments: - Argc - Number of command line arguments - Argv - Array of command line argument strings - Envp - Array of environmemt variable strings - -Returns: - 0 - Normal exit - 1 - Abnormal exit - ---*/ -{ - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS InitialStackMemory; - UINT64 InitialStackMemorySize; - UINTN Index; - UINTN Index1; - UINTN Index2; - UINTN PeiIndex; - CHAR8 *FileName; - BOOLEAN Done; - VOID *PeiCoreFile; - CHAR16 *MemorySizeStr; - CHAR16 *FirmwareVolumesStr; - UINTN *StackPointer; - - setbuf(stdout, 0); - setbuf(stderr, 0); - - MemorySizeStr = (CHAR16 *) PcdGetPtr (PcdUnixMemorySizeForSecMain); - FirmwareVolumesStr = (CHAR16 *) PcdGetPtr (PcdUnixFirmwareVolume); - - printf ("\nEDK SEC Main UNIX Emulation Environment from edk2.sourceforge.net\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") + 1); - strcpy (gGdbWorkingFileName, *Argv); - strcat (gGdbWorkingFileName, ".gdb"); -#endif - - - // - // Allocate space for gSystemMemory Array - // - gSystemMemoryCount = CountSeperatorsInString (MemorySizeStr, '!') + 1; - gSystemMemory = calloc (gSystemMemoryCount, sizeof (UNIX_SYSTEM_MEMORY)); - if (gSystemMemory == NULL) { - printf ("ERROR : Can not allocate memory for system. Exiting.\n"); - exit (1); - } - // - // Allocate space for gSystemMemory Array - // - gFdInfoCount = CountSeperatorsInString (FirmwareVolumesStr, '!') + 1; - gFdInfo = calloc (gFdInfoCount, sizeof (UNIX_FD_INFO)); - if (gFdInfo == NULL) { - printf ("ERROR : Can not allocate memory for fd info. Exiting.\n"); - exit (1); - } - // - // Setup Boot Mode. If BootModeStr == "" then BootMode = 0 (BOOT_WITH_FULL_CONFIGURATION) - // - printf (" BootMode 0x%02x\n", (unsigned int)PcdGet32 (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 UnixOpenFile will allocate a new mapping - // - InitialStackMemorySize = STACK_SIZE; - InitialStackMemory = (UINTN)MapMemory(0, - (UINT32) InitialStackMemorySize, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_ANONYMOUS | MAP_PRIVATE); - if (InitialStackMemory == 0) { - printf ("ERROR : Can not open SecStack Exiting\n"); - exit (1); - } - - 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 ++) { - *StackPointer = 0x5AA55AA5; - } - - // - // Open All the firmware volumes and remember the info in the gFdInfo global - // - FileName = (CHAR8 *)malloc (StrLen (FirmwareVolumesStr) + 1); - if (FileName == NULL) { - printf ("ERROR : Can not allocate memory for firmware volume string\n"); - exit (1); - } - - Index2 = 0; - for (Done = FALSE, Index = 0, PeiIndex = 0, PeiCoreFile = NULL; - FirmwareVolumesStr[Index2] != 0; - Index++) { - for (Index1 = 0; (FirmwareVolumesStr[Index2] != '!') && (FirmwareVolumesStr[Index2] != 0); Index2++) - FileName[Index1++] = FirmwareVolumesStr[Index2]; - if (FirmwareVolumesStr[Index2] == '!') - Index2++; - FileName[Index1] = '\0'; - - // - // Open the FD and remmeber where it got mapped into our processes address space - // - Status = MapFile ( - FileName, - &gFdInfo[Index].Address, - &gFdInfo[Index].Size - ); - if (EFI_ERROR (Status)) { - printf ("ERROR : Can not open Firmware Device File %s (%x). Exiting.\n", FileName, (unsigned int)Status); - exit (1); - } - - printf (" FD loaded from %s at 0x%08lx", - FileName, (unsigned long)gFdInfo[Index].Address); - - if (PeiCoreFile == NULL) { - // - // Assume the beginning of the FD is an FV and look for the PEI Core. - // Load the first one we find. - // - Status = SecFfsFindPeiCore ((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) gFdInfo[Index].Address, &PeiCoreFile); - if (!EFI_ERROR (Status)) { - PeiIndex = Index; - printf (" contains SEC Core"); - } - } - - printf ("\n"); - } - // - // Calculate memory regions and store the information in the gSystemMemory - // global for later use. The autosizing code will use this data to - // map this memory into the SEC process memory space. - // - Index1 = 0; - Index = 0; - while (1) { - UINTN val = 0; - // - // Save the size of the memory. - // - while (MemorySizeStr[Index1] >= '0' && MemorySizeStr[Index1] <= '9') { - val = val * 10 + MemorySizeStr[Index1] - '0'; - Index1++; - } - gSystemMemory[Index++].Size = val * 0x100000; - if (MemorySizeStr[Index1] == 0) - break; - Index1++; - } - - printf ("\n"); - - // - // Hand off to PEI Core - // - SecLoadFromCore ((UINTN) InitialStackMemory, (UINTN) InitialStackMemorySize, (UINTN) gFdInfo[0].Address, PeiCoreFile); - - // - // If we get here, then the PEI Core returned. This is an error as PEI should - // always hand off to DXE. - // - printf ("ERROR : PEI Core returned\n"); - exit (1); -} - -EFI_PHYSICAL_ADDRESS * -MapMemory ( - INTN fd, - UINT64 length, - INTN prot, - INTN flags) -{ - STATIC UINTN base = 0x40000000; - CONST UINTN align = (1 << 24); - VOID *res = NULL; - BOOLEAN isAligned = 0; - - // - // Try to get an aligned block somewhere in the address space of this - // process. - // - while((!isAligned) && (base != 0)) { - res = mmap ((void *)base, length, prot, flags, fd, 0); - if (res == MAP_FAILED) { - return NULL; - } - if ((((UINTN)res) & ~(align-1)) == (UINTN)res) { - isAligned=1; - } - else { - munmap(res, length); - base += align; - } - } - return res; -} - -EFI_STATUS -MapFile ( - IN CHAR8 *FileName, - IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress, - OUT UINT64 *Length - ) -/*++ - -Routine Description: - 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: - FileName - The name of the file to open and map - MapSize - The amount of the file to map in bytes - CreationDisposition - The flags to pass to CreateFile(). Use to create new files for - memory emulation, and exiting files for firmware volume emulation - BaseAddress - The base address of the mapped file in the user address space. - If passed in as NULL the a new memory region is used. - If passed in as non NULL the request memory region is used for - the mapping of the file into the process space. - Length - The size of the mapped region in bytes - -Returns: - EFI_SUCCESS - The file was opened and mapped. - EFI_NOT_FOUND - FileName was not found in the current directory - EFI_DEVICE_ERROR - An error occured attempting to map the opened file - ---*/ -{ - int fd; - VOID *res; - UINTN FileSize; - - fd = open (FileName, O_RDONLY); - if (fd < 0) - return EFI_NOT_FOUND; - FileSize = lseek (fd, 0, SEEK_END); - -#if 0 - if (IsMain) - { - /* Read entry address. */ - lseek (fd, FileSize - 0x20, SEEK_SET); - if (read (fd, &EntryAddress, 4) != 4) - { - 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) - return EFI_DEVICE_ERROR; - - *Length = (UINT64) FileSize; - *BaseAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) res; - - return EFI_SUCCESS; -} - -#define BYTES_PER_RECORD 512 - -EFI_STATUS -EFIAPI -SecPeiReportStatusCode ( - IN CONST EFI_PEI_SERVICES **PeiServices, - IN EFI_STATUS_CODE_TYPE CodeType, - IN EFI_STATUS_CODE_VALUE Value, - IN UINT32 Instance, - IN CONST EFI_GUID *CallerId, - IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL - ) -/*++ - -Routine Description: - - This routine produces the ReportStatusCode PEI service. It's passed - up to the PEI Core via a PPI. T - - This code currently uses the UNIX clib printf. This does not work the same way - as the EFI Print (), as %t, %g, %s as Unicode are not supported. - -Arguments: - (see EFI_PEI_REPORT_STATUS_CODE) - -Returns: - EFI_SUCCESS - Always return success - ---*/ -// TODO: PeiServices - add argument and description to function comment -// TODO: CodeType - add argument and description to function comment -// TODO: Value - add argument and description to function comment -// TODO: Instance - add argument and description to function comment -// TODO: CallerId - add argument and description to function comment -// TODO: Data - add argument and description to function comment -{ - CHAR8 *Format; - BASE_LIST Marker; - CHAR8 PrintBuffer[BYTES_PER_RECORD * 2]; - CHAR8 *Filename; - CHAR8 *Description; - UINT32 LineNumber; - UINT32 ErrorLevel; - - - if (Data == NULL) { - } else if (ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) { - // - // Processes ASSERT () - // - printf ("ASSERT %s(%d): %s\n", Filename, (int)LineNumber, Description); - - } else if (ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) { - // - // Process DEBUG () macro - // - AsciiBSPrint (PrintBuffer, BYTES_PER_RECORD, Format, Marker); - printf ("%s", PrintBuffer); - } - - return EFI_SUCCESS; -} - -VOID -EFIAPI -PeiSwitchStacks ( - IN SWITCH_STACK_ENTRY_POINT EntryPoint, - IN VOID *Context1, OPTIONAL - IN VOID *Context2, OPTIONAL - IN VOID *Context3, OPTIONAL - IN VOID *NewStack - ); - -VOID -SecLoadFromCore ( - IN UINTN LargestRegion, - IN UINTN LargestRegionSize, - IN UINTN BootFirmwareVolumeBase, - IN VOID *PeiCorePe32File - ) -/*++ - -Routine Description: - This is the service to load the PEI Core from the Firmware Volume - -Arguments: - LargestRegion - Memory to use for PEI. - LargestRegionSize - Size of Memory to use for PEI - BootFirmwareVolumeBase - Start of the Boot FV - PeiCorePe32File - PEI Core PE32 - -Returns: - Success means control is transfered and thus we should never return - ---*/ -{ - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS TopOfMemory; - VOID *TopOfStack; - UINT64 PeiCoreSize; - EFI_PHYSICAL_ADDRESS PeiCoreEntryPoint; - EFI_PHYSICAL_ADDRESS PeiImageAddress; - EFI_SEC_PEI_HAND_OFF *SecCoreData; - UINTN PeiStackSize; - EFI_PEI_PPI_DESCRIPTOR *DispatchTable; - UINTN DispatchTableSize; - - // - // Compute Top Of Memory for Stack and PEI Core Allocations - // - TopOfMemory = LargestRegion + LargestRegionSize; - PeiStackSize = (UINTN)RShiftU64((UINT64)STACK_SIZE,1); - - // - // |-----------| <---- TemporaryRamBase + TemporaryRamSize - // | Heap | - // | | - // |-----------| <---- StackBase / PeiTemporaryMemoryBase - // | | - // | 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 - // - SecCoreData = (EFI_SEC_PEI_HAND_OFF*)(UINTN) TopOfStack; - SecCoreData->DataSize = sizeof(EFI_SEC_PEI_HAND_OFF); - SecCoreData->BootFirmwareVolumeBase = (VOID*)BootFirmwareVolumeBase; - SecCoreData->BootFirmwareVolumeSize = PcdGet32 (PcdUnixFirmwareFdSize); - SecCoreData->TemporaryRamBase = (VOID*)(UINTN)LargestRegion; - SecCoreData->TemporaryRamSize = STACK_SIZE; - SecCoreData->StackBase = SecCoreData->TemporaryRamBase; - SecCoreData->StackSize = PeiStackSize; - SecCoreData->PeiTemporaryRamBase = (VOID*) ((UINTN) SecCoreData->TemporaryRamBase + PeiStackSize); - SecCoreData->PeiTemporaryRamSize = STACK_SIZE - PeiStackSize; - - // - // Load the PEI Core from a Firmware Volume - // - Status = SecUnixPeiLoadFile ( - PeiCorePe32File, - &PeiImageAddress, - &PeiCoreSize, - &PeiCoreEntryPoint - ); - 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 - // - PeiSwitchStacks ( - (SWITCH_STACK_ENTRY_POINT) (UINTN) PeiCoreEntryPoint, - SecCoreData, - (VOID *)DispatchTable, - NULL, - TopOfStack - ); - // - // If we get here, then the PEI Core returned. This is an error - // - return ; -} - -EFI_STATUS -EFIAPI -SecUnixPeiAutoScan ( - IN UINTN Index, - OUT EFI_PHYSICAL_ADDRESS *MemoryBase, - OUT UINT64 *MemorySize - ) -/*++ - -Routine Description: - This service is called from Index == 0 until it returns EFI_UNSUPPORTED. - It allows discontiguous memory regions to be supported by the emulator. - 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 - UnixOpenFile. - -Arguments: - Index - Which memory region to use - MemoryBase - Return Base address of memory region - MemorySize - Return size in bytes of the memory region - -Returns: - EFI_SUCCESS - If memory region was mapped - EFI_UNSUPPORTED - If Index is not supported - ---*/ -{ - void *res; - - if (Index >= gSystemMemoryCount) { - return EFI_UNSUPPORTED; - } - - *MemoryBase = 0; - res = MapMemory(0, gSystemMemory[Index].Size, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_PRIVATE | MAP_ANONYMOUS); - if (res == MAP_FAILED) - return EFI_DEVICE_ERROR; - *MemorySize = gSystemMemory[Index].Size; - *MemoryBase = (UINTN)res; - gSystemMemory[Index].Memory = *MemoryBase; - - return EFI_SUCCESS; -} - -VOID * -EFIAPI -SecUnixUnixThunkAddress ( - VOID - ) -/*++ - -Routine Description: - Since the SEC is the only Unix program in stack it must export - an interface to do POSIX calls. gUnix is initailized in UnixThunk.c. - -Arguments: - InterfaceSize - sizeof (EFI_WIN_NT_THUNK_PROTOCOL); - InterfaceBase - Address of the gUnix global - -Returns: - EFI_SUCCESS - Data returned - ---*/ -{ - return gUnix; -} - - -EFI_STATUS -SecUnixPeiLoadFile ( - IN VOID *Pe32Data, - OUT EFI_PHYSICAL_ADDRESS *ImageAddress, - OUT UINT64 *ImageSize, - OUT EFI_PHYSICAL_ADDRESS *EntryPoint - ) -/*++ - -Routine Description: - Loads and relocates a PE/COFF image into memory. - -Arguments: - Pe32Data - The base address of the PE/COFF file that is to be loaded and relocated - ImageAddress - The base address of the relocated PE/COFF image - ImageSize - The size of the relocated PE/COFF image - EntryPoint - The entry point of the relocated PE/COFF image - -Returns: - EFI_SUCCESS - The file was loaded and relocated - EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file - ---*/ -{ - EFI_STATUS Status; - PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; - - ZeroMem (&ImageContext, sizeof (ImageContext)); - ImageContext.Handle = Pe32Data; - - ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE) SecImageRead; - - Status = PeCoffLoaderGetImageInfo (&ImageContext); - 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, - (UINT32) (ImageContext.ImageSize + (ImageContext.SectionAlignment * 2)), - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_ANONYMOUS | MAP_PRIVATE - ); - if (ImageContext.ImageAddress == 0) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Align buffer on section boundry - // - ImageContext.ImageAddress += ImageContext.SectionAlignment - 1; - ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1)); - - - Status = PeCoffLoaderLoadImage (&ImageContext); - if (EFI_ERROR (Status)) { - return Status; - } - - Status = PeCoffLoaderRelocateImage (&ImageContext); - if (EFI_ERROR (Status)) { - return Status; - } - - - SecPeCoffRelocateImageExtraAction (&ImageContext); - - // - // BugBug: Flush Instruction Cache Here when CPU Lib is ready - // - - *ImageAddress = ImageContext.ImageAddress; - *ImageSize = ImageContext.ImageSize; - *EntryPoint = ImageContext.EntryPoint; - - 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 -SecUnixFdAddress ( - IN UINTN Index, - IN OUT EFI_PHYSICAL_ADDRESS *FdBase, - IN OUT UINT64 *FdSize, - IN OUT EFI_PHYSICAL_ADDRESS *FixUp - ) -/*++ - -Routine Description: - Return the FD Size and base address. Since the FD is loaded from a - file into host memory only the SEC will know it's address. - -Arguments: - Index - Which FD, starts at zero. - FdSize - Size of the FD in bytes - FdBase - Start address of the FD. Assume it points to an FV Header - FixUp - Difference between actual FD address and build address - -Returns: - EFI_SUCCESS - Return the Base address and size of the FV - EFI_UNSUPPORTED - Index does nto map to an FD in the system - ---*/ -{ - if (Index >= gFdInfoCount) { - return EFI_UNSUPPORTED; - } - - *FdBase = gFdInfo[Index].Address; - *FdSize = gFdInfo[Index].Size; - *FixUp = 0; - - if (*FdBase == 0 && *FdSize == 0) { - return EFI_UNSUPPORTED; - } - - if (Index == 0) { - // - // 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. - // - *FixUp = *FdBase - PcdGet64 (PcdUnixFdBaseAddress); - } - - return EFI_SUCCESS; -} - -EFI_STATUS -EFIAPI -SecImageRead ( - IN VOID *FileHandle, - IN UINTN FileOffset, - IN OUT UINTN *ReadSize, - OUT VOID *Buffer - ) -/*++ - -Routine Description: - Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file - -Arguments: - FileHandle - The handle to the PE/COFF file - FileOffset - The offset, in bytes, into the file to read - ReadSize - The number of bytes to read from the file starting at FileOffset - Buffer - A pointer to the buffer to read the data into. - -Returns: - EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset - ---*/ -{ - CHAR8 *Destination8; - CHAR8 *Source8; - UINTN Length; - - Destination8 = Buffer; - Source8 = (CHAR8 *) ((UINTN) FileHandle + FileOffset); - Length = *ReadSize; - while (Length--) { - *(Destination8++) = *(Source8++); - } - - return EFI_SUCCESS; -} - -UINTN -CountSeperatorsInString ( - IN const CHAR16 *String, - IN CHAR16 Seperator - ) -/*++ - -Routine Description: - Count the number of seperators in String - -Arguments: - String - String to process - Seperator - Item to count - -Returns: - Number of Seperator in String - ---*/ -{ - UINTN Count; - - for (Count = 0; *String != '\0'; String++) { - if (*String == Seperator) { - Count++; - } - } - - return Count; -} - - -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 ( - VOID - ) -{ -} - -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] == 'D' || PdbFileName[Len - 3] == 'd') && - (PdbFileName[Len - 2] == 'L' || PdbFileName[Len - 2] == 'l') && - (PdbFileName[Len - 1] == 'L' || PdbFileName[Len - 1] == 'l')) { - return TRUE; - } - - return FALSE; -} - - -#define MAX_SPRINT_BUFFER_SIZE 0x200 - -void -PrintLoadAddress ( - IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext - ) -{ - if (ImageContext->PdbPointer == NULL) { - fprintf (stderr, - "0x%08lx Loading NO DEBUG with entry point 0x%08lx\n", - (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, - (unsigned long)ImageContext->EntryPoint - ); - } - // Keep output synced up - fflush (stderr); -} - - -VOID -EFIAPI -SecPeCoffRelocateImageExtraAction ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext - ) -{ - -#ifdef __APPLE__ - BOOLEAN EnabledOnEntry; - - // - // Make sure writting of the file is an atomic operation - // - if (UnixInterruptEanbled ()) { - UnixDisableInterrupt (); - EnabledOnEntry = TRUE; - } else { - EnabledOnEntry = FALSE; - } - - 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. - // <library-list> - // <library name="/lib/libc.so.6"> // ImageContext->PdbPointer - // <segment address="0x10000000"/> // ImageContext->ImageAddress + ImageContext->SizeOfHeaders - // </library> - // </library-list> - // - - // - // Write the file we need for the gdb script - // - GdbTempFile = fopen (gGdbWorkingFileName, "w"); - 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. - // Hey what can you say scripting in gdb is not that great.... - // - SecGdbScriptBreak (); - } else { - ASSERT (FALSE); - } - - AddHandle (ImageContext, ImageContext->PdbPointer); - - if (EnabledOnEntry) { - UnixEnableInterrupt (); - } - - - } - -#else - - void *Handle = NULL; - void *Entry = NULL; - - 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()); - } - - if (Entry != NULL) { - ImageContext->EntryPoint = (UINTN)Entry; - printf("Change %s Entrypoint to :0x%08lx\n", ImageContext->PdbPointer, (unsigned long)Entry); - } - - SecUnixLoaderBreak (); - -#endif - - return; -} - - -VOID -EFIAPI -SecPeCoffLoaderUnloadImageExtraAction ( - IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext - ) -{ - VOID *Handle; - - Handle = RemoveHandle (ImageContext); - -#ifdef __APPLE__ - FILE *GdbTempFile; - BOOLEAN EnabledOnEntry; - - if (Handle != NULL) { - // - // Need to skip .PDB files created from VC++ - // - if (!IsPdbFile (ImageContext->PdbPointer)) { - if (UnixInterruptEanbled ()) { - UnixDisableInterrupt (); - EnabledOnEntry = TRUE; - } else { - EnabledOnEntry = FALSE; - } - - // - // 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 { - ASSERT (FALSE); - } - - if (EnabledOnEntry) { - UnixEnableInterrupt (); - } - } - } - -#else - // - // Don't want to confuse gdb with symbols for something that got unloaded - // - if (Handle != NULL) { - dlclose (Handle); - } - -#endif - return; -} - -VOID -ModuleEntryPoint ( - VOID - ) -{ -} - -EFI_STATUS -EFIAPI -SecTemporaryRamSupport ( - IN CONST EFI_PEI_SERVICES **PeiServices, - IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, - IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, - IN UINTN CopySize - ) -{ - // - // Migrate the whole temporary memory to permenent memory. - // - CopyMem ( - (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 - // permenent memory. - // - SecSwitchStack ( - (UINT32) TemporaryMemoryBase, - (UINT32) PermanentMemoryBase - ); - - // - // 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; -} diff --git a/UnixPkg/Sec/SecMain.h b/UnixPkg/Sec/SecMain.h deleted file mode 100644 index dc857d8fb0..0000000000 --- a/UnixPkg/Sec/SecMain.h +++ /dev/null @@ -1,601 +0,0 @@ -/*++
-
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
-Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-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:
- SecMain.h
-
-Abstract:
- Include file for host API based SEC
-
---*/
-#include <PiPei.h>
-
-#include <Protocol/UnixThunk.h>
-#include <Ppi/StatusCode.h>
-
-#include <Library/PeCoffLib.h>
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/PrintLib.h>
-#include <Library/PcdLib.h>
-#include <Library/DebugLib.h>
-#include <Library/ReportStatusCodeLib.h>
-#include <Library/SecDispatchTableLib.h>
-
-
-#define STACK_SIZE 0x20000
-
-typedef struct {
- EFI_PHYSICAL_ADDRESS Address;
- UINT64 Size;
-} UNIX_FD_INFO;
-
-typedef struct {
- EFI_PHYSICAL_ADDRESS Memory;
- UINT64 Size;
-} 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
-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
- EFI_PHYSICAL_ADDRESS *EntryPoint // TODO: add IN/OUT modifier to EntryPoint
- );
-
-EFI_STATUS
-EFIAPI
-GasketSecUnixPeiLoadFile (
- 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
- EFI_PHYSICAL_ADDRESS *EntryPoint // TODO: add IN/OUT modifier to EntryPoint
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- Pe32Data - TODO: add argument description
- ImageAddress - TODO: add argument description
- ImageSize - TODO: add argument description
- EntryPoint - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-EFI_STATUS
-EFIAPI
-SecUnixPeiAutoScan (
- IN UINTN Index,
- OUT EFI_PHYSICAL_ADDRESS *MemoryBase,
- OUT UINT64 *MemorySize
- );
-
-EFI_STATUS
-EFIAPI
-GasketSecUnixPeiAutoScan (
- IN UINTN Index,
- OUT EFI_PHYSICAL_ADDRESS *MemoryBase,
- OUT UINT64 *MemorySize
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- Index - TODO: add argument description
- MemoryBase - TODO: add argument description
- MemorySize - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-VOID *
-EFIAPI
-SecUnixUnixThunkAddress (
- VOID
- );
-
-VOID *
-EFIAPI
-GasketSecUnixUnixThunkAddress (
- VOID
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- InterfaceSize - TODO: add argument description
- InterfaceBase - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-EFI_STATUS
-EFIAPI
-SecUnixUnixFwhAddress (
- IN OUT UINT64 *FwhSize,
- IN OUT EFI_PHYSICAL_ADDRESS *FwhBase
- );
-
-EFI_STATUS
-EFIAPI
-GasketSecUnixUnixFwhAddress (
- IN OUT UINT64 *FwhSize,
- IN OUT EFI_PHYSICAL_ADDRESS *FwhBase
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- FwhSize - TODO: add argument description
- FwhBase - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-EFI_STATUS
-EFIAPI
-SecPeiReportStatusCode (
- IN CONST EFI_PEI_SERVICES **PeiServices,
- IN EFI_STATUS_CODE_TYPE CodeType,
- IN EFI_STATUS_CODE_VALUE Value,
- IN UINT32 Instance,
- IN CONST EFI_GUID *CallerId,
- IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL
- );
-
-EFI_STATUS
-EFIAPI
-GasketSecPeiReportStatusCode (
- IN CONST EFI_PEI_SERVICES **PeiServices,
- IN EFI_STATUS_CODE_TYPE CodeType,
- IN EFI_STATUS_CODE_VALUE Value,
- IN UINT32 Instance,
- IN CONST EFI_GUID *CallerId,
- IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- PeiServices - TODO: add argument description
- CodeType - TODO: add argument description
- Value - TODO: add argument description
- Instance - TODO: add argument description
- CallerId - TODO: add argument description
- Data - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-int
-main (
- IN int Argc,
- IN char **Argv,
- IN char **Envp
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- Argc - TODO: add argument description
- Argv - TODO: add argument description
- Envp - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-VOID
-SecLoadFromCore (
- IN UINTN LargestRegion,
- IN UINTN LargestRegionSize,
- IN UINTN BootFirmwareVolumeBase,
- IN VOID *PeiCoreFile
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- LargestRegion - TODO: add argument description
- LargestRegionSize - TODO: add argument description
- BootFirmwareVolumeBase - TODO: add argument description
- PeiCoreFile - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-EFI_STATUS
-SecLoadFile (
- IN VOID *Pe32Data,
- IN EFI_PHYSICAL_ADDRESS *ImageAddress,
- IN UINT64 *ImageSize,
- IN EFI_PHYSICAL_ADDRESS *EntryPoint
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- Pe32Data - TODO: add argument description
- ImageAddress - TODO: add argument description
- ImageSize - TODO: add argument description
- EntryPoint - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-EFI_STATUS
-SecFfsFindPeiCore (
- IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
- OUT VOID **Pe32Data
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- FwVolHeader - TODO: add argument description
- Pe32Data - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-EFI_STATUS
-SecFfsFindNextFile (
- IN EFI_FV_FILETYPE SearchType,
- IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
- IN OUT EFI_FFS_FILE_HEADER **FileHeader
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- SearchType - TODO: add argument description
- FwVolHeader - TODO: add argument description
- FileHeader - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-EFI_STATUS
-SecFfsFindSectionData (
- IN EFI_SECTION_TYPE SectionType,
- IN EFI_FFS_FILE_HEADER *FfsFileHeader,
- IN OUT VOID **SectionData
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- SectionType - TODO: add argument description
- FfsFileHeader - TODO: add argument description
- SectionData - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-EFI_STATUS
-EFIAPI
-SecUnixPeCoffLoaderLoadAsDll (
- IN CHAR8 *PdbFileName,
- IN VOID **ImageEntryPoint,
- OUT VOID **ModHandle
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- PdbFileName - TODO: add argument description
- ImageEntryPoint - TODO: add argument description
- ModHandle - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-EFI_STATUS
-EFIAPI
-SecUnixPeCoffLoaderFreeLibrary (
- OUT VOID *ModHandle
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- ModHandle - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-EFI_STATUS
-EFIAPI
-SecUnixFdAddress (
- IN UINTN Index,
- IN OUT EFI_PHYSICAL_ADDRESS *FdBase,
- IN OUT UINT64 *FdSize,
- IN OUT EFI_PHYSICAL_ADDRESS *FixUp
- )
-;
-
-EFI_STATUS
-EFIAPI
-GasketSecUnixFdAddress (
- IN UINTN Index,
- IN OUT EFI_PHYSICAL_ADDRESS *FdBase,
- IN OUT UINT64 *FdSize,
- IN OUT EFI_PHYSICAL_ADDRESS *FixUp
- )
-;
-
-
-EFI_STATUS
-GetImageReadFunction (
- IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,
- IN EFI_PHYSICAL_ADDRESS *TopOfMemory
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- ImageContext - TODO: add argument description
- TopOfMemory - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-EFI_STATUS
-EFIAPI
-SecImageRead (
- IN VOID *FileHandle,
- IN UINTN FileOffset,
- IN OUT UINTN *ReadSize,
- OUT VOID *Buffer
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- FileHandle - TODO: add argument description
- FileOffset - TODO: add argument description
- ReadSize - TODO: add argument description
- Buffer - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-CHAR16 *
-AsciiToUnicode (
- IN CHAR8 *Ascii,
- IN UINTN *StrLen OPTIONAL
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- Ascii - TODO: add argument description
- StrLen - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-UINTN
-CountSeperatorsInString (
- IN const CHAR16 *String,
- IN CHAR16 Seperator
- )
-/*++
-
-Routine Description:
-
- TODO: Add function description
-
-Arguments:
-
- String - TODO: add argument description
- Seperator - TODO: add argument description
-
-Returns:
-
- TODO: add return values
-
---*/
-;
-
-EFI_STATUS
-EFIAPI
-SecTemporaryRamSupport (
- IN CONST EFI_PEI_SERVICES **PeiServices,
- IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
- IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
- IN UINTN CopySize
- );
-
-EFI_STATUS
-EFIAPI
-GasketSecTemporaryRamSupport (
- IN CONST EFI_PEI_SERVICES **PeiServices,
- IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
- IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
- 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
- );
-
-
-VOID SetTimer (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs));
-void msSleep (unsigned long Milliseconds);
-void GetLocalTime (EFI_TIME *Time);
-void TzSet (void);
-long GetTimeZone(void);
-int GetDayLight(void);
-int GetErrno(void);
-void UnixEnableInterrupt (void);
-void UnixDisableInterrupt (void);
-BOOLEAN UnixInterruptEanbled (void);
-
-
-
-extern EFI_UNIX_THUNK_PROTOCOL *gUnix;
diff --git a/UnixPkg/Sec/SecMain.inf b/UnixPkg/Sec/SecMain.inf deleted file mode 100644 index b418d54617..0000000000 --- a/UnixPkg/Sec/SecMain.inf +++ /dev/null @@ -1,106 +0,0 @@ -## @file
-# Entry Point of Unix Emulator
-#
-# Main executable file of Unix Emulator that loads PEI core after initialization finished.
-# Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>
-# Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-#
-# 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.
-#
-#
-##
-
-[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = SecMain
- FILE_GUID = f43be88c-8985-11db-8f78-0040d02b1835
- MODULE_TYPE = USER_DEFINED
- VERSION_STRING = 1.0
- ENTRY_POINT = main
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-# VALID_ARCHITECTURES = IA32 X64 IPF EBC
-#
-
-[Sources]
- UgaX11.c
- UnixThunk.c
- FwVol.c
- SecMain.c
-
-[Sources.Ia32]
- Gasket.c
- Ia32/Gasket.S
- Ia32/Stack.S
- Ia32/SwitchStack.c
-
-[Sources.X64]
-# X64/Gasket.S # pure UNIX x86_64 ABI also need to fix issues in BaseLib
- X64/MangleGasket.S # convert between UNIX x86_64 ABI and EFI X64 ABI
-
- X64/SwitchStack.S
- X64/NameManglingFix.c
-
-
-[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- UnixPkg/UnixPkg.dec
- IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
-
-[LibraryClasses]
- DebugLib
- PcdLib
- PrintLib
- BaseMemoryLib
- BaseLib
- PeCoffLib
- ReportStatusCodeLib
- SecDispatchTableLib
-
-
-[Ppis]
- gUnixPeiLoadFilePpiGuid # PPI ALWAYS_PRODUCED
- gEfiPeiStatusCodePpiGuid # PPI ALWAYS_PRODUCED
- gUnixFwhPpiGuid # PPI ALWAYS_PRODUCED
- gPeiUnixAutoScanPpiGuid # PPI ALWAYS_PRODUCED
- gPeiUnixThunkPpiGuid # PPI ALWAYS_PRODUCED
- gEfiTemporaryRamSupportPpiGuid
-
-
-[Pcd]
- gEfiUnixPkgTokenSpaceGuid.PcdUnixBootMode
- gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareVolume
- gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySizeForSecMain
- gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareFdSize
- gEfiUnixPkgTokenSpaceGuid.PcdUnixFdBaseAddress
-
-[BuildOptions]
- GCC:*_*_IA32_DLINK_FLAGS == -o "$(BIN_DIR)/SecMain" -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o -L/usr/X11R6/lib -lXext -lX11 /usr/lib/crtn.o
- GCC:*_*_*_DLINK2_FLAGS == -lc
- GCC:*_*_IA32_CC_FLAGS == -m32 -g -fshort-wchar -fno-strict-aliasing -Wall -malign-double -idirafter/usr/include -c -include AutoGen.h
- GCC:*_*_IA32_PP_FLAGS == -m32 -E -x assembler-with-cpp -include AutoGen.h
- GCC:*_*_IA32_ASM_FLAGS == -m32 -c -x assembler -imacros AutoGen.h
-
- GCC:*_*_X64_DLINK_FLAGS == -o "$(BIN_DIR)/SecMain" -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/crt1.o /usr/lib/crti.o -L/usr/X11R6/lib -lXext -lX11 /usr/lib/crtn.o
- GCC:*_*_X64_CC_FLAGS == -m64 -g -fshort-wchar -fno-strict-aliasing -Wall -malign-double -idirafter/usr/include -c -include AutoGen.h
- GCC:*_*_X64_PP_FLAGS == -m64 -E -x assembler-with-cpp -include AutoGen.h
- GCC:*_*_X64_ASM_FLAGS == -m64 -c -x assembler -imacros 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 -o "$(BIN_DIR)/SecMain" -L/usr/X11R6/lib -lXext -lX11 -framework IOKit -framework Carbon
- XCODE:*_*_IA32_ASM_FLAGS == -arch i386 -g
-
- XCODE:*_*_X64_DLINK_PATH == gcc
- XCODE:*_*_X64_DLINK_FLAGS == -o "$(BIN_DIR)/SecMain" -L/usr/X11R6/lib -lXext -lX11 -lIOKit -framework Carbon
- XCODE:*_*_X64_ASM_FLAGS == -g
diff --git a/UnixPkg/Sec/UgaX11.c b/UnixPkg/Sec/UgaX11.c deleted file mode 100644 index 74775311e8..0000000000 --- a/UnixPkg/Sec/UgaX11.c +++ /dev/null @@ -1,865 +0,0 @@ -/*++ - -Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR> -Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR> -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 <Common/UnixInclude.h> - -#include <sys/ipc.h> -#include <sys/shm.h> - -#include <PiPei.h> -#include <Protocol/SimplePointer.h> -#include <Protocol/SimpleTextIn.h> -#include <Protocol/SimpleTextInEx.h> -#include <Protocol/UgaDraw.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/Xos.h> -#include <X11/extensions/XShm.h> -#include <X11/keysym.h> -#include <X11/cursorfont.h> - -#include <Protocol/UnixThunk.h> -#include <Protocol/UnixUgaIo.h> - -#include <Ppi/StatusCode.h> - -#include <Library/PeCoffLib.h> -#include <Library/BaseLib.h> -#include <Library/BaseMemoryLib.h> -#include <Library/PrintLib.h> -#include <Library/PcdLib.h> -#include <Library/DebugLib.h> - -#include "Gasket.h" -#include "SecMain.h" - - -extern void msSleep (unsigned long Milliseconds); - -/* XQueryPointer */ - -struct uga_drv_shift_mask { - unsigned char shift; - unsigned char size; - unsigned char csize; -}; - -#define NBR_KEYS 32 -typedef struct { - EFI_UNIX_UGA_IO_PROTOCOL UgaIo; - - Display *display; - int screen; /* values for window_size in main */ - Window win; - GC gc; - Visual *visual; - - int depth; - unsigned int width; - unsigned int height; - unsigned int line_bytes; - unsigned int pixel_shift; - unsigned char *image_data; - - struct uga_drv_shift_mask r, g, b; - - int use_shm; - XShmSegmentInfo xshm_info; - XImage *image; - - unsigned int key_rd; - unsigned int key_wr; - unsigned int key_count; - EFI_KEY_DATA keys[NBR_KEYS]; - - EFI_KEY_STATE KeyState; - - UGA_REGISTER_KEY_NOTIFY_CALLBACK RegisterdKeyCallback; - VOID *RegisterdKeyCallbackContext; - - int previous_x; - int previous_y; - EFI_SIMPLE_POINTER_STATE pointer_state; - int pointer_state_changed; -} UGA_IO_PRIVATE; - -void -HandleEvents(UGA_IO_PRIVATE *drv); - -void -fill_shift_mask (struct uga_drv_shift_mask *sm, unsigned long mask) -{ - sm->shift = 0; - sm->size = 0; - while ((mask & 1) == 0) - { - mask >>= 1; - sm->shift++; - } - while (mask & 1) - { - sm->size++; - mask >>= 1; - } - sm->csize = 8 - sm->size; -} - -int -TryCreateShmImage(UGA_IO_PRIVATE *drv) -{ - drv->image = XShmCreateImage (drv->display, drv->visual, - drv->depth, ZPixmap, NULL, &drv->xshm_info, - drv->width, drv->height); - if (drv->image == NULL) - return 0; - - switch (drv->image->bitmap_unit) { - case 32: - drv->pixel_shift = 2; - break; - case 16: - drv->pixel_shift = 1; - break; - case 8: - drv->pixel_shift = 0; - break; - } - - drv->xshm_info.shmid = shmget - (IPC_PRIVATE, drv->image->bytes_per_line * drv->image->height, - IPC_CREAT | 0777); - if (drv->xshm_info.shmid < 0) { - XDestroyImage(drv->image); - return 0; - } - - drv->image_data = shmat (drv->xshm_info.shmid, NULL, 0); - if(!drv->image_data) { - shmctl (drv->xshm_info.shmid, IPC_RMID, NULL); - 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; - - if (!XShmAttach (drv->display, &drv->xshm_info)) { - shmdt (drv->image_data); - XDestroyImage(drv->image); - return 0; - } - return 1; -} - -EFI_STATUS -UgaClose (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo) -{ - UGA_IO_PRIVATE *drv = (UGA_IO_PRIVATE *)UgaIo; - - if (drv == NULL) - return EFI_SUCCESS; - if (drv->image != NULL) - { - XDestroyImage(drv->image); - - if (drv->use_shm) - shmdt (drv->image_data); - - drv->image_data = NULL; - drv->image = NULL; - } - 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; -} - -EFI_STATUS -UgaSize(EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, UINT32 Width, UINT32 Height) -{ - UGA_IO_PRIVATE *drv = (UGA_IO_PRIVATE *)UgaIo; - XSizeHints size_hints; - - /* Destroy current buffer if created. */ - if (drv->image != NULL) - { - /* Before destroy buffer, need to make sure the buffer available for access. */ - XDestroyImage(drv->image); - - if (drv->use_shm) - shmdt (drv->image_data); - - drv->image_data = NULL; - drv->image = NULL; - } - - drv->width = Width; - drv->height = Height; - XResizeWindow (drv->display, drv->win, Width, Height); - - /* Allocate image. */ - if (XShmQueryExtension(drv->display) && TryCreateShmImage(drv)) { - drv->use_shm = 1; - } else { - drv->use_shm = 0; - if (drv->depth > 16) - drv->pixel_shift = 2; - else if (drv->depth > 8) - drv->pixel_shift = 1; - else - drv->pixel_shift = 0; - - drv->image_data = malloc((drv->width * drv->height) << drv->pixel_shift); - drv->image = XCreateImage (drv->display, drv->visual, drv->depth, - ZPixmap, 0, (char *)drv->image_data, - drv->width, drv->height, - 8 << drv->pixel_shift, 0); - } - drv->line_bytes = drv->image->bytes_per_line; - fill_shift_mask (&drv->r, drv->image->red_mask); - fill_shift_mask (&drv->g, drv->image->green_mask); - fill_shift_mask (&drv->b, drv->image->blue_mask); - - /* Set WM hints. */ - size_hints.flags = PSize | PMinSize | PMaxSize; - size_hints.min_width = size_hints.max_width = size_hints.base_width = Width; - size_hints.min_height = size_hints.max_height = size_hints.base_height = Height; - XSetWMNormalHints (drv->display, drv->win, &size_hints); - - XMapWindow (drv->display, drv->win); - HandleEvents(drv); - return EFI_SUCCESS; -} - -void -handleKeyEvent(UGA_IO_PRIVATE *drv, XEvent *ev) -{ - KeySym keysym; - char str[4]; - EFI_KEY_DATA KeyData; - int res; - - if (drv->key_count == NBR_KEYS) - return; - - res = XLookupString(&ev->xkey, str, sizeof(str), &keysym, NULL); - KeyData.Key.ScanCode = 0; - KeyData.Key.UnicodeChar = 0; - KeyData.KeyState.KeyShiftState = 0; - - // - // KeyRelease is not supported (on Mac) so we can not easily implement Ex functions. - // If a modifier key is hit by its self we get a keysym. If a modfifier and key is hit - // we get the state bit set and keysym is the modified key. - // - // We use lack of state bits being set to clear ToggleState and KeyShiftState. We can - // also use the stat bits to set ToggleState and KeyShiftState. - // Skipping EFI_SCROLL_LOCK_ACTIVE & EFI_NUM_LOCK_ACTIVE since they are not on Macs - // - if ((ev->xkey.state & LockMask) == 0) { - drv->KeyState.KeyToggleState &= ~EFI_CAPS_LOCK_ACTIVE; - } else { - drv->KeyState.KeyToggleState |= EFI_CAPS_LOCK_ACTIVE; - } - - if ((ev->xkey.state & ControlMask) == 0) { - drv->KeyState.KeyShiftState &= ~(EFI_RIGHT_CONTROL_PRESSED | EFI_LEFT_CONTROL_PRESSED); - } else if ((drv->KeyState.KeyShiftState & EFI_RIGHT_CONTROL_PRESSED) == 0) { - drv->KeyState.KeyShiftState |= EFI_LEFT_CONTROL_PRESSED; - } - - if ((ev->xkey.state & ShiftMask) == 0) { - drv->KeyState.KeyShiftState &= ~(EFI_RIGHT_SHIFT_PRESSED | EFI_LEFT_SHIFT_PRESSED); - } else if ((drv->KeyState.KeyShiftState & EFI_RIGHT_SHIFT_PRESSED) == 0) { - drv->KeyState.KeyShiftState |= EFI_LEFT_SHIFT_PRESSED; - } - - if ((ev->xkey.state & Mod2Mask) == 0) { - drv->KeyState.KeyShiftState &= ~(EFI_RIGHT_LOGO_PRESSED | EFI_LEFT_LOGO_PRESSED); - } else if ((drv->KeyState.KeyShiftState & EFI_RIGHT_LOGO_PRESSED) == 0) { - drv->KeyState.KeyShiftState |= EFI_LEFT_LOGO_PRESSED; - } - - if ((ev->xkey.state & 0x2000) == 0) { - drv->KeyState.KeyShiftState &= ~(EFI_LEFT_ALT_PRESSED); - } else { - drv->KeyState.KeyShiftState |= EFI_LEFT_ALT_PRESSED; - } - - - switch (keysym) { - case XK_Control_R: - drv->KeyState.KeyShiftState |= EFI_RIGHT_CONTROL_PRESSED; - break; - case XK_Control_L: - drv->KeyState.KeyShiftState |= EFI_LEFT_CONTROL_PRESSED; - break; - - case XK_Shift_R: - drv->KeyState.KeyShiftState |= EFI_RIGHT_SHIFT_PRESSED; - break; - case XK_Shift_L: - drv->KeyState.KeyShiftState |= EFI_LEFT_SHIFT_PRESSED; - break; - - case XK_Mode_switch: - drv->KeyState.KeyShiftState |= EFI_LEFT_ALT_PRESSED; - break; - - case XK_Meta_R: - drv->KeyState.KeyShiftState |= EFI_RIGHT_LOGO_PRESSED; - break; - case XK_Meta_L: - drv->KeyState.KeyShiftState |= EFI_LEFT_LOGO_PRESSED; - break; - - case XK_Home: KeyData.Key.ScanCode = SCAN_HOME; break; - case XK_End: KeyData.Key.ScanCode = SCAN_END; break; - case XK_Left: KeyData.Key.ScanCode = SCAN_LEFT; break; - case XK_Right: KeyData.Key.ScanCode = SCAN_RIGHT; break; - case XK_Up: KeyData.Key.ScanCode = SCAN_UP; break; - case XK_Down: KeyData.Key.ScanCode = SCAN_DOWN; break; - case XK_Delete: KeyData.Key.ScanCode = SCAN_DELETE; break; - case XK_Insert: KeyData.Key.ScanCode = SCAN_INSERT; break; - case XK_Page_Up: KeyData.Key.ScanCode = SCAN_PAGE_UP; break; - case XK_Page_Down: KeyData.Key.ScanCode = SCAN_PAGE_DOWN; break; - case XK_Escape: KeyData.Key.ScanCode = SCAN_ESC; break; - case XK_Pause: KeyData.Key.ScanCode = SCAN_PAUSE; break; - - case XK_F1: KeyData.Key.ScanCode = SCAN_F1; break; - case XK_F2: KeyData.Key.ScanCode = SCAN_F2; break; - case XK_F3: KeyData.Key.ScanCode = SCAN_F3; break; - case XK_F4: KeyData.Key.ScanCode = SCAN_F4; break; - case XK_F5: KeyData.Key.ScanCode = SCAN_F5; break; - case XK_F6: KeyData.Key.ScanCode = SCAN_F6; break; - case XK_F7: KeyData.Key.ScanCode = SCAN_F7; break; - case XK_F8: KeyData.Key.ScanCode = SCAN_F8; break; - case XK_F9: KeyData.Key.ScanCode = SCAN_F9; break; - - default: - if (res == 1) { - KeyData.Key.UnicodeChar = str[0]; - } else { - return; - } - } - - // The global state is our state - KeyData.KeyState.KeyShiftState = drv->KeyState.KeyShiftState; - KeyData.KeyState.KeyToggleState = drv->KeyState.KeyToggleState; - - CopyMem (&drv->keys[drv->key_wr], &KeyData, sizeof (EFI_KEY_DATA)); - drv->key_wr = (drv->key_wr + 1) % NBR_KEYS; - drv->key_count++; - - -#if defined(__APPLE__) || defined(MDE_CPU_X64) - ReverseGasketUint64Uint64 (drv->RegisterdKeyCallback ,drv->RegisterdKeyCallbackContext, &KeyData); -#else - drv->RegisterdKeyCallback (drv->RegisterdKeyCallbackContext, &KeyData); -#endif - - -} - - -void -handleMouseMoved(UGA_IO_PRIVATE *drv, XEvent *ev) -{ - if ( ev->xmotion.x != drv->previous_x ) - { - drv->pointer_state.RelativeMovementX += ( ev->xmotion.x - drv->previous_x ); - drv->previous_x = ev->xmotion.x; - drv->pointer_state_changed = 1; - } - - if ( ev->xmotion.y != drv->previous_y ) - { - drv->pointer_state.RelativeMovementY += ( ev->xmotion.y - drv->previous_y ); - drv->previous_y = ev->xmotion.y; - drv->pointer_state_changed = 1; - } - - drv->pointer_state.RelativeMovementZ = 0; -} - -void -handleMouseDown(UGA_IO_PRIVATE *drv, XEvent *ev, BOOLEAN Pressed) -{ - if ( ev->xbutton.button == Button1 ) - { - drv->pointer_state_changed = ( drv->pointer_state.LeftButton != Pressed ); - drv->pointer_state.LeftButton = Pressed; - } - if ( ev->xbutton.button == Button2 ) - { - drv->pointer_state_changed = ( drv->pointer_state.RightButton != Pressed ); - drv->pointer_state.RightButton = Pressed; - } -} - -void -Redraw(UGA_IO_PRIVATE *drv, UINTN X, UINTN Y, UINTN Width, UINTN Height) -{ - if (drv->use_shm) - XShmPutImage (drv->display, drv->win, drv->gc, drv->image, - X, Y, X, Y, Width, Height, False); - else - XPutImage (drv->display, drv->win, drv->gc, drv->image, - X, Y, X, Y, Width, Height); - XFlush(drv->display); -} - -void -HandleEvent(UGA_IO_PRIVATE *drv, XEvent *ev) -{ - switch (ev->type) - { - case Expose: - Redraw(drv, ev->xexpose.x, ev->xexpose.y, - ev->xexpose.width, ev->xexpose.height); - break; - case GraphicsExpose: - Redraw(drv, ev->xgraphicsexpose.x, ev->xgraphicsexpose.y, - ev->xgraphicsexpose.width, ev->xgraphicsexpose.height); - break; - case KeyPress: - handleKeyEvent(drv, ev); - break; - case KeyRelease: - break; - case MappingNotify: - XRefreshKeyboardMapping(&ev->xmapping); - break; - case MotionNotify: - handleMouseMoved(drv, ev); - break; - case ButtonPress: - handleMouseDown(drv, ev, TRUE); - break; - case ButtonRelease: - handleMouseDown(drv, ev, FALSE); - break; -#if 0 - case DestroyNotify: - XCloseDisplay (drv->display); - exit (1); - break; -#endif - case NoExpose: - default: - break; - } -} - -void -HandleEvents(UGA_IO_PRIVATE *drv) -{ - while (XPending(drv->display) != 0) - { - XEvent ev; - - XNextEvent (drv->display, &ev); - HandleEvent(drv, &ev); - } -} - -unsigned long -UgaPixelToColor (UGA_IO_PRIVATE *drv, EFI_UGA_PIXEL pixel) -{ - return ((pixel.Red >> drv->r.csize) << drv->r.shift) - | ((pixel.Green >> drv->g.csize) << drv->g.shift) - | ((pixel.Blue >> drv->b.csize) << drv->b.shift); -} - -EFI_UGA_PIXEL -UgaColorToPixel (UGA_IO_PRIVATE *drv, unsigned long val) -{ - EFI_UGA_PIXEL res; - - memset (&res, 0, sizeof (EFI_UGA_PIXEL)); - /* FIXME: should round instead of truncate. */ - res.Red = (val >> drv->r.shift) << drv->r.csize; - res.Green = (val >> drv->g.shift) << drv->g.csize; - res.Blue = (val >> drv->b.shift) << drv->b.csize; - - return res; -} - -STATIC EFI_STATUS -CheckKeyInternal( UGA_IO_PRIVATE *drv, BOOLEAN delay ) -{ - HandleEvents(drv); - if (drv->key_count != 0) - return EFI_SUCCESS; - if ( delay ) - /* EFI is polling. Be CPU-friendly. */ - msSleep (20); - return EFI_NOT_READY; - } - -EFI_STATUS -UgaCheckKey(EFI_UNIX_UGA_IO_PROTOCOL *UgaIo) -{ - UGA_IO_PRIVATE *drv = (UGA_IO_PRIVATE *)UgaIo; - return( CheckKeyInternal( drv, TRUE ) ); -} - -EFI_STATUS -EFIAPI -UgaGetKey ( - IN EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, - IN EFI_KEY_DATA *KeyData - ) -{ - UGA_IO_PRIVATE *drv = (UGA_IO_PRIVATE *)UgaIo; - EFI_STATUS status; - - status = CheckKeyInternal(drv, FALSE); - if (status != EFI_SUCCESS) - return status; - - CopyMem (KeyData, &drv->keys[drv->key_rd], sizeof (EFI_KEY_DATA)); - drv->key_rd = (drv->key_rd + 1) % NBR_KEYS; - drv->key_count--; - return EFI_SUCCESS; -} - - -EFI_STATUS -EFIAPI -UgaKeySetState ( - IN EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, - IN EFI_KEY_TOGGLE_STATE *KeyToggleState - ) -{ - UGA_IO_PRIVATE *drv = (UGA_IO_PRIVATE *)UgaIo; -// XKeyEvent event; - - if (*KeyToggleState & EFI_CAPS_LOCK_ACTIVE) { - if ((drv->KeyState.KeyToggleState & EFI_CAPS_LOCK_ACTIVE) == 0) { - // - // We could create an XKeyEvent and send a XK_Caps_Lock to - // the UGA/GOP Window - // - } - } - - drv->KeyState.KeyToggleState = *KeyToggleState; - return EFI_SUCCESS; -} - - -EFI_STATUS -EFIAPI -UgaRegisterKeyNotify ( - IN EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, - IN UGA_REGISTER_KEY_NOTIFY_CALLBACK CallBack, - IN VOID *Context - ) -{ - UGA_IO_PRIVATE *drv = (UGA_IO_PRIVATE *)UgaIo; - - drv->RegisterdKeyCallback = CallBack; - drv->RegisterdKeyCallbackContext = Context; - - return EFI_SUCCESS; -} - - -EFI_STATUS -UgaBlt( - IN EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, - IN EFI_UGA_PIXEL *BltBuffer OPTIONAL, - IN EFI_UGA_BLT_OPERATION BltOperation, - IN UGA_BLT_ARGS *Args - ) -{ - UGA_IO_PRIVATE *Private = (UGA_IO_PRIVATE *)UgaIo; - UINTN DstY; - UINTN SrcY; - UINTN DstX; - UINTN SrcX; - UINTN Index; - EFI_UGA_PIXEL *Blt; - UINT8 *Dst; - UINT8 *Src; - UINTN Nbr; - unsigned long Color; - - // - // Check bounds - // - if (BltOperation == EfiUgaVideoToBltBuffer - || BltOperation == EfiUgaVideoToVideo) { - // - // Source is Video. - // - if (Args->SourceY + Args->Height > Private->height) { - return EFI_INVALID_PARAMETER; - } - - if (Args->SourceX + Args->Width > Private->width) { - return EFI_INVALID_PARAMETER; - } - } - - if (BltOperation == EfiUgaBltBufferToVideo - || BltOperation == EfiUgaVideoToVideo - || BltOperation == EfiUgaVideoFill) { - // - // Destination is Video - // - if (Args->DestinationY + Args->Height > Private->height) { - return EFI_INVALID_PARAMETER; - } - - if (Args->DestinationX + Args->Width > Private->width) { - return EFI_INVALID_PARAMETER; - } - } - - switch (BltOperation) { - case EfiUgaVideoToBltBuffer: - Blt = (EFI_UGA_PIXEL *)((UINT8 *)BltBuffer + (Args->DestinationY * Args->Delta) + Args->DestinationX * sizeof (EFI_UGA_PIXEL)); - Args->Delta -= Args->Width * sizeof (EFI_UGA_PIXEL); - for (SrcY = Args->SourceY; SrcY < (Args->Height + Args->SourceY); SrcY++) { - for (SrcX = Args->SourceX; SrcX < (Args->Width + Args->SourceX); SrcX++) { - *Blt++ = UgaColorToPixel(Private, - XGetPixel(Private->image, SrcX, SrcY)); - } - Blt = (EFI_UGA_PIXEL *) ((UINT8 *) Blt + Args->Delta); - } - break; - case EfiUgaBltBufferToVideo: - Blt = (EFI_UGA_PIXEL *)((UINT8 *)BltBuffer + (Args->SourceY * Args->Delta) + Args->SourceX * sizeof (EFI_UGA_PIXEL)); - Args->Delta -= Args->Width * sizeof (EFI_UGA_PIXEL); - for (DstY = Args->DestinationY; DstY < (Args->Height + Args->DestinationY); DstY++) { - for (DstX = Args->DestinationX; DstX < (Args->Width + Args->DestinationX); DstX++) { - XPutPixel(Private->image, DstX, DstY, UgaPixelToColor(Private, *Blt)); - Blt++; - } - Blt = (EFI_UGA_PIXEL *) ((UINT8 *) Blt + Args->Delta); - } - break; - case EfiUgaVideoToVideo: - Dst = Private->image_data + (Args->DestinationX << Private->pixel_shift) - + Args->DestinationY * Private->line_bytes; - Src = Private->image_data + (Args->SourceX << Private->pixel_shift) - + Args->SourceY * Private->line_bytes; - Nbr = Args->Width << Private->pixel_shift; - if (Args->DestinationY < Args->SourceY) { - for (Index = 0; Index < Args->Height; Index++) { - memcpy (Dst, Src, Nbr); - Dst += Private->line_bytes; - Src += Private->line_bytes; - } - } - else { - Dst += (Args->Height - 1) * Private->line_bytes; - Src += (Args->Height - 1) * Private->line_bytes; - for (Index = 0; Index < Args->Height; Index++) { - // - // Source and Destination Y may be equal, therefore Dst and Src may - // overlap. - // - memmove (Dst, Src, Nbr); - Dst -= Private->line_bytes; - Src -= Private->line_bytes; - } - } - break; - case EfiUgaVideoFill: - Color = UgaPixelToColor(Private, *BltBuffer); - for (DstY = Args->DestinationY; DstY < (Args->Height + Args->DestinationY); DstY++) { - for (DstX = Args->DestinationX; DstX < (Args->Width + Args->DestinationX); DstX++) { - XPutPixel(Private->image, DstX, DstY, Color); - } - } - break; - default: - return EFI_INVALID_PARAMETER; - } - - // - // Refresh screen. - // - switch (BltOperation) { - case EfiUgaVideoToVideo: - XCopyArea(Private->display, Private->win, Private->win, Private->gc, - Args->SourceX, Args->SourceY, Args->Width, Args->Height, Args->DestinationX, Args->DestinationY); - while (1) { - XEvent ev; - - XNextEvent (Private->display, &ev); - HandleEvent(Private, &ev); - if (ev.type == NoExpose || ev.type == GraphicsExpose) - break; - } - break; - case EfiUgaVideoFill: - Color = UgaPixelToColor(Private, *BltBuffer); - XSetForeground(Private->display, Private->gc, Color); - XFillRectangle(Private->display, Private->win, Private->gc, - Args->DestinationX, Args->DestinationY, Args->Width, Args->Height); - XFlush(Private->display); - break; - case EfiUgaBltBufferToVideo: - Redraw(Private, Args->DestinationX, Args->DestinationY, Args->Width, Args->Height); - break; - default: - break; - } - return EFI_SUCCESS; -} - -STATIC EFI_STATUS -CheckPointerInternal( UGA_IO_PRIVATE *drv, BOOLEAN delay ) -{ - HandleEvents(drv); - if (drv->pointer_state_changed != 0) - return EFI_SUCCESS; - if ( delay ) - /* EFI is polling. Be CPU-friendly. */ - msSleep (20); - return EFI_NOT_READY; -} - -EFI_STATUS -UgaCheckPointer(EFI_UNIX_UGA_IO_PROTOCOL *UgaIo) -{ - UGA_IO_PRIVATE *drv = (UGA_IO_PRIVATE *)UgaIo; - return( CheckPointerInternal( drv, TRUE ) ); -} - -EFI_STATUS -UgaGetPointerState (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, EFI_SIMPLE_POINTER_STATE *state) -{ - UGA_IO_PRIVATE *drv = (UGA_IO_PRIVATE *)UgaIo; - EFI_STATUS status; - - status = CheckPointerInternal( drv, FALSE ); - if (status != EFI_SUCCESS) - return status; - - memcpy( state, &drv->pointer_state, sizeof( EFI_SIMPLE_POINTER_STATE ) ); - - drv->pointer_state.RelativeMovementX = 0; - drv->pointer_state.RelativeMovementY = 0; - drv->pointer_state.RelativeMovementZ = 0; - drv->pointer_state_changed = 0; - return EFI_SUCCESS; -} - -EFI_STATUS -UgaCreate (EFI_UNIX_UGA_IO_PROTOCOL **Uga, CONST CHAR16 *Title) -{ - UGA_IO_PRIVATE *drv; - unsigned int border_width = 0; - char *display_name = NULL; - int title_len; - - drv = (UGA_IO_PRIVATE *)calloc (1, sizeof (UGA_IO_PRIVATE)); - if (drv == NULL) - return EFI_OUT_OF_RESOURCES; - -#if defined(__APPLE__) || defined(MDE_CPU_X64) -// -// -// - drv->UgaIo.UgaClose = GasketUgaClose; - drv->UgaIo.UgaSize = GasketUgaSize; - drv->UgaIo.UgaCheckKey = GasketUgaCheckKey; - drv->UgaIo.UgaGetKey = GasketUgaGetKey; - drv->UgaIo.UgaKeySetState = GasketUgaKeySetState; - drv->UgaIo.UgaRegisterKeyNotify = GasketUgaRegisterKeyNotify; - drv->UgaIo.UgaBlt = GasketUgaBlt; - drv->UgaIo.UgaCheckPointer = GasketUgaCheckPointer; - drv->UgaIo.UgaGetPointerState = GasketUgaGetPointerState; -#else - drv->UgaIo.UgaClose = UgaClose; - drv->UgaIo.UgaSize = UgaSize; - drv->UgaIo.UgaCheckKey = UgaCheckKey; - drv->UgaIo.UgaGetKey = UgaGetKey; - drv->UgaIo.UgaKeySetState = UgaKeySetState; - drv->UgaIo.UgaRegisterKeyNotify = UgaRegisterKeyNotify; - drv->UgaIo.UgaBlt = UgaBlt; - drv->UgaIo.UgaCheckPointer = UgaCheckPointer; - drv->UgaIo.UgaGetPointerState = UgaGetPointerState; -#endif - - - - drv->key_count = 0; - drv->key_rd = 0; - drv->key_wr = 0; - drv->KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID; - drv->KeyState.KeyToggleState = EFI_TOGGLE_STATE_VALID; - drv->RegisterdKeyCallback = NULL; - drv->RegisterdKeyCallbackContext = NULL; - - - drv->display = XOpenDisplay (display_name); - if (drv->display == NULL) - { - fprintf (stderr, "uga: cannot connect to X server %s\n", - XDisplayName (display_name)); - free (drv); - return EFI_DEVICE_ERROR; - } - drv->screen = DefaultScreen (drv->display); - drv->visual = DefaultVisual (drv->display, drv->screen); - drv->win = XCreateSimpleWindow - (drv->display, RootWindow (drv->display, drv->screen), - 0, 0, 4, 4, border_width, - WhitePixel (drv->display, drv->screen), - BlackPixel (drv->display, drv->screen)); - - drv->depth = DefaultDepth (drv->display, drv->screen); - XDefineCursor (drv->display, drv->win, XCreateFontCursor (drv->display, XC_pirate)); - - /* Compute title len and convert to Ascii. */ - for (title_len = 0; Title[title_len] != 0; title_len++) - ; - { - char title[title_len + 1]; - int i; - for (i = 0; i < title_len; i++) - title[i] = Title[i]; - title[i] = 0; - - XStoreName (drv->display, drv->win, title); - } - - XSelectInput (drv->display, drv->win, - ExposureMask | KeyPressMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask ); - drv->gc = DefaultGC (drv->display, drv->screen); - - *Uga = (EFI_UNIX_UGA_IO_PROTOCOL *)drv; - return EFI_SUCCESS; -} diff --git a/UnixPkg/Sec/UnixThunk.c b/UnixPkg/Sec/UnixThunk.c deleted file mode 100644 index eb9e536989..0000000000 --- a/UnixPkg/Sec/UnixThunk.c +++ /dev/null @@ -1,343 +0,0 @@ -/*++ - -Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR> -Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR> -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: - - UnixThunk.c - -Abstract: - - Since the SEC is the only program in our emulation we - must use a Tiano mechanism to export APIs to other modules. - This is the role of the EFI_UNIX_THUNK_PROTOCOL. - - The mUnixThunkTable exists so that a change to EFI_UNIX_THUNK_PROTOCOL - will cause an error in initializing the array if all the member functions - are not added. It looks like adding a element to end and not initializing - it may cause the table to be initaliized with the members at the end being - set to zero. This is bad as jumping to zero will crash. - - - gUnix is a a public exported global that contains the initialized - data. - ---*/ - -#include "SecMain.h" -#include "Uefi.h" -#include "Library/UnixLib.h" - -#if defined(__APPLE__) || defined(MDE_CPU_X64) -#include "Gasket.h" -#endif - -int settimer_initialized; -struct timeval settimer_timeval; -void (*settimer_callback)(UINT64 delta); - -BOOLEAN gEmulatorInterruptEnabled = FALSE; - - -void -settimer_handler (int sig) -{ - struct timeval timeval; - UINT64 delta; - - gettimeofday (&timeval, NULL); - delta = ((UINT64)timeval.tv_sec * 1000) + (timeval.tv_usec / 1000) - - ((UINT64)settimer_timeval.tv_sec * 1000) - - (settimer_timeval.tv_usec / 1000); - settimer_timeval = timeval; - - if (settimer_callback) { -#if defined(__APPLE__) || defined(MDE_CPU_X64) - ReverseGasketUint64 (settimer_callback, delta); -#else - (*settimer_callback)(delta); -#endif - } -} - -VOID -SetTimer (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs)) -{ - struct itimerval timerval; - UINT32 remainder; - - if (!settimer_initialized) { - struct sigaction act; - - settimer_initialized = 1; - act.sa_handler = settimer_handler; - act.sa_flags = 0; - sigemptyset (&act.sa_mask); - gEmulatorInterruptEnabled = TRUE; - if (sigaction (SIGALRM, &act, NULL) != 0) { - printf ("SetTimer: sigaction error %s\n", strerror (errno)); - } - if (gettimeofday (&settimer_timeval, NULL) != 0) { - printf ("SetTimer: gettimeofday error %s\n", strerror (errno)); - } - } - timerval.it_value.tv_sec = DivU64x32(PeriodMs, 1000); - DivU64x32Remainder(PeriodMs, 1000, &remainder); - timerval.it_value.tv_usec = remainder * 1000; - timerval.it_value.tv_sec = DivU64x32(PeriodMs, 1000); - timerval.it_interval = timerval.it_value; - - if (setitimer (ITIMER_REAL, &timerval, NULL) != 0) { - printf ("SetTimer: setitimer error %s\n", strerror (errno)); - } - settimer_callback = CallBack; -} - - -void -UnixEnableInterrupt (void) -{ - sigset_t sigset; - - gEmulatorInterruptEnabled = TRUE; - // Since SetTimer() uses SIGALRM we emulate turning on and off interrupts - // by enabling/disabling SIGALRM. - sigemptyset (&sigset); - sigaddset (&sigset, SIGALRM); - sigprocmask (SIG_UNBLOCK, &sigset, NULL); -} - - -void -UnixDisableInterrupt (void) -{ - sigset_t sigset; - - // Since SetTimer() uses SIGALRM we emulate turning on and off interrupts - // by enabling/disabling SIGALRM. - sigemptyset (&sigset); - sigaddset (&sigset, SIGALRM); - sigprocmask (SIG_BLOCK, &sigset, NULL); - gEmulatorInterruptEnabled = FALSE; -} - - -BOOLEAN -UnixInterruptEanbled (void) -{ - return gEmulatorInterruptEnabled; -} - - - -void -msSleep (unsigned long Milliseconds) -{ - struct timespec rq, rm; - struct timeval start, end; - unsigned long MicroSec; - - rq.tv_sec = Milliseconds / 1000; - rq.tv_nsec = (Milliseconds % 1000) * 1000000; - - // - // nanosleep gets interrupted by our timer tic. - // we need to track wall clock time or we will stall for way too long - // - gettimeofday (&start, NULL); - end.tv_sec = start.tv_sec + rq.tv_sec; - MicroSec = (start.tv_usec + rq.tv_nsec/1000); - end.tv_usec = MicroSec % 1000000; - if (MicroSec > 1000000) { - end.tv_sec++; - } - - while (nanosleep (&rq, &rm) == -1) { - if (errno != EINTR) { - break; - } - gettimeofday (&start, NULL); - if (start.tv_sec > end.tv_sec) { - break; - } if ((start.tv_sec == end.tv_sec) && (start.tv_usec > end.tv_usec)) { - break; - } - rq = rm; - } -} - -void -GetLocalTime (EFI_TIME *Time) -{ - struct tm *tm; - time_t t; - - t = time (NULL); - tm = localtime (&t); - - Time->Year = 1900 + tm->tm_year; - Time->Month = tm->tm_mon + 1; - Time->Day = tm->tm_mday; - Time->Hour = tm->tm_hour; - Time->Minute = tm->tm_min; - Time->Second = tm->tm_sec; - Time->Nanosecond = 0; - Time->TimeZone = GetTimeZone (); - Time->Daylight = (daylight ? EFI_TIME_ADJUST_DAYLIGHT : 0) - | (tm->tm_isdst > 0 ? EFI_TIME_IN_DAYLIGHT : 0); -} - -void -TzSet (void) -{ - STATIC int done = 0; - if (!done) { - tzset (); - done = 1; - } -} - -long -GetTimeZone(void) -{ - TzSet (); - return timezone; -} - -int -GetDayLight(void) -{ - TzSet (); - return daylight; -} - -int -GetErrno(void) -{ - return errno; -} - - -extern EFI_STATUS -UgaCreate(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo, CONST CHAR16 *Title); - -EFI_UNIX_THUNK_PROTOCOL mUnixThunkTable = { - EFI_UNIX_THUNK_PROTOCOL_SIGNATURE, -#if defined(__APPLE__) || defined(MDE_CPU_X64) -// -// 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, - Gasketpoll, - Gasketread, - Gasketwrite, - Gasketgetenv, - Gasketopen, - Gasketlseek, - Gasketftruncate, - Gasketclose, - Gasketmkdir, - Gasketrmdir, - Gasketunlink, - GasketGetErrno, - Gasketopendir, - Gasketrewinddir, - Gasketreaddir, - Gasketclosedir, - Gasketstat, - Gasketstatfs, - Gasketrename, - Gasketmktime, - Gasketfsync, - Gasketchmod, - Gasketutime, - Gaskettcflush, - GasketUgaCreate, - Gasketperror, - Gasketioctl, - Gasketfcntl, - Gasketcfsetispeed, - Gasketcfsetospeed, - Gaskettcgetattr, - Gaskettcsetattr, - GasketUnixPeCoffGetEntryPoint, - GasketUnixPeCoffRelocateImageExtraAction, - GasketUnixPeCoffUnloadImageExtraAction, - - GasketUnixEnableInterrupt, - GasketUnixDisableInterrupt, - - Gasketgetifaddrs, - Gasketfreeifaddrs, - Gasketsocket, - -#else - msSleep, /* Sleep */ - exit, /* Exit */ - SetTimer, - GetLocalTime, - gmtime, - GetTimeZone, - GetDayLight, - (UnixPoll)poll, - (UnixRead)read, - (UnixWrite)write, - getenv, - (UnixOpen)open, - (UnixSeek)lseek, - (UnixFtruncate)ftruncate, - close, - mkdir, - rmdir, - unlink, - GetErrno, - opendir, - rewinddir, - readdir, - closedir, - (UnixStat)stat, - statfs, - rename, - mktime, - fsync, - chmod, - utime, - tcflush, - UgaCreate, - perror, - ioctl, - fcntl, - cfsetispeed, - cfsetospeed, - tcgetattr, - tcsetattr, - SecPeCoffGetEntryPoint, - SecPeCoffRelocateImageExtraAction, - SecPeCoffLoaderUnloadImageExtraAction, - UnixEnableInterrupt, - UnixDisableInterrupt, - getifaddrs, - freeifaddrs, - socket -#endif -}; - - -EFI_UNIX_THUNK_PROTOCOL *gUnix = &mUnixThunkTable; diff --git a/UnixPkg/Sec/X64/MangleGasket.S b/UnixPkg/Sec/X64/MangleGasket.S deleted file mode 100644 index ea1e6aa2eb..0000000000 --- a/UnixPkg/Sec/X64/MangleGasket.S +++ /dev/null @@ -1,1294 +0,0 @@ -#------------------------------------------------------------------------------ -# -# This template was generated from GasketEfiTemplate.c Unix x86_64 ABI -# -# The EFI_UNIX_THUNK_PROTOCOL member functions call these these generic assembly -# routines. -# -# Some OS X POSIX calls get name mangled in C code and we need to fill in a C global -# to get the correct binding (does not work from assembly). So we have 4 functions -# that do an indirect call, while the others call POSIX APIs directly -# -# movq _gUnixRmDir@GOTPCREL(%rip), %rax -# -# -# UNIX Arg passing: RCX, RDX, R8, R9 -# EFI Arg passing: RDI, RSI, RDX, RCX, R8, R9 -# Callee allocates 32 bytes on stack to spill registers -# RSI, RDI calle-save on EFI, scatch on UNIX callign -# -# -# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR> -# 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. -# -#------------------------------------------------------------------------------ - -// -// Gaskets are EFI ABI to UNIX ABI calls -// EFI ABI code will sub 40 (0x28) from %rsp before calling a function -// This is the 32 (0x20) byte to spill registers and 8 bytes to align stack on 16 byte boundry. -// - .text - -// 32 byte shadow to spill rcx-r9, 8 bytes to align stack on 16 byte boundry -// Any call with 0 - 4 arguments allocates 40 bytes on the stack. -// For more than 4 args you always have to increase in quanta of 16 so 5 or 6 args is 56, -// 7 or 8 args is 72, and 9 or 10 args is 88 -#define EFI_STACK_SHADOW_SPACE 40 -#define EFI_STACK_SHADOW_SPACE_5_6 56 -#define EFI_STACK_SHADOW_SPACE_7_8 72 -#define EFI_STACK_SHADOW_SPACE_9_10 88 - - - - .text - - -ASM_GLOBAL ASM_PFX(Gasketrmdir) -ASM_PFX(Gasketrmdir): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - movq ASM_PFX(gUnixRmDir)@GOTPCREL(%rip), %rax // Get function name mangled by C - movq (%rax), %rax - call *%rax - - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketopendir) -ASM_PFX(Gasketopendir): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - movq ASM_PFX(gUnixOpenDir)@GOTPCREL(%rip), %rax // Get function name mangled by C - movq (%rax), %rax - call *%rax - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - -ASM_GLOBAL ASM_PFX(Gasketstat) -ASM_PFX(Gasketstat): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - movq ASM_PFX(gUnixStat)@GOTPCREL(%rip), %rax // Get function name mangled by C - movq (%rax), %rax - call *%rax - - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketstatfs) -ASM_PFX(Gasketstatfs): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - movq ASM_PFX(gUnixStatFs)@GOTPCREL(%rip), %rax // Get function name mangled by C - movq (%rax), %rax - call *%rax - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - -ASM_GLOBAL ASM_PFX(Gasketrewinddir) -ASM_PFX(Gasketrewinddir): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - movq ASM_PFX(gUnixRewinddir)@GOTPCREL(%rip), %rax // Get function name mangled by C - movq (%rax), %rax - call *%rax - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - -ASM_GLOBAL ASM_PFX(Gasketreaddir) -ASM_PFX(Gasketreaddir): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - movq ASM_PFX(gUnixReaddir)@GOTPCREL(%rip), %rax // Get function name mangled by C - movq (%rax), %rax - call *%rax - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketmsSleep) -ASM_PFX(GasketmsSleep): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - call ASM_PFX(msSleep) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketexit) -ASM_PFX(Gasketexit): - movq %rcx, %rdi // Swizzle args - call ASM_PFX(exit) // Less to do as we will never return to EFI ABI world -LDEAD_LOOP: - jmp LDEAD_LOOP // _exit should never return - - - -ASM_GLOBAL ASM_PFX(GasketSetTimer) -ASM_PFX(GasketSetTimer): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(SetTimer) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketGetLocalTime) -ASM_PFX(GasketGetLocalTime): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - call ASM_PFX(GetLocalTime) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - -ASM_GLOBAL ASM_PFX(Gasketgmtime) -ASM_PFX(Gasketgmtime): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - call ASM_PFX(localtime) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - -ASM_GLOBAL ASM_PFX(GasketGetTimeZone) -ASM_PFX(GasketGetTimeZone): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - call ASM_PFX(GetTimeZone) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketGetDayLight) -ASM_PFX(GasketGetDayLight): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - call ASM_PFX(GetDayLight) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketpoll) -ASM_PFX(Gasketpoll): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - - call ASM_PFX(poll) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - -ASM_GLOBAL ASM_PFX(Gasketread) -ASM_PFX(Gasketread): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - - call ASM_PFX(read) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketwrite) -ASM_PFX(Gasketwrite): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - - call ASM_PFX(write) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketgetenv) -ASM_PFX(Gasketgetenv): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - call ASM_PFX(getenv) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketopen) -ASM_PFX(Gasketopen): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - - call ASM_PFX(open) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketlseek) -ASM_PFX(Gasketlseek): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - - call ASM_PFX(lseek) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketftruncate) -ASM_PFX(Gasketftruncate): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - - call ASM_PFX(ftruncate) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketclose) -ASM_PFX(Gasketclose): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - call ASM_PFX(close) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - -ASM_GLOBAL ASM_PFX(Gasketmkdir) -ASM_PFX(Gasketmkdir): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(mkdir) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketunlink) -ASM_PFX(Gasketunlink): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - call ASM_PFX(unlink) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketGetErrno) -ASM_PFX(GasketGetErrno): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - call ASM_PFX(GetErrno) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - -ASM_GLOBAL ASM_PFX(Gasketclosedir) -ASM_PFX(Gasketclosedir): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - call ASM_PFX(closedir) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketrename) -ASM_PFX(Gasketrename): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(rename) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketmktime) -ASM_PFX(Gasketmktime): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(mktime) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketfsync) -ASM_PFX(Gasketfsync): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(fsync) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketchmod) -ASM_PFX(Gasketchmod): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(chmod) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketutime) -ASM_PFX(Gasketutime): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(utime) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gaskettcflush) -ASM_PFX(Gaskettcflush): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(tcflush) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketUgaCreate) -ASM_PFX(GasketUgaCreate): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(UgaCreate) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketperror) -ASM_PFX(Gasketperror): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(perror) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketioctl) -ASM_PFX(Gasketioctl): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - - call ASM_PFX(UnixIoCtl1) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketfcntl) -ASM_PFX(Gasketfcntl): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - - call ASM_PFX(UnixFcntl1) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - -ASM_GLOBAL ASM_PFX(Gasketcfsetispeed) -ASM_PFX(Gasketcfsetispeed): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(cfsetispeed) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - -ASM_GLOBAL ASM_PFX(Gasketcfsetospeed) -ASM_PFX(Gasketcfsetospeed): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(cfsetospeed) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gaskettcgetattr) -ASM_PFX(Gaskettcgetattr): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - - call ASM_PFX(tcgetattr) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gaskettcsetattr) -ASM_PFX(Gaskettcsetattr): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - - call ASM_PFX(tcsetattr) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketUnixPeCoffGetEntryPoint) -ASM_PFX(GasketUnixPeCoffGetEntryPoint): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(SecPeCoffGetEntryPoint) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - -ASM_GLOBAL ASM_PFX(GasketUnixPeCoffRelocateImageExtraAction) -ASM_PFX(GasketUnixPeCoffRelocateImageExtraAction): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - call ASM_PFX(SecPeCoffRelocateImageExtraAction) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketUnixPeCoffUnloadImageExtraAction) -ASM_PFX(GasketUnixPeCoffUnloadImageExtraAction): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - call ASM_PFX(SecPeCoffLoaderUnloadImageExtraAction) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - - - -ASM_GLOBAL ASM_PFX(Gasketsocket) -ASM_PFX(Gasketsocket): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - - call ASM_PFX(socket) - - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - -ASM_GLOBAL ASM_PFX(Gasketgetifaddrs) -ASM_PFX(Gasketgetifaddrs): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - call ASM_PFX(getifaddrs) - - - popq %rbp - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(Gasketfreeifaddrs) -ASM_PFX(Gasketfreeifaddrs): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - call ASM_PFX(freeifaddrs) - - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketUgaClose) -ASM_PFX(GasketUgaClose): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - call ASM_PFX(UgaClose) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - - -ASM_GLOBAL ASM_PFX(GasketUgaSize) -ASM_PFX(GasketUgaSize): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - - call ASM_PFX(UgaSize) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketUgaCheckKey) -ASM_PFX(GasketUgaCheckKey): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - call ASM_PFX(UgaCheckKey) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketUgaGetKey) -ASM_PFX(GasketUgaGetKey): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(UgaGetKey) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - -ASM_GLOBAL ASM_PFX(GasketUgaKeySetState) -ASM_PFX(GasketUgaKeySetState): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(UgaKeySetState) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketUgaRegisterKeyNotify) -ASM_PFX(GasketUgaRegisterKeyNotify): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - - call ASM_PFX(UgaRegisterKeyNotify) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - - - -ASM_GLOBAL ASM_PFX(GasketUgaBlt) -ASM_PFX(GasketUgaBlt): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - movq %r9, %rcx - - call ASM_PFX(UgaBlt) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketUgaCheckPointer) -ASM_PFX(GasketUgaCheckPointer): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - - call ASM_PFX(UgaCheckPointer) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketUgaGetPointerState) -ASM_PFX(GasketUgaGetPointerState): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - - call ASM_PFX(UgaGetPointerState) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketUnixEnableInterrupt) -ASM_PFX(GasketUnixEnableInterrupt): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - call ASM_PFX(UnixEnableInterrupt) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - -ASM_GLOBAL ASM_PFX(GasketUnixDisableInterrupt) -ASM_PFX(GasketUnixDisableInterrupt): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - call ASM_PFX(UnixDisableInterrupt) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - -// -// UNIX ABI to EFI ABI call -// -// UINTN -// ReverseGasketUint64 ( -// void *Api, -// UINTN Arg1 -// ); -ASM_GLOBAL ASM_PFX(ReverseGasketUint64) -ASM_PFX(ReverseGasketUint64): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - movq %rdi, %rax // Swizzle args - movq %rsi, %rcx - - subq $32, %rsp // 32-byte shadow space - call *%rax - addq $32, %rsp - - popq %rbp - ret - -// -// UNIX ABI to EFI ABI call -// -// UINTN -// ReverseGasketUint64Uint64 ( -// void *Api, -// UINTN Arg1 -// UINTN Arg2 -// ); -ASM_GLOBAL ASM_PFX(ReverseGasketUint64Uint64) -ASM_PFX(ReverseGasketUint64Uint64): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - movq %rdi, %rax // Swizzle args - movq %rsi, %rcx - - subq $32, %rsp // 32-byte shadow space - call *%rax - addq $32, %rsp - - popq %rbp - ret - - -// Sec PPI Callbacks - -ASM_GLOBAL ASM_PFX(GasketSecUnixPeiLoadFile) -ASM_PFX(GasketSecUnixPeiLoadFile): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - movq %r9, %rcx - - call ASM_PFX(SecUnixPeiLoadFile) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - -ASM_GLOBAL ASM_PFX(GasketSecUnixPeiAutoScan) -ASM_PFX(GasketSecUnixPeiAutoScan): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - - call ASM_PFX(SecUnixPeiAutoScan) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - -ASM_GLOBAL ASM_PFX(GasketSecUnixUnixThunkAddress) -ASM_PFX(GasketSecUnixUnixThunkAddress): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - call ASM_PFX(SecUnixUnixThunkAddress) - - - popq %rdi - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketSecPeiReportStatusCode) -ASM_PFX(GasketSecPeiReportStatusCode): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - movq %r9, %rcx - movq $0, %r8 // BugBug: This should come from the stack - movq $0, %r9 // But we can cheat since they are optional for bringup.... - - call ASM_PFX(SecPeiReportStatusCode) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - -ASM_GLOBAL ASM_PFX(GasketSecUnixFdAddress) -ASM_PFX(GasketSecUnixFdAddress): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - movq %r9, %rcx - - call ASM_PFX(SecUnixFdAddress) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - - -ASM_GLOBAL ASM_PFX(GasketSecTemporaryRamSupport) -ASM_PFX(GasketSecTemporaryRamSupport): - pushq %rbp // stack frame is for the debugger - movq %rsp, %rbp - - pushq %rsi // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI - pushq %rdi - - movq %rcx, %rdi // Swizzle args - movq %rdx, %rsi - movq %r8, %rdx - movq %r9, %rcx - - call ASM_PFX(SecTemporaryRamSupport) - - popq %rdi // restore state - popq %rsi - popq %rbp - ret - - - - - diff --git a/UnixPkg/Sec/X64/NameManglingFix.c b/UnixPkg/Sec/X64/NameManglingFix.c deleted file mode 100644 index a3fd6a6edf..0000000000 --- a/UnixPkg/Sec/X64/NameManglingFix.c +++ /dev/null @@ -1,44 +0,0 @@ -/** @file
-
- Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
-
- 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 "SecMain.h"
-
-//
-// OS X Posix does some strange name mangling on these names in C.
-// If you call from assembler you get the wrong version of the function
-// So these globals get you the correct name mangled functions that can
-// be accessed from assembly
-//
-UnixRmDir gUnixRmDir = rmdir;
-UnixOpenDir gUnixOpenDir = opendir;
-UnixStat gUnixStat = (UnixStat)stat;
-UnixStatFs gUnixStatFs = statfs;
-UnixReadDir gUnixReaddir = readdir;
-UnixRewindDir gUnixRewinddir = rewinddir;
-
-int
-UnixIoCtl1 (
- int fd,
- unsigned long int __request,
- UINTN Arg
- )
-{
- return ioctl (fd, __request, Arg);
-}
-
-int
-UnixFcntl1 (int __fd, int __cmd, UINTN Arg)
-{
- return fcntl (__fd, __cmd, Arg);
-}
\ No newline at end of file diff --git a/UnixPkg/Sec/X64/SwitchStack.S b/UnixPkg/Sec/X64/SwitchStack.S deleted file mode 100644 index e9adefce39..0000000000 --- a/UnixPkg/Sec/X64/SwitchStack.S +++ /dev/null @@ -1,120 +0,0 @@ -#------------------------------------------------------------------------------
-#
-# Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
-# 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:
-#
-# SwitchStack.S
-#
-# Abstract:
-#
-#------------------------------------------------------------------------------
-
-
-#------------------------------------------------------------------------------
-# Routine Description:
-#
-# Routine for switching stacks with 3 parameters EFI ABI
-# Convert UNIX to EFI ABI
-#
-# Arguments:
-#
-# (rdi) EntryPoint - Entry point with new stack.
-# (rsi) Context1 - Parameter1 for entry point. (rcx)
-# (rdx) Context2 - Parameter2 for entry point. (rdx)
-# (rcx) Context3 - Parameter3 for entry point. (r8)
-# (r8) NewStack - The pointer to new stack.
-#
-# Returns:
-#
-# None
-#
-#------------------------------------------------------------------------------
-ASM_GLOBAL ASM_PFX(PeiSwitchStacks)
-ASM_PFX(PeiSwitchStacks):
- pushq %rbp // stack frame is for the debugger
- movq %rsp, %rbp
-
- movq %r8, %rsp
-
- movq %rdi, %rax
- movq %rsi, %rcx
- movq %rcx, %r8
-
- #
- # Reserve space for register parameters (rcx, rdx, r8 & r9) on the stack,
- # in case the callee wishes to spill them.
- #
- subq $32, %rsp // 32-byte shadow space plus alignment pad
- call *%rax
-
-
-#------------------------------------------------------------------------------
-# Routine Description:
-#
-# Routine for switching stacks with 3 parameters UNIX ABI
-#
-# Arguments:
-#
-# (rdi) EntryPoint - Entry point with new stack.
-# (rsi) Context1 - Parameter1 for entry point.
-# (rdx) Context2 - Parameter2 for entry point.
-# (rcx) Context3 - Parameter3 for entry point.
-# (r8) NewStack - The pointer to new stack.
-#
-# Returns:
-#
-# None
-#
-#------------------------------------------------------------------------------
-ASM_GLOBAL ASM_PFX(UnixPeiSwitchStacks)
-ASM_PFX(UnixPeiSwitchStacks):
- pushq %rbp // stack frame is for the debugger
- movq %rsp, %rbp
-
- mov %rdi, %rax
- mov %rsi, %rdi
- mov %rdx, %rsi
- mov %rcx, %rdx
- mov %r8, %rsp
-
-
- #
- # Reserve space for redzone on the stack,
- # in case the callee wishes to spill them.
- #
- lea -0x80(%rsp), %rsp
- call *%rax
-
-
-
-#------------------------------------------------------------------------------
-# VOID
-# EFIAPI
-# SecSwitchStack (
-# UINT32 TemporaryMemoryBase, // Rcx, Rdi
-# UINT32 PermenentMemoryBase // Rdx, Rsi
-# );
-#------------------------------------------------------------------------------
-ASM_GLOBAL ASM_PFX(SecSwitchStack)
-ASM_PFX(SecSwitchStack):
- pushq %rbp // stack frame is for the debugger
- movq %rsp, %rbp
-
- mov %rsp, %rax
- sub %rdi, %rax
- add %rsi, %rax
- mov (%rip), %r10
- mov %r10, (%rax)
-
- popq %rbp
- ret
-
-
\ No newline at end of file |