TianoCore EDK2 master
Loading...
Searching...
No Matches
DebugAgent.h File Reference
#include <Register/LocalApic.h>
#include <Guid/DebugAgentGuid.h>
#include <Guid/VectorHandoffTable.h>
#include <Ppi/VectorHandoffInfo.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/ResetSystemLib.h>
#include <Library/IoLib.h>
#include <Library/HobLib.h>
#include <Library/DebugCommunicationLib.h>
#include <Library/DebugAgentLib.h>
#include <Library/PcdLib.h>
#include <Library/SynchronizationLib.h>
#include <Library/LocalApicLib.h>
#include <Library/DebugLib.h>
#include <Library/TimerLib.h>
#include <Library/PrintLib.h>
#include <Library/PeCoffGetEntryPointLib.h>
#include <Library/PeCoffExtraActionLib.h>
#include <Register/ArchitecturalMsr.h>
#include <TransferProtocol.h>
#include <ImageDebugSupport.h>
#include "DebugMp.h"
#include "DebugTimer.h"
#include "ArchDebugSupport.h"
#include "DebugException.h"

Go to the source code of this file.

Data Structures

struct  DEBUG_AGENT_EXCEPTION_BUFFER
 
union  DEBUG_AGENT_FLAG
 
struct  DEBUG_AGENT_MAILBOX
 
union  IA32_IDT_ENTRY
 
union  IA32_GDT
 

Macros

#define DEBUG_AGENT_INIT_PEI   9
 
#define DEBUG_AGENT_INIT_DXE_LOAD   10
 
#define DEBUG_AGENT_INIT_DXE_UNLOAD   11
 
#define DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64   12
 
#define DEBUG_INT1_VECTOR   DEBUG_EXCEPT_DEBUG
 
#define DEBUG_INT3_VECTOR   DEBUG_EXCEPT_BREAKPOINT
 
#define DEBUG_TIMER_VECTOR   32
 
#define DEBUG_MAILBOX_VECTOR   33
 
#define READ_PACKET_TIMEOUT   (500 * 1000)
 
#define DEBUG_TIMER_INTERVAL   (100 * 1000)
 
#define SOFT_INTERRUPT_SIGNATURE   SIGNATURE_32('S','O','F','T')
 
#define SYSTEM_RESET_SIGNATURE   SIGNATURE_32('S','Y','S','R')
 
#define MEMORY_READY_SIGNATURE   SIGNATURE_32('M','E','M','R')
 
#define DEBUG_AGENT_FLAG_HOST_ATTACHED   BIT0
 
#define DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS   BIT1
 
#define DEBUG_AGENT_FLAG_MEMORY_READY   BIT2
 
#define DEBUG_AGENT_FLAG_STEPPING   BIT3
 
#define DEBUG_AGENT_FLAG_CHECK_MAILBOX_IN_HOB   BIT4
 
#define DEBUG_AGENT_FLAG_INIT_ARCH   BIT5|BIT6
 
#define DEBUG_AGENT_FLAG_INTERRUPT_FLAG   BIT7
 
#define DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI   BIT32
 
#define DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL   (BIT33|BIT34|BIT35|BIT36)
 
#define DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT   BIT37
 
#define DEBUG_MAILBOX_DEBUG_FLAG_INDEX   1
 
#define DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX   2
 
#define DEBUG_MAILBOX_EXCEPTION_BUFFER_POINTER_INDEX   3
 
#define DEBUG_MAILBOX_LAST_ACK   4
 
#define DEBUG_MAILBOX_SEQUENCE_NO_INDEX   5
 
#define DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX   6
 
#define DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY   7
 

Functions

VOID InitializeDebugIdt (VOID)
 
UINT8 * ArchReadRegisterBuffer (IN DEBUG_CPU_CONTEXT *CpuContext, IN UINT8 Index, IN UINT8 *Width)
 
RETURN_STATUS SendDataResponsePacket (IN UINT8 *Data, IN UINT16 DataSize, IN OUT DEBUG_PACKET_HEADER *DebugHeader)
 
BOOLEAN IsHostAttached (VOID)
 
DEBUG_AGENT_MAILBOXGetMailboxPointer (VOID)
 
DEBUG_PORT_HANDLE GetDebugPortHandle (VOID)
 
EFI_STATUS DebugReadBreakSymbol (IN DEBUG_PORT_HANDLE Handle, OUT UINT8 *BreakSymbol)
 
VOID EFIAPI DebugAgentMsgPrint (IN UINT8 ErrorLevel, IN CHAR8 *Format,...)
 
VOID TriggerSoftInterrupt (IN UINT32 Signature)
 
BOOLEAN MultiProcessorDebugSupport (VOID)
 
VOID FindAndReportModuleImageInfo (IN UINTN AlignSize)
 
BOOLEAN IsDebugAgentInitialzed (VOID)
 
VOID UpdateMailboxChecksum (IN DEBUG_AGENT_MAILBOX *Mailbox)
 
VOID VerifyMailboxChecksum (IN DEBUG_AGENT_MAILBOX *Mailbox)
 
VOID SetDebugFlag (IN UINT64 FlagMask, IN UINT32 FlagValue)
 
UINT32 GetDebugFlag (IN UINT64 FlagMask)
 
VOID UpdateMailboxContent (IN DEBUG_AGENT_MAILBOX *Mailbox, IN UINTN Index, IN UINT64 Value)
 
VOID * GetExceptionHandlerInIdtEntry (IN UINTN ExceptionNum)
 
VOID SetExceptionHandlerInIdtEntry (IN UINTN ExceptionNum, IN VOID *ExceptionHandler)
 
VOID EFIAPI DebugAgentDataMsgPrint (IN UINT8 ErrorLevel, IN BOOLEAN IsSend, IN UINT8 *Data, IN UINT8 Length)
 
EFI_STATUS ReadRemainingBreakPacket (IN DEBUG_PORT_HANDLE Handle, IN OUT DEBUG_PACKET_HEADER *DebugHeader)
 
UINTN DebugAgentReadBuffer (IN DEBUG_PORT_HANDLE Handle, IN OUT UINT8 *Buffer, IN UINTN NumberOfBytes, IN UINTN Timeout)
 

Variables

UINTN Exception0Handle
 
UINTN TimerInterruptHandle
 
UINT32 ExceptionStubHeaderSize
 
BOOLEAN mSkipBreakpoint
 
EFI_VECTOR_HANDOFF_INFO mVectorHandoffInfoDebugAgent []
 
UINTN mVectorHandoffInfoCount
 

Detailed Description

Command header of for Debug Agent library instance.

Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file DebugAgent.h.

Macro Definition Documentation

◆ DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS

#define DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS   BIT1

Definition at line 86 of file DebugAgent.h.

◆ DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT

#define DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT   BIT37

Definition at line 94 of file DebugAgent.h.

◆ DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI

#define DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI   BIT32

Definition at line 92 of file DebugAgent.h.

◆ DEBUG_AGENT_FLAG_CHECK_MAILBOX_IN_HOB

#define DEBUG_AGENT_FLAG_CHECK_MAILBOX_IN_HOB   BIT4

Definition at line 89 of file DebugAgent.h.

◆ DEBUG_AGENT_FLAG_HOST_ATTACHED

#define DEBUG_AGENT_FLAG_HOST_ATTACHED   BIT0

Definition at line 85 of file DebugAgent.h.

◆ DEBUG_AGENT_FLAG_INIT_ARCH

#define DEBUG_AGENT_FLAG_INIT_ARCH   BIT5|BIT6

Definition at line 90 of file DebugAgent.h.

◆ DEBUG_AGENT_FLAG_INTERRUPT_FLAG

#define DEBUG_AGENT_FLAG_INTERRUPT_FLAG   BIT7

Definition at line 91 of file DebugAgent.h.

◆ DEBUG_AGENT_FLAG_MEMORY_READY

#define DEBUG_AGENT_FLAG_MEMORY_READY   BIT2

Definition at line 87 of file DebugAgent.h.

◆ DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL

#define DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL   (BIT33|BIT34|BIT35|BIT36)

Definition at line 93 of file DebugAgent.h.

◆ DEBUG_AGENT_FLAG_STEPPING

#define DEBUG_AGENT_FLAG_STEPPING   BIT3

Definition at line 88 of file DebugAgent.h.

◆ DEBUG_AGENT_INIT_DXE_LOAD

#define DEBUG_AGENT_INIT_DXE_LOAD   10

Definition at line 45 of file DebugAgent.h.

◆ DEBUG_AGENT_INIT_DXE_UNLOAD

#define DEBUG_AGENT_INIT_DXE_UNLOAD   11

Definition at line 46 of file DebugAgent.h.

◆ DEBUG_AGENT_INIT_PEI

#define DEBUG_AGENT_INIT_PEI   9

Definition at line 44 of file DebugAgent.h.

◆ DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64

#define DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64   12

Definition at line 47 of file DebugAgent.h.

◆ DEBUG_INT1_VECTOR

#define DEBUG_INT1_VECTOR   DEBUG_EXCEPT_DEBUG

Definition at line 49 of file DebugAgent.h.

◆ DEBUG_INT3_VECTOR

#define DEBUG_INT3_VECTOR   DEBUG_EXCEPT_BREAKPOINT

Definition at line 50 of file DebugAgent.h.

◆ DEBUG_MAILBOX_DEBUG_FLAG_INDEX

#define DEBUG_MAILBOX_DEBUG_FLAG_INDEX   1

Definition at line 96 of file DebugAgent.h.

◆ DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX

#define DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX   2

Definition at line 97 of file DebugAgent.h.

◆ DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY

#define DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY   7

Definition at line 102 of file DebugAgent.h.

◆ DEBUG_MAILBOX_EXCEPTION_BUFFER_POINTER_INDEX

#define DEBUG_MAILBOX_EXCEPTION_BUFFER_POINTER_INDEX   3

Definition at line 98 of file DebugAgent.h.

◆ DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX

#define DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX   6

Definition at line 101 of file DebugAgent.h.

◆ DEBUG_MAILBOX_LAST_ACK

#define DEBUG_MAILBOX_LAST_ACK   4

Definition at line 99 of file DebugAgent.h.

◆ DEBUG_MAILBOX_SEQUENCE_NO_INDEX

#define DEBUG_MAILBOX_SEQUENCE_NO_INDEX   5

Definition at line 100 of file DebugAgent.h.

◆ DEBUG_MAILBOX_VECTOR

#define DEBUG_MAILBOX_VECTOR   33

Definition at line 52 of file DebugAgent.h.

◆ DEBUG_TIMER_INTERVAL

#define DEBUG_TIMER_INTERVAL   (100 * 1000)

Definition at line 58 of file DebugAgent.h.

◆ DEBUG_TIMER_VECTOR

#define DEBUG_TIMER_VECTOR   32

Definition at line 51 of file DebugAgent.h.

◆ MEMORY_READY_SIGNATURE

#define MEMORY_READY_SIGNATURE   SIGNATURE_32('M','E','M','R')

Definition at line 62 of file DebugAgent.h.

◆ READ_PACKET_TIMEOUT

#define READ_PACKET_TIMEOUT   (500 * 1000)

Definition at line 57 of file DebugAgent.h.

◆ SOFT_INTERRUPT_SIGNATURE

#define SOFT_INTERRUPT_SIGNATURE   SIGNATURE_32('S','O','F','T')

Definition at line 60 of file DebugAgent.h.

◆ SYSTEM_RESET_SIGNATURE

#define SYSTEM_RESET_SIGNATURE   SIGNATURE_32('S','Y','S','R')

Definition at line 61 of file DebugAgent.h.

Function Documentation

◆ ArchReadRegisterBuffer()

UINT8 * ArchReadRegisterBuffer ( IN DEBUG_CPU_CONTEXT CpuContext,
IN UINT8  Index,
IN UINT8 *  Width 
)

Read register value from saved CPU context.

Parameters
[in]CpuContextPointer to saved CPU context.
[in]IndexRegister index value.
[in]WidthData width to read.
Returns
The address of register value.

◆ DebugAgentDataMsgPrint()

VOID EFIAPI DebugAgentDataMsgPrint ( IN UINT8  ErrorLevel,
IN BOOLEAN  IsSend,
IN UINT8 *  Data,
IN UINT8  Length 
)

Prints a debug message to the debug output device if the specified error level is enabled.

If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function GetDebugPrintErrorLevel (), then print the message specified by Format and the associated variable argument list to the debug output device.

If Format is NULL, then ASSERT().

Parameters
[in]ErrorLevelThe error level of the debug message.
[in]IsSendFlag of debug message to declare that the data is being sent or being received.
[in]DataVariable argument list whose contents are accessed
[in]Lengthbased on the format string specified by Format.

Definition at line 561 of file DebugAgent.c.

◆ DebugAgentMsgPrint()

VOID EFIAPI DebugAgentMsgPrint ( IN UINT8  ErrorLevel,
IN CHAR8 *  Format,
  ... 
)

Prints a debug message to the debug port if the specified error level is enabled.

If any bit in ErrorLevel is also set in Mainbox, then print the message specified by Format and the associated variable argument list to the debug port.

Parameters
[in]ErrorLevelThe error level of the debug message.
[in]FormatFormat string for the debug message to print.
[in]...Variable argument list whose contents are accessed based on the format string specified by Format.

Definition at line 518 of file DebugAgent.c.

◆ DebugAgentReadBuffer()

UINTN DebugAgentReadBuffer ( IN DEBUG_PORT_HANDLE  Handle,
IN OUT UINT8 *  Buffer,
IN UINTN  NumberOfBytes,
IN UINTN  Timeout 
)

Read data from debug channel and save the data in buffer.

Reads NumberOfBytes data bytes from a debug device into the buffer specified by Buffer. The number of bytes actually read is returned. If the return value is less than NumberOfBytes, then the rest operation failed. If NumberOfBytes is zero, then return 0.

Parameters
HandleDebug port handle.
BufferPointer to the data buffer to store the data read from the debug device.
NumberOfBytesNumber of bytes which will be read.
TimeoutTimeout value for reading from debug device. It unit is Microsecond.
Return values
0Read data failed, no data is to be read.
>0Actual number of bytes read from debug device.

◆ DebugReadBreakSymbol()

EFI_STATUS DebugReadBreakSymbol ( IN DEBUG_PORT_HANDLE  Handle,
OUT UINT8 *  BreakSymbol 
)

Read the Attach/Break-in symbols from the debug port.

Parameters
[in]HandlePointer to Debug Port handle.
[out]BreakSymbolReturned break symbol.
Return values
EFI_SUCCESSRead the symbol in BreakSymbol.
EFI_NOT_FOUNDNo read the break symbol.

Read the Attach/Break-in symbols.

Parameters
[in]HandlePointer to Debug Port handle.
[out]BreakSymbolReturned break symbol.
Return values
EFI_SUCCESSRead the symbol in BreakSymbol.
EFI_NOT_FOUNDNo read the break symbol.

Definition at line 806 of file SerialIo.c.

◆ FindAndReportModuleImageInfo()

VOID FindAndReportModuleImageInfo ( IN UINTN  AlignSize)

Find and report module image info to HOST.

Parameters
[in]AlignSizeImage aligned size.

Definition at line 193 of file DebugAgent.c.

◆ GetDebugFlag()

UINT32 GetDebugFlag ( IN UINT64  FlagMask)

Get debug flag in mailbox.

Parameters
[in]FlagMaskDebug flag mask value.
Returns
Debug flag value.

Definition at line 458 of file DebugAgent.c.

◆ GetDebugPortHandle()

DEBUG_PORT_HANDLE GetDebugPortHandle ( VOID  )

Get debug port handle.

Returns
Debug port handle.

Definition at line 226 of file DxeDebugAgentLib.c.

◆ GetExceptionHandlerInIdtEntry()

VOID * GetExceptionHandlerInIdtEntry ( IN UINTN  ExceptionNum)

Retrieve exception handler from IDT table by ExceptionNum.

Parameters
[in]ExceptionNumException number
Returns
Exception handler

Definition at line 76 of file ArchDebugSupport.c.

◆ GetMailboxPointer()

DEBUG_AGENT_MAILBOX * GetMailboxPointer ( VOID  )

Get Debug Agent Mailbox pointer.

Returns
Mailbox pointer.

Definition at line 209 of file DxeDebugAgentLib.c.

◆ InitializeDebugIdt()

VOID InitializeDebugIdt ( VOID  )

Initialize IDT entries to support source level debug.

Definition at line 16 of file ArchDebugSupport.c.

◆ IsDebugAgentInitialzed()

BOOLEAN IsDebugAgentInitialzed ( VOID  )

Read IDT entry to check if IDT entries are setup by Debug Agent.

Return values
TRUEIDT entries were setup by Debug Agent.
FALSEIDT entries were not setup by Debug Agent.

Definition at line 172 of file DebugAgent.c.

◆ IsHostAttached()

BOOLEAN IsHostAttached ( VOID  )

Check if HOST is attached based on Mailbox.

Return values
TRUEHOST is attached.
FALSEHOST is not attached.

Definition at line 676 of file DebugAgent.c.

◆ MultiProcessorDebugSupport()

BOOLEAN MultiProcessorDebugSupport ( VOID  )

Check if debug agent support multi-processor.

Return values
TRUEMulti-processor is supported.
FALSEMulti-processor is not supported.

Definition at line 29 of file DxeDebugAgentLib.c.

◆ ReadRemainingBreakPacket()

EFI_STATUS ReadRemainingBreakPacket ( IN DEBUG_PORT_HANDLE  Handle,
IN OUT DEBUG_PACKET_HEADER DebugHeader 
)

Read remaining debug packet except for the start symbol

Parameters
[in]HandlePointer to Debug Port handle.
[in,out]DebugHeaderDebug header buffer including start symbol.
Return values
EFI_SUCCESSRead the symbol in BreakSymbol.
EFI_CRC_ERRORCRC check fail.
EFI_TIMEOUTTimeout occurs when reading debug packet.

Read remaining debug packet except for the start symbol

Parameters
[in]HandlePointer to Debug Port handle.
[in,out]DebugHeaderDebug header buffer including start symbol.
Return values
EFI_SUCCESSRead the symbol in BreakSymbol.
EFI_CRC_ERRORCRC check fail.
EFI_TIMEOUTTimeout occurs when reading debug packet.
EFI_DEVICE_ERRORReceive the old or response packet.

Definition at line 623 of file DebugAgent.c.

◆ SendDataResponsePacket()

RETURN_STATUS SendDataResponsePacket ( IN UINT8 *  Data,
IN UINT16  DataSize,
IN OUT DEBUG_PACKET_HEADER DebugHeader 
)

Send packet with response data to HOST.

Parameters
[in]DataPointer to response data buffer.
[in]DataSizeSize of response data in byte.
[in,out]DebugHeaderPointer to a buffer for creating response packet and receiving ACK packet, to minimize the stack usage.
Return values
RETURN_SUCCESSResponse data was sent successfully.
RETURN_DEVICE_ERRORCannot receive DEBUG_COMMAND_OK from HOST.

Send packet with response data to HOST.

Parameters
[in]DataPointer to response data buffer.
[in]DataSizeSize of response data in byte.
[in,out]DebugHeaderPointer to a buffer for creating response packet and receiving ACK packet, to minimize the stack usage.
Return values
RETURN_SUCCESSResponse data was sent successfully.

Definition at line 1688 of file DebugAgent.c.

◆ SetDebugFlag()

VOID SetDebugFlag ( IN UINT64  FlagMask,
IN UINT32  FlagValue 
)

Set debug flag in mailbox.

Parameters
[in]FlagMaskDebug flag mask value.
[in]FlagValueDebug flag value.

Definition at line 435 of file DebugAgent.c.

◆ SetExceptionHandlerInIdtEntry()

VOID SetExceptionHandlerInIdtEntry ( IN UINTN  ExceptionNum,
IN VOID *  ExceptionHandler 
)

Set exception handler in IDT table by ExceptionNum.

Parameters
[in]ExceptionNumException number
[in]ExceptionHandlerException Handler to be set

Definition at line 98 of file ArchDebugSupport.c.

◆ TriggerSoftInterrupt()

VOID TriggerSoftInterrupt ( IN UINT32  Signature)

Trigger one software interrupt to debug agent to handle it.

Parameters
[in]SignatureSoftware interrupt signature.

Definition at line 218 of file DebugAgent.c.

◆ UpdateMailboxChecksum()

VOID UpdateMailboxChecksum ( IN DEBUG_AGENT_MAILBOX Mailbox)

Calculate Mailbox checksum and update the checksum field.

Parameters
[in]MailboxDebug Agent Mailbox pointer.

Definition at line 257 of file DebugAgent.c.

◆ UpdateMailboxContent()

VOID UpdateMailboxContent ( IN DEBUG_AGENT_MAILBOX Mailbox,
IN UINTN  Index,
IN UINT64  Value 
)

Update Mailbox content by index.

Parameters
[in]MailboxDebug Agent Mailbox pointer.
[in]IndexMailbox content index.
[in]ValueValue to be set into mail box.

Update Mailbox content by index.

Parameters
[in]MailboxDebug Agent Mailbox pointer.
[in]IndexMailbox content index.
[in]ValueValue to be set into Mailbox.

Definition at line 300 of file DebugAgent.c.

◆ VerifyMailboxChecksum()

VOID VerifyMailboxChecksum ( IN DEBUG_AGENT_MAILBOX Mailbox)

Verify Mailbox checksum.

If checksum error, print debug message and run init dead loop.

Parameters
[in]MailboxDebug Agent Mailbox pointer.

Definition at line 273 of file DebugAgent.c.

Variable Documentation

◆ mSkipBreakpoint

BOOLEAN mSkipBreakpoint
extern

Definition at line 19 of file DxeDebugAgentLib.c.

◆ mVectorHandoffInfoCount

UINTN mVectorHandoffInfoCount
extern

Definition at line 127 of file DebugAgent.c.

◆ mVectorHandoffInfoDebugAgent

EFI_VECTOR_HANDOFF_INFO mVectorHandoffInfoDebugAgent[]
extern

Definition at line 24 of file DebugAgent.c.