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