2 Command header of for Debug Agent library instance.
4 Copyright (c) 2010 - 2015, 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>
19 #include <Guid/DebugAgentGuid.h>
20 #include <Guid/VectorHandoffTable.h>
21 #include <Ppi/VectorHandoffInfo.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"
44 #include "DebugException.h"
47 // These macros may be already defined in DebugAgentLib.h
49 #define DEBUG_AGENT_INIT_PEI 9
50 #define DEBUG_AGENT_INIT_DXE_LOAD 10
51 #define DEBUG_AGENT_INIT_DXE_UNLOAD 11
52 #define DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64 12
54 #define DEBUG_INT1_VECTOR DEBUG_EXCEPT_DEBUG
55 #define DEBUG_INT3_VECTOR DEBUG_EXCEPT_BREAKPOINT
56 #define DEBUG_TIMER_VECTOR 32
57 #define DEBUG_MAILBOX_VECTOR 33
60 // Timeout value for reading packet (unit is microsecond)
62 #define READ_PACKET_TIMEOUT (500 * 1000)
63 #define DEBUG_TIMER_INTERVAL (100 * 1000)
65 #define SOFT_INTERRUPT_SIGNATURE SIGNATURE_32('S','O','F','T')
66 #define SYSTEM_RESET_SIGNATURE SIGNATURE_32('S','Y','S','R')
67 #define MEMORY_READY_SIGNATURE SIGNATURE_32('M','E','M','R')
69 extern UINTN Exception0Handle
;
70 extern UINTN TimerInterruptHandle
;
71 extern UINT32 ExceptionStubHeaderSize
;
72 extern BOOLEAN mSkipBreakpoint
;
73 extern EFI_VECTOR_HANDOFF_INFO mVectorHandoffInfoDebugAgent
[];
74 extern UINTN mVectorHandoffInfoCount
;
77 // CPU exception information issued by debug agent
81 // This field is used to save CPU content before executing HOST command
83 BASE_LIBRARY_JUMP_BUFFER JumpBuffer
;
85 // This field returns the exception information issued by the HOST command
87 DEBUG_DATA_RESPONSE_GET_EXCEPTION ExceptionContent
;
88 } DEBUG_AGENT_EXCEPTION_BUFFER
;
90 #define DEBUG_AGENT_FLAG_HOST_ATTACHED BIT0
91 #define DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS BIT1
92 #define DEBUG_AGENT_FLAG_MEMORY_READY BIT2
93 #define DEBUG_AGENT_FLAG_STEPPING BIT3
94 #define DEBUG_AGENT_FLAG_CHECK_MAILBOX_IN_HOB BIT4
95 #define DEBUG_AGENT_FLAG_INIT_ARCH BIT5|BIT6
96 #define DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI BIT32
97 #define DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL (BIT33|BIT34|BIT35|BIT36)
98 #define DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT BIT37
100 #define DEBUG_MAILBOX_DEBUG_FLAG_INDEX 1
101 #define DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX 2
102 #define DEBUG_MAILBOX_EXCEPTION_BUFFER_POINTER_INDEX 3
103 #define DEBUG_MAILBOX_LAST_ACK 4
104 #define DEBUG_MAILBOX_SEQUENCE_NO_INDEX 5
105 #define DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX 6
106 #define DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY 7
112 // Lower 32 bits to store the status of DebugAgent
114 UINT32 HostAttached
: 1; // 1: HOST is attached
115 UINT32 AgentInProgress
: 1; // 1: Debug Agent is communicating with HOST
116 UINT32 MemoryReady
: 1; // 1: Memory is ready
117 UINT32 SteppingFlag
: 1; // 1: Agent is running stepping command
118 UINT32 CheckMailboxInHob
: 1; // 1: Need to check mailbox saved in HOB
119 UINT32 InitArch
: 2; // value of DEBUG_DATA_RESPONSE_ARCH_MODE
120 UINT32 Reserved1
: 25;
122 // Higher 32bits to control the behavior of DebugAgent
124 UINT32 BreakOnNextSmi
: 1; // 1: Break on next SMI
125 UINT32 PrintErrorLevel
: 4; // Bitmask of print error level for debug message
126 UINT32 BreakOnBootScript
: 1; // 1: Break before executing boot script
127 UINT32 Reserved2
: 26;
133 DEBUG_AGENT_FLAG DebugFlag
;
134 UINT64 DebugPortHandle
;
136 // Pointer to DEBUG_AGENT_EXCEPTION_BUFFER
138 UINT64 ExceptionBufferPointer
;
139 UINT8 LastAck
; // The last ack packet type
141 UINT8 HostSequenceNo
;
142 UINT32 DebugTimerFrequency
;
143 UINT8 CheckSum
; // Mailbox checksum
144 UINT8 ToBeCheckSum
; // To be Mailbox checksum at the next
145 } DEBUG_AGENT_MAILBOX
;
149 /// Byte packed structure for an IA-32 Interrupt Gate Descriptor.
153 UINT32 OffsetLow
:16; ///< Offset bits 15..0.
154 UINT32 Selector
:16; ///< Selector.
155 UINT32 Reserved_0
:8; ///< Reserved.
156 UINT32 GateType
:8; ///< Gate Type. See #defines above.
157 UINT32 OffsetHigh
:16; ///< Offset bits 31..16.
165 UINT32 LimitLow
: 16;
172 UINT32 LimitHigh
: 4;
175 UINT32 DefaultSize
: 1;
176 UINT32 Granularity
: 1;
183 Initialize IDT entries to support source level debug.
192 Read register value from saved CPU context.
194 @param[in] CpuContext Pointer to saved CPU context.
195 @param[in] Index Register index value.
196 @param[in] Width Data width to read.
198 @return The address of register value.
202 ArchReadRegisterBuffer (
203 IN DEBUG_CPU_CONTEXT
*CpuContext
,
209 Send packet with response data to HOST.
211 @param[in] Data Pointer to response data buffer.
212 @param[in] DataSize Size of response data in byte.
213 @param[in, out] DebugHeader Pointer to a buffer for creating response packet and receiving ACK packet,
214 to minimize the stack usage.
216 @retval RETURN_SUCCESS Response data was sent successfully.
217 @retval RETURN_DEVICE_ERROR Cannot receive DEBUG_COMMAND_OK from HOST.
221 SendDataResponsePacket (
224 IN OUT DEBUG_PACKET_HEADER
*DebugHeader
228 Check if HOST is attached based on Mailbox.
230 @retval TRUE HOST is attached.
231 @retval FALSE HOST is not attached.
240 Get Debug Agent Mailbox pointer.
242 @return Mailbox pointer.
245 DEBUG_AGENT_MAILBOX
*
251 Get debug port handle.
253 @return Debug port handle.
262 Read the Attach/Break-in symbols from the debug port.
264 @param[in] Handle Pointer to Debug Port handle.
265 @param[out] BreakSymbol Returned break symbol.
267 @retval EFI_SUCCESS Read the symbol in BreakSymbol.
268 @retval EFI_NOT_FOUND No read the break symbol.
272 DebugReadBreakSymbol (
273 IN DEBUG_PORT_HANDLE Handle
,
274 OUT UINT8
*BreakSymbol
278 Prints a debug message to the debug port if the specified error level is enabled.
280 If any bit in ErrorLevel is also set in Mainbox, then print the message specified
281 by Format and the associated variable argument list to the debug port.
283 @param[in] ErrorLevel The error level of the debug message.
284 @param[in] Format Format string for the debug message to print.
285 @param[in] ... Variable argument list whose contents are accessed
286 based on the format string specified by Format.
298 Trigger one software interrupt to debug agent to handle it.
300 @param[in] Signature Software interrupt signature.
304 TriggerSoftInterrupt (
309 Check if debug agent support multi-processor.
311 @retval TRUE Multi-processor is supported.
312 @retval FALSE Multi-processor is not supported.
316 MultiProcessorDebugSupport (
321 Find and report module image info to HOST.
323 @param[in] AlignSize Image aligned size.
327 FindAndReportModuleImageInfo (
332 Read IDT entry to check if IDT entries are setup by Debug Agent.
334 @retval TRUE IDT entries were setup by Debug Agent.
335 @retval FALSE IDT entries were not setup by Debug Agent.
339 IsDebugAgentInitialzed (
344 Calculate Mailbox checksum and update the checksum field.
346 @param[in] Mailbox Debug Agent Mailbox pointer.
350 UpdateMailboxChecksum (
351 IN DEBUG_AGENT_MAILBOX
*Mailbox
355 Verify Mailbox checksum.
357 If checksum error, print debug message and run init dead loop.
359 @param[in] Mailbox Debug Agent Mailbox pointer.
363 VerifyMailboxChecksum (
364 IN DEBUG_AGENT_MAILBOX
*Mailbox
368 Set debug flag in mailbox.
370 @param[in] FlagMask Debug flag mask value.
371 @param[in] FlagValue Debug flag value.
381 Get debug flag in mailbox.
383 @param[in] FlagMask Debug flag mask value.
385 @return Debug flag value.
394 Update Mailbox content by index.
396 @param[in] Mailbox Debug Agent Mailbox pointer.
397 @param[in] Index Mailbox content index.
398 @param[in] Value Value to be set into mail box.
402 UpdateMailboxContent (
403 IN DEBUG_AGENT_MAILBOX
*Mailbox
,
409 Retrieve exception handler from IDT table by ExceptionNum.
411 @param[in] ExceptionNum Exception number
413 @return Exception handler
417 GetExceptionHandlerInIdtEntry (
418 IN UINTN ExceptionNum
422 Set exception handler in IDT table by ExceptionNum.
424 @param[in] ExceptionNum Exception number
425 @param[in] ExceptionHandler Exception Handler to be set
429 SetExceptionHandlerInIdtEntry (
430 IN UINTN ExceptionNum
,
431 IN VOID
*ExceptionHandler
435 Prints a debug message to the debug output device if the specified error level is enabled.
437 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
438 GetDebugPrintErrorLevel (), then print the message specified by Format and the
439 associated variable argument list to the debug output device.
441 If Format is NULL, then ASSERT().
443 @param[in] ErrorLevel The error level of the debug message.
444 @param[in] IsSend Flag of debug message to declare that the data is being sent or being received.
445 @param[in] Data Variable argument list whose contents are accessed
446 @param[in] Length based on the format string specified by Format.
451 DebugAgentDataMsgPrint (
459 Read remaing debug packet except for the start symbol
461 @param[in] Handle Pointer to Debug Port handle.
462 @param[in, out] DebugHeader Debug header buffer including start symbol.
464 @retval EFI_SUCCESS Read the symbol in BreakSymbol.
465 @retval EFI_CRC_ERROR CRC check fail.
466 @retval EFI_TIMEOUT Timeout occurs when reading debug packet.
470 ReadRemainingBreakPacket (
471 IN DEBUG_PORT_HANDLE Handle
,
472 IN OUT DEBUG_PACKET_HEADER
*DebugHeader
476 Read data from debug channel and save the data in buffer.
478 Reads NumberOfBytes data bytes from a debug device into the buffer
479 specified by Buffer. The number of bytes actually read is returned.
480 If the return value is less than NumberOfBytes, then the rest operation failed.
481 If NumberOfBytes is zero, then return 0.
483 @param Handle Debug port handle.
484 @param Buffer Pointer to the data buffer to store the data read from the debug device.
485 @param NumberOfBytes Number of bytes which will be read.
486 @param Timeout Timeout value for reading from debug device. It unit is Microsecond.
488 @retval 0 Read data failed, no data is to be read.
489 @retval >0 Actual number of bytes read from debug device.
493 DebugAgentReadBuffer (
494 IN DEBUG_PORT_HANDLE Handle
,
495 IN OUT UINT8
*Buffer
,
496 IN UINTN NumberOfBytes
,