]> git.proxmox.com Git - mirror_edk2.git/blob - SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
This revision can only work with Intel(c) UDK Debugger Tool version 1.2 or greater...
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / DebugAgentCommon / DebugAgent.h
1 /** @file
2 Command header of for Debug Agent library instance.
3
4 Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef _DEBUG_AGENT_H_
16 #define _DEBUG_AGENT_H_
17
18 #include <Register/LocalApic.h>
19
20 #include <Guid/DebugAgentGuid.h>
21
22 #include <Library/BaseLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/ResetSystemLib.h>
25 #include <Library/IoLib.h>
26 #include <Library/HobLib.h>
27 #include <Library/DebugCommunicationLib.h>
28 #include <Library/DebugAgentLib.h>
29 #include <Library/PcdLib.h>
30 #include <Library/SynchronizationLib.h>
31 #include <Library/LocalApicLib.h>
32 #include <Library/DebugLib.h>
33 #include <Library/TimerLib.h>
34 #include <Library/PrintLib.h>
35
36 #include <TransferProtocol.h>
37 #include <ImageDebugSupport.h>
38
39 #include "DebugMp.h"
40 #include "DebugTimer.h"
41 #include "ArchDebugSupport.h"
42
43 #define DEBUG_INT1_VECTOR 1
44 #define DEBUG_INT3_VECTOR 3
45 #define DEBUG_TIMER_VECTOR 32
46 #define DEBUG_MAILBOX_VECTOR 33
47
48 #define SOFT_INTERRUPT_SIGNATURE SIGNATURE_32('S','O','F','T')
49 #define SYSTEM_RESET_SIGNATURE SIGNATURE_32('S','Y','S','R')
50 #define MEMORY_READY_SIGNATURE SIGNATURE_32('M','E','M','R')
51
52 extern UINTN Exception0Handle;
53 extern UINTN TimerInterruptHandle;
54 extern UINT16 ExceptionStubHeaderSize;
55
56 //
57 // CPU exception information issued by debug agent
58 //
59 typedef struct {
60 //
61 // This field is used to save CPU content before executing HOST command
62 //
63 BASE_LIBRARY_JUMP_BUFFER JumpBuffer;
64 //
65 // This filed returens the exception information issued by HOST command
66 //
67 DEBUG_DATA_RESPONSE_GET_EXCEPTION ExceptionContent;
68 } DEBUG_AGENT_EXCEPTION_BUFFER;
69
70 #pragma pack(1)
71 typedef struct {
72 //
73 // Lower 32 bits to store the status of DebugAgent
74 //
75 UINT32 HostAttached : 1; // 1: HOST is attached
76 UINT32 AgentInProgress : 1; // 1: Debug Agent is communicating with HOST
77 UINT32 MemoryReady : 1; // 1: Memory is ready
78 UINT32 SteppingFlag : 1; // 1: Agent is running stepping command
79 UINT32 Reserved1 : 28;
80
81 //
82 // Higher 32bits to control the behavior of DebugAgent
83 //
84 UINT32 BreakOnNextSmi : 1; // 1: Break on next SMI
85 UINT32 PrintErrorLevel : 8; // Bitmask of print error level for debug message
86 UINT32 Reserved2 : 23;
87 } DEBUG_AGENT_FLAG;
88
89 typedef struct {
90 DEBUG_AGENT_FLAG DebugFlag;
91 UINT64 DebugPortHandle;
92 //
93 // Pointer to DEBUG_AGENT_EXCEPTION_BUFFER
94 //
95 UINT64 ExceptionBufferPointer;
96 } DEBUG_AGENT_MAILBOX;
97 #pragma pack()
98
99 typedef union {
100 struct {
101 UINT32 LimitLow : 16;
102 UINT32 BaseLow : 16;
103 UINT32 BaseMid : 8;
104 UINT32 Type : 4;
105 UINT32 System : 1;
106 UINT32 Dpl : 2;
107 UINT32 Present : 1;
108 UINT32 LimitHigh : 4;
109 UINT32 Software : 1;
110 UINT32 Reserved : 1;
111 UINT32 DefaultSize : 1;
112 UINT32 Granularity : 1;
113 UINT32 BaseHigh : 8;
114 } Bits;
115 UINT64 Uint64;
116 } IA32_GDT;
117
118 /**
119 Caller provided function to be invoked at the end of DebugPortInitialize().
120
121 Refer to the descrption for DebugPortInitialize() for more details.
122
123 @param[in] Context The first input argument of DebugPortInitialize().
124 @param[in] DebugPortHandle Debug port handle created by Debug Communication Libary.
125
126 **/
127 VOID
128 EFIAPI
129 InitializeDebugAgentPhase2 (
130 IN VOID *Context,
131 IN DEBUG_PORT_HANDLE DebugPortHandle
132 );
133
134 /**
135 Initialize IDT entries to support source level debug.
136
137 **/
138 VOID
139 InitializeDebugIdt (
140 VOID
141 );
142
143 /**
144 Read register value from saved CPU context.
145
146 @param[in] CpuContext Pointer to saved CPU context.
147 @param[in] Index Register index value.
148 @param[in] Width Data width to read.
149
150 @return The address of register value.
151
152 **/
153 UINT8 *
154 ArchReadRegisterBuffer (
155 IN DEBUG_CPU_CONTEXT *CpuContext,
156 IN UINT8 Index,
157 IN UINT8 *Width
158 );
159
160 /**
161 Send packet with response data to HOST.
162
163 @param[in] Data Pointer to response data buffer.
164 @param[in] DataSize Size of response data in byte.
165
166 @retval RETURN_SUCCESS Response data was sent successfully.
167 @retval RETURN_DEVICE_ERROR Cannot receive DEBUG_COMMAND_OK from HOST.
168
169 **/
170 RETURN_STATUS
171 SendDataResponsePacket (
172 IN UINT8 *Data,
173 IN UINT16 DataSize
174 );
175
176 /**
177 Check if HOST is attached based on Mailbox.
178
179 @retval TRUE HOST is attached.
180 @retval FALSE HOST is not attached.
181
182 **/
183 BOOLEAN
184 IsHostAttached (
185 VOID
186 );
187
188 /**
189 Get Debug Agent Mailbox pointer.
190
191 @return Mailbox pointer.
192
193 **/
194 DEBUG_AGENT_MAILBOX *
195 GetMailboxPointer (
196 VOID
197 );
198
199 /**
200 Get debug port handle.
201
202 @return Debug port handle.
203
204 **/
205 DEBUG_PORT_HANDLE
206 GetDebugPortHandle (
207 VOID
208 );
209
210 /**
211 Read the Attach/Break-in symbols from the debug port.
212
213 @param[in] Handle Pointer to Debug Port handle.
214 @param[out] BreakSymbol Returned break symbol.
215
216 @retval EFI_SUCCESS Read the symbol in BreakSymbol.
217 @retval EFI_NOT_FOUND No read the break symbol.
218
219 **/
220 EFI_STATUS
221 DebugReadBreakSymbol (
222 IN DEBUG_PORT_HANDLE Handle,
223 OUT UINT8 *BreakSymbol
224 );
225
226 /**
227 Prints a debug message to the debug port if the specified error level is enabled.
228
229 If any bit in ErrorLevel is also set in Mainbox, then print the message specified
230 by Format and the associated variable argument list to the debug port.
231
232 @param[in] ErrorLevel The error level of the debug message.
233 @param[in] Format Format string for the debug message to print.
234 @param[in] ... Variable argument list whose contents are accessed
235 based on the format string specified by Format.
236
237 **/
238 VOID
239 EFIAPI
240 DebugAgentMsgPrint (
241 IN UINT8 ErrorLevel,
242 IN CHAR8 *Format,
243 ...
244 );
245 #endif
246