2 EBC VM Test protocol for test purposes.
4 Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution. The
9 full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #ifndef _EBC_VM_TEST_PROTOCOL_H_
18 #define _EBC_VM_TEST_PROTOCOL_H_
21 // Define a protocol for an EBC VM test interface.
23 #define EFI_EBC_VM_TEST_PROTOCOL_GUID \
25 0xAAEACCFD, 0xF27B, 0x4C17, { 0xB6, 0x10, 0x75, 0xCA, 0x1F, 0x2D, 0xFB, 0x52 } \
29 // Define for forward reference.
31 typedef struct _EFI_EBC_VM_TEST_PROTOCOL EFI_EBC_VM_TEST_PROTOCOL
;
34 // VM major/minor version
36 #define VM_MAJOR_VERSION 1
37 #define VM_MINOR_VERSION 0
40 // Bits in the VM->StopFlags field
42 #define STOPFLAG_APP_DONE 0x0001
43 #define STOPFLAG_BREAKPOINT 0x0002
44 #define STOPFLAG_INVALID_BREAK 0x0004
45 #define STOPFLAG_BREAK_ON_CALLEX 0x0008
48 // Masks for working with the VM flags register
50 #define VMFLAGS_CC 0x0001 // condition flag
51 #define VMFLAGS_STEP 0x0002 // step instruction mode
52 #define VMFLAGS_ALL_VALID (VMFLAGS_CC | VMFLAGS_STEP)
55 // Macros for operating on the VM flags register
57 #define VMFLAG_SET(pVM, Flag) (pVM->Flags |= (Flag))
58 #define VMFLAG_ISSET(pVM, Flag) ((pVM->Flags & (Flag)) ? 1 : 0)
59 #define VMFLAG_CLEAR(pVM, Flag) (pVM->Flags &= ~(Flag))
62 // Define a macro to get the operand. Then we can change it to be either a
63 // direct read or have it call a function to read memory.
65 #define GETOPERANDS(pVM) (UINT8) (*(UINT8 *) (pVM->Ip + 1))
66 #define GETOPCODE(pVM) (UINT8) (*(UINT8 *) pVM->Ip)
69 // Macros for operating on the VM GP registers
71 #define OPERAND1_REGDATA(pVM, Op) pVM->Gpr[OPERAND1_REGNUM (Op)]
72 #define OPERAND2_REGDATA(pVM, Op) pVM->Gpr[OPERAND2_REGNUM (Op)]
75 // Bits of exception flags field of VM context
77 #define EXCEPTION_FLAG_FATAL 0x80000000 // can't continue
78 #define EXCEPTION_FLAG_ERROR 0x40000000 // bad, but try to continue
79 #define EXCEPTION_FLAG_WARNING 0x20000000 // harmless problem
80 #define EXCEPTION_FLAG_NONE 0x00000000 // for normal return
83 /// instruction pointer for the VM
87 typedef INT64 VM_REGISTER
;
88 typedef UINT32 EXCEPTION_FLAGS
;
91 VM_REGISTER Gpr
[8]; ///< General purpose registers.
93 ///< 0 Set to 1 if the result of the last compare was true
94 ///< 1 Set to 1 if stepping
95 UINT64 Flags
; ///< 2..63 Reserved.
96 VMIP Ip
; ///< Instruction pointer.
98 EXCEPTION_FLAGS ExceptionFlags
; ///< to keep track of exceptions
100 UINT32 CompilerVersion
; ///< via break(6)
101 UINTN HighStackBottom
; ///< bottom of the upper stack
102 UINTN LowStackTop
; ///< top of the lower stack
103 UINT64 StackRetAddr
; ///< location of final return address on stack
104 UINTN
*StackMagicPtr
; ///< pointer to magic value on stack to detect corruption
105 EFI_HANDLE ImageHandle
; ///< for this EBC driver
106 EFI_SYSTEM_TABLE
*SystemTable
; ///< for debugging only
107 UINTN LastAddrConverted
; ///< for debug
108 UINTN LastAddrConvertedValue
; ///< for debug
110 VOID
*EntryPoint
; ///< entry point of EBC image
117 Given a pointer to a new VM context, execute one or more instructions. This
118 function is only used for test purposes.
120 @param[in] This A pointer to the EFI_EBC_VM_TEST_PROTOCOL structure.
121 @param[in] VmPtr A pointer to a VM context.
122 @param[in, out] InstructionCount A pointer to a UINTN value holding the number of
123 instructions to execute. If it holds value of 0,
124 then the instruction to be executed is 1.
126 @retval EFI_UNSUPPORTED At least one of the opcodes is not supported.
127 @retval EFI_SUCCESS All of the instructions are executed successfully.
132 (EFIAPI
*EBC_VM_TEST_EXECUTE
) (
133 IN EFI_EBC_VM_TEST_PROTOCOL
*This
,
134 IN VM_CONTEXT
*VmPtr
,
135 IN OUT UINTN
*InstructionCount
139 Convert AsmText to the instruction. This function is only used for test purposes.
141 @param[in] This A pointer to the EFI_EBC_VM_TEST_PROTOCOL structure.
142 @param[in] AsmText A pointer to EBC ASM text code.
143 @param[out] Buffer Buffer to store the instruction.
144 @param[out] BufferLen Size of buffer that is required to store data.
146 @retval EFI_UNSUPPORTED This functionality is unsupported.
147 @retval EFI_SUCCESS Successfully convert AsmText to the instruction.
152 (EFIAPI
*EBC_VM_TEST_ASM
) (
153 IN EFI_EBC_VM_TEST_PROTOCOL
*This
,
156 IN OUT UINTN
*BufferLen
160 Dump the executed instruction. This function is only used for test purposes.
162 @param[in] This A pointer to the EFI_EBC_VM_TEST_PROTOCOL structure.
163 @param[out] AsmText Contain the disasm text.
164 @param[out] Buffer Buffer to store the instruction.
165 @param[out] BufferLen Size of buffer that is required to store data.
167 @retval EFI_UNSUPPORTED This functionality is unsupported.
168 @retval EFI_SUCCESS Successfully dump the executed instruction.
173 (EFIAPI
*EBC_VM_TEST_DASM
) (
174 IN EFI_EBC_VM_TEST_PROTOCOL
*This
,
175 IN OUT CHAR16
*AsmText
,
181 // Prototype for the actual EBC test protocol interface
183 struct _EFI_EBC_VM_TEST_PROTOCOL
{
184 EBC_VM_TEST_EXECUTE Execute
;
185 EBC_VM_TEST_ASM Assemble
;
186 EBC_VM_TEST_DASM Disassemble
;
189 extern EFI_GUID gEfiEbcVmTestProtocolGuid
;