TianoCore EDK2 master
Loading...
Searching...
No Matches
EbcInt.c File Reference
#include "EbcInt.h"
#include "EbcExecute.h"
#include "EbcDebuggerHook.h"

Go to the source code of this file.

Data Structures

struct  _EBC_THUNK_LIST
 
struct  _EBC_IMAGE_LIST
 

Typedefs

typedef struct _EBC_THUNK_LIST EBC_THUNK_LIST
 
typedef struct _EBC_IMAGE_LIST EBC_IMAGE_LIST
 

Functions

EFI_STATUS EFIAPI EbcUnloadImage (IN EFI_EBC_PROTOCOL *This, IN EFI_HANDLE ImageHandle)
 
EFI_STATUS EFIAPI EbcCreateThunk (IN EFI_EBC_PROTOCOL *This, IN EFI_HANDLE ImageHandle, IN VOID *EbcEntryPoint, OUT VOID **Thunk)
 
EFI_STATUS EFIAPI EbcGetVersion (IN EFI_EBC_PROTOCOL *This, IN OUT UINT64 *Version)
 
EFI_STATUS EFIAPI InitializeEbcCallback (IN EFI_DEBUG_SUPPORT_PROTOCOL *This)
 
VOID EFIAPI CommonEbcExceptionHandler (IN EFI_EXCEPTION_TYPE InterruptType, IN EFI_SYSTEM_CONTEXT SystemContext)
 
VOID EFIAPI EbcPeriodicNotifyFunction (IN EFI_EVENT Event, IN VOID *Context)
 
EFI_STATUS EFIAPI EbcDebugPeriodic (IN VM_CONTEXT *VmPtr)
 
EFI_STATUS InitEbcVmTestProtocol (IN EFI_HANDLE *IHandle)
 
EFI_STATUS EFIAPI EbcVmTestUnsupported (VOID)
 
EFI_STATUS EFIAPI EbcRegisterICacheFlush (IN EFI_EBC_PROTOCOL *This, IN EBC_ICACHE_FLUSH Flush)
 
EFI_STATUS EFIAPI EbcDebugGetMaximumProcessorIndex (IN EFI_DEBUG_SUPPORT_PROTOCOL *This, OUT UINTN *MaxProcessorIndex)
 
EFI_STATUS EFIAPI EbcDebugRegisterPeriodicCallback (IN EFI_DEBUG_SUPPORT_PROTOCOL *This, IN UINTN ProcessorIndex, IN EFI_PERIODIC_CALLBACK PeriodicCallback)
 
EFI_STATUS EFIAPI EbcDebugRegisterExceptionCallback (IN EFI_DEBUG_SUPPORT_PROTOCOL *This, IN UINTN ProcessorIndex, IN EFI_EXCEPTION_CALLBACK ExceptionCallback, IN EFI_EXCEPTION_TYPE ExceptionType)
 
EFI_STATUS EFIAPI EbcDebugInvalidateInstructionCache (IN EFI_DEBUG_SUPPORT_PROTOCOL *This, IN UINTN ProcessorIndex, IN VOID *Start, IN UINT64 Length)
 
BOOLEAN EFIAPI EbcIsImageSupported (IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, IN UINT16 ImageType, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL)
 
EFI_STATUS EFIAPI EbcRegisterImage (IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS ImageBase, IN UINT64 ImageSize, IN OUT EFI_IMAGE_ENTRY_POINT *EntryPoint)
 
EFI_STATUS EFIAPI EbcUnregisterImage (IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS ImageBase)
 
EFI_STATUS EFIAPI InitializeEbcDriver (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 
EFI_STATUS EbcDebugSignalException (IN EFI_EXCEPTION_TYPE ExceptionType, IN EXCEPTION_FLAGS ExceptionFlags, IN VM_CONTEXT *VmPtr)
 
EFI_STATUS EbcAddImageThunk (IN EFI_HANDLE ImageHandle, IN VOID *ThunkBuffer, IN UINT32 ThunkSize)
 
EFI_STATUS GetEBCStack (IN EFI_HANDLE Handle, OUT VOID **StackBuffer, OUT UINTN *BufferIndex)
 
EFI_STATUS ReturnEBCStack (IN UINTN Index)
 
EFI_STATUS ReturnEBCStackByHandle (IN EFI_HANDLE Handle)
 
EFI_STATUS InitEBCStack (VOID)
 
EFI_STATUS FreeEBCStack (VOID)
 
VOID *EFIAPI EbcAllocatePoolForThunk (IN UINTN AllocationSize)
 

Variables

EBC_IMAGE_LISTmEbcImageList = NULL
 
EBC_ICACHE_FLUSH mEbcICacheFlush
 
EFI_PERIODIC_CALLBACK mDebugPeriodicCallback = NULL
 
EFI_EXCEPTION_CALLBACK mDebugExceptionCallback [MAX_EBC_EXCEPTION+1] = { NULL }
 
VOID * mStackBuffer [MAX_STACK_NUM]
 
EFI_HANDLE mStackBufferIndex [MAX_STACK_NUM]
 
UINTN mStackNum = 0
 
EFI_EVENT mEbcPeriodicEvent
 
VM_CONTEXTmVmPtr = NULL
 
STATIC EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL mPeCoffEmuProtocol
 

Detailed Description

Top level module for the EBC virtual machine implementation. Provides auxiliary support routines for the VM. That is, routines that are not particularly related to VM execution of EBC instructions.

Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file EbcInt.c.

Typedef Documentation

◆ EBC_IMAGE_LIST

Definition at line 27 of file EbcInt.c.

◆ EBC_THUNK_LIST

Definition at line 21 of file EbcInt.c.

Function Documentation

◆ CommonEbcExceptionHandler()

VOID EFIAPI CommonEbcExceptionHandler ( IN EFI_EXCEPTION_TYPE  InterruptType,
IN EFI_SYSTEM_CONTEXT  SystemContext 
)

The default Exception Callback for the VM interpreter. In this function, we report status code, and print debug information about EBC_CONTEXT, then dead loop.

Parameters
InterruptTypeInterrupt type.
SystemContextEBC system context.

Definition at line 993 of file EbcInt.c.

◆ EbcAddImageThunk()

EFI_STATUS EbcAddImageThunk ( IN EFI_HANDLE  ImageHandle,
IN VOID *  ThunkBuffer,
IN UINT32  ThunkSize 
)

Add a thunk to our list of thunks for a given image handle. Also flush the instruction cache since we've written thunk code to memory that will be executed eventually.

Parameters
ImageHandleThe image handle to which the thunk is tied.
ThunkBufferThe buffer that has been created/allocated.
ThunkSizeThe size of the thunk memory allocated.
Return values
EFI_OUT_OF_RESOURCESMemory allocation failed.
EFI_SUCCESSThe function completed successfully.

Definition at line 1239 of file EbcInt.c.

◆ EbcAllocatePoolForThunk()

VOID *EFIAPI EbcAllocatePoolForThunk ( IN UINTN  AllocationSize)

Allocates a buffer of type EfiBootServicesCode.

Parameters
AllocationSizeThe number of bytes to allocate.
Returns
A pointer to the allocated buffer or NULL if allocation fails.

Definition at line 1554 of file EbcInt.c.

◆ EbcCreateThunk()

EFI_STATUS EFIAPI EbcCreateThunk ( IN EFI_EBC_PROTOCOL This,
IN EFI_HANDLE  ImageHandle,
IN VOID *  EbcEntryPoint,
OUT VOID **  Thunk 
)

This is the top-level routine plugged into the EBC protocol. Since thunks are very processor-specific, from here we dispatch directly to the very processor-specific routine EbcCreateThunks().

Parameters
ThisA pointer to the EFI_EBC_PROTOCOL instance.
ImageHandleHandle of image for which the thunk is being created. The EBC interpreter may use this to keep track of any resource allocations performed in loading and executing the image.
EbcEntryPointAddress of the actual EBC entry point or protocol service the thunk should call.
ThunkReturned pointer to a thunk created.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERImage entry point is not 2-byte aligned.
EFI_OUT_OF_RESOURCESMemory could not be allocated for the thunk.

Definition at line 689 of file EbcInt.c.

◆ EbcDebugGetMaximumProcessorIndex()

EFI_STATUS EFIAPI EbcDebugGetMaximumProcessorIndex ( IN EFI_DEBUG_SUPPORT_PROTOCOL This,
OUT UINTN MaxProcessorIndex 
)

This EBC debugger protocol service is called by the debug agent

Parameters
ThisA pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
MaxProcessorIndexPointer to a caller-allocated UINTN in which the maximum supported processor index is returned.
Return values
EFI_SUCCESSThe function completed successfully.

Definition at line 720 of file EbcInt.c.

◆ EbcDebugInvalidateInstructionCache()

EFI_STATUS EFIAPI EbcDebugInvalidateInstructionCache ( IN EFI_DEBUG_SUPPORT_PROTOCOL This,
IN UINTN  ProcessorIndex,
IN VOID *  Start,
IN UINT64  Length 
)

This EBC debugger protocol service is called by the debug agent. Required for DebugSupport compliance but is only stubbed out for EBC.

Parameters
ThisA pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
ProcessorIndexSpecifies which processor the callback function applies to.
StartStartSpecifies the physical base of the memory range to be invalidated.
LengthSpecifies the minimum number of bytes in the processor's instruction cache to invalidate.
Return values
EFI_SUCCESSThe function completed successfully.

Definition at line 838 of file EbcInt.c.

◆ EbcDebugPeriodic()

EFI_STATUS EFIAPI EbcDebugPeriodic ( IN VM_CONTEXT VmPtr)

The VM interpreter calls this function on a periodic basis to support the EFI debug support protocol.

Parameters
VmPtrPointer to a VM context for passing info to the debugger.
Return values
EFI_SUCCESSThe function completed successfully.

Definition at line 1097 of file EbcInt.c.

◆ EbcDebugRegisterExceptionCallback()

EFI_STATUS EFIAPI EbcDebugRegisterExceptionCallback ( IN EFI_DEBUG_SUPPORT_PROTOCOL This,
IN UINTN  ProcessorIndex,
IN EFI_EXCEPTION_CALLBACK  ExceptionCallback,
IN EFI_EXCEPTION_TYPE  ExceptionType 
)

This protocol service is called by the debug agent to register a function for us to call when we detect an exception.

Parameters
ThisA pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
ProcessorIndexSpecifies which processor the callback function applies to.
ExceptionCallbackA pointer to a function of type EXCEPTION_CALLBACK that is called when the processor exception specified by ExceptionType occurs. Passing NULL unregisters any previously registered function associated with ExceptionType.
ExceptionTypeSpecifies which processor exception to hook.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_ALREADY_STARTEDNon-NULL ExceptionCallback parameter when a callback function was previously registered.
EFI_INVALID_PARAMETERExceptionType parameter is negative or exceeds MAX_EBC_EXCEPTION.
EFI_INVALID_PARAMETERNull ExceptionCallback parameter when no callback function was previously registered.

Definition at line 797 of file EbcInt.c.

◆ EbcDebugRegisterPeriodicCallback()

EFI_STATUS EFIAPI EbcDebugRegisterPeriodicCallback ( IN EFI_DEBUG_SUPPORT_PROTOCOL This,
IN UINTN  ProcessorIndex,
IN EFI_PERIODIC_CALLBACK  PeriodicCallback 
)

This protocol service is called by the debug agent to register a function for us to call on a periodic basis.

Parameters
ThisA pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
ProcessorIndexSpecifies which processor the callback function applies to.
PeriodicCallbackA pointer to a function of type PERIODIC_CALLBACK that is the main periodic entry point of the debug agent. It receives as a parameter a pointer to the full context of the interrupted execution thread.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_ALREADY_STARTEDNon-NULL PeriodicCallback parameter when a callback function was previously registered.
EFI_INVALID_PARAMETERNull PeriodicCallback parameter when no callback function was previously registered.

Definition at line 752 of file EbcInt.c.

◆ EbcDebugSignalException()

EFI_STATUS EbcDebugSignalException ( IN EFI_EXCEPTION_TYPE  ExceptionType,
IN EXCEPTION_FLAGS  ExceptionFlags,
IN VM_CONTEXT VmPtr 
)

The VM interpreter calls this function when an exception is detected.

Parameters
ExceptionTypeSpecifies the processor exception detected.
ExceptionFlagsSpecifies the exception context.
VmPtrPointer to a VM context for passing info to the EFI debugger.
Return values
EFI_SUCCESSThis function completed successfully.

Definition at line 860 of file EbcInt.c.

◆ EbcGetVersion()

EFI_STATUS EFIAPI EbcGetVersion ( IN EFI_EBC_PROTOCOL This,
IN OUT UINT64 *  Version 
)

Called to get the version of the interpreter.

Parameters
ThisA pointer to the EFI_EBC_PROTOCOL instance.
VersionPointer to where to store the returned version of the interpreter.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERVersion pointer is NULL.

Definition at line 1337 of file EbcInt.c.

◆ EbcIsImageSupported()

BOOLEAN EFIAPI EbcIsImageSupported ( IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL This,
IN UINT16  ImageType,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath  OPTIONAL 
)

Check whether the emulator supports executing a certain PE/COFF image

Parameters
[in]ThisThis pointer for EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL structure
[in]ImageTypeWhether the image is an application, a boot time driver or a runtime driver.
[in]DevicePathPath to device where the image originated (e.g., a PCI option ROM)
Return values
TRUEThe image is supported by the emulator
FALSEThe image is not supported by the emulator.

Definition at line 362 of file EbcInt.c.

◆ EbcPeriodicNotifyFunction()

VOID EFIAPI EbcPeriodicNotifyFunction ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

The periodic callback function for EBC VM interpreter, which is used to support the EFI debug support protocol.

Parameters
EventThe Periodic Callback Event.
ContextIt should be the address of VM_CONTEXT pointer.

Definition at line 1069 of file EbcInt.c.

◆ EbcRegisterICacheFlush()

EFI_STATUS EFIAPI EbcRegisterICacheFlush ( IN EFI_EBC_PROTOCOL This,
IN EBC_ICACHE_FLUSH  Flush 
)

Registers a callback function that the EBC interpreter calls to flush the processor instruction cache following creation of thunks.

Parameters
ThisA pointer to the EFI_EBC_PROTOCOL instance.
FlushPointer to a function of type EBC_ICACH_FLUSH.
Return values
EFI_SUCCESSThe function completed successfully.

Definition at line 1315 of file EbcInt.c.

◆ EbcRegisterImage()

EFI_STATUS EFIAPI EbcRegisterImage ( IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL This,
IN EFI_PHYSICAL_ADDRESS  ImageBase,
IN UINT64  ImageSize,
IN OUT EFI_IMAGE_ENTRY_POINT EntryPoint 
)

Register a supported PE/COFF image with the emulator. After this call completes successfully, the PE/COFF image may be started as usual, and it is the responsibility of the emulator implementation that any branch into the code section of the image (including returns from functions called from the foreign code) is executed as if it were running on the machine type it was built for.

Parameters
[in]ThisThis pointer for EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL structure
[in]ImageBaseThe base address in memory of the PE/COFF image
[in]ImageSizeThe size in memory of the PE/COFF image
[in,out]EntryPointThe entry point of the PE/COFF image. Passed by reference so that the emulator may modify it.
Return values
EFI_SUCCESSThe image was registered with the emulator and can be started as usual.
otherThe image could not be registered.

If the PE/COFF machine type or image type are not supported by the emulator, then ASSERT().

Definition at line 401 of file EbcInt.c.

◆ EbcUnloadImage()

EFI_STATUS EFIAPI EbcUnloadImage ( IN EFI_EBC_PROTOCOL This,
IN EFI_HANDLE  ImageHandle 
)

This routine is called by the core when an image is being unloaded from memory. Basically we now have the opportunity to do any necessary cleanup. Typically this will include freeing any memory allocated for thunk-creation.

Parameters
ThisA pointer to the EFI_EBC_PROTOCOL instance.
ImageHandleHandle of image for which the thunk is being created.
Return values
EFI_INVALID_PARAMETERThe ImageHandle passed in was not found in the internal list of EBC image handles.
EFI_SUCCESSThe function completed successfully.

Definition at line 1160 of file EbcInt.c.

◆ EbcUnregisterImage()

EFI_STATUS EFIAPI EbcUnregisterImage ( IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL This,
IN EFI_PHYSICAL_ADDRESS  ImageBase 
)

Unregister a PE/COFF image that has been registered with the emulator. This should be done before the image is unloaded from memory.

Parameters
[in]ThisThis pointer for EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL structure
[in]ImageBaseThe base address in memory of the PE/COFF image
Return values
EFI_SUCCESSThe image was unregistered with the emulator.
otherImage could not be unloaded.

Definition at line 455 of file EbcInt.c.

◆ EbcVmTestUnsupported()

EFI_STATUS EFIAPI EbcVmTestUnsupported ( VOID  )

Returns the EFI_UNSUPPORTED Status.

Returns
EFI_UNSUPPORTED This function always return EFI_UNSUPPORTED status.

Definition at line 1537 of file EbcInt.c.

◆ FreeEBCStack()

EFI_STATUS FreeEBCStack ( VOID  )

Free all EBC stacks allocated before.

Return values
EFI_SUCCESSAll the EBC stacks were freed.

Definition at line 1471 of file EbcInt.c.

◆ GetEBCStack()

EFI_STATUS GetEBCStack ( IN EFI_HANDLE  Handle,
OUT VOID **  StackBuffer,
OUT UINTN BufferIndex 
)

Returns the stack index and buffer assosicated with the Handle parameter.

Parameters
HandleThe EFI handle as the index to the EBC stack.
StackBufferA pointer to hold the returned stack buffer.
BufferIndexA pointer to hold the returned stack index.
Return values
EFI_OUT_OF_RESOURCESThe Handle parameter does not correspond to any existing EBC stack.
EFI_SUCCESSThe stack index and buffer were found and returned to the caller.

Definition at line 1364 of file EbcInt.c.

◆ InitEBCStack()

EFI_STATUS InitEBCStack ( VOID  )

Allocates memory to hold all the EBC stacks.

Return values
EFI_SUCCESSThe EBC stacks were allocated successfully.
EFI_OUT_OF_RESOURCESNot enough memory available for EBC stacks.

Definition at line 1445 of file EbcInt.c.

◆ InitEbcVmTestProtocol()

EFI_STATUS InitEbcVmTestProtocol ( IN EFI_HANDLE IHandle)

Produces an EBC VM test protocol that can be used for regression tests.

Parameters
IHandleHandle on which to install the protocol.
Return values
EFI_OUT_OF_RESOURCESMemory allocation failed.
EFI_SUCCESSThe function completed successfully.

Definition at line 1494 of file EbcInt.c.

◆ InitializeEbcCallback()

EFI_STATUS EFIAPI InitializeEbcCallback ( IN EFI_DEBUG_SUPPORT_PROTOCOL This)

To install default Callback function for the VM interpreter.

Parameters
ThisA pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
Return values
EFI_SUCCESSThe function completed successfully.
OthersSome error occurs when creating periodic event.

Definition at line 937 of file EbcInt.c.

◆ InitializeEbcDriver()

EFI_STATUS EFIAPI InitializeEbcDriver ( IN EFI_HANDLE  ImageHandle,
IN EFI_SYSTEM_TABLE SystemTable 
)

Initializes the VM EFI interface. Allocates memory for the VM interface and registers the VM protocol.

Parameters
ImageHandleEFI image handle.
SystemTablePointer to the EFI system table.
Returns
Standard EFI status code.

Definition at line 483 of file EbcInt.c.

◆ ReturnEBCStack()

EFI_STATUS ReturnEBCStack ( IN UINTN  Index)

Returns from the EBC stack by stack Index.

Parameters
IndexSpecifies which EBC stack to return from.
Return values
EFI_SUCCESSThe function completed successfully.

Definition at line 1400 of file EbcInt.c.

◆ ReturnEBCStackByHandle()

EFI_STATUS ReturnEBCStackByHandle ( IN EFI_HANDLE  Handle)

Returns from the EBC stack associated with the Handle parameter.

Parameters
HandleSpecifies the EFI handle to find the EBC stack with.
Return values
EFI_SUCCESSThe function completed successfully.

Definition at line 1417 of file EbcInt.c.

Variable Documentation

◆ mDebugExceptionCallback

EFI_EXCEPTION_CALLBACK mDebugExceptionCallback[MAX_EBC_EXCEPTION+1] = { NULL }

Definition at line 335 of file EbcInt.c.

◆ mDebugPeriodicCallback

EFI_PERIODIC_CALLBACK mDebugPeriodicCallback = NULL

Definition at line 334 of file EbcInt.c.

◆ mEbcICacheFlush

EBC_ICACHE_FLUSH mEbcICacheFlush

Definition at line 329 of file EbcInt.c.

◆ mEbcImageList

EBC_IMAGE_LIST* mEbcImageList = NULL

Definition at line 324 of file EbcInt.c.

◆ mEbcPeriodicEvent

EFI_EVENT mEbcPeriodicEvent

Definition at line 344 of file EbcInt.c.

◆ mPeCoffEmuProtocol

Initial value:
= {
EDKII_PECOFF_IMAGE_EMULATOR_VERSION,
}
EFI_STATUS EFIAPI EbcRegisterImage(IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS ImageBase, IN UINT64 ImageSize, IN OUT EFI_IMAGE_ENTRY_POINT *EntryPoint)
Definition: EbcInt.c:401
EFI_STATUS EFIAPI EbcUnregisterImage(IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS ImageBase)
Definition: EbcInt.c:455
BOOLEAN EFIAPI EbcIsImageSupported(IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, IN UINT16 ImageType, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL)
Definition: EbcInt.c:362
#define EFI_IMAGE_MACHINE_EBC
Definition: UefiBaseType.h:228

Definition at line 463 of file EbcInt.c.

◆ mStackBuffer

VOID* mStackBuffer[MAX_STACK_NUM]

Definition at line 337 of file EbcInt.c.

◆ mStackBufferIndex

EFI_HANDLE mStackBufferIndex[MAX_STACK_NUM]

Definition at line 338 of file EbcInt.c.

◆ mStackNum

UINTN mStackNum = 0

Definition at line 339 of file EbcInt.c.

◆ mVmPtr

VM_CONTEXT* mVmPtr = NULL

Definition at line 345 of file EbcInt.c.