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