TianoCore EDK2 master
Loading...
Searching...
No Matches
EbcInt.h File Reference

Go to the source code of this file.

Data Structures

struct  EFI_EBC_THUNK_DATA
 

Macros

#define FLAG_THUNK_ENTRY_POINT   0x01
 
#define FLAG_THUNK_PROTOCOL   0x00
 
#define VM_STACK_KEY_VALUE   0xDEADBEEF
 
#define EFI_TIMER_UNIT_1MS   (1000 * 10)
 
#define EBC_VM_PERIODIC_CALLBACK_RATE   (1000 * EFI_TIMER_UNIT_1MS)
 
#define STACK_POOL_SIZE   (1024 * 1020)
 
#define MAX_STACK_NUM   4
 
#define EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE   SIGNATURE_32 ('e', 'b', 'c', 'p')
 
#define EBC_PROTOCOL_PRIVATE_DATA_FROM_THIS(a)    CR(a, EBC_PROTOCOL_PRIVATE_DATA, EbcProtocol, EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE)
 

Functions

EFI_STATUS EbcCreateThunks (IN EFI_HANDLE ImageHandle, IN VOID *EbcEntryPoint, OUT VOID **Thunk, IN UINT32 Flags)
 
EFI_STATUS EbcAddImageThunk (IN EFI_HANDLE ImageHandle, IN VOID *ThunkBuffer, IN UINT32 ThunkSize)
 
UINTN EFIAPI EbcLLGetEbcEntryPoint (VOID)
 
INT64 EFIAPI EbcLLCALLEXNative (IN UINTN CallAddr, IN UINTN EbcSp, IN VOID *FramePtr)
 
VOID EbcLLCALLEX (IN VM_CONTEXT *VmPtr, IN UINTN FuncAddr, IN UINTN NewStackPointer, IN VOID *FramePtr, IN UINT8 Size)
 
EFI_STATUS GetEBCStack (IN EFI_HANDLE Handle, OUT VOID **StackBuffer, OUT UINTN *BufferIndex)
 
EFI_STATUS ReturnEBCStack (IN UINTN Index)
 
EFI_STATUS InitEBCStack (VOID)
 
EFI_STATUS FreeEBCStack (VOID)
 
EFI_STATUS ReturnEBCStackByHandle (IN EFI_HANDLE Handle)
 
VOID *EFIAPI EbcAllocatePoolForThunk (IN UINTN AllocationSize)
 

Variables

VM_CONTEXTmVmPtr
 

Detailed Description

Main routines for the EBC interpreter. Includes the initialization and main interpreter routines.

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

Definition in file EbcInt.h.

Macro Definition Documentation

◆ EBC_PROTOCOL_PRIVATE_DATA_FROM_THIS

#define EBC_PROTOCOL_PRIVATE_DATA_FROM_THIS (   a)     CR(a, EBC_PROTOCOL_PRIVATE_DATA, EbcProtocol, EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE)

Definition at line 241 of file EbcInt.h.

◆ EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE

#define EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE   SIGNATURE_32 ('e', 'b', 'c', 'p')

Definition at line 239 of file EbcInt.h.

◆ EBC_VM_PERIODIC_CALLBACK_RATE

#define EBC_VM_PERIODIC_CALLBACK_RATE   (1000 * EFI_TIMER_UNIT_1MS)

Definition at line 93 of file EbcInt.h.

◆ EFI_TIMER_UNIT_1MS

#define EFI_TIMER_UNIT_1MS   (1000 * 10)

Definition at line 92 of file EbcInt.h.

◆ FLAG_THUNK_ENTRY_POINT

#define FLAG_THUNK_ENTRY_POINT   0x01

Definition at line 35 of file EbcInt.h.

◆ FLAG_THUNK_PROTOCOL

#define FLAG_THUNK_PROTOCOL   0x00

Definition at line 36 of file EbcInt.h.

◆ MAX_STACK_NUM

#define MAX_STACK_NUM   4

Definition at line 95 of file EbcInt.h.

◆ STACK_POOL_SIZE

#define STACK_POOL_SIZE   (1024 * 1020)

Definition at line 94 of file EbcInt.h.

◆ VM_STACK_KEY_VALUE

#define VM_STACK_KEY_VALUE   0xDEADBEEF

Definition at line 41 of file EbcInt.h.

Function Documentation

◆ 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.

◆ EbcCreateThunks()

EFI_STATUS EbcCreateThunks ( IN EFI_HANDLE  ImageHandle,
IN VOID *  EbcEntryPoint,
OUT VOID **  Thunk,
IN UINT32  Flags 
)

Create thunks for an EBC image entry point, or an EBC protocol service.

Parameters
ImageHandleImage handle for the EBC image. If not null, then we're creating a thunk for an image entry point.
EbcEntryPointAddress of the EBC code that the thunk is to call
ThunkReturned thunk we create here
FlagsFlags indicating options for creating the thunk
Return values
EFI_SUCCESSThe thunk was created successfully.
EFI_INVALID_PARAMETERThe parameter of EbcEntryPoint is not 16-bit aligned.
EFI_OUT_OF_RESOURCESThere is not enough memory to created the EBC Thunk.
EFI_BUFFER_TOO_SMALLEBC_THUNK_SIZE is not larger enough.

Definition at line 362 of file EbcSupport.c.

◆ EbcLLCALLEX()

VOID EbcLLCALLEX ( IN VM_CONTEXT VmPtr,
IN UINTN  FuncAddr,
IN UINTN  NewStackPointer,
IN VOID *  FramePtr,
IN UINT8  Size 
)

This function is called to execute an EBC CALLEX instruction. The function check the callee's content to see whether it is common native code or a thunk to another piece of EBC code. If the callee is common native code, use EbcLLCAllEXASM to manipulate, otherwise, set the VM->IP to target EBC code directly to avoid another VM be startup which cost time and stack space.

Parameters
VmPtrPointer to a VM context.
FuncAddrCallee's address
NewStackPointerNew stack pointer after the call
FramePtrNew frame pointer after the call
SizeThe size of call instruction

Definition at line 436 of file EbcSupport.c.

◆ EbcLLCALLEXNative()

INT64 EFIAPI EbcLLCALLEXNative ( IN UINTN  CallAddr,
IN UINTN  EbcSp,
IN VOID *  FramePtr 
)

This function is called to execute an EBC CALLEX instruction. This instruction requires that we thunk out to external native code. For x64, we switch stacks, copy the arguments to the stack and jump to the specified function. On return, we restore the stack pointer to its original location. Destroys no working registers.

Parameters
CallAddrThe function address.
EbcSpThe new EBC stack pointer.
FramePtrThe frame pointer.
Returns
The unmodified value returned by the native code.

◆ EbcLLGetEbcEntryPoint()

UINTN EFIAPI EbcLLGetEbcEntryPoint ( VOID  )

The VM thunk code stuffs an EBC entry point into a processor register. Since we can't use inline assembly to get it from the interpreter C code, stuff it into the return value register and return.

Returns
The contents of the register in which the entry point is passed.

◆ 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.

◆ 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

◆ mVmPtr

VM_CONTEXT* mVmPtr
extern

Definition at line 345 of file EbcInt.c.