• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 
3 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution.  The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8 
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 
12 **/
13 
14 #ifndef _EFI_EDB_COMMON_H_
15 #define _EFI_EDB_COMMON_H_
16 
17 #include <Uefi.h>
18 #include <Library/BaseLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/UefiLib.h>
23 #include <Library/PrintLib.h>
24 #include <Library/UefiBootServicesTableLib.h>
25 #include <Protocol/Ebc.h>
26 #include <Protocol/EbcVmTest.h>
27 #include <Protocol/DebugSupport.h>
28 #include <Protocol/PciRootBridgeIo.h>
29 #include <Protocol/SimpleFileSystem.h>
30 #include <Protocol/DebuggerConfiguration.h>
31 #include <Guid/FileInfo.h>
32 #include <Guid/FileSystemInfo.h>
33 #include <Guid/FileSystemVolumeLabelInfo.h>
34 #include <Guid/DebugImageInfoTable.h>
35 
36 typedef UINTN EFI_DEBUG_STATUS;
37 
38 typedef struct _EFI_DEBUGGER_PRIVATE_DATA EFI_DEBUGGER_PRIVATE_DATA;
39 
40 //
41 // Definition for Debugger Command
42 //
43 typedef
44 EFI_DEBUG_STATUS
45 (* EFI_DEBUGGER_COMMAND) (
46   IN     CHAR16                    *CommandArg,
47   IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
48   IN     EFI_EXCEPTION_TYPE        ExceptionType,
49   IN OUT EFI_SYSTEM_CONTEXT        SystemContext
50 );
51 
52 typedef struct {
53   CHAR16                *CommandName;
54   CHAR16                *CommandTitle;
55   CHAR16                *CommandHelp;
56   CHAR16                *CommandSyntax;
57   CHAR16                *ClassName;
58   EFI_INPUT_KEY         CommandKey;
59   EFI_DEBUGGER_COMMAND  CommandFunc;
60 } EFI_DEBUGGER_COMMAND_SET;
61 
62 //
63 // Definition for Debugger Symbol
64 //
65 #define EFI_DEBUGGER_SYMBOL_NAME_MAX     256
66 #define EFI_DEBUGGER_SYMBOL_ENTRY_MAX    512
67 #define EFI_DEBUGGER_SYMBOL_OBJECT_MAX   32
68 
69 //
70 // We have following SYMBOL data structure:
71 //
72 // SYMBOL_CONTEXT -> SYMBOL_OBJECT -> SYMBOL_ENTRY (FuncXXX, 0xXXX)
73 //                                    SYMBOL_ENTRY (VarYYY,  0xYYY)
74 //                                    SYMBOL_ENTRY
75 //
76 //                   SYMBOL_OBJECT -> SYMBOL_ENTRY
77 //                                    SYMBOL_ENTRY
78 //
79 //                   SYMBOL_OBJECT -> SYMBOL_ENTRY
80 //                                    SYMBOL_ENTRY
81 //
82 
83 typedef enum {
84   EfiDebuggerSymbolFunction,
85   EfiDebuggerSymbolStaticFunction,
86   EfiDebuggerSymbolGlobalVariable,
87   EfiDebuggerSymbolStaticVariable,
88   EfiDebuggerSymbolTypeMax,
89 } EFI_DEBUGGER_SYMBOL_TYPE;
90 
91 typedef struct {
92   CHAR8                      Name[EFI_DEBUGGER_SYMBOL_NAME_MAX];
93   UINTN                      Rva;
94   EFI_DEBUGGER_SYMBOL_TYPE   Type;
95   CHAR8                      ObjName[EFI_DEBUGGER_SYMBOL_NAME_MAX];
96   CHAR8                      *CodBuffer;
97   UINTN                      CodBufferSize;
98   UINTN                      FuncOffsetBase;
99   CHAR8                      *SourceBuffer;
100 } EFI_DEBUGGER_SYMBOL_ENTRY;
101 
102 typedef struct {
103   CHAR16                     Name[EFI_DEBUGGER_SYMBOL_NAME_MAX];
104   UINTN                      EntryCount;
105   UINTN                      MaxEntryCount;
106   UINTN                      BaseAddress;
107   UINTN                      StartEntrypointRVA;
108   UINTN                      MainEntrypointRVA;
109   EFI_DEBUGGER_SYMBOL_ENTRY  *Entry;
110   VOID                       **SourceBuffer;
111 } EFI_DEBUGGER_SYMBOL_OBJECT;
112 
113 typedef struct {
114   UINTN                       ObjectCount;
115   UINTN                       MaxObjectCount;
116   EFI_DEBUGGER_SYMBOL_OBJECT  *Object;
117   BOOLEAN                     DisplaySymbol;
118   BOOLEAN                     DisplayCodeOnly;
119 } EFI_DEBUGGER_SYMBOL_CONTEXT;
120 
121 //
122 // Definition for Debugger Breakpoint
123 //
124 #define EFI_DEBUGGER_BREAKPOINT_MAX    0x10
125 
126 typedef struct {
127   EFI_PHYSICAL_ADDRESS      BreakpointAddress;
128   UINT64                    OldInstruction;    // UINT64 is enough for an instruction
129   BOOLEAN                   State;
130 } EFI_DEBUGGER_BREAKPOINT_CONTEXT;
131 
132 //
133 // Definition for Debugger Call-Stack
134 //
135 #define EFI_DEBUGGER_CALLSTACK_MAX     0x10
136 
137 typedef enum {
138   EfiDebuggerBranchTypeEbcCall,
139   EfiDebuggerBranchTypeEbcCallEx,
140   EfiDebuggerBranchTypeEbcRet,
141   EfiDebuggerBranchTypeEbcJmp,
142   EfiDebuggerBranchTypeEbcJmp8,
143   EfiDebuggerBranchTypeEbcMax,
144 } EFI_DEBUGGER_BRANCH_TYPE;
145 
146 #define EFI_DEBUGGER_CALL_MAX_PARAMETER      0x16
147 #define EFI_DEBUGGER_CALL_DEFAULT_PARAMETER  0x8
148 
149 typedef struct {
150   EFI_PHYSICAL_ADDRESS      SourceAddress;
151   EFI_PHYSICAL_ADDRESS      DestAddress;
152   //
153   // We save all parameter here, because code may update the parameter as local variable.
154   //
155   UINTN                     ParameterAddr;
156   UINTN                     Parameter[EFI_DEBUGGER_CALL_MAX_PARAMETER];
157   EFI_DEBUGGER_BRANCH_TYPE  Type;
158 } EFI_DEBUGGER_CALLSTACK_CONTEXT;
159 
160 //
161 // Definition for Debugger Trace
162 //
163 #define EFI_DEBUGGER_TRACE_MAX         0x10
164 
165 typedef struct {
166   EFI_PHYSICAL_ADDRESS      SourceAddress;
167   EFI_PHYSICAL_ADDRESS      DestAddress;
168   EFI_DEBUGGER_BRANCH_TYPE  Type;
169 } EFI_DEBUGGER_TRACE_CONTEXT;
170 
171 //
172 // Definition for Debugger Step
173 //
174 typedef struct {
175   EFI_PHYSICAL_ADDRESS      BreakAddress;
176   EFI_PHYSICAL_ADDRESS      FramePointer;
177 } EFI_DEBUGGER_STEP_CONTEXT;
178 
179 //
180 // Definition for Debugger GoTil
181 //
182 typedef struct {
183   EFI_PHYSICAL_ADDRESS      BreakAddress;
184 } EFI_DEBUGGER_GOTIL_CONTEXT;
185 
186 //
187 // Definition for Debugger private data structure
188 //
189 #define EFI_DEBUGGER_SIGNATURE         SIGNATURE_32 ('e', 'd', 'b', '!')
190 
191 #define EFI_DEBUG_DEFAULT_INSTRUCTION_NUMBER  5
192 
193 #define EFI_DEBUG_BREAK_TIMER_INTERVAL        10000000   // 1 second
194 
195 #define EFI_DEBUG_FLAG_EBC            0x80000000
196 #define EFI_DEBUG_FLAG_EBC_B_BOC      0x1
197 #define EFI_DEBUG_FLAG_EBC_B_BOCX     0x2
198 #define EFI_DEBUG_FLAG_EBC_B_BOR      0x4
199 #define EFI_DEBUG_FLAG_EBC_B_BOE      0x8
200 #define EFI_DEBUG_FLAG_EBC_B_BOT      0x10
201 #define EFI_DEBUG_FLAG_EBC_B_STEPOVER 0x20
202 #define EFI_DEBUG_FLAG_EBC_B_STEPOUT  0x40
203 #define EFI_DEBUG_FLAG_EBC_B_BP       0x80
204 #define EFI_DEBUG_FLAG_EBC_B_GT       0x100
205 #define EFI_DEBUG_FLAG_EBC_B_BOK      0x200
206 #define EFI_DEBUG_FLAG_EBC_BOC        (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_BOC)
207 #define EFI_DEBUG_FLAG_EBC_BOCX       (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_BOCX)
208 #define EFI_DEBUG_FLAG_EBC_BOR        (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_BOR)
209 #define EFI_DEBUG_FLAG_EBC_BOE        (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_BOE)
210 #define EFI_DEBUG_FLAG_EBC_BOT        (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_BOT)
211 #define EFI_DEBUG_FLAG_EBC_STEPOVER   (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_STEPOVER)
212 #define EFI_DEBUG_FLAG_EBC_STEPOUT    (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_STEPOUT)
213 #define EFI_DEBUG_FLAG_EBC_BP         (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_BP)
214 #define EFI_DEBUG_FLAG_EBC_GT         (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_GT)
215 #define EFI_DEBUG_FLAG_EBC_BOK        (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_BOK)
216 
217 //
218 // Debugger private data structure
219 //
220 typedef struct _EFI_DEBUGGER_PRIVATE_DATA {
221   UINT32                                      Signature;
222   EFI_INSTRUCTION_SET_ARCHITECTURE            Isa;
223   UINT32                                      EfiDebuggerRevision;
224   UINT32                                      EbcVmRevision;
225   EFI_DEBUGGER_CONFIGURATION_PROTOCOL         DebuggerConfiguration;
226   EFI_DEBUG_IMAGE_INFO_TABLE_HEADER           *DebugImageInfoTableHeader;
227   EFI_SIMPLE_FILE_SYSTEM_PROTOCOL             *Vol;
228   EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL             *PciRootBridgeIo;
229   EFI_DEBUGGER_COMMAND_SET                    *DebuggerCommandSet;
230   EFI_DEBUGGER_SYMBOL_CONTEXT                 DebuggerSymbolContext;
231   UINTN                                       DebuggerBreakpointCount;
232   EFI_DEBUGGER_BREAKPOINT_CONTEXT             DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX + 1];
233   UINTN                                       CallStackEntryCount;
234   EFI_DEBUGGER_CALLSTACK_CONTEXT              CallStackEntry[EFI_DEBUGGER_CALLSTACK_MAX + 1];
235   UINTN                                       TraceEntryCount;
236   EFI_DEBUGGER_TRACE_CONTEXT                  TraceEntry[EFI_DEBUGGER_TRACE_MAX + 1];
237   EFI_DEBUGGER_STEP_CONTEXT                   StepContext;
238   EFI_DEBUGGER_GOTIL_CONTEXT                  GoTilContext;
239   EFI_PHYSICAL_ADDRESS                        InstructionScope;
240   UINTN                                       InstructionNumber;
241   UINT32                                      FeatureFlags;
242   UINT32                                      StatusFlags;
243   BOOLEAN                                     EnablePageBreak;
244   EFI_EVENT                                   BreakEvent;
245 } EFI_DEBUGGER_PRIVATE_DATA;
246 
247 #endif
248