InOsEmuPkg: Rename package to EmulatorPkg & Sec to Host
* Rename InOsEmuPkg to EmulatorPkg * Rename Unix/Sec to Unix/Host Signed-off-by: jljusten Reviewed-by: andrewfish Reviewed-by: geekboy15a git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11918 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
1111
EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c
Normal file
1111
EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c
Normal file
File diff suppressed because it is too large
Load Diff
706
EmulatorPkg/Unix/Host/BlockIo.c
Normal file
706
EmulatorPkg/Unix/Host/BlockIo.c
Normal file
@@ -0,0 +1,706 @@
|
||||
/**@file
|
||||
|
||||
Copyright (c) 2004 - 2009, 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.
|
||||
|
||||
**/
|
||||
|
||||
#include "SecMain.h"
|
||||
|
||||
#define EMU_BLOCK_IO_PRIVATE_SIGNATURE SIGNATURE_32 ('E', 'M', 'b', 'k')
|
||||
typedef struct {
|
||||
UINTN Signature;
|
||||
|
||||
EMU_IO_THUNK_PROTOCOL *Thunk;
|
||||
|
||||
char *Filename;
|
||||
UINTN ReadMode;
|
||||
UINTN Mode;
|
||||
|
||||
int fd;
|
||||
|
||||
BOOLEAN RemovableMedia;
|
||||
BOOLEAN WriteProtected;
|
||||
|
||||
UINT64 NumberOfBlocks;
|
||||
UINT32 BlockSize;
|
||||
|
||||
EMU_BLOCK_IO_PROTOCOL EmuBlockIo;
|
||||
EFI_BLOCK_IO_MEDIA *Media;
|
||||
|
||||
} EMU_BLOCK_IO_PRIVATE;
|
||||
|
||||
#define EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS(a) \
|
||||
CR(a, EMU_BLOCK_IO_PRIVATE, EmuBlockIo, EMU_BLOCK_IO_PRIVATE_SIGNATURE)
|
||||
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
EmuBlockIoReset (
|
||||
IN EMU_BLOCK_IO_PROTOCOL *This,
|
||||
IN BOOLEAN ExtendedVerification
|
||||
);
|
||||
|
||||
|
||||
/*++
|
||||
|
||||
This function extends the capability of SetFilePointer to accept 64 bit parameters
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
SetFilePointer64 (
|
||||
IN EMU_BLOCK_IO_PRIVATE *Private,
|
||||
IN INT64 DistanceToMove,
|
||||
OUT UINT64 *NewFilePointer,
|
||||
IN INT32 MoveMethod
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
off_t res;
|
||||
off_t offset = DistanceToMove;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
res = lseek (Private->fd, offset, (int)MoveMethod);
|
||||
if (res == -1) {
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (NewFilePointer != NULL) {
|
||||
*NewFilePointer = res;
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
EmuBlockIoOpenDevice (
|
||||
IN EMU_BLOCK_IO_PRIVATE *Private
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT64 FileSize;
|
||||
struct statfs buf;
|
||||
|
||||
|
||||
//
|
||||
// If the device is already opened, close it
|
||||
//
|
||||
if (Private->fd >= 0) {
|
||||
EmuBlockIoReset (&Private->EmuBlockIo, FALSE);
|
||||
}
|
||||
|
||||
//
|
||||
// Open the device
|
||||
//
|
||||
Private->fd = open (Private->Filename, Private->Mode, 0644);
|
||||
if (Private->fd < 0) {
|
||||
printf ("EmuOpenBlock: Could not open %s: %s\n", Private->Filename, strerror(errno));
|
||||
Private->Media->MediaPresent = FALSE;
|
||||
Status = EFI_NO_MEDIA;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
if (!Private->Media->MediaPresent) {
|
||||
//
|
||||
// BugBug: try to emulate if a CD appears - notify drivers to check it out
|
||||
//
|
||||
Private->Media->MediaPresent = TRUE;
|
||||
}
|
||||
|
||||
//
|
||||
// get the size of the file
|
||||
//
|
||||
Status = SetFilePointer64 (Private, 0, &FileSize, SEEK_END);
|
||||
if (EFI_ERROR (Status)) {
|
||||
printf ("EmuOpenBlock: Could not get filesize of %s\n", Private->Filename);
|
||||
Status = EFI_UNSUPPORTED;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
if (FileSize == 0) {
|
||||
// lseek fails on a real device. ioctl calls are OS specific
|
||||
#if __APPLE__
|
||||
{
|
||||
UINT32 BlockSize;
|
||||
|
||||
if (ioctl (Private->fd, DKIOCGETBLOCKSIZE, &BlockSize) == 0) {
|
||||
Private->Media->BlockSize = BlockSize;
|
||||
}
|
||||
if (ioctl (Private->fd, DKIOCGETBLOCKCOUNT, &Private->NumberOfBlocks) == 0) {
|
||||
if ((Private->NumberOfBlocks == 0) && (BlockSize == 0x800)) {
|
||||
// A DVD is ~ 4.37 GB so make up a number
|
||||
Private->Media->LastBlock = (0x100000000ULL/0x800) - 1;
|
||||
} else {
|
||||
Private->Media->LastBlock = Private->NumberOfBlocks - 1;
|
||||
}
|
||||
}
|
||||
ioctl (Private->fd, DKIOCGETMAXBLOCKCOUNTWRITE, &Private->Media->OptimalTransferLengthGranularity);
|
||||
}
|
||||
#else
|
||||
{
|
||||
size_t BlockSize;
|
||||
UINT64 DiskSize;
|
||||
|
||||
if (ioctl (Private->fd, BLKSSZGET, &BlockSize) == 0) {
|
||||
Private->Media->BlockSize = BlockSize;
|
||||
}
|
||||
if (ioctl (Private->fd, BLKGETSIZE64, &DiskSize) == 0) {
|
||||
Private->NumberOfBlocks = DivU64x32 (DiskSize, (UINT32)BlockSize);
|
||||
Private->Media->LastBlock = Private->NumberOfBlocks - 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} else {
|
||||
Private->Media->BlockSize = Private->BlockSize;
|
||||
Private->NumberOfBlocks = DivU64x32 (FileSize, Private->Media->BlockSize);
|
||||
Private->Media->LastBlock = Private->NumberOfBlocks - 1;
|
||||
|
||||
if (fstatfs (Private->fd, &buf) == 0) {
|
||||
#if __APPLE__
|
||||
Private->Media->OptimalTransferLengthGranularity = buf.f_iosize/buf.f_bsize;
|
||||
#else
|
||||
Private->Media->OptimalTransferLengthGranularity = buf.f_bsize/buf.f_bsize;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG ((EFI_D_INIT, "%HEmuOpenBlock: opened %a%N\n", Private->Filename));
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
Done:
|
||||
if (EFI_ERROR (Status)) {
|
||||
if (Private->fd >= 0) {
|
||||
EmuBlockIoReset (&Private->EmuBlockIo, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
EmuBlockIoCreateMapping (
|
||||
IN EMU_BLOCK_IO_PROTOCOL *This,
|
||||
IN EFI_BLOCK_IO_MEDIA *Media
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EMU_BLOCK_IO_PRIVATE *Private;
|
||||
|
||||
Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
Private->Media = Media;
|
||||
|
||||
Media->MediaId = 0;
|
||||
Media->RemovableMedia = Private->RemovableMedia;
|
||||
Media->MediaPresent = TRUE;
|
||||
Media->LogicalPartition = FALSE;
|
||||
Media->ReadOnly = Private->WriteProtected;
|
||||
Media->WriteCaching = FALSE;
|
||||
Media->IoAlign = 1;
|
||||
Media->LastBlock = 0; // Filled in by OpenDevice
|
||||
|
||||
// EFI_BLOCK_IO_PROTOCOL_REVISION2
|
||||
Media->LowestAlignedLba = 0;
|
||||
Media->LogicalBlocksPerPhysicalBlock = 0;
|
||||
|
||||
|
||||
// EFI_BLOCK_IO_PROTOCOL_REVISION3
|
||||
Media->OptimalTransferLengthGranularity = 0;
|
||||
|
||||
Status = EmuBlockIoOpenDevice (Private);
|
||||
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
EmuBlockIoError (
|
||||
IN EMU_BLOCK_IO_PRIVATE *Private
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
BOOLEAN ReinstallBlockIoFlag;
|
||||
|
||||
|
||||
switch (errno) {
|
||||
|
||||
case EAGAIN:
|
||||
Status = EFI_NO_MEDIA;
|
||||
Private->Media->ReadOnly = FALSE;
|
||||
Private->Media->MediaPresent = FALSE;
|
||||
ReinstallBlockIoFlag = FALSE;
|
||||
break;
|
||||
|
||||
case EACCES:
|
||||
Private->Media->ReadOnly = FALSE;
|
||||
Private->Media->MediaPresent = TRUE;
|
||||
Private->Media->MediaId += 1;
|
||||
ReinstallBlockIoFlag = TRUE;
|
||||
Status = EFI_MEDIA_CHANGED;
|
||||
break;
|
||||
|
||||
case EROFS:
|
||||
Private->Media->ReadOnly = TRUE;
|
||||
ReinstallBlockIoFlag = FALSE;
|
||||
Status = EFI_WRITE_PROTECTED;
|
||||
break;
|
||||
|
||||
default:
|
||||
ReinstallBlockIoFlag = FALSE;
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
break;
|
||||
}
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
EmuBlockIoReadWriteCommon (
|
||||
IN EMU_BLOCK_IO_PRIVATE *Private,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer,
|
||||
IN CHAR8 *CallerName
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN BlockSize;
|
||||
UINT64 LastBlock;
|
||||
INT64 DistanceToMove;
|
||||
UINT64 DistanceMoved;
|
||||
|
||||
if (Private->fd < 0) {
|
||||
Status = EmuBlockIoOpenDevice (Private);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Private->Media->MediaPresent) {
|
||||
DEBUG ((EFI_D_INIT, "%s: No Media\n", CallerName));
|
||||
return EFI_NO_MEDIA;
|
||||
}
|
||||
|
||||
if (Private->Media->MediaId != MediaId) {
|
||||
return EFI_MEDIA_CHANGED;
|
||||
}
|
||||
|
||||
if ((UINTN) Buffer % Private->Media->IoAlign != 0) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
//
|
||||
// Verify buffer size
|
||||
//
|
||||
BlockSize = Private->Media->BlockSize;
|
||||
if (BufferSize == 0) {
|
||||
DEBUG ((EFI_D_INIT, "%s: Zero length read\n", CallerName));
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
if ((BufferSize % BlockSize) != 0) {
|
||||
DEBUG ((EFI_D_INIT, "%s: Invalid read size\n", CallerName));
|
||||
return EFI_BAD_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
LastBlock = Lba + (BufferSize / BlockSize) - 1;
|
||||
if (LastBlock > Private->Media->LastBlock) {
|
||||
DEBUG ((EFI_D_INIT, "ReadBlocks: Attempted to read off end of device\n"));
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
//
|
||||
// Seek to End of File
|
||||
//
|
||||
DistanceToMove = MultU64x32 (Lba, BlockSize);
|
||||
Status = SetFilePointer64 (Private, DistanceToMove, &DistanceMoved, SEEK_SET);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((EFI_D_INIT, "WriteBlocks: SetFilePointer failed\n"));
|
||||
return EmuBlockIoError (Private);
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Read BufferSize bytes from Lba into Buffer.
|
||||
|
||||
This function reads the requested number of blocks from the device. All the
|
||||
blocks are read, or an error is returned.
|
||||
If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_or EFI_MEDIA_CHANGED is returned and
|
||||
non-blocking I/O is being used, the Event associated with this request will
|
||||
not be signaled.
|
||||
|
||||
@param[in] This Indicates a pointer to the calling context.
|
||||
@param[in] MediaId Id of the media, changes every time the media is
|
||||
replaced.
|
||||
@param[in] Lba The starting Logical Block Address to read from.
|
||||
@param[in, out] Token A pointer to the token associated with the transaction.
|
||||
@param[in] BufferSize Size of Buffer, must be a multiple of device block size.
|
||||
@param[out] Buffer A pointer to the destination buffer for the data. The
|
||||
caller is responsible for either having implicit or
|
||||
explicit ownership of the buffer.
|
||||
|
||||
@retval EFI_SUCCESS The read request was queued if Token->Event is
|
||||
not NULL.The data was read correctly from the
|
||||
device if the Token->Event is NULL.
|
||||
@retval EFI_DEVICE_ERROR The device reported an error while performing
|
||||
the read.
|
||||
@retval EFI_NO_MEDIA There is no media in the device.
|
||||
@retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
|
||||
@retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
|
||||
intrinsic block size of the device.
|
||||
@retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
|
||||
or the buffer is not on proper alignment.
|
||||
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
|
||||
of resources.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuBlockIoReadBlocks (
|
||||
IN EMU_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA LBA,
|
||||
IN OUT EFI_BLOCK_IO2_TOKEN *Token,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EMU_BLOCK_IO_PRIVATE *Private;
|
||||
ssize_t len;
|
||||
|
||||
Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
Status = EmuBlockIoReadWriteCommon (Private, MediaId, LBA, BufferSize, Buffer, "UnixReadBlocks");
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
len = read (Private->fd, Buffer, BufferSize);
|
||||
if (len != BufferSize) {
|
||||
DEBUG ((EFI_D_INIT, "ReadBlocks: ReadFile failed.\n"));
|
||||
Status = EmuBlockIoError (Private);
|
||||
goto Done;
|
||||
}
|
||||
|
||||
//
|
||||
// If we read then media is present.
|
||||
//
|
||||
Private->Media->MediaPresent = TRUE;
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
Done:
|
||||
if (Token != NULL) {
|
||||
if (Token->Event != NULL) {
|
||||
// Caller is responcible for signaling EFI Event
|
||||
Token->TransactionStatus = Status;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
}
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Write BufferSize bytes from Lba into Buffer.
|
||||
|
||||
This function writes the requested number of blocks to the device. All blocks
|
||||
are written, or an error is returned.If EFI_DEVICE_ERROR, EFI_NO_MEDIA,
|
||||
EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED is returned and non-blocking I/O is
|
||||
being used, the Event associated with this request will not be signaled.
|
||||
|
||||
@param[in] This Indicates a pointer to the calling context.
|
||||
@param[in] MediaId The media ID that the write request is for.
|
||||
@param[in] Lba The starting logical block address to be written. The
|
||||
caller is responsible for writing to only legitimate
|
||||
locations.
|
||||
@param[in, out] Token A pointer to the token associated with the transaction.
|
||||
@param[in] BufferSize Size of Buffer, must be a multiple of device block size.
|
||||
@param[in] Buffer A pointer to the source buffer for the data.
|
||||
|
||||
@retval EFI_SUCCESS The write request was queued if Event is not NULL.
|
||||
The data was written correctly to the device if
|
||||
the Event is NULL.
|
||||
@retval EFI_WRITE_PROTECTED The device can not be written to.
|
||||
@retval EFI_NO_MEDIA There is no media in the device.
|
||||
@retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
|
||||
@retval EFI_DEVICE_ERROR The device reported an error while performing the write.
|
||||
@retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
|
||||
@retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
|
||||
or the buffer is not on proper alignment.
|
||||
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
|
||||
of resources.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuBlockIoWriteBlocks (
|
||||
IN EMU_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA LBA,
|
||||
IN OUT EFI_BLOCK_IO2_TOKEN *Token,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
EMU_BLOCK_IO_PRIVATE *Private;
|
||||
ssize_t len;
|
||||
EFI_STATUS Status;
|
||||
|
||||
|
||||
Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
Status = EmuBlockIoReadWriteCommon (Private, MediaId, LBA, BufferSize, Buffer, "UnixWriteBlocks");
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
len = write (Private->fd, Buffer, BufferSize);
|
||||
if (len != BufferSize) {
|
||||
DEBUG ((EFI_D_INIT, "ReadBlocks: WriteFile failed.\n"));
|
||||
Status = EmuBlockIoError (Private);
|
||||
goto Done;
|
||||
}
|
||||
|
||||
//
|
||||
// If the write succeeded, we are not write protected and media is present.
|
||||
//
|
||||
Private->Media->MediaPresent = TRUE;
|
||||
Private->Media->ReadOnly = FALSE;
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
Done:
|
||||
if (Token != NULL) {
|
||||
if (Token->Event != NULL) {
|
||||
// Caller is responcible for signaling EFI Event
|
||||
Token->TransactionStatus = Status;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Flush the Block Device.
|
||||
|
||||
If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED
|
||||
is returned and non-blocking I/O is being used, the Event associated with
|
||||
this request will not be signaled.
|
||||
|
||||
@param[in] This Indicates a pointer to the calling context.
|
||||
@param[in,out] Token A pointer to the token associated with the transaction
|
||||
|
||||
@retval EFI_SUCCESS The flush request was queued if Event is not NULL.
|
||||
All outstanding data was written correctly to the
|
||||
device if the Event is NULL.
|
||||
@retval EFI_DEVICE_ERROR The device reported an error while writting back
|
||||
the data.
|
||||
@retval EFI_WRITE_PROTECTED The device cannot be written to.
|
||||
@retval EFI_NO_MEDIA There is no media in the device.
|
||||
@retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
|
||||
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
|
||||
of resources.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuBlockIoFlushBlocks (
|
||||
IN EMU_BLOCK_IO_PROTOCOL *This,
|
||||
IN OUT EFI_BLOCK_IO2_TOKEN *Token
|
||||
)
|
||||
{
|
||||
EMU_BLOCK_IO_PRIVATE *Private;
|
||||
|
||||
Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
if (Private->fd >= 0) {
|
||||
fsync (Private->fd);
|
||||
#if __APPLE__
|
||||
fcntl (Private->fd, F_FULLFSYNC);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
if (Token != NULL) {
|
||||
if (Token->Event != NULL) {
|
||||
// Caller is responcible for signaling EFI Event
|
||||
Token->TransactionStatus = EFI_SUCCESS;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Reset the block device hardware.
|
||||
|
||||
@param[in] This Indicates a pointer to the calling context.
|
||||
@param[in] ExtendedVerification Indicates that the driver may perform a more
|
||||
exhausive verfication operation of the device
|
||||
during reset.
|
||||
|
||||
@retval EFI_SUCCESS The device was reset.
|
||||
@retval EFI_DEVICE_ERROR The device is not functioning properly and could
|
||||
not be reset.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuBlockIoReset (
|
||||
IN EMU_BLOCK_IO_PROTOCOL *This,
|
||||
IN BOOLEAN ExtendedVerification
|
||||
)
|
||||
{
|
||||
EMU_BLOCK_IO_PRIVATE *Private;
|
||||
|
||||
Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
if (Private->fd >= 0) {
|
||||
close (Private->fd);
|
||||
Private->fd = -1;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
StdDupUnicodeToAscii (
|
||||
IN CHAR16 *Str
|
||||
)
|
||||
{
|
||||
UINTN Size;
|
||||
char *Ascii;
|
||||
char *Ptr;
|
||||
|
||||
Size = StrLen (Str) + 1;
|
||||
Ascii = malloc (Size);
|
||||
if (Ascii == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (Ptr = Ascii; *Str != '\0'; Ptr++, Str++) {
|
||||
*Ptr = *Str;
|
||||
}
|
||||
*Ptr = 0;
|
||||
|
||||
return Ascii;
|
||||
}
|
||||
|
||||
|
||||
EMU_BLOCK_IO_PROTOCOL gEmuBlockIoProtocol = {
|
||||
GasketEmuBlockIoReset,
|
||||
GasketEmuBlockIoReadBlocks,
|
||||
GasketEmuBlockIoWriteBlocks,
|
||||
GasketEmuBlockIoFlushBlocks,
|
||||
GasketEmuBlockIoCreateMapping
|
||||
};
|
||||
|
||||
EFI_STATUS
|
||||
EmuBlockIoThunkOpen (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
)
|
||||
{
|
||||
EMU_BLOCK_IO_PRIVATE *Private;
|
||||
char *Str;
|
||||
|
||||
if (This->Private != NULL) {
|
||||
return EFI_ALREADY_STARTED;
|
||||
}
|
||||
|
||||
if (!CompareGuid (This->Protocol, &gEmuBlockIoProtocolGuid)) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
Private = malloc (sizeof (EMU_BLOCK_IO_PRIVATE));
|
||||
if (Private == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
|
||||
Private->Signature = EMU_BLOCK_IO_PRIVATE_SIGNATURE;
|
||||
Private->Thunk = This;
|
||||
CopyMem (&Private->EmuBlockIo, &gEmuBlockIoProtocol, sizeof (gEmuBlockIoProtocol));
|
||||
Private->fd = -1;
|
||||
Private->BlockSize = 512;
|
||||
|
||||
Private->Filename = StdDupUnicodeToAscii (This->ConfigString);
|
||||
if (Private->Filename == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
Str = strstr (Private->Filename, ":");
|
||||
if (Str == NULL) {
|
||||
Private->RemovableMedia = FALSE;
|
||||
Private->WriteProtected = FALSE;
|
||||
} else {
|
||||
for (*Str++ = '\0'; *Str != 0; Str++) {
|
||||
if (*Str == 'R' || *Str == 'F') {
|
||||
Private->RemovableMedia = (BOOLEAN) (*Str == 'R');
|
||||
}
|
||||
if (*Str == 'O' || *Str == 'W') {
|
||||
Private->WriteProtected = (BOOLEAN) (*Str == 'O');
|
||||
}
|
||||
if (*Str == ':') {
|
||||
Private->BlockSize = strtol (++Str, NULL, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
This->Interface = &Private->EmuBlockIo;
|
||||
This->Private = Private;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
EmuBlockIoThunkClose (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
)
|
||||
{
|
||||
EMU_BLOCK_IO_PRIVATE *Private;
|
||||
|
||||
if (!CompareGuid (This->Protocol, &gEmuBlockIoProtocolGuid)) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
Private = This->Private;
|
||||
|
||||
if (This->Private != NULL) {
|
||||
if (Private->Filename != NULL) {
|
||||
free (Private->Filename);
|
||||
}
|
||||
free (This->Private);
|
||||
This->Private = NULL;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo = {
|
||||
&gEmuBlockIoProtocolGuid,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
GasketBlockIoThunkOpen,
|
||||
GasketBlockIoThunkClose,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
432
EmulatorPkg/Unix/Host/EmuThunk.c
Normal file
432
EmulatorPkg/Unix/Host/EmuThunk.c
Normal file
@@ -0,0 +1,432 @@
|
||||
/*++ @file
|
||||
Since the SEC is the only program in our emulation we
|
||||
must use a UEFI/PI mechanism to export APIs to other modules.
|
||||
This is the role of the EFI_EMU_THUNK_PROTOCOL.
|
||||
|
||||
The mUnixThunkTable exists so that a change to EFI_EMU_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.
|
||||
|
||||
Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
|
||||
Portions copyright (c) 2008 - 2011, 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"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define DebugAssert _Mangle__DebugAssert
|
||||
|
||||
#include <assert.h>
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include <mach/mach.h>
|
||||
#include <mach/mach_time.h>
|
||||
|
||||
#undef DebugAssert
|
||||
#endif
|
||||
|
||||
int settimer_initialized;
|
||||
struct timeval settimer_timeval;
|
||||
void (*settimer_callback)(UINT64 delta);
|
||||
|
||||
BOOLEAN gEmulatorInterruptEnabled = FALSE;
|
||||
|
||||
|
||||
UINTN
|
||||
SecWriteStdErr (
|
||||
IN UINT8 *Buffer,
|
||||
IN UINTN NumberOfBytes
|
||||
)
|
||||
{
|
||||
ssize_t Return;
|
||||
|
||||
Return = write (STDERR_FILENO, (const void *)Buffer, (size_t)NumberOfBytes);
|
||||
|
||||
return (Return == -1) ? 0 : Return;
|
||||
}
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
SecConfigStdIn (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
struct termios tty;
|
||||
|
||||
//
|
||||
// Need to turn off line buffering, ECHO, and make it unbuffered.
|
||||
//
|
||||
tcgetattr (STDIN_FILENO, &tty);
|
||||
tty.c_lflag &= ~(ICANON | ECHO);
|
||||
tcsetattr (STDIN_FILENO, TCSANOW, &tty);
|
||||
|
||||
// setvbuf (STDIN_FILENO, NULL, _IONBF, 0);
|
||||
|
||||
// now ioctl FIONREAD will do what we need
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
UINTN
|
||||
SecWriteStdOut (
|
||||
IN UINT8 *Buffer,
|
||||
IN UINTN NumberOfBytes
|
||||
)
|
||||
{
|
||||
ssize_t Return;
|
||||
|
||||
Return = write (STDOUT_FILENO, (const void *)Buffer, (size_t)NumberOfBytes);
|
||||
|
||||
return (Return == -1) ? 0 : Return;
|
||||
}
|
||||
|
||||
UINTN
|
||||
SecReadStdIn (
|
||||
IN UINT8 *Buffer,
|
||||
IN UINTN NumberOfBytes
|
||||
)
|
||||
{
|
||||
ssize_t Return;
|
||||
|
||||
Return = read (STDIN_FILENO, Buffer, (size_t)NumberOfBytes);
|
||||
|
||||
return (Return == -1) ? 0 : Return;
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
SecPollStdIn (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
int Result;
|
||||
int Bytes;
|
||||
|
||||
Result = ioctl (STDIN_FILENO, FIONREAD, &Bytes);
|
||||
if (Result == -1) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return (BOOLEAN)(Bytes > 0);
|
||||
}
|
||||
|
||||
|
||||
VOID *
|
||||
SecMalloc (
|
||||
IN UINTN Size
|
||||
)
|
||||
{
|
||||
return malloc ((size_t)Size);
|
||||
}
|
||||
|
||||
VOID *
|
||||
SecValloc (
|
||||
IN UINTN Size
|
||||
)
|
||||
{
|
||||
return valloc ((size_t)Size);
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
SecFree (
|
||||
IN VOID *Ptr
|
||||
)
|
||||
{
|
||||
if (EfiSystemMemoryRange (Ptr)) {
|
||||
// If an address range is in the EFI memory map it was alloced via EFI.
|
||||
// So don't free those ranges and let the caller know.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
free (Ptr);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
ReverseGasketUint64 (settimer_callback, delta);
|
||||
}
|
||||
}
|
||||
|
||||
VOID
|
||||
SecSetTimer (
|
||||
IN UINT64 PeriodMs,
|
||||
IN EMU_SET_TIMER_CALLBACK CallBack
|
||||
)
|
||||
{
|
||||
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
|
||||
SecEnableInterrupt (
|
||||
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);
|
||||
pthread_sigmask (SIG_UNBLOCK, &sigset, NULL);
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
SecDisableInterrupt (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
sigset_t sigset;
|
||||
|
||||
// Since SetTimer() uses SIGALRM we emulate turning on and off interrupts
|
||||
// by enabling/disabling SIGALRM.
|
||||
sigemptyset (&sigset);
|
||||
sigaddset (&sigset, SIGALRM);
|
||||
pthread_sigmask (SIG_BLOCK, &sigset, NULL);
|
||||
gEmulatorInterruptEnabled = FALSE;
|
||||
}
|
||||
|
||||
|
||||
BOOLEAN
|
||||
SecInterruptEanbled (void)
|
||||
{
|
||||
return gEmulatorInterruptEnabled;
|
||||
}
|
||||
|
||||
|
||||
UINT64
|
||||
QueryPerformanceFrequency (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
// Hard code to nanoseconds
|
||||
return 1000000000ULL;
|
||||
}
|
||||
|
||||
UINT64
|
||||
QueryPerformanceCounter (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
#if __APPLE__
|
||||
UINT64 Start;
|
||||
Nanoseconds elapsedNano;
|
||||
|
||||
Start = mach_absolute_time ();
|
||||
|
||||
// Convert to nanoseconds.
|
||||
|
||||
// Have to do some pointer fun because AbsoluteToNanoseconds
|
||||
// works in terms of UnsignedWide, which is a structure rather
|
||||
// than a proper 64-bit integer.
|
||||
elapsedNano = AbsoluteToNanoseconds (*(AbsoluteTime *) &Start);
|
||||
|
||||
return *(uint64_t *) &elapsedNano;
|
||||
#else
|
||||
// Need to figure out what to do for Linux?
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
VOID
|
||||
SecSleep (
|
||||
IN UINT64 Nanoseconds
|
||||
)
|
||||
{
|
||||
struct timespec rq, rm;
|
||||
struct timeval start, end;
|
||||
unsigned long MicroSec;
|
||||
|
||||
rq.tv_sec = DivU64x32 (Nanoseconds, 1000000000);
|
||||
rq.tv_nsec = ModU64x32 (Nanoseconds, 1000000000);
|
||||
|
||||
//
|
||||
// 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
|
||||
SecCpuSleep (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
struct timespec rq, rm;
|
||||
|
||||
// nanosleep gets interrupted by the timer tic
|
||||
rq.tv_sec = 1;
|
||||
rq.tv_nsec = 0;
|
||||
|
||||
nanosleep (&rq, &rm);
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
SecExit (
|
||||
UINTN Status
|
||||
)
|
||||
{
|
||||
exit (Status);
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
SecGetTime (
|
||||
OUT EFI_TIME *Time,
|
||||
OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL
|
||||
)
|
||||
{
|
||||
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 = timezone;
|
||||
Time->Daylight = (daylight ? EFI_TIME_ADJUST_DAYLIGHT : 0)
|
||||
| (tm->tm_isdst > 0 ? EFI_TIME_IN_DAYLIGHT : 0);
|
||||
|
||||
if (Capabilities != NULL) {
|
||||
Capabilities->Resolution = 1;
|
||||
Capabilities->Accuracy = 50000000;
|
||||
Capabilities->SetsToZero = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
VOID
|
||||
SecSetTime (
|
||||
IN EFI_TIME *Time
|
||||
)
|
||||
{
|
||||
// Don't change the time on the system
|
||||
// We could save delta to localtime() and have SecGetTime adjust return values?
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
SecGetNextProtocol (
|
||||
IN BOOLEAN EmuBusDriver,
|
||||
OUT EMU_IO_THUNK_PROTOCOL **Instance OPTIONAL
|
||||
)
|
||||
{
|
||||
return GetNextThunkProtocol (EmuBusDriver, Instance);
|
||||
}
|
||||
|
||||
|
||||
EMU_THUNK_PROTOCOL gEmuThunkProtocol = {
|
||||
GasketSecWriteStdErr,
|
||||
GasketSecConfigStdIn,
|
||||
GasketSecWriteStdOut,
|
||||
GasketSecReadStdIn,
|
||||
GasketSecPollStdIn,
|
||||
GasketSecMalloc,
|
||||
GasketSecValloc,
|
||||
GasketSecFree,
|
||||
GasketSecPeCoffGetEntryPoint,
|
||||
GasketSecPeCoffRelocateImageExtraAction,
|
||||
GasketSecPeCoffUnloadImageExtraAction,
|
||||
GasketSecEnableInterrupt,
|
||||
GasketSecDisableInterrupt,
|
||||
GasketQueryPerformanceFrequency,
|
||||
GasketQueryPerformanceCounter,
|
||||
GasketSecSleep,
|
||||
GasketSecCpuSleep,
|
||||
GasketSecExit,
|
||||
GasketSecGetTime,
|
||||
GasketSecSetTime,
|
||||
GasketSecSetTimer,
|
||||
GasketSecGetNextProtocol
|
||||
};
|
||||
|
||||
|
||||
VOID
|
||||
SecInitThunkProtocol (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
// timezone and daylight lib globals depend on tzset be called 1st.
|
||||
tzset ();
|
||||
}
|
||||
|
651
EmulatorPkg/Unix/Host/Gasket.h
Normal file
651
EmulatorPkg/Unix/Host/Gasket.h
Normal file
@@ -0,0 +1,651 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
|
||||
Copyright (c) 2011, 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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef _GASKET_H_
|
||||
#define _GASKET_H_
|
||||
|
||||
//
|
||||
// EMU_THUNK_PROTOCOL gaskets (EFIAPI to UNIX ABI)
|
||||
//
|
||||
|
||||
UINTN
|
||||
EFIAPI
|
||||
GasketSecWriteStdErr (
|
||||
IN UINT8 *Buffer,
|
||||
IN UINTN NumberOfBytes
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSecConfigStdIn (
|
||||
VOID
|
||||
);
|
||||
|
||||
UINTN
|
||||
EFIAPI
|
||||
GasketSecWriteStdOut (
|
||||
IN UINT8 *Buffer,
|
||||
IN UINTN NumberOfBytes
|
||||
);
|
||||
|
||||
UINTN
|
||||
EFIAPI
|
||||
GasketSecReadStdIn (
|
||||
IN UINT8 *Buffer,
|
||||
IN UINTN NumberOfBytes
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
GasketSecPollStdIn (
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID *
|
||||
EFIAPI
|
||||
GasketSecMalloc (
|
||||
IN UINTN Size
|
||||
);
|
||||
|
||||
VOID *
|
||||
EFIAPI
|
||||
GasketSecValloc (
|
||||
IN UINTN Size
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
GasketSecFree (
|
||||
IN VOID *Ptr
|
||||
);
|
||||
|
||||
|
||||
RETURN_STATUS
|
||||
EFIAPI
|
||||
GasketSecPeCoffGetEntryPoint (
|
||||
IN VOID *Pe32Data,
|
||||
IN OUT VOID **EntryPoint
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
GasketSecPeCoffRelocateImageExtraAction (
|
||||
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
GasketSecPeCoffUnloadImageExtraAction (
|
||||
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
GasketSecSetTimer (
|
||||
IN UINT64 PeriodMs,
|
||||
IN EMU_SET_TIMER_CALLBACK CallBack
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
GasketSecEnableInterrupt (
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
GasketSecDisableInterrupt (
|
||||
VOID
|
||||
);
|
||||
|
||||
UINT64
|
||||
EFIAPI
|
||||
GasketQueryPerformanceFrequency (
|
||||
VOID
|
||||
);
|
||||
|
||||
UINT64
|
||||
EFIAPI
|
||||
GasketQueryPerformanceCounter (
|
||||
VOID
|
||||
);
|
||||
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
GasketSecSleep (
|
||||
IN UINT64 Nanoseconds
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
GasketSecCpuSleep (
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
GasketSecExit (
|
||||
UINTN Status
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
GasketSecGetTime (
|
||||
OUT EFI_TIME *Time,
|
||||
OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
GasketSecSetTime (
|
||||
IN EFI_TIME *Time
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSecGetNextProtocol (
|
||||
IN BOOLEAN EmuBusDriver,
|
||||
OUT EMU_IO_THUNK_PROTOCOL **Instance OPTIONAL
|
||||
);
|
||||
|
||||
|
||||
// PPIs produced by SEC
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSecUnixPeiAutoScan (
|
||||
IN UINTN Index,
|
||||
OUT EFI_PHYSICAL_ADDRESS *MemoryBase,
|
||||
OUT UINT64 *MemorySize
|
||||
);
|
||||
|
||||
VOID *
|
||||
EFIAPI
|
||||
GasketSecEmuThunkAddress (
|
||||
VOID
|
||||
);
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSecUnixUnixFwhAddress (
|
||||
IN OUT UINT64 *FwhSize,
|
||||
IN OUT EFI_PHYSICAL_ADDRESS *FwhBase
|
||||
);
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Reverse (UNIX to EFIAPI) gaskets
|
||||
//
|
||||
|
||||
typedef
|
||||
void
|
||||
(EFIAPI *CALL_BACK) (
|
||||
UINT64 Delta
|
||||
);
|
||||
|
||||
UINTN
|
||||
ReverseGasketUint64 (
|
||||
CALL_BACK CallBack,
|
||||
UINT64 a
|
||||
);
|
||||
|
||||
UINTN
|
||||
ReverseGasketUint64Uint64 (
|
||||
VOID *CallBack,
|
||||
VOID *Context,
|
||||
VOID *Key
|
||||
);
|
||||
|
||||
//
|
||||
// Gasket functions for EFI_EMU_UGA_IO_PROTOCOL
|
||||
//
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketX11Size (
|
||||
EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo,
|
||||
UINT32 Width,
|
||||
UINT32 Height
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketX11CheckKey (
|
||||
EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketX11GetKey (
|
||||
EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo,
|
||||
EFI_KEY_DATA *key
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketX11KeySetState (
|
||||
EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo,
|
||||
EFI_KEY_TOGGLE_STATE *KeyToggleState
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketX11RegisterKeyNotify (
|
||||
IN EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo,
|
||||
IN EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK MakeCallBack,
|
||||
IN EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK BreakCallBack,
|
||||
IN VOID *Context
|
||||
);
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketX11Blt (
|
||||
IN EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows,
|
||||
IN EFI_UGA_PIXEL *BltBuffer OPTIONAL,
|
||||
IN EFI_UGA_BLT_OPERATION BltOperation,
|
||||
IN EMU_GRAPHICS_WINDOWS__BLT_ARGS *Args
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketX11CheckPointer (
|
||||
EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketX11GetPointerState (
|
||||
EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo,
|
||||
EFI_SIMPLE_POINTER_STATE *state
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketX11GraphicsWindowOpen (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketX11GraphicsWindowClose (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
);
|
||||
|
||||
// Pthreads
|
||||
|
||||
UINTN
|
||||
EFIAPI
|
||||
GasketPthreadMutexLock (
|
||||
IN VOID *Mutex
|
||||
);
|
||||
|
||||
|
||||
|
||||
UINTN
|
||||
EFIAPI
|
||||
GasketPthreadMutexUnLock (
|
||||
IN VOID *Mutex
|
||||
);
|
||||
|
||||
|
||||
UINTN
|
||||
EFIAPI
|
||||
GasketPthreadMutexTryLock (
|
||||
IN VOID *Mutex
|
||||
);
|
||||
|
||||
|
||||
VOID *
|
||||
EFIAPI
|
||||
GasketPthreadMutexInit (
|
||||
IN VOID
|
||||
);
|
||||
|
||||
|
||||
UINTN
|
||||
EFIAPI
|
||||
GasketPthreadMutexDestroy (
|
||||
IN VOID *Mutex
|
||||
);
|
||||
|
||||
|
||||
UINTN
|
||||
EFIAPI
|
||||
GasketPthreadCreate (
|
||||
IN VOID *Thread,
|
||||
IN VOID *Attribute,
|
||||
IN THREAD_THUNK_THREAD_ENTRY Start,
|
||||
IN VOID *Context
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
GasketPthreadExit (
|
||||
IN VOID *ValuePtr
|
||||
);
|
||||
|
||||
|
||||
UINTN
|
||||
EFIAPI
|
||||
GasketPthreadSelf (
|
||||
VOID
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketPthreadOpen (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketPthreadClose (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
);
|
||||
|
||||
|
||||
// PosixFileSystem
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketPosixOpenVolume (
|
||||
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
|
||||
OUT EFI_FILE_PROTOCOL **Root
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketPosixFileOpen (
|
||||
IN EFI_FILE_PROTOCOL *This,
|
||||
OUT EFI_FILE_PROTOCOL **NewHandle,
|
||||
IN CHAR16 *FileName,
|
||||
IN UINT64 OpenMode,
|
||||
IN UINT64 Attributes
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketPosixFileCLose (
|
||||
IN EFI_FILE_PROTOCOL *This
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketPosixFileDelete (
|
||||
IN EFI_FILE_PROTOCOL *This
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketPosixFileRead (
|
||||
IN EFI_FILE_PROTOCOL *This,
|
||||
IN OUT UINTN *BufferSize,
|
||||
OUT VOID *Buffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketPosixFileWrite (
|
||||
IN EFI_FILE_PROTOCOL *This,
|
||||
IN OUT UINTN *BufferSize,
|
||||
IN VOID *Buffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketPosixFileSetPossition (
|
||||
IN EFI_FILE_PROTOCOL *This,
|
||||
IN UINT64 Position
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketPosixFileGetPossition (
|
||||
IN EFI_FILE_PROTOCOL *This,
|
||||
OUT UINT64 *Position
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketPosixFileGetInfo (
|
||||
IN EFI_FILE_PROTOCOL *This,
|
||||
IN EFI_GUID *InformationType,
|
||||
IN OUT UINTN *BufferSize,
|
||||
OUT VOID *Buffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketPosixFileSetInfo (
|
||||
IN EFI_FILE_PROTOCOL *This,
|
||||
IN EFI_GUID *InformationType,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketPosixFileFlush (
|
||||
IN EFI_FILE_PROTOCOL *This
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketPosixFileSystmeThunkOpen (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketPosixFileSystmeThunkClose (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketEmuBlockIoReset (
|
||||
IN EMU_BLOCK_IO_PROTOCOL *This,
|
||||
IN BOOLEAN ExtendedVerification
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketEmuBlockIoReadBlocks (
|
||||
IN EMU_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA LBA,
|
||||
IN OUT EFI_BLOCK_IO2_TOKEN *Token,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketEmuBlockIoWriteBlocks (
|
||||
IN EMU_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA LBA,
|
||||
IN OUT EFI_BLOCK_IO2_TOKEN *Token,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketEmuBlockIoFlushBlocks (
|
||||
IN EMU_BLOCK_IO_PROTOCOL *This,
|
||||
IN OUT EFI_BLOCK_IO2_TOKEN *Token
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketEmuBlockIoCreateMapping (
|
||||
IN EMU_BLOCK_IO_PROTOCOL *This,
|
||||
IN EFI_BLOCK_IO_MEDIA *Media
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketBlockIoThunkOpen (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketBlockIoThunkClose (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpThunkOpen (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpThunkClose (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpCreateMapping (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN EFI_SIMPLE_NETWORK_MODE *Media
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpStart (
|
||||
IN EMU_SNP_PROTOCOL *This
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpStop (
|
||||
IN EMU_SNP_PROTOCOL *This
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpInitialize (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN UINTN ExtraRxBufferSize OPTIONAL,
|
||||
IN UINTN ExtraTxBufferSize OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpReset (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN BOOLEAN ExtendedVerification
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpShutdown (
|
||||
IN EMU_SNP_PROTOCOL *This
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpReceiveFilters (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN UINT32 Enable,
|
||||
IN UINT32 Disable,
|
||||
IN BOOLEAN ResetMCastFilter,
|
||||
IN UINTN MCastFilterCnt OPTIONAL,
|
||||
IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpStationAddress (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN BOOLEAN Reset,
|
||||
IN EFI_MAC_ADDRESS *New OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpStatistics (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN BOOLEAN Reset,
|
||||
IN OUT UINTN *StatisticsSize OPTIONAL,
|
||||
OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpMCastIpToMac (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN BOOLEAN IPv6,
|
||||
IN EFI_IP_ADDRESS *IP,
|
||||
OUT EFI_MAC_ADDRESS *MAC
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpNvData (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN BOOLEAN ReadWrite,
|
||||
IN UINTN Offset,
|
||||
IN UINTN BufferSize,
|
||||
IN OUT VOID *Buffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpGetStatus (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
OUT UINT32 *InterruptStatus OPTIONAL,
|
||||
OUT VOID **TxBuf OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpTransmit (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN UINTN HeaderSize,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer,
|
||||
IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
|
||||
IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,
|
||||
IN UINT16 *Protocol OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GasketSnpReceive (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
OUT UINTN *HeaderSize OPTIONAL,
|
||||
IN OUT UINTN *BufferSize,
|
||||
OUT VOID *Buffer,
|
||||
OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
|
||||
OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL,
|
||||
OUT UINT16 *Protocol OPTIONAL
|
||||
);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
1492
EmulatorPkg/Unix/Host/Ia32/Gasket.S
Normal file
1492
EmulatorPkg/Unix/Host/Ia32/Gasket.S
Normal file
File diff suppressed because it is too large
Load Diff
74
EmulatorPkg/Unix/Host/Ia32/SwitchStack.c
Normal file
74
EmulatorPkg/Unix/Host/Ia32/SwitchStack.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/*++
|
||||
|
||||
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.
|
||||
|
||||
|
||||
--*/
|
||||
|
||||
#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.
|
||||
|
||||
**/
|
||||
VOID
|
||||
EFIAPI
|
||||
PeiSwitchStacks (
|
||||
IN SWITCH_STACK_ENTRY_POINT EntryPoint,
|
||||
IN VOID *Context1, OPTIONAL
|
||||
IN VOID *Context2, 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);
|
||||
((VOID**)JumpBuffer.Esp)[1] = Context1;
|
||||
((VOID**)JumpBuffer.Esp)[2] = Context2;
|
||||
|
||||
LongJump (&JumpBuffer, (UINTN)-1);
|
||||
|
||||
|
||||
//
|
||||
// PeiSwitchStacks () will never return
|
||||
//
|
||||
ASSERT (FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
604
EmulatorPkg/Unix/Host/LinuxPacketFilter.c
Normal file
604
EmulatorPkg/Unix/Host/LinuxPacketFilter.c
Normal file
@@ -0,0 +1,604 @@
|
||||
/**@file
|
||||
Linux Packet Filter implementation of the EMU_SNP_PROTOCOL that allows the
|
||||
emulator to get on real networks.
|
||||
|
||||
Currently only the Berkeley Packet Filter is fully implemented and this file
|
||||
is just a template that needs to get filled in.
|
||||
|
||||
Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
|
||||
Portitions copyright (c) 2011, Apple Inc. All rights reserved.
|
||||
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
|
||||
#include "SecMain.h"
|
||||
|
||||
#ifndef __APPLE__
|
||||
|
||||
#define EMU_SNP_PRIVATE_SIGNATURE SIGNATURE_32('E', 'M', 's', 'n')
|
||||
typedef struct {
|
||||
UINTN Signature;
|
||||
|
||||
EMU_IO_THUNK_PROTOCOL *Thunk;
|
||||
|
||||
|
||||
EMU_SNP_PROTOCOL EmuSnp;
|
||||
EFI_SIMPLE_NETWORK_MODE *Mode;
|
||||
|
||||
} EMU_SNP_PRIVATE;
|
||||
|
||||
#define EMU_SNP_PRIVATE_DATA_FROM_THIS(a) \
|
||||
CR(a, EMU_SNP_PRIVATE, EmuSnp, EMU_SNP_PRIVATE_SIGNATURE)
|
||||
|
||||
/**
|
||||
Register storage for SNP Mode.
|
||||
|
||||
@param This Protocol instance pointer.
|
||||
@param Mode SimpleNetworkProtocol Mode structure passed into driver.
|
||||
|
||||
@retval EFI_SUCCESS The network interface was started.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuSnpCreateMapping (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN EFI_SIMPLE_NETWORK_MODE *Mode
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
Private->Mode = Mode;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
Changes the state of a network interface from "stopped" to "started".
|
||||
|
||||
@param This Protocol instance pointer.
|
||||
|
||||
@retval EFI_SUCCESS The network interface was started.
|
||||
@retval EFI_ALREADY_STARTED The network interface is already in the started state.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
|
||||
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
||||
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuSnpStart (
|
||||
IN EMU_SNP_PROTOCOL *This
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
Changes the state of a network interface from "started" to "stopped".
|
||||
|
||||
@param This Protocol instance pointer.
|
||||
|
||||
@retval EFI_SUCCESS The network interface was stopped.
|
||||
@retval EFI_ALREADY_STARTED The network interface is already in the stopped state.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
|
||||
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
||||
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuSnpStop (
|
||||
IN EMU_SNP_PROTOCOL *This
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
Resets a network adapter and allocates the transmit and receive buffers
|
||||
required by the network interface; optionally, also requests allocation
|
||||
of additional transmit and receive buffers.
|
||||
|
||||
@param This The protocol instance pointer.
|
||||
@param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
|
||||
that the driver should allocate for the network interface.
|
||||
Some network interfaces will not be able to use the extra
|
||||
buffer, and the caller will not know if it is actually
|
||||
being used.
|
||||
@param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
|
||||
that the driver should allocate for the network interface.
|
||||
Some network interfaces will not be able to use the extra
|
||||
buffer, and the caller will not know if it is actually
|
||||
being used.
|
||||
|
||||
@retval EFI_SUCCESS The network interface was initialized.
|
||||
@retval EFI_NOT_STARTED The network interface has not been started.
|
||||
@retval EFI_OUT_OF_RESOURCES There was not enough memory for the transmit and
|
||||
receive buffers.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
|
||||
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
||||
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuSnpInitialize (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN UINTN ExtraRxBufferSize OPTIONAL,
|
||||
IN UINTN ExtraTxBufferSize OPTIONAL
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
Resets a network adapter and re-initializes it with the parameters that were
|
||||
provided in the previous call to Initialize().
|
||||
|
||||
@param This The protocol instance pointer.
|
||||
@param ExtendedVerification Indicates that the driver may perform a more
|
||||
exhaustive verification operation of the device
|
||||
during reset.
|
||||
|
||||
@retval EFI_SUCCESS The network interface was reset.
|
||||
@retval EFI_NOT_STARTED The network interface has not been started.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
|
||||
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
||||
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuSnpReset (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN BOOLEAN ExtendedVerification
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
Resets a network adapter and leaves it in a state that is safe for
|
||||
another driver to initialize.
|
||||
|
||||
@param This Protocol instance pointer.
|
||||
|
||||
@retval EFI_SUCCESS The network interface was shutdown.
|
||||
@retval EFI_NOT_STARTED The network interface has not been started.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
|
||||
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
||||
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuSnpShutdown (
|
||||
IN EMU_SNP_PROTOCOL *This
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
Manages the multicast receive filters of a network interface.
|
||||
|
||||
@param This The protocol instance pointer.
|
||||
@param Enable A bit mask of receive filters to enable on the network interface.
|
||||
@param Disable A bit mask of receive filters to disable on the network interface.
|
||||
@param ResetMCastFilter Set to TRUE to reset the contents of the multicast receive
|
||||
filters on the network interface to their default values.
|
||||
@param McastFilterCnt Number of multicast HW MAC addresses in the new
|
||||
MCastFilter list. This value must be less than or equal to
|
||||
the MCastFilterCnt field of EMU_SNP_MODE. This
|
||||
field is optional if ResetMCastFilter is TRUE.
|
||||
@param MCastFilter A pointer to a list of new multicast receive filter HW MAC
|
||||
addresses. This list will replace any existing multicast
|
||||
HW MAC address list. This field is optional if
|
||||
ResetMCastFilter is TRUE.
|
||||
|
||||
@retval EFI_SUCCESS The multicast receive filter list was updated.
|
||||
@retval EFI_NOT_STARTED The network interface has not been started.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
|
||||
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
||||
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuSnpReceiveFilters (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN UINT32 Enable,
|
||||
IN UINT32 Disable,
|
||||
IN BOOLEAN ResetMCastFilter,
|
||||
IN UINTN MCastFilterCnt OPTIONAL,
|
||||
IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
Modifies or resets the current station address, if supported.
|
||||
|
||||
@param This The protocol instance pointer.
|
||||
@param Reset Flag used to reset the station address to the network interfaces
|
||||
permanent address.
|
||||
@param New The new station address to be used for the network interface.
|
||||
|
||||
@retval EFI_SUCCESS The network interfaces station address was updated.
|
||||
@retval EFI_NOT_STARTED The network interface has not been started.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
|
||||
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
||||
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuSnpStationAddress (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN BOOLEAN Reset,
|
||||
IN EFI_MAC_ADDRESS *New OPTIONAL
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
Resets or collects the statistics on a network interface.
|
||||
|
||||
@param This Protocol instance pointer.
|
||||
@param Reset Set to TRUE to reset the statistics for the network interface.
|
||||
@param StatisticsSize On input the size, in bytes, of StatisticsTable. On
|
||||
output the size, in bytes, of the resulting table of
|
||||
statistics.
|
||||
@param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
|
||||
contains the statistics.
|
||||
|
||||
@retval EFI_SUCCESS The statistics were collected from the network interface.
|
||||
@retval EFI_NOT_STARTED The network interface has not been started.
|
||||
@retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
|
||||
size needed to hold the statistics is returned in
|
||||
StatisticsSize.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
|
||||
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
||||
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuSnpStatistics (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN BOOLEAN Reset,
|
||||
IN OUT UINTN *StatisticsSize OPTIONAL,
|
||||
OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
Converts a multicast IP address to a multicast HW MAC address.
|
||||
|
||||
@param This The protocol instance pointer.
|
||||
@param IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
|
||||
to FALSE if the multicast IP address is IPv4 [RFC 791].
|
||||
@param IP The multicast IP address that is to be converted to a multicast
|
||||
HW MAC address.
|
||||
@param MAC The multicast HW MAC address that is to be generated from IP.
|
||||
|
||||
@retval EFI_SUCCESS The multicast IP address was mapped to the multicast
|
||||
HW MAC address.
|
||||
@retval EFI_NOT_STARTED The network interface has not been started.
|
||||
@retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
|
||||
size needed to hold the statistics is returned in
|
||||
StatisticsSize.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
|
||||
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
||||
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuSnpMCastIpToMac (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN BOOLEAN IPv6,
|
||||
IN EFI_IP_ADDRESS *IP,
|
||||
OUT EFI_MAC_ADDRESS *MAC
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
Performs read and write operations on the NVRAM device attached to a
|
||||
network interface.
|
||||
|
||||
@param This The protocol instance pointer.
|
||||
@param ReadWrite TRUE for read operations, FALSE for write operations.
|
||||
@param Offset Byte offset in the NVRAM device at which to start the read or
|
||||
write operation. This must be a multiple of NvRamAccessSize and
|
||||
less than NvRamSize.
|
||||
@param BufferSize The number of bytes to read or write from the NVRAM device.
|
||||
This must also be a multiple of NvramAccessSize.
|
||||
@param Buffer A pointer to the data buffer.
|
||||
|
||||
@retval EFI_SUCCESS The NVRAM access was performed.
|
||||
@retval EFI_NOT_STARTED The network interface has not been started.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
|
||||
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
||||
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuSnpNvData (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN BOOLEAN ReadWrite,
|
||||
IN UINTN Offset,
|
||||
IN UINTN BufferSize,
|
||||
IN OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
Reads the current interrupt status and recycled transmit buffer status from
|
||||
a network interface.
|
||||
|
||||
@param This The protocol instance pointer.
|
||||
@param InterruptStatus A pointer to the bit mask of the currently active interrupts
|
||||
If this is NULL, the interrupt status will not be read from
|
||||
the device. If this is not NULL, the interrupt status will
|
||||
be read from the device. When the interrupt status is read,
|
||||
it will also be cleared. Clearing the transmit interrupt
|
||||
does not empty the recycled transmit buffer array.
|
||||
@param TxBuf Recycled transmit buffer address. The network interface will
|
||||
not transmit if its internal recycled transmit buffer array
|
||||
is full. Reading the transmit buffer does not clear the
|
||||
transmit interrupt. If this is NULL, then the transmit buffer
|
||||
status will not be read. If there are no transmit buffers to
|
||||
recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
|
||||
|
||||
@retval EFI_SUCCESS The status of the network interface was retrieved.
|
||||
@retval EFI_NOT_STARTED The network interface has not been started.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
|
||||
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
||||
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuSnpGetStatus (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
OUT UINT32 *InterruptStatus OPTIONAL,
|
||||
OUT VOID **TxBuf OPTIONAL
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
Places a packet in the transmit queue of a network interface.
|
||||
|
||||
@param This The protocol instance pointer.
|
||||
@param HeaderSize The size, in bytes, of the media header to be filled in by
|
||||
the Transmit() function. If HeaderSize is non-zero, then it
|
||||
must be equal to This->Mode->MediaHeaderSize and the DestAddr
|
||||
and Protocol parameters must not be NULL.
|
||||
@param BufferSize The size, in bytes, of the entire packet (media header and
|
||||
data) to be transmitted through the network interface.
|
||||
@param Buffer A pointer to the packet (media header followed by data) to be
|
||||
transmitted. This parameter cannot be NULL. If HeaderSize is zero,
|
||||
then the media header in Buffer must already be filled in by the
|
||||
caller. If HeaderSize is non-zero, then the media header will be
|
||||
filled in by the Transmit() function.
|
||||
@param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
|
||||
is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
|
||||
This->Mode->CurrentAddress is used for the source HW MAC address.
|
||||
@param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
|
||||
parameter is ignored.
|
||||
@param Protocol The type of header to build. If HeaderSize is zero, then this
|
||||
parameter is ignored. See RFC 1700, section "Ether Types", for
|
||||
examples.
|
||||
|
||||
@retval EFI_SUCCESS The packet was placed on the transmit queue.
|
||||
@retval EFI_NOT_STARTED The network interface has not been started.
|
||||
@retval EFI_NOT_READY The network interface is too busy to accept this transmit request.
|
||||
@retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
|
||||
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
||||
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuSnpTransmit (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
IN UINTN HeaderSize,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer,
|
||||
IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
|
||||
IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,
|
||||
IN UINT16 *Protocol OPTIONAL
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
Receives a packet from a network interface.
|
||||
|
||||
@param This The protocol instance pointer.
|
||||
@param HeaderSize The size, in bytes, of the media header received on the network
|
||||
interface. If this parameter is NULL, then the media header size
|
||||
will not be returned.
|
||||
@param BufferSize On entry, the size, in bytes, of Buffer. On exit, the size, in
|
||||
bytes, of the packet that was received on the network interface.
|
||||
@param Buffer A pointer to the data buffer to receive both the media header and
|
||||
the data.
|
||||
@param SrcAddr The source HW MAC address. If this parameter is NULL, the
|
||||
HW MAC source address will not be extracted from the media
|
||||
header.
|
||||
@param DestAddr The destination HW MAC address. If this parameter is NULL,
|
||||
the HW MAC destination address will not be extracted from the
|
||||
media header.
|
||||
@param Protocol The media header type. If this parameter is NULL, then the
|
||||
protocol will not be extracted from the media header. See
|
||||
RFC 1700 section "Ether Types" for examples.
|
||||
|
||||
@retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
|
||||
been updated to the number of bytes received.
|
||||
@retval EFI_NOT_STARTED The network interface has not been started.
|
||||
@retval EFI_NOT_READY The network interface is too busy to accept this transmit
|
||||
request.
|
||||
@retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
|
||||
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
||||
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EmuSnpReceive (
|
||||
IN EMU_SNP_PROTOCOL *This,
|
||||
OUT UINTN *HeaderSize OPTIONAL,
|
||||
IN OUT UINTN *BufferSize,
|
||||
OUT VOID *Buffer,
|
||||
OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
|
||||
OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL,
|
||||
OUT UINT16 *Protocol OPTIONAL
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
EMU_SNP_PROTOCOL gEmuSnpProtocol = {
|
||||
GasketSnpCreateMapping,
|
||||
GasketSnpStart,
|
||||
GasketSnpStop,
|
||||
GasketSnpInitialize,
|
||||
GasketSnpReset,
|
||||
GasketSnpShutdown,
|
||||
GasketSnpReceiveFilters,
|
||||
GasketSnpStationAddress,
|
||||
GasketSnpStatistics,
|
||||
GasketSnpMCastIpToMac,
|
||||
GasketSnpNvData,
|
||||
GasketSnpGetStatus,
|
||||
GasketSnpTransmit,
|
||||
GasketSnpReceive
|
||||
};
|
||||
|
||||
EFI_STATUS
|
||||
EmuSnpThunkOpen (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
if (This->Private != NULL) {
|
||||
return EFI_ALREADY_STARTED;
|
||||
}
|
||||
|
||||
if (!CompareGuid (This->Protocol, &gEmuSnpProtocolGuid)) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
Private = malloc (sizeof (EMU_SNP_PRIVATE));
|
||||
if (Private == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
|
||||
Private->Signature = EMU_SNP_PRIVATE_SIGNATURE;
|
||||
Private->Thunk = This;
|
||||
CopyMem (&Private->EmuSnp, &gEmuSnpProtocol, sizeof (gEmuSnpProtocol));
|
||||
|
||||
This->Interface = &Private->EmuSnp;
|
||||
This->Private = Private;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
EmuSnpThunkClose (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
)
|
||||
{
|
||||
EMU_SNP_PRIVATE *Private;
|
||||
|
||||
if (!CompareGuid (This->Protocol, &gEmuSnpProtocolGuid)) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
Private = This->Private;
|
||||
free (Private);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
EMU_IO_THUNK_PROTOCOL gSnpThunkIo = {
|
||||
&gEmuSnpProtocolGuid,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
GasketSnpThunkOpen,
|
||||
GasketSnpThunkClose,
|
||||
NULL
|
||||
};
|
||||
|
||||
#endif
|
145
EmulatorPkg/Unix/Host/MemoryAllocationLib.c
Normal file
145
EmulatorPkg/Unix/Host/MemoryAllocationLib.c
Normal file
@@ -0,0 +1,145 @@
|
||||
/*++ @file
|
||||
|
||||
Copyright (c) 2011, 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.
|
||||
|
||||
**/
|
||||
|
||||
#include "Base.h"
|
||||
#include "Library/BaseMemoryLib.h"
|
||||
#include "Library/MemoryAllocationLib.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
Allocates a buffer of type EfiBootServicesData.
|
||||
|
||||
Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
|
||||
pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
|
||||
returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
|
||||
|
||||
@param AllocationSize The number of bytes to allocate.
|
||||
|
||||
@return A pointer to the allocated buffer or NULL if allocation fails.
|
||||
|
||||
**/
|
||||
VOID *
|
||||
EFIAPI
|
||||
AllocatePool (
|
||||
IN UINTN AllocationSize
|
||||
)
|
||||
{
|
||||
return (VOID*) malloc (AllocationSize);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Allocates and zeros a buffer of type EfiBootServicesData.
|
||||
|
||||
Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
|
||||
buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
|
||||
valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
|
||||
request, then NULL is returned.
|
||||
|
||||
@param AllocationSize The number of bytes to allocate and zero.
|
||||
|
||||
@return A pointer to the allocated buffer or NULL if allocation fails.
|
||||
|
||||
**/
|
||||
VOID *
|
||||
EFIAPI
|
||||
AllocateZeroPool (
|
||||
IN UINTN AllocationSize
|
||||
)
|
||||
{
|
||||
VOID *Buffer;
|
||||
|
||||
Buffer = AllocatePool (AllocationSize);
|
||||
if (Buffer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ZeroMem (Buffer, AllocationSize);
|
||||
|
||||
return Buffer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Reallocates a buffer of type EfiBootServicesData.
|
||||
|
||||
Allocates and zeros the number bytes specified by NewSize from memory of type
|
||||
EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
|
||||
NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
|
||||
OldBuffer is freed. A pointer to the newly allocated buffer is returned.
|
||||
If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
|
||||
enough memory remaining to satisfy the request, then NULL is returned.
|
||||
|
||||
If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
|
||||
is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
|
||||
|
||||
@param OldSize The size, in bytes, of OldBuffer.
|
||||
@param NewSize The size, in bytes, of the buffer to reallocate.
|
||||
@param OldBuffer The buffer to copy to the allocated buffer. This is an optional
|
||||
parameter that may be NULL.
|
||||
|
||||
@return A pointer to the allocated buffer or NULL if allocation fails.
|
||||
|
||||
**/
|
||||
VOID *
|
||||
EFIAPI
|
||||
ReallocatePool (
|
||||
IN UINTN OldSize,
|
||||
IN UINTN NewSize,
|
||||
IN VOID *OldBuffer OPTIONAL
|
||||
)
|
||||
{
|
||||
VOID *NewBuffer;
|
||||
|
||||
NewBuffer = AllocatePool (NewSize);
|
||||
if (NewBuffer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (OldBuffer != NULL) {
|
||||
if (OldSize > 0) {
|
||||
CopyMem (NewBuffer, OldBuffer, OldSize);
|
||||
}
|
||||
|
||||
FreePool (OldBuffer);
|
||||
}
|
||||
|
||||
return NewBuffer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Frees a buffer that was previously allocated with one of the pool allocation functions in the
|
||||
Memory Allocation Library.
|
||||
|
||||
Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
|
||||
pool allocation services of the Memory Allocation Library. If it is not possible to free pool
|
||||
resources, then this function will perform no actions.
|
||||
|
||||
If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
|
||||
then ASSERT().
|
||||
|
||||
@param Buffer Pointer to the buffer to free.
|
||||
|
||||
**/
|
||||
VOID
|
||||
EFIAPI
|
||||
FreePool (
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
free ((void *) Buffer);
|
||||
}
|
||||
|
1556
EmulatorPkg/Unix/Host/PosixFileSystem.c
Normal file
1556
EmulatorPkg/Unix/Host/PosixFileSystem.c
Normal file
File diff suppressed because it is too large
Load Diff
235
EmulatorPkg/Unix/Host/Pthreads.c
Normal file
235
EmulatorPkg/Unix/Host/Pthreads.c
Normal file
@@ -0,0 +1,235 @@
|
||||
/*++ @file
|
||||
POSIX Pthreads to emulate APs and implement threads
|
||||
|
||||
Copyright (c) 2011, Apple Inc. All rights reserved.
|
||||
Copyright (c) 2011, 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.
|
||||
|
||||
|
||||
**/
|
||||
|
||||
#include "SecMain.h"
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
UINTN
|
||||
EFIAPI
|
||||
PthreadMutexLock (
|
||||
IN VOID *Mutex
|
||||
)
|
||||
{
|
||||
return (UINTN)pthread_mutex_lock ((pthread_mutex_t *)Mutex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
UINTN
|
||||
EFIAPI
|
||||
PthreadMutexUnLock (
|
||||
IN VOID *Mutex
|
||||
)
|
||||
{
|
||||
return (UINTN)pthread_mutex_unlock ((pthread_mutex_t *)Mutex);
|
||||
}
|
||||
|
||||
|
||||
UINTN
|
||||
EFIAPI
|
||||
PthreadMutexTryLock (
|
||||
IN VOID *Mutex
|
||||
)
|
||||
{
|
||||
return (UINTN)pthread_mutex_trylock ((pthread_mutex_t *)Mutex);
|
||||
}
|
||||
|
||||
|
||||
VOID *
|
||||
PthreadMutexInit (
|
||||
IN VOID
|
||||
)
|
||||
{
|
||||
pthread_mutex_t *Mutex;
|
||||
int err;
|
||||
|
||||
Mutex = malloc (sizeof (pthread_mutex_t));
|
||||
err = pthread_mutex_init (Mutex, NULL);
|
||||
if (err == 0) {
|
||||
return Mutex;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
UINTN
|
||||
PthreadMutexDestroy (
|
||||
IN VOID *Mutex
|
||||
)
|
||||
{
|
||||
if (Mutex != NULL) {
|
||||
return pthread_mutex_destroy ((pthread_mutex_t *)Mutex);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Can't store this data on PthreadCreate stack so we need a global
|
||||
typedef struct {
|
||||
pthread_mutex_t Mutex;
|
||||
THREAD_THUNK_THREAD_ENTRY Start;
|
||||
} THREAD_MANGLE;
|
||||
|
||||
THREAD_MANGLE mThreadMangle = {
|
||||
PTHREAD_MUTEX_INITIALIZER,
|
||||
NULL
|
||||
};
|
||||
|
||||
VOID *
|
||||
SecFakePthreadStart (
|
||||
VOID *Context
|
||||
)
|
||||
{
|
||||
THREAD_THUNK_THREAD_ENTRY Start;
|
||||
sigset_t SigMask;
|
||||
|
||||
// Save global on the stack before we unlock
|
||||
Start = mThreadMangle.Start;
|
||||
pthread_mutex_unlock (&mThreadMangle.Mutex);
|
||||
|
||||
// Mask all signals to the APs
|
||||
sigfillset (&SigMask);
|
||||
pthread_sigmask (SIG_BLOCK, &SigMask, NULL);
|
||||
|
||||
//
|
||||
// We have to start the thread in SEC as we need to follow
|
||||
// OS X calling conventions. We can then call back into
|
||||
// to the callers Start.
|
||||
//
|
||||
// This is a great example of how all problems in computer
|
||||
// science can be solved by adding another level of indirection
|
||||
//
|
||||
return (VOID *)ReverseGasketUint64 ((CALL_BACK)Start, (UINTN)Context);
|
||||
}
|
||||
|
||||
UINTN
|
||||
PthreadCreate (
|
||||
IN VOID *Thread,
|
||||
IN VOID *Attribute,
|
||||
IN THREAD_THUNK_THREAD_ENTRY Start,
|
||||
IN VOID *Context
|
||||
)
|
||||
{
|
||||
int err;
|
||||
BOOLEAN EnabledOnEntry;
|
||||
|
||||
//
|
||||
// Threads inherit interrupt state so disable interrupts before we start thread
|
||||
//
|
||||
if (SecInterruptEanbled ()) {
|
||||
SecDisableInterrupt ();
|
||||
EnabledOnEntry = TRUE;
|
||||
} else {
|
||||
EnabledOnEntry = FALSE;
|
||||
}
|
||||
|
||||
// Aquire lock for global, SecFakePthreadStart runs in a different thread.
|
||||
pthread_mutex_lock (&mThreadMangle.Mutex);
|
||||
mThreadMangle.Start = Start;
|
||||
|
||||
err = pthread_create (Thread, Attribute, SecFakePthreadStart, Context);
|
||||
if (err != 0) {
|
||||
// Thread failed to launch so release the lock;
|
||||
pthread_mutex_unlock (&mThreadMangle.Mutex);
|
||||
}
|
||||
|
||||
if (EnabledOnEntry) {
|
||||
// Restore interrupt state
|
||||
SecEnableInterrupt ();
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
PthreadExit (
|
||||
IN VOID *ValuePtr
|
||||
)
|
||||
{
|
||||
pthread_exit (ValuePtr);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
UINTN
|
||||
PthreadSelf (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
// POSIX currently allows pthread_t to be a structure or arithmetic type.
|
||||
// Check out sys/types.h to make sure this will work if you are porting.
|
||||
// On OS X (Darwin) pthread_t is a pointer to a structure so this code works.
|
||||
return (UINTN)pthread_self ();
|
||||
}
|
||||
|
||||
|
||||
EMU_THREAD_THUNK_PROTOCOL gPthreadThunk = {
|
||||
GasketPthreadMutexLock,
|
||||
GasketPthreadMutexUnLock,
|
||||
GasketPthreadMutexTryLock,
|
||||
GasketPthreadMutexInit,
|
||||
GasketPthreadMutexDestroy,
|
||||
GasketPthreadCreate,
|
||||
GasketPthreadExit,
|
||||
GasketPthreadSelf
|
||||
};
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
PthreadOpen (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
)
|
||||
{
|
||||
if (This->Instance != 0) {
|
||||
// Only single instance is supported
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (This->ConfigString[0] == L'0') {
|
||||
// If AP count is zero no need for threads
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
This->Interface = &gPthreadThunk;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
PthreadClose (
|
||||
IN EMU_IO_THUNK_PROTOCOL *This
|
||||
)
|
||||
{
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
EMU_IO_THUNK_PROTOCOL gPthreadThunkIo = {
|
||||
&gEmuThreadThunkProtocolGuid,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
GasketPthreadOpen,
|
||||
GasketPthreadClose,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
1226
EmulatorPkg/Unix/Host/SecMain.c
Normal file
1226
EmulatorPkg/Unix/Host/SecMain.c
Normal file
File diff suppressed because it is too large
Load Diff
356
EmulatorPkg/Unix/Host/SecMain.h
Normal file
356
EmulatorPkg/Unix/Host/SecMain.h
Normal file
@@ -0,0 +1,356 @@
|
||||
/*++ @file
|
||||
|
||||
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||
Portions copyright (c) 2008 - 2011, 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 _SEC_MAIN_H__
|
||||
#define _SEC_MAIN_H__
|
||||
|
||||
//
|
||||
// Name mangle to prevent build errors. I.e conflicts between EFI and OS
|
||||
//
|
||||
#define NTOHL _UNIX_EFI_NAME_MANGLE_NTOHL_
|
||||
#define HTONL _UNIX_EFI_NAME_MANGLE_HTONL_
|
||||
#define NTOHS _UNIX_EFI_NAME_MANGLE_NTOHS_
|
||||
#define HTONS _UNIX_EFI_NAME_MANGLE_HTOHS_
|
||||
#define B0 _UNIX_EFI_NAME_MANGLE_B0_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/termios.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#if __CYGWIN__
|
||||
#include <sys/dirent.h>
|
||||
#else
|
||||
#include <sys/dir.h>
|
||||
#endif
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <poll.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <net/if_dl.h>
|
||||
#include <net/bpf.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/disk.h>
|
||||
#define _XOPEN_SOURCE
|
||||
#ifndef _Bool
|
||||
#define _Bool char // for clang debug
|
||||
#endif
|
||||
#else
|
||||
#include <termio.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <linux/fs.h>
|
||||
#endif
|
||||
|
||||
#include <utime.h>
|
||||
|
||||
#undef NTOHL
|
||||
#undef HTONL
|
||||
#undef NTOHS
|
||||
#undef HTONS
|
||||
#undef B0
|
||||
|
||||
|
||||
#include <PiPei.h>
|
||||
#include <Uefi.h>
|
||||
|
||||
#include <Library/PeCoffLib.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/PrintLib.h>
|
||||
#include <Library/PcdLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/ReportStatusCodeLib.h>
|
||||
|
||||
#include <Library/ThunkPpiList.h>
|
||||
#include <Library/ThunkProtocolList.h>
|
||||
#include <Library/PeiServicesLib.h>
|
||||
#include <Library/PeCoffGetEntryPointLib.h>
|
||||
#include <Library/EmuMagicPageLib.h>
|
||||
|
||||
#include <Ppi/EmuThunk.h>
|
||||
#include <Ppi/StatusCode.h>
|
||||
|
||||
#include <Protocol/SimplePointer.h>
|
||||
#include <Protocol/SimpleTextIn.h>
|
||||
#include <Protocol/SimpleTextInEx.h>
|
||||
#include <Protocol/UgaDraw.h>
|
||||
#include <Protocol/SimpleFileSystem.h>
|
||||
|
||||
#include <Protocol/EmuThunk.h>
|
||||
#include <Protocol/EmuIoThunk.h>
|
||||
#include <Protocol/EmuGraphicsWindow.h>
|
||||
#include <Protocol/EmuThread.h>
|
||||
#include <Protocol/EmuBlockIo.h>
|
||||
#include <Protocol/EmuSnp.h>
|
||||
|
||||
#include <Guid/FileInfo.h>
|
||||
#include <Guid/FileSystemInfo.h>
|
||||
#include <Guid/FileSystemVolumeLabelInfo.h>
|
||||
|
||||
|
||||
#include "Gasket.h"
|
||||
|
||||
|
||||
#define STACK_SIZE 0x20000
|
||||
|
||||
typedef struct {
|
||||
EFI_PHYSICAL_ADDRESS Address;
|
||||
UINT64 Size;
|
||||
} EMU_FD_INFO;
|
||||
|
||||
typedef struct {
|
||||
EFI_PHYSICAL_ADDRESS Memory;
|
||||
UINT64 Size;
|
||||
} EMU_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,
|
||||
EFI_PHYSICAL_ADDRESS *ImageAddress,
|
||||
UINT64 *ImageSize,
|
||||
EFI_PHYSICAL_ADDRESS *EntryPoint
|
||||
);
|
||||
|
||||
int
|
||||
main (
|
||||
IN int Argc,
|
||||
IN char **Argv,
|
||||
IN char **Envp
|
||||
);
|
||||
|
||||
VOID
|
||||
SecLoadFromCore (
|
||||
IN UINTN LargestRegion,
|
||||
IN UINTN LargestRegionSize,
|
||||
IN UINTN BootFirmwareVolumeBase,
|
||||
IN VOID *PeiCoreFile
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
SecLoadFile (
|
||||
IN VOID *Pe32Data,
|
||||
IN EFI_PHYSICAL_ADDRESS *ImageAddress,
|
||||
IN UINT64 *ImageSize,
|
||||
IN EFI_PHYSICAL_ADDRESS *EntryPoint
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
SecFfsFindPeiCore (
|
||||
IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
|
||||
OUT VOID **Pe32Data
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
SecFfsFindNextFile (
|
||||
IN EFI_FV_FILETYPE SearchType,
|
||||
IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
|
||||
IN OUT EFI_FFS_FILE_HEADER **FileHeader
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
SecFfsFindSectionData (
|
||||
IN EFI_SECTION_TYPE SectionType,
|
||||
IN EFI_FFS_FILE_HEADER *FfsFileHeader,
|
||||
IN OUT VOID **SectionData
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SecUnixPeCoffLoaderLoadAsDll (
|
||||
IN CHAR8 *PdbFileName,
|
||||
IN VOID **ImageEntryPoint,
|
||||
OUT VOID **ModHandle
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SecUnixPeCoffLoaderFreeLibrary (
|
||||
OUT VOID *ModHandle
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
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
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SecImageRead (
|
||||
IN VOID *FileHandle,
|
||||
IN UINTN FileOffset,
|
||||
IN OUT UINTN *ReadSize,
|
||||
OUT VOID *Buffer
|
||||
);
|
||||
|
||||
CHAR16 *
|
||||
AsciiToUnicode (
|
||||
IN CHAR8 *Ascii,
|
||||
IN UINTN *StrLen OPTIONAL
|
||||
);
|
||||
|
||||
UINTN
|
||||
CountSeperatorsInString (
|
||||
IN const CHAR16 *String,
|
||||
IN CHAR16 Seperator
|
||||
);
|
||||
|
||||
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
|
||||
PeiSwitchStacks (
|
||||
IN SWITCH_STACK_ENTRY_POINT EntryPoint,
|
||||
IN VOID *Context1, OPTIONAL
|
||||
IN VOID *Context2, OPTIONAL
|
||||
IN VOID *NewStack
|
||||
);
|
||||
|
||||
VOID
|
||||
SecInitThunkProtocol (
|
||||
VOID
|
||||
);
|
||||
|
||||
|
||||
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
|
||||
MapFd0 (
|
||||
IN CHAR8 *FileName,
|
||||
IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
|
||||
OUT UINT64 *Length
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
EfiSystemMemoryRange (
|
||||
IN VOID *MemoryAddress
|
||||
);
|
||||
|
||||
|
||||
VOID SecSleep (UINT64 Nanoseconds);
|
||||
VOID SecEnableInterrupt (VOID);
|
||||
VOID SecDisableInterrupt (VOID);
|
||||
BOOLEAN SecInterruptEanbled (VOID);
|
||||
|
||||
|
||||
extern EMU_THUNK_PROTOCOL gEmuThunkProtocol;
|
||||
extern EMU_IO_THUNK_PROTOCOL gX11ThunkIo;
|
||||
extern EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo;
|
||||
extern EMU_IO_THUNK_PROTOCOL gPthreadThunkIo;
|
||||
extern EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo;
|
||||
extern EMU_IO_THUNK_PROTOCOL gSnpThunkIo;
|
||||
|
||||
#endif
|
140
EmulatorPkg/Unix/Host/SecMain.inf
Normal file
140
EmulatorPkg/Unix/Host/SecMain.inf
Normal file
@@ -0,0 +1,140 @@
|
||||
## @file
|
||||
# Entry Point of Emu 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 - 2011, 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 = 8863C0AD-7724-C84B-88E5-A33B116D1485
|
||||
MODULE_TYPE = USER_DEFINED
|
||||
VERSION_STRING = 1.0
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||
#
|
||||
|
||||
[Sources]
|
||||
SecMain.c
|
||||
EmuThunk.c
|
||||
X11GraphicsWindow.c
|
||||
Pthreads.c
|
||||
PosixFileSystem.c
|
||||
BlockIo.c
|
||||
LinuxPacketFilter.c
|
||||
BerkeleyPacketFilter.c
|
||||
MemoryAllocationLib.c
|
||||
|
||||
[Sources.X64]
|
||||
X64/Gasket.S # convert between Emu x86_64 ABI and EFI X64 ABI
|
||||
X64/SwitchStack.S
|
||||
|
||||
[Sources.IA32]
|
||||
Ia32/Gasket.S # enforce 16-byte stack alignment for Mac OS X
|
||||
Ia32/SwitchStack.c
|
||||
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
EmulatorPkg/EmulatorPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
DebugLib
|
||||
PcdLib
|
||||
PrintLib
|
||||
BaseMemoryLib
|
||||
BaseLib
|
||||
PeCoffLib
|
||||
ThunkPpiList
|
||||
ThunkProtocolList
|
||||
PpiListLib
|
||||
PeiServicesLib
|
||||
PeCoffGetEntryPointLib
|
||||
|
||||
[Ppis]
|
||||
gEfiPeiStatusCodePpiGuid # PPI ALWAYS_PRODUCED
|
||||
gEmuThunkPpiGuid
|
||||
|
||||
[Protocols]
|
||||
gEmuIoThunkProtocolGuid
|
||||
gEmuIoThunkProtocolGuid
|
||||
gEmuGraphicsWindowProtocolGuid
|
||||
gEmuThreadThunkProtocolGuid
|
||||
gEmuBlockIoProtocolGuid
|
||||
gEmuSnpProtocolGuid
|
||||
gEfiSimpleFileSystemProtocolGuid
|
||||
|
||||
[Guids]
|
||||
gEfiFileSystemVolumeLabelInfoIdGuid # SOMETIMES_CONSUMED
|
||||
gEfiFileInfoGuid # SOMETIMES_CONSUMED
|
||||
gEfiFileSystemInfoGuid # SOMETIMES_CONSUMED
|
||||
|
||||
[Pcd]
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuBootMode
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuFirmwareVolume
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuMemorySize
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuFdBaseAddress
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuFirmwareFdSize
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuFirmwareBlockSize
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuApCount
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuVirtualDisk
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuGop|L"GOP Window"
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuFileSystem
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuSerialPort
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuNetworkInterface
|
||||
gEmulatorPkgTokenSpaceGuid.PcdNetworkPacketFilterSize
|
||||
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashFvRecoveryBase
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashFvRecoverySize
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageVariableBase
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageEventLogBase
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageEventLogSize
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwWorkingBase
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
|
||||
gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwSpareBase
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
|
||||
gEmulatorPkgTokenSpaceGuid.PcdPeiServicesTablePage
|
||||
|
||||
|
||||
[BuildOptions]
|
||||
GCC:*_*_IA32_DLINK_FLAGS == -o $(BIN_DIR)/SecMain -m elf_i386 -dynamic-linker /lib$(LIB_ARCH_SFX)/ld-linux.so.2 /usr/lib$(LIB_ARCH_SFX)/crt1.o /usr/lib$(LIB_ARCH_SFX)/crti.o -L/usr/X11R6/lib -lXext -lX11 /usr/lib$(LIB_ARCH_SFX)/crtn.o
|
||||
GCC:*_*_*_DLINK2_FLAGS == -lpthread -lc
|
||||
GCC:*_*_IA32_CC_FLAGS == -m32 -g -fshort-wchar -fno-strict-aliasing -Wall -malign-double -idirafter/usr/include -c -include $(DEST_DIR_DEBUG)/AutoGen.h -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings
|
||||
GCC:*_*_IA32_PP_FLAGS == -m32 -E -x assembler-with-cpp -include $(DEST_DIR_DEBUG)/AutoGen.h
|
||||
GCC:*_*_IA32_ASM_FLAGS == -m32 -c -x assembler -imacros $(DEST_DIR_DEBUG)/AutoGen.h
|
||||
|
||||
GCC:*_*_X64_DLINK_FLAGS == -o $(BIN_DIR)/SecMain -m elf_x86_64 -dynamic-linker /lib$(LIB_ARCH_SFX)/ld-linux-x86-64.so.2 /usr/lib$(LIB_ARCH_SFX)/crt1.o /usr/lib$(LIB_ARCH_SFX)/crti.o -L/usr/X11R6/lib -lXext -lX11 /usr/lib$(LIB_ARCH_SFX)/crtn.o
|
||||
GCC:*_*_X64_CC_FLAGS == -m64 -g -fshort-wchar -fno-strict-aliasing -Wall -malign-double -idirafter/usr/include -c -include $(DEST_DIR_DEBUG)/AutoGen.h -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings
|
||||
GCC:*_GCC44_X64_CC_FLAGS = "-DEFIAPI=__attribute__((ms_abi))"
|
||||
GCC:*_GCC45_X64_CC_FLAGS = "-DEFIAPI=__attribute__((ms_abi))"
|
||||
GCC:*_*_X64_PP_FLAGS == -m64 -E -x assembler-with-cpp -include $(DEST_DIR_DEBUG)/AutoGen.h
|
||||
GCC:*_*_X64_ASM_FLAGS == -m64 -c -x assembler -imacros $(DEST_DIR_DEBUG)/AutoGen.h
|
||||
|
||||
#
|
||||
# Need to do this link via gcc and not ld as the pathing to libraries changes from OS version to OS version
|
||||
#
|
||||
XCODE:*_*_IA32_DLINK_PATH == gcc
|
||||
XCODE:*_*_IA32_CC_FLAGS == -arch i386 -O0 -g -include $(DEST_DIR_DEBUG)/AutoGen.h -c -fshort-wchar -fno-strict-aliasing
|
||||
XCODE:*_*_IA32_DLINK_FLAGS == -arch i386 -o $(BIN_DIR)/SecMain -L/usr/X11R6/lib -lXext -lX11 -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 -framework Carbon
|
||||
XCODE:*_*_X64_ASM_FLAGS == -g
|
||||
|
1028
EmulatorPkg/Unix/Host/X11GraphicsWindow.c
Normal file
1028
EmulatorPkg/Unix/Host/X11GraphicsWindow.c
Normal file
File diff suppressed because it is too large
Load Diff
1631
EmulatorPkg/Unix/Host/X64/Gasket.S
Normal file
1631
EmulatorPkg/Unix/Host/X64/Gasket.S
Normal file
File diff suppressed because it is too large
Load Diff
53
EmulatorPkg/Unix/Host/X64/SwitchStack.S
Normal file
53
EmulatorPkg/Unix/Host/X64/SwitchStack.S
Normal file
@@ -0,0 +1,53 @@
|
||||
#------------------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
|
||||
# Portitions copyright (c) 2011, Apple Inc. All rights reserved.
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php.
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Routine Description:
|
||||
#
|
||||
# Routine for switching stacks with 2 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) NewStack - The pointer to new stack.
|
||||
#
|
||||
# Returns:
|
||||
#
|
||||
# None
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
ASM_GLOBAL ASM_PFX(PeiSwitchStacks)
|
||||
ASM_PFX(PeiSwitchStacks):
|
||||
pushq $0 // tells gdb to stop unwinding frame
|
||||
movq %rsp, %rbp
|
||||
|
||||
movq %rcx, %rsp // update stack pointer
|
||||
|
||||
movq %rdi, %rax // entry point to %rax
|
||||
movq %rsi, %rcx // Adjust Context1
|
||||
// Context2 already in the rigth spot
|
||||
|
||||
#
|
||||
# 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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user