]> git.proxmox.com Git - mirror_edk2.git/blob - SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
Import SourceLevelDebugPkg.
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / DebugAgentCommon / DebugAgent.h
1 /** @file
2 Command header of for Debug Agent library instance.
3
4 Copyright (c) 2010, 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.
9
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.
12
13 **/
14
15 #ifndef _DEBUG_AGENT_H_
16 #define _DEBUG_AGENT_H_
17
18 #include <Register/LocalApic.h>
19
20 #include <Guid/DebugAgentGuid.h>
21
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
33 #include <TransferProtocol.h>
34 #include <ImageDebugSupport.h>
35
36 #include "DebugMp.h"
37 #include "DebugTimer.h"
38 #include "ArchDebugSupport.h"
39
40 #define DEBUG_AGENT_REVISION ((0 << 16) | 01)
41 #define DEBUG_AGENT_CAPABILITIES 0
42
43 #define DEBUG_INT1_VECTOR 1
44 #define DEBUG_INT3_VECTOR 3
45 #define DEBUG_TIMER_VECTOR 32
46 #define DEBUG_MAILBOX_VECTOR 33
47
48 #define SOFT_INTERRUPT_SIGNATURE SIGNATURE_32('S','O','F','T')
49 #define SYSTEM_RESET_SIGNATURE SIGNATURE_32('S','Y','S','R')
50 #define MEMORY_READY_SIGNATURE SIGNATURE_32('M','E','M','R')
51
52 extern UINTN Exception0Handle;
53 extern UINTN TimerInterruptHandle;
54 extern UINT16 ExceptionStubHeaderSize;
55
56 typedef union {
57 struct {
58 UINT32 HostPresent : 1;
59 UINT32 BreakOnNextSmi : 1;
60 UINT32 Reserved : 30;
61 } Bits;
62 UINT32 Uint32;
63 } DEBUG_AGENT_FLAG;
64
65 #pragma pack(1)
66 typedef struct {
67 DEBUG_AGENT_FLAG DebugFlag;
68 UINT64 DebugPortHandle;
69 } DEBUG_AGENT_MAILBOX;
70 #pragma pack()
71
72 typedef union {
73 struct {
74 UINT32 LimitLow : 16;
75 UINT32 BaseLow : 16;
76 UINT32 BaseMid : 8;
77 UINT32 Type : 4;
78 UINT32 System : 1;
79 UINT32 Dpl : 2;
80 UINT32 Present : 1;
81 UINT32 LimitHigh : 4;
82 UINT32 Software : 1;
83 UINT32 Reserved : 1;
84 UINT32 DefaultSize : 1;
85 UINT32 Granularity : 1;
86 UINT32 BaseHigh : 8;
87 } Bits;
88 UINT64 Uint64;
89 } IA32_GDT;
90
91 /**
92 Caller provided function to be invoked at the end of DebugPortInitialize().
93
94 Refer to the descrption for DebugPortInitialize() for more details.
95
96 @param[in] Context The first input argument of DebugPortInitialize().
97 @param[in] DebugPortHandle Debug port handle created by Debug Communication Libary.
98
99 **/
100 VOID
101 EFIAPI
102 InitializeDebugAgentPhase2 (
103 IN VOID *Context,
104 IN DEBUG_PORT_HANDLE DebugPortHandle
105 );
106
107 /**
108 Initialize IDT entries to support source level debug.
109
110 **/
111 VOID
112 InitializeDebugIdt (
113 VOID
114 );
115
116 /**
117 Write specified register into save CPU context.
118
119 @param[in] CpuContext Pointer to saved CPU context.
120 @param[in] Index Register index value.
121 @param[in] Offset Offset in register address range
122 @param[in] Width Data width to read.
123 @param[in] RegisterBuffer Pointer to input buffer with data.
124
125 **/
126 VOID
127 ArchWriteRegisterBuffer (
128 IN DEBUG_CPU_CONTEXT *CpuContext,
129 IN UINT8 Index,
130 IN UINT8 Offset,
131 IN UINT8 Width,
132 IN UINT8 *RegisterBuffer
133 );
134
135 /**
136 Read register value from saved CPU context.
137
138 @param[in] CpuContext Pointer to saved CPU context.
139 @param[in] Index Register index value.
140 @param[in] Offset Offset in register address range
141 @param[in] Width Data width to read.
142
143 @return The address of register value.
144
145 **/
146 UINT8 *
147 ArchReadRegisterBuffer (
148 IN DEBUG_CPU_CONTEXT *CpuContext,
149 IN UINT8 Index,
150 IN UINT8 Offset,
151 IN UINT8 *Width
152 );
153
154 /**
155 Send packet with response data to HOST.
156
157 @param[in] CpuContext Pointer to saved CPU context.
158 @param[in] Data Pointer to response data buffer.
159 @param[in] DataSize Size of response data in byte.
160
161 @retval RETURN_SUCCESS Response data was sent successfully.
162 @retval RETURN_DEVICE_ERROR Cannot receive DEBUG_COMMAND_OK from HOST.
163
164 **/
165 RETURN_STATUS
166 SendDataResponsePacket (
167 IN DEBUG_CPU_CONTEXT *CpuContext,
168 IN UINT8 *Data,
169 IN UINT16 DataSize
170 );
171
172 /**
173 Read segment selector by register index.
174
175 @param[in] CpuContext Pointer to saved CPU context.
176 @param[in] RegisterIndex Register Index.
177
178 @return Value of segment selector.
179
180 **/
181 UINT64
182 ReadRegisterSelectorByIndex (
183 IN DEBUG_CPU_CONTEXT *CpuContext,
184 IN UINT8 RegisterIndex
185 );
186
187 /**
188 Read group register of common registers.
189
190 @param[in] CpuContext Pointer to saved CPU context.
191 @param[in] RegisterGroup Pointer to Group registers.
192
193 **/
194 VOID
195 ReadRegisterGroup (
196 IN DEBUG_CPU_CONTEXT *CpuContext,
197 IN DEBUG_DATA_REPONSE_READ_REGISTER_GROUP *RegisterGroup
198 );
199
200 /**
201 Read group register of Segment Base.
202
203 @param[in] CpuContext Pointer to saved CPU context.
204 @param[in] RegisterGroupSegBase Pointer to Group registers.
205
206 **/
207 VOID
208 ReadRegisterGroupSegBase (
209 IN DEBUG_CPU_CONTEXT *CpuContext,
210 IN DEBUG_DATA_REPONSE_READ_REGISTER_GROUP_SEGBASE *RegisterGroupSegBase
211 );
212
213 /**
214 Read gourp register of Segment Limit.
215
216 @param[in] CpuContext Pointer to saved CPU context.
217 @param[in] RegisterGroupSegLim Pointer to Group registers.
218
219 **/
220 VOID
221 ReadRegisterGroupSegLim (
222 IN DEBUG_CPU_CONTEXT *CpuContext,
223 IN DEBUG_DATA_REPONSE_READ_REGISTER_GROUP_SEGLIM *RegisterGroupSegLim
224 );
225
226 /**
227 Read group register by group index.
228
229 @param[in] CpuContext Pointer to saved CPU context.
230 @param[in] GroupIndex Group Index.
231
232 @retval RETURN_SUCCESS Read successfully.
233 @retval RETURN_NOT_SUPPORTED Group index cannot be supported.
234
235 **/
236 RETURN_STATUS
237 ArchReadRegisterGroup (
238 IN DEBUG_CPU_CONTEXT *CpuContext,
239 IN UINT8 GroupIndex
240 );
241
242 /**
243 Send acknowledge packet to HOST.
244
245 @param AckCommand Type of Acknowledge packet.
246
247 **/
248 VOID
249 SendAckPacket (
250 IN UINT8 AckCommand
251 );
252
253 /**
254 Receive acknowledge packet OK from HOST in specified time.
255
256 @param[in] Timeout Time out value to wait for acknowlege from HOST.
257 The unit is microsecond.
258 @param[out] BreakReceived If BreakReceived is not NULL,
259 TRUE is retured if break-in symbol received.
260 FALSE is retured if break-in symbol not received.
261
262 @retval RETRUEN_SUCCESS Succeed to receive acknowlege packet from HOST,
263 the type of acknowlege packet saved in Ack.
264 @retval RETURN_TIMEOUT Specified timeout value was up.
265
266 **/
267 RETURN_STATUS
268 WaitForAckPacketOK (
269 IN UINTN Timeout,
270 OUT BOOLEAN *BreakReceived OPTIONAL
271 );
272
273 /**
274 Check if HOST is connected based on Mailbox.
275
276 @retval TRUE HOST is connected.
277 @retval FALSE HOST is not connected.
278
279 **/
280 BOOLEAN
281 IsHostConnected (
282 VOID
283 );
284
285 /**
286 Get Debug Agent Mailbox pointer.
287
288 @return Mailbox pointer.
289
290 **/
291 DEBUG_AGENT_MAILBOX *
292 GetMailboxPointer (
293 VOID
294 );
295
296 /**
297 Get debug port handle.
298
299 @return Debug port handle.
300
301 **/
302 DEBUG_PORT_HANDLE
303 GetDebugPortHandle (
304 VOID
305 );
306
307 #endif
308