2 EBC VM Test protocol for test purposes.
4 Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef _EBC_VM_TEST_PROTOCOL_H_
11 #define _EBC_VM_TEST_PROTOCOL_H_
14 // Define a protocol for an EBC VM test interface.
16 #define EFI_EBC_VM_TEST_PROTOCOL_GUID \
18 0xAAEACCFD, 0xF27B, 0x4C17, { 0xB6, 0x10, 0x75, 0xCA, 0x1F, 0x2D, 0xFB, 0x52 } \
22 // Define for forward reference.
24 typedef struct _EFI_EBC_VM_TEST_PROTOCOL EFI_EBC_VM_TEST_PROTOCOL
;
27 // VM major/minor version
29 #define VM_MAJOR_VERSION 1
30 #define VM_MINOR_VERSION 0
33 // Bits in the VM->StopFlags field
35 #define STOPFLAG_APP_DONE 0x0001
36 #define STOPFLAG_BREAKPOINT 0x0002
37 #define STOPFLAG_INVALID_BREAK 0x0004
38 #define STOPFLAG_BREAK_ON_CALLEX 0x0008
41 // Masks for working with the VM flags register
43 #define VMFLAGS_CC 0x0001 // condition flag
44 #define VMFLAGS_STEP 0x0002 // step instruction mode
45 #define VMFLAGS_ALL_VALID (VMFLAGS_CC | VMFLAGS_STEP)
48 // Macros for operating on the VM flags register
50 #define VMFLAG_SET(pVM, Flag) (pVM->Flags |= (Flag))
51 #define VMFLAG_ISSET(pVM, Flag) ((pVM->Flags & (Flag)) ? 1 : 0)
52 #define VMFLAG_CLEAR(pVM, Flag) (pVM->Flags &= ~(Flag))
55 // Define a macro to get the operand. Then we can change it to be either a
56 // direct read or have it call a function to read memory.
58 #define GETOPERANDS(pVM) (UINT8) (*(UINT8 *) (pVM->Ip + 1))
59 #define GETOPCODE(pVM) (UINT8) (*(UINT8 *) pVM->Ip)
62 // Macros for operating on the VM GP registers
64 #define OPERAND1_REGDATA(pVM, Op) pVM->Gpr[OPERAND1_REGNUM (Op)]
65 #define OPERAND2_REGDATA(pVM, Op) pVM->Gpr[OPERAND2_REGNUM (Op)]
68 // Bits of exception flags field of VM context
70 #define EXCEPTION_FLAG_FATAL 0x80000000 // can't continue
71 #define EXCEPTION_FLAG_ERROR 0x40000000 // bad, but try to continue
72 #define EXCEPTION_FLAG_WARNING 0x20000000 // harmless problem
73 #define EXCEPTION_FLAG_NONE 0x00000000 // for normal return
76 /// instruction pointer for the VM
80 typedef INT64 VM_REGISTER
;
81 typedef UINT32 EXCEPTION_FLAGS
;
84 VM_REGISTER Gpr
[8]; ///< General purpose registers.
86 ///< 0 Set to 1 if the result of the last compare was true
87 ///< 1 Set to 1 if stepping
88 UINT64 Flags
; ///< 2..63 Reserved.
89 VMIP Ip
; ///< Instruction pointer.
91 EXCEPTION_FLAGS ExceptionFlags
; ///< to keep track of exceptions
93 UINT32 CompilerVersion
; ///< via break(6)
94 UINTN HighStackBottom
; ///< bottom of the upper stack
95 UINTN LowStackTop
; ///< top of the lower stack
96 UINT64 StackRetAddr
; ///< location of final return address on stack
97 UINTN
*StackMagicPtr
; ///< pointer to magic value on stack to detect corruption
98 EFI_HANDLE ImageHandle
; ///< for this EBC driver
99 EFI_SYSTEM_TABLE
*SystemTable
; ///< for debugging only
100 UINTN LastAddrConverted
; ///< for debug
101 UINTN LastAddrConvertedValue
; ///< for debug
103 VOID
*EntryPoint
; ///< entry point of EBC image
110 Given a pointer to a new VM context, execute one or more instructions. This
111 function is only used for test purposes.
113 @param[in] This A pointer to the EFI_EBC_VM_TEST_PROTOCOL structure.
114 @param[in] VmPtr A pointer to a VM context.
115 @param[in, out] InstructionCount A pointer to a UINTN value holding the number of
116 instructions to execute. If it holds value of 0,
117 then the instruction to be executed is 1.
119 @retval EFI_UNSUPPORTED At least one of the opcodes is not supported.
120 @retval EFI_SUCCESS All of the instructions are executed successfully.
125 (EFIAPI
*EBC_VM_TEST_EXECUTE
)(
126 IN EFI_EBC_VM_TEST_PROTOCOL
*This
,
127 IN VM_CONTEXT
*VmPtr
,
128 IN OUT UINTN
*InstructionCount
132 Convert AsmText to the instruction. This function is only used for test purposes.
134 @param[in] This A pointer to the EFI_EBC_VM_TEST_PROTOCOL structure.
135 @param[in] AsmText A pointer to EBC ASM text code.
136 @param[out] Buffer Buffer to store the instruction.
137 @param[out] BufferLen Size of buffer that is required to store data.
139 @retval EFI_UNSUPPORTED This functionality is unsupported.
140 @retval EFI_SUCCESS Successfully convert AsmText to the instruction.
145 (EFIAPI
*EBC_VM_TEST_ASM
)(
146 IN EFI_EBC_VM_TEST_PROTOCOL
*This
,
149 IN OUT UINTN
*BufferLen
153 Dump the executed instruction. This function is only used for test purposes.
155 @param[in] This A pointer to the EFI_EBC_VM_TEST_PROTOCOL structure.
156 @param[out] AsmText Contain the disasm text.
157 @param[out] Buffer Buffer to store the instruction.
158 @param[out] BufferLen Size of buffer that is required to store data.
160 @retval EFI_UNSUPPORTED This functionality is unsupported.
161 @retval EFI_SUCCESS Successfully dump the executed instruction.
166 (EFIAPI
*EBC_VM_TEST_DASM
)(
167 IN EFI_EBC_VM_TEST_PROTOCOL
*This
,
168 IN OUT CHAR16
*AsmText
,
174 // Prototype for the actual EBC test protocol interface
176 struct _EFI_EBC_VM_TEST_PROTOCOL
{
177 EBC_VM_TEST_EXECUTE Execute
;
178 EBC_VM_TEST_ASM Assemble
;
179 EBC_VM_TEST_DASM Disassemble
;
182 extern EFI_GUID gEfiEbcVmTestProtocolGuid
;