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