Path: blob/main/sys/contrib/edk2/Include/Protocol/Ebc.h
96339 views
/** @file1Describes the protocol interface to the EBC interpreter.23Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>4SPDX-License-Identifier: BSD-2-Clause-Patent56**/78#ifndef __EFI_EBC_PROTOCOL_H__9#define __EFI_EBC_PROTOCOL_H__1011#define EFI_EBC_INTERPRETER_PROTOCOL_GUID \12{ \130x13AC6DD1, 0x73D0, 0x11D4, {0xB0, 0x6B, 0x00, 0xAA, 0x00, 0xBD, 0x6D, 0xE7 } \14}1516//17// Define OPCODES18//19#define OPCODE_BREAK 0x0020#define OPCODE_JMP 0x0121#define OPCODE_JMP8 0x0222#define OPCODE_CALL 0x0323#define OPCODE_RET 0x0424#define OPCODE_CMPEQ 0x0525#define OPCODE_CMPLTE 0x0626#define OPCODE_CMPGTE 0x0727#define OPCODE_CMPULTE 0x0828#define OPCODE_CMPUGTE 0x0929#define OPCODE_NOT 0x0A30#define OPCODE_NEG 0x0B31#define OPCODE_ADD 0x0C32#define OPCODE_SUB 0x0D33#define OPCODE_MUL 0x0E34#define OPCODE_MULU 0x0F35#define OPCODE_DIV 0x1036#define OPCODE_DIVU 0x1137#define OPCODE_MOD 0x1238#define OPCODE_MODU 0x1339#define OPCODE_AND 0x1440#define OPCODE_OR 0x1541#define OPCODE_XOR 0x1642#define OPCODE_SHL 0x1743#define OPCODE_SHR 0x1844#define OPCODE_ASHR 0x1945#define OPCODE_EXTNDB 0x1A46#define OPCODE_EXTNDW 0x1B47#define OPCODE_EXTNDD 0x1C48#define OPCODE_MOVBW 0x1D49#define OPCODE_MOVWW 0x1E50#define OPCODE_MOVDW 0x1F51#define OPCODE_MOVQW 0x2052#define OPCODE_MOVBD 0x2153#define OPCODE_MOVWD 0x2254#define OPCODE_MOVDD 0x2355#define OPCODE_MOVQD 0x2456#define OPCODE_MOVSNW 0x25 // Move signed natural with word index57#define OPCODE_MOVSND 0x26 // Move signed natural with dword index58//59// #define OPCODE_27 0x2760//61#define OPCODE_MOVQQ 0x28 // Does this go away?62#define OPCODE_LOADSP 0x2963#define OPCODE_STORESP 0x2A64#define OPCODE_PUSH 0x2B65#define OPCODE_POP 0x2C66#define OPCODE_CMPIEQ 0x2D67#define OPCODE_CMPILTE 0x2E68#define OPCODE_CMPIGTE 0x2F69#define OPCODE_CMPIULTE 0x3070#define OPCODE_CMPIUGTE 0x3171#define OPCODE_MOVNW 0x3272#define OPCODE_MOVND 0x3373//74// #define OPCODE_34 0x3475//76#define OPCODE_PUSHN 0x3577#define OPCODE_POPN 0x3678#define OPCODE_MOVI 0x3779#define OPCODE_MOVIN 0x3880#define OPCODE_MOVREL 0x398182//83// Bit masks for opcode encodings84//85#define OPCODE_M_OPCODE 0x3F // bits of interest for first level decode86#define OPCODE_M_IMMDATA 0x8087#define OPCODE_M_IMMDATA64 0x4088#define OPCODE_M_64BIT 0x40 // for CMP89#define OPCODE_M_RELADDR 0x10 // for CALL instruction90#define OPCODE_M_CMPI32_DATA 0x80 // for CMPI91#define OPCODE_M_CMPI64 0x40 // for CMPI 32 or 64 bit comparison92#define OPERAND_M_MOVIN_N 0x8093#define OPERAND_M_CMPI_INDEX 0x109495//96// Masks for instructions that encode presence of indexes for operand1 and/or97// operand2.98//99#define OPCODE_M_IMMED_OP1 0x80100#define OPCODE_M_IMMED_OP2 0x40101102//103// Bit masks for operand encodings104//105#define OPERAND_M_INDIRECT1 0x08106#define OPERAND_M_INDIRECT2 0x80107#define OPERAND_M_OP1 0x07108#define OPERAND_M_OP2 0x70109110//111// Masks for data manipulation instructions112//113#define DATAMANIP_M_64 0x40 // 64-bit width operation114#define DATAMANIP_M_IMMDATA 0x80115116//117// For MOV instructions, need a mask for the opcode when immediate118// data applies to R2.119//120#define OPCODE_M_IMMED_OP2 0x40121122//123// The MOVI/MOVIn instructions use bit 6 of operands byte to indicate124// if an index is present. Then bits 4 and 5 are used to indicate the width125// of the move.126//127#define MOVI_M_IMMDATA 0x40128#define MOVI_M_DATAWIDTH 0xC0129#define MOVI_DATAWIDTH16 0x40130#define MOVI_DATAWIDTH32 0x80131#define MOVI_DATAWIDTH64 0xC0132#define MOVI_M_MOVEWIDTH 0x30133#define MOVI_MOVEWIDTH8 0x00134#define MOVI_MOVEWIDTH16 0x10135#define MOVI_MOVEWIDTH32 0x20136#define MOVI_MOVEWIDTH64 0x30137138//139// Masks for CALL instruction encodings140//141#define OPERAND_M_RELATIVE_ADDR 0x10142#define OPERAND_M_NATIVE_CALL 0x20143144//145// Masks for decoding push/pop instructions146//147#define PUSHPOP_M_IMMDATA 0x80 // opcode bit indicating immediate data148#define PUSHPOP_M_64 0x40 // opcode bit indicating 64-bit operation149//150// Mask for operand of JMP instruction151//152#define JMP_M_RELATIVE 0x10153#define JMP_M_CONDITIONAL 0x80154#define JMP_M_CS 0x40155156//157// Macros to determine if a given operand is indirect158//159#define OPERAND1_INDIRECT(op) ((op) & OPERAND_M_INDIRECT1)160#define OPERAND2_INDIRECT(op) ((op) & OPERAND_M_INDIRECT2)161162//163// Macros to extract the operands from second byte of instructions164//165#define OPERAND1_REGNUM(op) ((op) & OPERAND_M_OP1)166#define OPERAND2_REGNUM(op) (((op) & OPERAND_M_OP2) >> 4)167168#define OPERAND1_CHAR(op) ('0' + OPERAND1_REGNUM (op))169#define OPERAND2_CHAR(op) ('0' + OPERAND2_REGNUM (op))170171//172// Condition masks usually for byte 1 encodings of code173//174#define CONDITION_M_CONDITIONAL 0x80175#define CONDITION_M_CS 0x40176177///178/// Protocol Guid Name defined in spec.179///180#define EFI_EBC_PROTOCOL_GUID EFI_EBC_INTERPRETER_PROTOCOL_GUID181182///183/// Define for forward reference.184///185typedef struct _EFI_EBC_PROTOCOL EFI_EBC_PROTOCOL;186187/**188Creates a thunk for an EBC entry point, returning the address of the thunk.189190A PE32+ EBC image, like any other PE32+ image, contains an optional header that specifies the191entry point for image execution. However, for EBC images, this is the entry point of EBC192instructions, so is not directly executable by the native processor. Therefore, when an EBC image is193loaded, the loader must call this service to get a pointer to native code (thunk) that can be executed,194which will invoke the interpreter to begin execution at the original EBC entry point.195196@param This A pointer to the EFI_EBC_PROTOCOL instance.197@param ImageHandle Handle of image for which the thunk is being created.198@param EbcEntryPoint Address of the actual EBC entry point or protocol service the thunk should call.199@param Thunk Returned pointer to a thunk created.200201@retval EFI_SUCCESS The function completed successfully.202@retval EFI_INVALID_PARAMETER Image entry point is not 2-byte aligned.203@retval EFI_OUT_OF_RESOURCES Memory could not be allocated for the thunk.204**/205typedef206EFI_STATUS207(EFIAPI *EFI_EBC_CREATE_THUNK)(208IN EFI_EBC_PROTOCOL *This,209IN EFI_HANDLE ImageHandle,210IN VOID *EbcEntryPoint,211OUT VOID **Thunk212);213214/**215Called prior to unloading an EBC image from memory.216217This function is called after an EBC image has exited, but before the image is actually unloaded. It218is intended to provide the interpreter with the opportunity to perform any cleanup that may be219necessary as a result of loading and executing the image.220221@param This A pointer to the EFI_EBC_PROTOCOL instance.222@param ImageHandle Image handle of the EBC image that is being unloaded from memory.223224@retval EFI_SUCCESS The function completed successfully.225@retval EFI_INVALID_PARAMETER Image handle is not recognized as belonging226to an EBC image that has been executed.227**/228typedef229EFI_STATUS230(EFIAPI *EFI_EBC_UNLOAD_IMAGE)(231IN EFI_EBC_PROTOCOL *This,232IN EFI_HANDLE ImageHandle233);234235/**236This is the prototype for the Flush callback routine. A pointer to a routine237of this type is passed to the EBC EFI_EBC_REGISTER_ICACHE_FLUSH protocol service.238239@param Start The beginning physical address to flush from the processor's instruction cache.240@param Length The number of bytes to flush from the processor's instruction cache.241242@retval EFI_SUCCESS The function completed successfully.243244**/245typedef246EFI_STATUS247(EFIAPI *EBC_ICACHE_FLUSH)(248IN EFI_PHYSICAL_ADDRESS Start,249IN UINT64 Length250);251252/**253Registers a callback function that the EBC interpreter calls to flush254the processor instruction cache following creation of thunks.255256@param This A pointer to the EFI_EBC_PROTOCOL instance.257@param Flush Pointer to a function of type EBC_ICACH_FLUSH.258259@retval EFI_SUCCESS The function completed successfully.260261**/262typedef263EFI_STATUS264(EFIAPI *EFI_EBC_REGISTER_ICACHE_FLUSH)(265IN EFI_EBC_PROTOCOL *This,266IN EBC_ICACHE_FLUSH Flush267);268269/**270Called to get the version of the interpreter.271272This function is called to get the version of the loaded EBC interpreter. The value and format of the273returned version is identical to that returned by the EBC BREAK 1 instruction.274275@param This A pointer to the EFI_EBC_PROTOCOL instance.276@param Version Pointer to where to store the returned version of the interpreter.277278@retval EFI_SUCCESS The function completed successfully.279@retval EFI_INVALID_PARAMETER Version pointer is NULL.280281**/282typedef283EFI_STATUS284(EFIAPI *EFI_EBC_GET_VERSION)(285IN EFI_EBC_PROTOCOL *This,286IN OUT UINT64 *Version287);288289///290/// The EFI EBC protocol provides services to load and execute EBC images, which will typically be291/// loaded into option ROMs. The image loader will load the EBC image, perform standard relocations,292/// and invoke the CreateThunk() service to create a thunk for the EBC image's entry point. The293/// image can then be run using the standard EFI start image services.294///295struct _EFI_EBC_PROTOCOL {296EFI_EBC_CREATE_THUNK CreateThunk;297EFI_EBC_UNLOAD_IMAGE UnloadImage;298EFI_EBC_REGISTER_ICACHE_FLUSH RegisterICacheFlush;299EFI_EBC_GET_VERSION GetVersion;300};301302//303// Extern the global EBC protocol GUID304//305extern EFI_GUID gEfiEbcProtocolGuid;306307#endif308309310