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