]>
Commit | Line | Data |
---|---|---|
c8ad2d7a LG |
1 | /** @file\r |
2 | EBC VM Test protocol for test purposes.\r | |
3 | \r | |
2048c585 | 4 | Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>\r |
c8ad2d7a LG |
5 | \r |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions\r | |
8 | of the BSD License which accompanies this distribution. The\r | |
9 | full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #ifndef _EBC_VM_TEST_PROTOCOL_H_\r | |
18 | #define _EBC_VM_TEST_PROTOCOL_H_\r | |
19 | \r | |
20 | //\r | |
21 | // Define a protocol for an EBC VM test interface.\r | |
22 | //\r | |
23 | #define EFI_EBC_VM_TEST_PROTOCOL_GUID \\r | |
24 | { \\r | |
25 | 0xAAEACCFD, 0xF27B, 0x4C17, { 0xB6, 0x10, 0x75, 0xCA, 0x1F, 0x2D, 0xFB, 0x52 } \\r | |
26 | }\r | |
27 | \r | |
28 | //\r | |
29 | // Define for forward reference.\r | |
30 | //\r | |
31 | typedef struct _EFI_EBC_VM_TEST_PROTOCOL EFI_EBC_VM_TEST_PROTOCOL;\r | |
32 | \r | |
3e2c7843 PB |
33 | //\r |
34 | // VM major/minor version\r | |
35 | //\r | |
36 | #define VM_MAJOR_VERSION 1\r | |
37 | #define VM_MINOR_VERSION 0\r | |
38 | \r | |
39 | //\r | |
40 | // Bits in the VM->StopFlags field\r | |
41 | //\r | |
42 | #define STOPFLAG_APP_DONE 0x0001\r | |
43 | #define STOPFLAG_BREAKPOINT 0x0002\r | |
44 | #define STOPFLAG_INVALID_BREAK 0x0004\r | |
45 | #define STOPFLAG_BREAK_ON_CALLEX 0x0008\r | |
46 | \r | |
47 | //\r | |
48 | // Masks for working with the VM flags register\r | |
49 | //\r | |
50 | #define VMFLAGS_CC 0x0001 // condition flag\r | |
51 | #define VMFLAGS_STEP 0x0002 // step instruction mode\r | |
52 | #define VMFLAGS_ALL_VALID (VMFLAGS_CC | VMFLAGS_STEP)\r | |
53 | \r | |
54 | //\r | |
55 | // Macros for operating on the VM flags register\r | |
56 | //\r | |
57 | #define VMFLAG_SET(pVM, Flag) (pVM->Flags |= (Flag))\r | |
58 | #define VMFLAG_ISSET(pVM, Flag) ((pVM->Flags & (Flag)) ? 1 : 0)\r | |
59 | #define VMFLAG_CLEAR(pVM, Flag) (pVM->Flags &= ~(Flag))\r | |
60 | \r | |
61 | //\r | |
62 | // Define a macro to get the operand. Then we can change it to be either a\r | |
63 | // direct read or have it call a function to read memory.\r | |
64 | //\r | |
65 | #define GETOPERANDS(pVM) (UINT8) (*(UINT8 *) (pVM->Ip + 1))\r | |
66 | #define GETOPCODE(pVM) (UINT8) (*(UINT8 *) pVM->Ip)\r | |
67 | \r | |
68 | //\r | |
69 | // Macros for operating on the VM GP registers\r | |
70 | //\r | |
71 | #define OPERAND1_REGDATA(pVM, Op) pVM->Gpr[OPERAND1_REGNUM (Op)]\r | |
72 | #define OPERAND2_REGDATA(pVM, Op) pVM->Gpr[OPERAND2_REGNUM (Op)]\r | |
73 | \r | |
74 | //\r | |
75 | // Bits of exception flags field of VM context\r | |
76 | //\r | |
77 | #define EXCEPTION_FLAG_FATAL 0x80000000 // can't continue\r | |
78 | #define EXCEPTION_FLAG_ERROR 0x40000000 // bad, but try to continue\r | |
79 | #define EXCEPTION_FLAG_WARNING 0x20000000 // harmless problem\r | |
80 | #define EXCEPTION_FLAG_NONE 0x00000000 // for normal return\r | |
81 | \r | |
c8ad2d7a LG |
82 | ///\r |
83 | /// instruction pointer for the VM\r | |
84 | ///\r | |
85 | typedef UINT8 *VMIP;\r | |
86 | \r | |
87 | typedef INT64 VM_REGISTER;\r | |
88 | typedef UINT32 EXCEPTION_FLAGS;\r | |
89 | \r | |
90 | typedef struct {\r | |
91 | VM_REGISTER Gpr[8]; ///< General purpose registers.\r | |
92 | ///< Flags register:\r | |
93 | ///< 0 Set to 1 if the result of the last compare was true\r | |
94 | ///< 1 Set to 1 if stepping\r | |
95 | UINT64 Flags; ///< 2..63 Reserved.\r | |
96 | VMIP Ip; ///< Instruction pointer.\r | |
97 | UINTN LastException;\r | |
98 | EXCEPTION_FLAGS ExceptionFlags; ///< to keep track of exceptions\r | |
99 | UINT32 StopFlags;\r | |
100 | UINT32 CompilerVersion; ///< via break(6)\r | |
101 | UINTN HighStackBottom; ///< bottom of the upper stack\r | |
102 | UINTN LowStackTop; ///< top of the lower stack\r | |
103 | UINT64 StackRetAddr; ///< location of final return address on stack\r | |
104 | UINTN *StackMagicPtr; ///< pointer to magic value on stack to detect corruption\r | |
105 | EFI_HANDLE ImageHandle; ///< for this EBC driver\r | |
106 | EFI_SYSTEM_TABLE *SystemTable; ///< for debugging only\r | |
107 | UINTN LastAddrConverted; ///< for debug\r | |
108 | UINTN LastAddrConvertedValue; ///< for debug\r | |
109 | VOID *FramePtr;\r | |
110 | VOID *EntryPoint; ///< entry point of EBC image\r | |
111 | UINTN ImageBase;\r | |
112 | VOID *StackPool;\r | |
113 | VOID *StackTop;\r | |
114 | } VM_CONTEXT;\r | |
115 | \r | |
116 | /**\r | |
117 | Given a pointer to a new VM context, execute one or more instructions. This\r | |
118 | function is only used for test purposes.\r | |
119 | \r | |
120 | @param[in] This A pointer to the EFI_EBC_VM_TEST_PROTOCOL structure.\r | |
121 | @param[in] VmPtr A pointer to a VM context.\r | |
122 | @param[in, out] InstructionCount A pointer to a UINTN value holding the number of\r | |
123 | instructions to execute. If it holds value of 0,\r | |
124 | then the instruction to be executed is 1.\r | |
125 | \r | |
126 | @retval EFI_UNSUPPORTED At least one of the opcodes is not supported.\r | |
127 | @retval EFI_SUCCESS All of the instructions are executed successfully.\r | |
128 | \r | |
129 | **/\r | |
130 | typedef\r | |
131 | EFI_STATUS\r | |
132 | (EFIAPI *EBC_VM_TEST_EXECUTE) (\r | |
133 | IN EFI_EBC_VM_TEST_PROTOCOL *This,\r | |
134 | IN VM_CONTEXT *VmPtr,\r | |
135 | IN OUT UINTN *InstructionCount\r | |
136 | );\r | |
137 | \r | |
138 | /**\r | |
139 | Convert AsmText to the instruction. This function is only used for test purposes.\r | |
140 | \r | |
141 | @param[in] This A pointer to the EFI_EBC_VM_TEST_PROTOCOL structure.\r | |
142 | @param[in] AsmText A pointer to EBC ASM text code.\r | |
143 | @param[out] Buffer Buffer to store the instruction.\r | |
2048c585 | 144 | @param[out] BufferLen Size of buffer that is required to store data.\r |
c8ad2d7a LG |
145 | \r |
146 | @retval EFI_UNSUPPORTED This functionality is unsupported.\r | |
147 | @retval EFI_SUCCESS Successfully convert AsmText to the instruction. \r | |
148 | \r | |
149 | **/\r | |
150 | typedef\r | |
151 | EFI_STATUS\r | |
152 | (EFIAPI *EBC_VM_TEST_ASM) (\r | |
153 | IN EFI_EBC_VM_TEST_PROTOCOL *This,\r | |
154 | IN CHAR16 *AsmText,\r | |
155 | IN OUT INT8 *Buffer,\r | |
156 | IN OUT UINTN *BufferLen\r | |
157 | );\r | |
158 | \r | |
159 | /**\r | |
160 | Dump the executed instruction. This function is only used for test purposes.\r | |
161 | \r | |
162 | @param[in] This A pointer to the EFI_EBC_VM_TEST_PROTOCOL structure.\r | |
163 | @param[out] AsmText Contain the disasm text.\r | |
164 | @param[out] Buffer Buffer to store the instruction.\r | |
2048c585 | 165 | @param[out] BufferLen Size of buffer that is required to store data.\r |
c8ad2d7a LG |
166 | \r |
167 | @retval EFI_UNSUPPORTED This functionality is unsupported.\r | |
168 | @retval EFI_SUCCESS Successfully dump the executed instruction.\r | |
169 | \r | |
170 | **/\r | |
171 | typedef\r | |
172 | EFI_STATUS\r | |
173 | (EFIAPI *EBC_VM_TEST_DASM) (\r | |
174 | IN EFI_EBC_VM_TEST_PROTOCOL *This,\r | |
175 | IN OUT CHAR16 *AsmText,\r | |
176 | IN OUT INT8 *Buffer,\r | |
177 | IN OUT UINTN *Len\r | |
178 | );\r | |
179 | \r | |
180 | //\r | |
181 | // Prototype for the actual EBC test protocol interface\r | |
182 | //\r | |
183 | struct _EFI_EBC_VM_TEST_PROTOCOL {\r | |
184 | EBC_VM_TEST_EXECUTE Execute;\r | |
185 | EBC_VM_TEST_ASM Assemble;\r | |
186 | EBC_VM_TEST_DASM Disassemble;\r | |
187 | };\r | |
188 | \r | |
189 | extern EFI_GUID gEfiEbcVmTestProtocolGuid;\r | |
190 | \r | |
191 | #endif\r |