]> git.proxmox.com Git - mirror_edk2.git/blame - SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
Fix GCC build error.
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / DebugAgentCommon / DebugAgent.h
CommitLineData
18b144ea 1/** @file\r
2 Command header of for Debug Agent library instance.\r
3\r
b422b62c 4 Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
18b144ea 5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php.\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef _DEBUG_AGENT_H_\r
16#define _DEBUG_AGENT_H_\r
17\r
18#include <Register/LocalApic.h>\r
18b144ea 19#include <Guid/DebugAgentGuid.h>\r
8cc26df4
JF
20#include <Guid/VectorHandoffTable.h>\r
21#include <Ppi/VectorHandoffInfo.h>\r
18b144ea 22#include <Library/BaseLib.h>\r
23#include <Library/BaseMemoryLib.h>\r
24#include <Library/ResetSystemLib.h>\r
25#include <Library/IoLib.h>\r
26#include <Library/HobLib.h>\r
27#include <Library/DebugCommunicationLib.h>\r
28#include <Library/DebugAgentLib.h>\r
29#include <Library/PcdLib.h>\r
30#include <Library/SynchronizationLib.h>\r
31#include <Library/LocalApicLib.h>\r
e2104834 32#include <Library/DebugLib.h>\r
b4ebbaff 33#include <Library/TimerLib.h>\r
93c0bdec 34#include <Library/PrintLib.h>\r
b422b62c 35#include <Library/PeCoffGetEntryPointLib.h>\r
36#include <Library/PeCoffExtraActionLib.h>\r
18b144ea 37\r
38#include <TransferProtocol.h>\r
39#include <ImageDebugSupport.h>\r
40\r
41#include "DebugMp.h"\r
42#include "DebugTimer.h"\r
43#include "ArchDebugSupport.h"\r
8cc26df4 44#include "DebugException.h"\r
18b144ea 45\r
b422b62c 46//\r
47// These macros may be already defined in DebugAgentLib.h\r
48//\r
49#define DEBUG_AGENT_INIT_PEI 9\r
50#define DEBUG_AGENT_INIT_DXE_LOAD 10\r
51#define DEBUG_AGENT_INIT_DXE_UNLOAD 11\r
52#define DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64 12\r
53\r
8cc26df4
JF
54#define DEBUG_INT1_VECTOR DEBUG_EXCEPT_DEBUG\r
55#define DEBUG_INT3_VECTOR DEBUG_EXCEPT_BREAKPOINT\r
18b144ea 56#define DEBUG_TIMER_VECTOR 32\r
57#define DEBUG_MAILBOX_VECTOR 33\r
58\r
b422b62c 59//\r
60// Timeout value for reading packet (unit is microsecond)\r
61//\r
62#define READ_PACKET_TIMEOUT (500 * 1000)\r
63\r
18b144ea 64#define SOFT_INTERRUPT_SIGNATURE SIGNATURE_32('S','O','F','T')\r
65#define SYSTEM_RESET_SIGNATURE SIGNATURE_32('S','Y','S','R')\r
66#define MEMORY_READY_SIGNATURE SIGNATURE_32('M','E','M','R')\r
67\r
68extern UINTN Exception0Handle;\r
69extern UINTN TimerInterruptHandle;\r
19ee4a90 70extern UINT32 ExceptionStubHeaderSize;\r
b422b62c 71extern BOOLEAN mSkipBreakpoint;\r
8cc26df4
JF
72extern EFI_VECTOR_HANDOFF_INFO mVectorHandoffInfoDebugAgent[];\r
73extern UINTN mVectorHandoffInfoCount;\r
b422b62c 74\r
93c0bdec 75//\r
76// CPU exception information issued by debug agent\r
77//\r
78typedef struct {\r
79 //\r
80 // This field is used to save CPU content before executing HOST command\r
81 //\r
82 BASE_LIBRARY_JUMP_BUFFER JumpBuffer;\r
83 //\r
ff8ad584 84 // This field returns the exception information issued by the HOST command\r
93c0bdec 85 //\r
86 DEBUG_DATA_RESPONSE_GET_EXCEPTION ExceptionContent;\r
87} DEBUG_AGENT_EXCEPTION_BUFFER;\r
18b144ea 88\r
b422b62c 89#define DEBUG_AGENT_FLAG_HOST_ATTACHED BIT0\r
90#define DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS BIT1\r
91#define DEBUG_AGENT_FLAG_MEMORY_READY BIT2\r
92#define DEBUG_AGENT_FLAG_STEPPING BIT3\r
93#define DEBUG_AGENT_FLAG_CHECK_MAILBOX_IN_HOB BIT4\r
0a488765 94#define DEBUG_AGENT_FLAG_INIT_ARCH BIT5|BIT6\r
b422b62c 95#define DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI BIT32\r
96#define DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL (BIT33|BIT34|BIT35|BIT36)\r
97#define DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT BIT37\r
98\r
99#define DEBUG_MAILBOX_DEBUG_FLAG_INDEX 1\r
100#define DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX 2\r
101#define DEBUG_MAILBOX_EXCEPTION_BUFFER_POINTER_INDEX 3\r
102#define DEBUG_MAILBOX_LAST_ACK 4\r
103#define DEBUG_MAILBOX_SEQUENCE_NO_INDEX 5\r
104#define DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX 6\r
93c0bdec 105\r
b422b62c 106#pragma pack(1)\r
107typedef union {\r
108 struct {\r
109 //\r
110 // Lower 32 bits to store the status of DebugAgent\r
111 //\r
112 UINT32 HostAttached : 1; // 1: HOST is attached\r
113 UINT32 AgentInProgress : 1; // 1: Debug Agent is communicating with HOST\r
114 UINT32 MemoryReady : 1; // 1: Memory is ready\r
115 UINT32 SteppingFlag : 1; // 1: Agent is running stepping command\r
116 UINT32 CheckMailboxInHob : 1; // 1: Need to check mailbox saved in HOB\r
0a488765 117 UINT32 InitArch : 2; // value of DEBUG_DATA_RESPONSE_ARCH_MODE\r
118 UINT32 Reserved1 : 25;\r
b422b62c 119 //\r
120 // Higher 32bits to control the behavior of DebugAgent\r
121 //\r
122 UINT32 BreakOnNextSmi : 1; // 1: Break on next SMI\r
123 UINT32 PrintErrorLevel : 4; // Bitmask of print error level for debug message\r
124 UINT32 BreakOnBootScript : 1; // 1: Break before executing boot script \r
125 UINT32 Reserved2 : 26;\r
126 } Bits;\r
127 UINT64 Uint64;\r
93c0bdec 128} DEBUG_AGENT_FLAG;\r
129\r
18b144ea 130typedef struct {\r
131 DEBUG_AGENT_FLAG DebugFlag;\r
132 UINT64 DebugPortHandle;\r
93c0bdec 133 //\r
134 // Pointer to DEBUG_AGENT_EXCEPTION_BUFFER\r
135 //\r
136 UINT64 ExceptionBufferPointer;\r
b422b62c 137 UINT8 LastAck; // The last ack packet type\r
138 UINT8 SequenceNo;\r
139 UINT8 HostSequenceNo;\r
140 UINT8 CheckSum; // Mailbox checksum\r
141 UINT8 ToBeCheckSum; // To be Mailbox checksum at the next\r
18b144ea 142} DEBUG_AGENT_MAILBOX;\r
143#pragma pack()\r
144\r
b422b62c 145///\r
146/// Byte packed structure for an IA-32 Interrupt Gate Descriptor.\r
147///\r
148typedef union {\r
149 struct {\r
150 UINT32 OffsetLow:16; ///< Offset bits 15..0.\r
151 UINT32 Selector:16; ///< Selector.\r
152 UINT32 Reserved_0:8; ///< Reserved.\r
153 UINT32 GateType:8; ///< Gate Type. See #defines above.\r
154 UINT32 OffsetHigh:16; ///< Offset bits 31..16.\r
155 } Bits;\r
156 UINT64 Uint64;\r
157} IA32_IDT_ENTRY;\r
158\r
159\r
18b144ea 160typedef union {\r
161 struct {\r
162 UINT32 LimitLow : 16;\r
163 UINT32 BaseLow : 16;\r
164 UINT32 BaseMid : 8;\r
165 UINT32 Type : 4;\r
166 UINT32 System : 1;\r
167 UINT32 Dpl : 2;\r
168 UINT32 Present : 1;\r
169 UINT32 LimitHigh : 4;\r
170 UINT32 Software : 1;\r
171 UINT32 Reserved : 1;\r
172 UINT32 DefaultSize : 1;\r
173 UINT32 Granularity : 1;\r
174 UINT32 BaseHigh : 8;\r
175 } Bits;\r
176 UINT64 Uint64;\r
177} IA32_GDT;\r
178\r
18b144ea 179/**\r
180 Initialize IDT entries to support source level debug.\r
181\r
182**/\r
183VOID\r
184InitializeDebugIdt (\r
185 VOID\r
186 );\r
187\r
18b144ea 188/**\r
189 Read register value from saved CPU context.\r
190\r
191 @param[in] CpuContext Pointer to saved CPU context.\r
192 @param[in] Index Register index value.\r
18b144ea 193 @param[in] Width Data width to read.\r
194\r
195 @return The address of register value.\r
196\r
197**/\r
198UINT8 *\r
199ArchReadRegisterBuffer (\r
200 IN DEBUG_CPU_CONTEXT *CpuContext,\r
201 IN UINT8 Index,\r
18b144ea 202 IN UINT8 *Width\r
203 );\r
204\r
205/**\r
206 Send packet with response data to HOST.\r
207\r
18b144ea 208 @param[in] Data Pointer to response data buffer.\r
209 @param[in] DataSize Size of response data in byte.\r
210\r
211 @retval RETURN_SUCCESS Response data was sent successfully.\r
212 @retval RETURN_DEVICE_ERROR Cannot receive DEBUG_COMMAND_OK from HOST.\r
213\r
214**/\r
215RETURN_STATUS\r
216SendDataResponsePacket (\r
18b144ea 217 IN UINT8 *Data,\r
218 IN UINT16 DataSize\r
219 );\r
220\r
221/**\r
93c0bdec 222 Check if HOST is attached based on Mailbox.\r
18b144ea 223\r
93c0bdec 224 @retval TRUE HOST is attached.\r
225 @retval FALSE HOST is not attached.\r
18b144ea 226\r
227**/\r
93c0bdec 228BOOLEAN\r
229IsHostAttached (\r
230 VOID\r
18b144ea 231 );\r
232\r
233/**\r
93c0bdec 234 Get Debug Agent Mailbox pointer.\r
18b144ea 235\r
93c0bdec 236 @return Mailbox pointer.\r
18b144ea 237\r
238**/\r
93c0bdec 239DEBUG_AGENT_MAILBOX *\r
240GetMailboxPointer (\r
241 VOID\r
18b144ea 242 );\r
243\r
244/**\r
93c0bdec 245 Get debug port handle.\r
18b144ea 246\r
93c0bdec 247 @return Debug port handle.\r
18b144ea 248\r
249**/\r
93c0bdec 250DEBUG_PORT_HANDLE\r
251GetDebugPortHandle (\r
252 VOID\r
18b144ea 253 );\r
254\r
255/**\r
93c0bdec 256 Read the Attach/Break-in symbols from the debug port.\r
18b144ea 257\r
93c0bdec 258 @param[in] Handle Pointer to Debug Port handle.\r
259 @param[out] BreakSymbol Returned break symbol.\r
18b144ea 260\r
93c0bdec 261 @retval EFI_SUCCESS Read the symbol in BreakSymbol.\r
262 @retval EFI_NOT_FOUND No read the break symbol.\r
18b144ea 263\r
264**/\r
93c0bdec 265EFI_STATUS\r
266DebugReadBreakSymbol (\r
267 IN DEBUG_PORT_HANDLE Handle,\r
268 OUT UINT8 *BreakSymbol\r
18b144ea 269 );\r
270\r
271/**\r
93c0bdec 272 Prints a debug message to the debug port if the specified error level is enabled.\r
18b144ea 273\r
93c0bdec 274 If any bit in ErrorLevel is also set in Mainbox, then print the message specified\r
275 by Format and the associated variable argument list to the debug port.\r
18b144ea 276\r
93c0bdec 277 @param[in] ErrorLevel The error level of the debug message.\r
278 @param[in] Format Format string for the debug message to print.\r
279 @param[in] ... Variable argument list whose contents are accessed \r
280 based on the format string specified by Format.\r
18b144ea 281\r
282**/\r
93c0bdec 283VOID\r
284EFIAPI\r
285DebugAgentMsgPrint (\r
286 IN UINT8 ErrorLevel,\r
287 IN CHAR8 *Format,\r
288 ...\r
18b144ea 289 );\r
b422b62c 290\r
291/**\r
292 Trigger one software interrupt to debug agent to handle it.\r
293\r
294 @param[in] Signature Software interrupt signature.\r
295\r
296**/\r
297VOID\r
298TriggerSoftInterrupt (\r
299 IN UINT32 Signature\r
300 );\r
301\r
302/**\r
303 Check if debug agent support multi-processor.\r
304\r
305 @retval TRUE Multi-processor is supported.\r
306 @retval FALSE Multi-processor is not supported.\r
307\r
308**/\r
309BOOLEAN\r
310MultiProcessorDebugSupport (\r
311 VOID\r
312 );\r
313\r
314/**\r
315 Find and report module image info to HOST.\r
316 \r
317 @param[in] AlignSize Image aligned size.\r
318 \r
319**/\r
320VOID \r
321FindAndReportModuleImageInfo (\r
322 IN UINTN AlignSize \r
323 );\r
324\r
325/**\r
326 Read IDT entry to check if IDT entries are setup by Debug Agent.\r
327\r
328 @retval TRUE IDT entries were setup by Debug Agent.\r
329 @retval FALSE IDT entries were not setup by Debug Agent.\r
330\r
331**/\r
332BOOLEAN \r
333IsDebugAgentInitialzed (\r
334 VOID\r
335 );\r
336\r
337/**\r
338 Caculate Mailbox checksum and update the checksum field.\r
339\r
340 @param[in] Mailbox Debug Agent Mailbox pointer.\r
341\r
342**/\r
343VOID\r
344UpdateMailboxChecksum (\r
345 IN DEBUG_AGENT_MAILBOX *Mailbox\r
346 );\r
347\r
348/**\r
349 Verify Mailbox checksum.\r
350\r
351 If checksum error, print debug message and run init dead loop.\r
352\r
353 @param[in] Mailbox Debug Agent Mailbox pointer.\r
354\r
355**/\r
356VOID \r
357VerifyMailboxChecksum (\r
358 IN DEBUG_AGENT_MAILBOX *Mailbox\r
359 );\r
360\r
361/**\r
362 Set debug flag in mailbox.\r
363\r
364 @param[in] FlagMask Debug flag mask value.\r
365 @param[in] FlagValue Debug flag value.\r
366\r
367**/\r
368VOID \r
369SetDebugFlag (\r
370 IN UINT64 FlagMask,\r
371 IN UINT32 FlagValue \r
372 );\r
373\r
374/**\r
375 Get debug flag in mailbox.\r
376\r
377 @param[in] FlagMask Debug flag mask value.\r
378 \r
379 @return Debug flag value.\r
380\r
381**/\r
382UINT32\r
383GetDebugFlag (\r
384 IN UINT64 FlagMask\r
385 );\r
386\r
387/**\r
388 Update Mailbox content by index.\r
389\r
390 @param[in] Mailbox Debug Agent Mailbox pointer.\r
391 @param[in] Index Mailbox content index.\r
392 @param[in] Value Value to be set into mail box.\r
393 \r
394**/\r
395VOID\r
396UpdateMailboxContent ( \r
397 IN DEBUG_AGENT_MAILBOX *Mailbox,\r
398 IN UINTN Index,\r
399 IN UINT64 Value\r
400 );\r
401\r
402/**\r
403 Retrieve exception handler from IDT table by ExceptionNum.\r
404\r
405 @param[in] ExceptionNum Exception number\r
406 \r
407 @return Exception handler\r
408\r
409**/\r
410VOID *\r
411GetExceptionHandlerInIdtEntry (\r
412 IN UINTN ExceptionNum\r
413 );\r
414\r
415/**\r
416 Set exception handler in IDT table by ExceptionNum.\r
417\r
418 @param[in] ExceptionNum Exception number\r
419 @param[in] ExceptionHandler Exception Handler to be set \r
420\r
421**/\r
422VOID\r
423SetExceptionHandlerInIdtEntry (\r
424 IN UINTN ExceptionNum,\r
425 IN VOID *ExceptionHandler\r
426 );\r
427\r
428/**\r
429 Prints a debug message to the debug output device if the specified error level is enabled.\r
430\r
431 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function \r
432 GetDebugPrintErrorLevel (), then print the message specified by Format and the \r
433 associated variable argument list to the debug output device.\r
434\r
435 If Format is NULL, then ASSERT().\r
436\r
437 @param[in] ErrorLevel The error level of the debug message.\r
438 @param[in] IsSend Flag of debug message to declare that the data is being sent or being received.\r
439 @param[in] Data Variable argument list whose contents are accessed \r
440 @param[in] Length based on the format string specified by Format.\r
441\r
442**/\r
443VOID\r
444EFIAPI\r
445DebugAgentDataMsgPrint (\r
446 IN UINT8 ErrorLevel,\r
447 IN BOOLEAN IsSend,\r
448 IN UINT8 *Data,\r
449 IN UINT8 Length \r
450 );\r
451\r
452/**\r
453 Read remaing debug packet except for the start symbol\r
454\r
455 @param[in] Handle Pointer to Debug Port handle.\r
456 @param[in, out] DebugHeader Debug header buffer including start symbol.\r
457\r
458 @retval EFI_SUCCESS Read the symbol in BreakSymbol.\r
459 @retval EFI_CRC_ERROR CRC check fail.\r
460 @retval EFI_TIMEOUT Timeout occurs when reading debug packet.\r
461\r
462**/\r
463EFI_STATUS\r
464ReadRemainingBreakPacket (\r
465 IN DEBUG_PORT_HANDLE Handle,\r
466 IN OUT DEBUG_PACKET_HEADER *DebugHeader\r
467 );\r
468\r
18b144ea 469#endif\r
470\r