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