1 /** @file
2   EBC VM Test protocol for test purposes.
3 
4 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
5 
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
11 
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.
14 
15 **/
16 
17 #ifndef _EBC_VM_TEST_PROTOCOL_H_
18 #define _EBC_VM_TEST_PROTOCOL_H_
19 
20 //
21 // Define a protocol for an EBC VM test interface.
22 //
23 #define EFI_EBC_VM_TEST_PROTOCOL_GUID \
24   { \
25     0xAAEACCFD, 0xF27B, 0x4C17, { 0xB6, 0x10, 0x75, 0xCA, 0x1F, 0x2D, 0xFB, 0x52 } \
26   }
27 
28 //
29 // Define for forward reference.
30 //
31 typedef struct _EFI_EBC_VM_TEST_PROTOCOL EFI_EBC_VM_TEST_PROTOCOL;
32 
33 ///
34 /// instruction pointer for the VM
35 ///
36 typedef UINT8   *VMIP;
37 
38 typedef INT64   VM_REGISTER;
39 typedef UINT32  EXCEPTION_FLAGS;
40 
41 typedef struct {
42   VM_REGISTER       Gpr[8];                 ///< General purpose registers.
43                                             ///< Flags register:
44                                             ///<   0  Set to 1 if the result of the last compare was true
45                                             ///<   1  Set to 1 if stepping
46   UINT64            Flags;                  ///<   2..63 Reserved.
47   VMIP              Ip;                     ///< Instruction pointer.
48   UINTN             LastException;
49   EXCEPTION_FLAGS   ExceptionFlags;         ///< to keep track of exceptions
50   UINT32            StopFlags;
51   UINT32            CompilerVersion;        ///< via break(6)
52   UINTN             HighStackBottom;        ///< bottom of the upper stack
53   UINTN             LowStackTop;            ///< top of the lower stack
54   UINT64            StackRetAddr;           ///< location of final return address on stack
55   UINTN             *StackMagicPtr;         ///< pointer to magic value on stack to detect corruption
56   EFI_HANDLE        ImageHandle;            ///< for this EBC driver
57   EFI_SYSTEM_TABLE  *SystemTable;           ///< for debugging only
58   UINTN             LastAddrConverted;      ///< for debug
59   UINTN             LastAddrConvertedValue; ///< for debug
60   VOID              *FramePtr;
61   VOID              *EntryPoint;            ///< entry point of EBC image
62   UINTN             ImageBase;
63   VOID              *StackPool;
64   VOID              *StackTop;
65 } VM_CONTEXT;
66 
67 /**
68   Given a pointer to a new VM context, execute one or more instructions. This
69   function is only used for test purposes.
70 
71   @param[in]      This              A pointer to the EFI_EBC_VM_TEST_PROTOCOL structure.
72   @param[in]      VmPtr             A pointer to a VM context.
73   @param[in, out] InstructionCount  A pointer to a UINTN value holding the number of
74                                     instructions to execute. If it holds value of 0,
75                                     then the instruction to be executed is 1.
76 
77   @retval EFI_UNSUPPORTED       At least one of the opcodes is not supported.
78   @retval EFI_SUCCESS           All of the instructions are executed successfully.
79 
80 **/
81 typedef
82 EFI_STATUS
83 (EFIAPI *EBC_VM_TEST_EXECUTE) (
84   IN EFI_EBC_VM_TEST_PROTOCOL         *This,
85   IN VM_CONTEXT                       *VmPtr,
86   IN OUT UINTN                        *InstructionCount
87   );
88 
89 /**
90   Convert AsmText to the instruction. This function is only used for test purposes.
91 
92   @param[in]  This              A pointer to the EFI_EBC_VM_TEST_PROTOCOL structure.
93   @param[in]  AsmText           A pointer to EBC ASM text code.
94   @param[out] Buffer            Buffer to store the instruction.
95   @param[out] BufferLen         Size of buffer that is requried to store data.
96 
97   @retval EFI_UNSUPPORTED       This functionality is unsupported.
98   @retval EFI_SUCCESS           Successfully convert AsmText to the instruction.
99 
100 **/
101 typedef
102 EFI_STATUS
103 (EFIAPI *EBC_VM_TEST_ASM) (
104   IN EFI_EBC_VM_TEST_PROTOCOL         *This,
105   IN CHAR16                           *AsmText,
106   IN OUT INT8                         *Buffer,
107   IN OUT UINTN                        *BufferLen
108   );
109 
110 /**
111   Dump the executed instruction. This function is only used for test purposes.
112 
113   @param[in]  This              A pointer to the EFI_EBC_VM_TEST_PROTOCOL structure.
114   @param[out] AsmText           Contain the disasm text.
115   @param[out] Buffer            Buffer to store the instruction.
116   @param[out] BufferLen         Size of buffer that is requried to store data.
117 
118   @retval EFI_UNSUPPORTED       This functionality is unsupported.
119   @retval EFI_SUCCESS           Successfully dump the executed instruction.
120 
121 **/
122 typedef
123 EFI_STATUS
124 (EFIAPI *EBC_VM_TEST_DASM) (
125   IN EFI_EBC_VM_TEST_PROTOCOL         *This,
126   IN OUT CHAR16                       *AsmText,
127   IN OUT INT8                         *Buffer,
128   IN OUT UINTN                        *Len
129   );
130 
131 //
132 // Prototype for the actual EBC test protocol interface
133 //
134 struct _EFI_EBC_VM_TEST_PROTOCOL {
135   EBC_VM_TEST_EXECUTE Execute;
136   EBC_VM_TEST_ASM     Assemble;
137   EBC_VM_TEST_DASM    Disassemble;
138 };
139 
140 extern EFI_GUID gEfiEbcVmTestProtocolGuid;
141 
142 #endif
143