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