2 Command header of for Debug Agent library instance.
4 Copyright (c) 2010 - 2013, 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.
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.
15 #ifndef _DEBUG_AGENT_H_
16 #define _DEBUG_AGENT_H_
18 #include <Register/LocalApic.h>
20 #include <Guid/DebugAgentGuid.h>
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 #include <Library/PeCoffGetEntryPointLib.h>
36 #include <Library/PeCoffExtraActionLib.h>
38 #include <TransferProtocol.h>
39 #include <ImageDebugSupport.h>
42 #include "DebugTimer.h"
43 #include "ArchDebugSupport.h"
46 // These macros may be already defined in DebugAgentLib.h
48 #define DEBUG_AGENT_INIT_PEI 9
49 #define DEBUG_AGENT_INIT_DXE_LOAD 10
50 #define DEBUG_AGENT_INIT_DXE_UNLOAD 11
51 #define DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64 12
53 #define DEBUG_INT1_VECTOR 1
54 #define DEBUG_INT3_VECTOR 3
55 #define DEBUG_TIMER_VECTOR 32
56 #define DEBUG_MAILBOX_VECTOR 33
59 // Timeout value for reading packet (unit is microsecond)
61 #define READ_PACKET_TIMEOUT (500 * 1000)
63 #define SOFT_INTERRUPT_SIGNATURE SIGNATURE_32('S','O','F','T')
64 #define SYSTEM_RESET_SIGNATURE SIGNATURE_32('S','Y','S','R')
65 #define MEMORY_READY_SIGNATURE SIGNATURE_32('M','E','M','R')
67 extern UINTN Exception0Handle
;
68 extern UINTN TimerInterruptHandle
;
69 extern UINT16 ExceptionStubHeaderSize
;
71 extern BOOLEAN mSkipBreakpoint
;
74 // CPU exception information issued by debug agent
78 // This field is used to save CPU content before executing HOST command
80 BASE_LIBRARY_JUMP_BUFFER JumpBuffer
;
82 // This filed returens the exception information issued by HOST command
84 DEBUG_DATA_RESPONSE_GET_EXCEPTION ExceptionContent
;
85 } DEBUG_AGENT_EXCEPTION_BUFFER
;
87 #define DEBUG_AGENT_FLAG_HOST_ATTACHED BIT0
88 #define DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS BIT1
89 #define DEBUG_AGENT_FLAG_MEMORY_READY BIT2
90 #define DEBUG_AGENT_FLAG_STEPPING BIT3
91 #define DEBUG_AGENT_FLAG_CHECK_MAILBOX_IN_HOB BIT4
92 #define DEBUG_AGENT_FLAG_INIT_ARCH BIT5|BIT6
93 #define DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI BIT32
94 #define DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL (BIT33|BIT34|BIT35|BIT36)
95 #define DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT BIT37
97 #define DEBUG_MAILBOX_DEBUG_FLAG_INDEX 1
98 #define DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX 2
99 #define DEBUG_MAILBOX_EXCEPTION_BUFFER_POINTER_INDEX 3
100 #define DEBUG_MAILBOX_LAST_ACK 4
101 #define DEBUG_MAILBOX_SEQUENCE_NO_INDEX 5
102 #define DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX 6
108 // Lower 32 bits to store the status of DebugAgent
110 UINT32 HostAttached
: 1; // 1: HOST is attached
111 UINT32 AgentInProgress
: 1; // 1: Debug Agent is communicating with HOST
112 UINT32 MemoryReady
: 1; // 1: Memory is ready
113 UINT32 SteppingFlag
: 1; // 1: Agent is running stepping command
114 UINT32 CheckMailboxInHob
: 1; // 1: Need to check mailbox saved in HOB
115 UINT32 InitArch
: 2; // value of DEBUG_DATA_RESPONSE_ARCH_MODE
116 UINT32 Reserved1
: 25;
118 // Higher 32bits to control the behavior of DebugAgent
120 UINT32 BreakOnNextSmi
: 1; // 1: Break on next SMI
121 UINT32 PrintErrorLevel
: 4; // Bitmask of print error level for debug message
122 UINT32 BreakOnBootScript
: 1; // 1: Break before executing boot script
123 UINT32 Reserved2
: 26;
129 DEBUG_AGENT_FLAG DebugFlag
;
130 UINT64 DebugPortHandle
;
132 // Pointer to DEBUG_AGENT_EXCEPTION_BUFFER
134 UINT64 ExceptionBufferPointer
;
135 UINT8 LastAck
; // The last ack packet type
137 UINT8 HostSequenceNo
;
138 UINT8 CheckSum
; // Mailbox checksum
139 UINT8 ToBeCheckSum
; // To be Mailbox checksum at the next
140 } DEBUG_AGENT_MAILBOX
;
144 /// Byte packed structure for an IA-32 Interrupt Gate Descriptor.
148 UINT32 OffsetLow
:16; ///< Offset bits 15..0.
149 UINT32 Selector
:16; ///< Selector.
150 UINT32 Reserved_0
:8; ///< Reserved.
151 UINT32 GateType
:8; ///< Gate Type. See #defines above.
152 UINT32 OffsetHigh
:16; ///< Offset bits 31..16.
160 UINT32 LimitLow
: 16;
167 UINT32 LimitHigh
: 4;
170 UINT32 DefaultSize
: 1;
171 UINT32 Granularity
: 1;
178 Initialize IDT entries to support source level debug.
187 Read register value from saved CPU context.
189 @param[in] CpuContext Pointer to saved CPU context.
190 @param[in] Index Register index value.
191 @param[in] Width Data width to read.
193 @return The address of register value.
197 ArchReadRegisterBuffer (
198 IN DEBUG_CPU_CONTEXT
*CpuContext
,
204 Send packet with response data to HOST.
206 @param[in] Data Pointer to response data buffer.
207 @param[in] DataSize Size of response data in byte.
209 @retval RETURN_SUCCESS Response data was sent successfully.
210 @retval RETURN_DEVICE_ERROR Cannot receive DEBUG_COMMAND_OK from HOST.
214 SendDataResponsePacket (
220 Check if HOST is attached based on Mailbox.
222 @retval TRUE HOST is attached.
223 @retval FALSE HOST is not attached.
232 Get Debug Agent Mailbox pointer.
234 @return Mailbox pointer.
237 DEBUG_AGENT_MAILBOX
*
243 Get debug port handle.
245 @return Debug port handle.
254 Read the Attach/Break-in symbols from the debug port.
256 @param[in] Handle Pointer to Debug Port handle.
257 @param[out] BreakSymbol Returned break symbol.
259 @retval EFI_SUCCESS Read the symbol in BreakSymbol.
260 @retval EFI_NOT_FOUND No read the break symbol.
264 DebugReadBreakSymbol (
265 IN DEBUG_PORT_HANDLE Handle
,
266 OUT UINT8
*BreakSymbol
270 Prints a debug message to the debug port if the specified error level is enabled.
272 If any bit in ErrorLevel is also set in Mainbox, then print the message specified
273 by Format and the associated variable argument list to the debug port.
275 @param[in] ErrorLevel The error level of the debug message.
276 @param[in] Format Format string for the debug message to print.
277 @param[in] ... Variable argument list whose contents are accessed
278 based on the format string specified by Format.
290 Trigger one software interrupt to debug agent to handle it.
292 @param[in] Signature Software interrupt signature.
296 TriggerSoftInterrupt (
301 Check if debug agent support multi-processor.
303 @retval TRUE Multi-processor is supported.
304 @retval FALSE Multi-processor is not supported.
308 MultiProcessorDebugSupport (
313 Find and report module image info to HOST.
315 @param[in] AlignSize Image aligned size.
319 FindAndReportModuleImageInfo (
324 Read IDT entry to check if IDT entries are setup by Debug Agent.
326 @retval TRUE IDT entries were setup by Debug Agent.
327 @retval FALSE IDT entries were not setup by Debug Agent.
331 IsDebugAgentInitialzed (
336 Caculate Mailbox checksum and update the checksum field.
338 @param[in] Mailbox Debug Agent Mailbox pointer.
342 UpdateMailboxChecksum (
343 IN DEBUG_AGENT_MAILBOX
*Mailbox
347 Verify Mailbox checksum.
349 If checksum error, print debug message and run init dead loop.
351 @param[in] Mailbox Debug Agent Mailbox pointer.
355 VerifyMailboxChecksum (
356 IN DEBUG_AGENT_MAILBOX
*Mailbox
360 Set debug flag in mailbox.
362 @param[in] FlagMask Debug flag mask value.
363 @param[in] FlagValue Debug flag value.
373 Get debug flag in mailbox.
375 @param[in] FlagMask Debug flag mask value.
377 @return Debug flag value.
386 Update Mailbox content by index.
388 @param[in] Mailbox Debug Agent Mailbox pointer.
389 @param[in] Index Mailbox content index.
390 @param[in] Value Value to be set into mail box.
394 UpdateMailboxContent (
395 IN DEBUG_AGENT_MAILBOX
*Mailbox
,
401 Retrieve exception handler from IDT table by ExceptionNum.
403 @param[in] ExceptionNum Exception number
405 @return Exception handler
409 GetExceptionHandlerInIdtEntry (
410 IN UINTN ExceptionNum
414 Set exception handler in IDT table by ExceptionNum.
416 @param[in] ExceptionNum Exception number
417 @param[in] ExceptionHandler Exception Handler to be set
421 SetExceptionHandlerInIdtEntry (
422 IN UINTN ExceptionNum
,
423 IN VOID
*ExceptionHandler
427 Prints a debug message to the debug output device if the specified error level is enabled.
429 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
430 GetDebugPrintErrorLevel (), then print the message specified by Format and the
431 associated variable argument list to the debug output device.
433 If Format is NULL, then ASSERT().
435 @param[in] ErrorLevel The error level of the debug message.
436 @param[in] IsSend Flag of debug message to declare that the data is being sent or being received.
437 @param[in] Data Variable argument list whose contents are accessed
438 @param[in] Length based on the format string specified by Format.
443 DebugAgentDataMsgPrint (
451 Read remaing debug packet except for the start symbol
453 @param[in] Handle Pointer to Debug Port handle.
454 @param[in, out] DebugHeader Debug header buffer including start symbol.
456 @retval EFI_SUCCESS Read the symbol in BreakSymbol.
457 @retval EFI_CRC_ERROR CRC check fail.
458 @retval EFI_TIMEOUT Timeout occurs when reading debug packet.
462 ReadRemainingBreakPacket (
463 IN DEBUG_PORT_HANDLE Handle
,
464 IN OUT DEBUG_PACKET_HEADER
*DebugHeader