TianoCore EDK2 master
Loading...
Searching...
No Matches
DebugAgent.h
Go to the documentation of this file.
1
9#ifndef _DEBUG_AGENT_H_
10#define _DEBUG_AGENT_H_
11
12#include <Register/LocalApic.h>
13#include <Guid/DebugAgentGuid.h>
16#include <Library/BaseLib.h>
19#include <Library/IoLib.h>
20#include <Library/HobLib.h>
23#include <Library/PcdLib.h>
26#include <Library/DebugLib.h>
27#include <Library/TimerLib.h>
28#include <Library/PrintLib.h>
32
33#include <TransferProtocol.h>
34#include <ImageDebugSupport.h>
35
36#include "DebugMp.h"
37#include "DebugTimer.h"
38#include "ArchDebugSupport.h"
39#include "DebugException.h"
40
41//
42// These macros may be already defined in DebugAgentLib.h
43//
44#define DEBUG_AGENT_INIT_PEI 9
45#define DEBUG_AGENT_INIT_DXE_LOAD 10
46#define DEBUG_AGENT_INIT_DXE_UNLOAD 11
47#define DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64 12
48
49#define DEBUG_INT1_VECTOR DEBUG_EXCEPT_DEBUG
50#define DEBUG_INT3_VECTOR DEBUG_EXCEPT_BREAKPOINT
51#define DEBUG_TIMER_VECTOR 32
52#define DEBUG_MAILBOX_VECTOR 33
53
54//
55// Timeout value for reading packet (unit is microsecond)
56//
57#define READ_PACKET_TIMEOUT (500 * 1000)
58#define DEBUG_TIMER_INTERVAL (100 * 1000)
59
60#define SOFT_INTERRUPT_SIGNATURE SIGNATURE_32('S','O','F','T')
61#define SYSTEM_RESET_SIGNATURE SIGNATURE_32('S','Y','S','R')
62#define MEMORY_READY_SIGNATURE SIGNATURE_32('M','E','M','R')
63
64extern UINTN Exception0Handle;
65extern UINTN TimerInterruptHandle;
66extern UINT32 ExceptionStubHeaderSize;
67extern BOOLEAN mSkipBreakpoint;
68extern EFI_VECTOR_HANDOFF_INFO mVectorHandoffInfoDebugAgent[];
69extern UINTN mVectorHandoffInfoCount;
70
71//
72// CPU exception information issued by debug agent
73//
74typedef struct {
75 //
76 // This field is used to save CPU content before executing HOST command
77 //
78 BASE_LIBRARY_JUMP_BUFFER JumpBuffer;
79 //
80 // This field returns the exception information issued by the HOST command
81 //
82 DEBUG_DATA_RESPONSE_GET_EXCEPTION ExceptionContent;
84
85#define DEBUG_AGENT_FLAG_HOST_ATTACHED BIT0
86#define DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS BIT1
87#define DEBUG_AGENT_FLAG_MEMORY_READY BIT2
88#define DEBUG_AGENT_FLAG_STEPPING BIT3
89#define DEBUG_AGENT_FLAG_CHECK_MAILBOX_IN_HOB BIT4
90#define DEBUG_AGENT_FLAG_INIT_ARCH BIT5|BIT6
91#define DEBUG_AGENT_FLAG_INTERRUPT_FLAG BIT7
92#define DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI BIT32
93#define DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL (BIT33|BIT34|BIT35|BIT36)
94#define DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT BIT37
95
96#define DEBUG_MAILBOX_DEBUG_FLAG_INDEX 1
97#define DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX 2
98#define DEBUG_MAILBOX_EXCEPTION_BUFFER_POINTER_INDEX 3
99#define DEBUG_MAILBOX_LAST_ACK 4
100#define DEBUG_MAILBOX_SEQUENCE_NO_INDEX 5
101#define DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX 6
102#define DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY 7
103
104#pragma pack(1)
105typedef union {
106 struct {
107 //
108 // Lower 32 bits to store the status of DebugAgent
109 //
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 InterruptFlag : 1; // 1: EFLAGS.IF is set
117 UINT32 Reserved1 : 24;
118 //
119 // Higher 32bits to control the behavior of DebugAgent
120 //
121 UINT32 BreakOnNextSmi : 1; // 1: Break on next SMI
122 UINT32 PrintErrorLevel : 4; // Bitmask of print error level for debug message
123 UINT32 BreakOnBootScript : 1; // 1: Break before executing boot script
124 UINT32 Reserved2 : 26;
125 } Bits;
126 UINT64 Uint64;
128
129typedef struct {
130 DEBUG_AGENT_FLAG DebugFlag;
131 UINT64 DebugPortHandle;
132 //
133 // Pointer to DEBUG_AGENT_EXCEPTION_BUFFER
134 //
135 UINT64 ExceptionBufferPointer;
136 UINT8 LastAck; // The last ack packet type
137 UINT8 SequenceNo;
138 UINT8 HostSequenceNo;
139 UINT32 DebugTimerFrequency;
140 UINT8 CheckSum; // Mailbox checksum
141 UINT8 ToBeCheckSum; // To be Mailbox checksum at the next
143#pragma pack()
144
148typedef union {
149 struct {
150 UINT32 OffsetLow : 16;
151 UINT32 Selector : 16;
152 UINT32 Reserved_0 : 8;
153 UINT32 GateType : 8;
154 UINT32 OffsetHigh : 16;
155 } Bits;
156 UINT64 Uint64;
158
159typedef union {
160 struct {
161 UINT32 LimitLow : 16;
162 UINT32 BaseLow : 16;
163 UINT32 BaseMid : 8;
164 UINT32 Type : 4;
165 UINT32 System : 1;
166 UINT32 Dpl : 2;
167 UINT32 Present : 1;
168 UINT32 LimitHigh : 4;
169 UINT32 Software : 1;
170 UINT32 Reserved : 1;
171 UINT32 DefaultSize : 1;
172 UINT32 Granularity : 1;
173 UINT32 BaseHigh : 8;
174 } Bits;
175 UINT64 Uint64;
176} IA32_GDT;
177
182VOID
184 VOID
185 );
186
197UINT8 *
199 IN DEBUG_CPU_CONTEXT *CpuContext,
200 IN UINT8 Index,
201 IN UINT8 *Width
202 );
203
216RETURN_STATUS
218 IN UINT8 *Data,
219 IN UINT16 DataSize,
220 IN OUT DEBUG_PACKET_HEADER *DebugHeader
221 );
222
230BOOLEAN
232 VOID
233 );
234
243 VOID
244 );
245
252DEBUG_PORT_HANDLE
254 VOID
255 );
256
269 IN DEBUG_PORT_HANDLE Handle,
270 OUT UINT8 *BreakSymbol
271 );
272
285VOID
286EFIAPI
288 IN UINT8 ErrorLevel,
289 IN CHAR8 *Format,
290 ...
291 );
292
299VOID
301 IN UINT32 Signature
302 );
303
311BOOLEAN
313 VOID
314 );
315
322VOID
324 IN UINTN AlignSize
325 );
326
334BOOLEAN
336 VOID
337 );
338
345VOID
347 IN DEBUG_AGENT_MAILBOX *Mailbox
348 );
349
358VOID
360 IN DEBUG_AGENT_MAILBOX *Mailbox
361 );
362
370VOID
372 IN UINT64 FlagMask,
373 IN UINT32 FlagValue
374 );
375
384UINT32
386 IN UINT64 FlagMask
387 );
388
397VOID
399 IN DEBUG_AGENT_MAILBOX *Mailbox,
400 IN UINTN Index,
401 IN UINT64 Value
402 );
403
412VOID *
414 IN UINTN ExceptionNum
415 );
416
424VOID
426 IN UINTN ExceptionNum,
427 IN VOID *ExceptionHandler
428 );
429
445VOID
446EFIAPI
448 IN UINT8 ErrorLevel,
449 IN BOOLEAN IsSend,
450 IN UINT8 *Data,
451 IN UINT8 Length
452 );
453
467 IN DEBUG_PORT_HANDLE Handle,
468 IN OUT DEBUG_PACKET_HEADER *DebugHeader
469 );
470
488UINTN
490 IN DEBUG_PORT_HANDLE Handle,
491 IN OUT UINT8 *Buffer,
492 IN UINTN NumberOfBytes,
493 IN UINTN Timeout
494 );
495
496#endif
UINT64 UINTN
UINTN DebugAgentReadBuffer(IN DEBUG_PORT_HANDLE Handle, IN OUT UINT8 *Buffer, IN UINTN NumberOfBytes, IN UINTN Timeout)
VOID UpdateMailboxContent(IN DEBUG_AGENT_MAILBOX *Mailbox, IN UINTN Index, IN UINT64 Value)
Definition: DebugAgent.c:300
UINT32 GetDebugFlag(IN UINT64 FlagMask)
Definition: DebugAgent.c:458
VOID EFIAPI DebugAgentMsgPrint(IN UINT8 ErrorLevel, IN CHAR8 *Format,...)
Definition: DebugAgent.c:518
BOOLEAN IsHostAttached(VOID)
Definition: DebugAgent.c:676
DEBUG_AGENT_MAILBOX * GetMailboxPointer(VOID)
VOID VerifyMailboxChecksum(IN DEBUG_AGENT_MAILBOX *Mailbox)
Definition: DebugAgent.c:273
BOOLEAN MultiProcessorDebugSupport(VOID)
RETURN_STATUS SendDataResponsePacket(IN UINT8 *Data, IN UINT16 DataSize, IN OUT DEBUG_PACKET_HEADER *DebugHeader)
Definition: DebugAgent.c:1688
VOID UpdateMailboxChecksum(IN DEBUG_AGENT_MAILBOX *Mailbox)
Definition: DebugAgent.c:257
VOID EFIAPI DebugAgentDataMsgPrint(IN UINT8 ErrorLevel, IN BOOLEAN IsSend, IN UINT8 *Data, IN UINT8 Length)
Definition: DebugAgent.c:561
VOID SetDebugFlag(IN UINT64 FlagMask, IN UINT32 FlagValue)
Definition: DebugAgent.c:435
VOID FindAndReportModuleImageInfo(IN UINTN AlignSize)
Definition: DebugAgent.c:193
VOID * GetExceptionHandlerInIdtEntry(IN UINTN ExceptionNum)
BOOLEAN IsDebugAgentInitialzed(VOID)
Definition: DebugAgent.c:172
DEBUG_PORT_HANDLE GetDebugPortHandle(VOID)
VOID TriggerSoftInterrupt(IN UINT32 Signature)
Definition: DebugAgent.c:218
EFI_STATUS ReadRemainingBreakPacket(IN DEBUG_PORT_HANDLE Handle, IN OUT DEBUG_PACKET_HEADER *DebugHeader)
Definition: DebugAgent.c:623
EFI_STATUS DebugReadBreakSymbol(IN DEBUG_PORT_HANDLE Handle, OUT UINT8 *BreakSymbol)
Definition: SerialIo.c:806
UINT8 * ArchReadRegisterBuffer(IN DEBUG_CPU_CONTEXT *CpuContext, IN UINT8 Index, IN UINT8 *Width)
VOID InitializeDebugIdt(VOID)
VOID SetExceptionHandlerInIdtEntry(IN UINTN ExceptionNum, IN VOID *ExceptionHandler)
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINT32 GateType
Gate Type. See #defines above.
Definition: DebugAgent.h:153
UINT32 Reserved_0
Reserved.
Definition: DebugAgent.h:152
UINT32 OffsetLow
Offset bits 15..0.
Definition: DebugAgent.h:150
UINT32 OffsetHigh
Offset bits 31..16.
Definition: DebugAgent.h:154
UINT32 Selector
Selector.
Definition: DebugAgent.h:151