]>
Commit | Line | Data |
---|---|---|
18b144ea | 1 | /** @file\r |
2 | Debug Agent library implementition for Dxe Core and Dxr modules.\r | |
3 | \r | |
3bf04a71 | 4 | Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r |
18b144ea | 5 | This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php.\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "DxeDebugAgentLib.h"\r | |
16 | \r | |
17 | DEBUG_AGENT_MAILBOX mMailbox;\r | |
b422b62c | 18 | DEBUG_AGENT_MAILBOX *mMailboxPointer = NULL;\r |
18b144ea | 19 | IA32_IDT_GATE_DESCRIPTOR mIdtEntryTable[33];\r |
b422b62c | 20 | BOOLEAN mDxeCoreFlag = FALSE;\r |
21 | BOOLEAN mMultiProcessorDebugSupport = FALSE;\r | |
22 | VOID *mSavedIdtTable = NULL;\r | |
23 | UINTN mSaveIdtTableSize = 0;\r | |
24 | BOOLEAN mDebugAgentInitialized = FALSE;\r | |
25 | BOOLEAN mSkipBreakpoint = FALSE;\r | |
18b144ea | 26 | \r |
27 | /**\r | |
b422b62c | 28 | Check if debug agent support multi-processor.\r |
18b144ea | 29 | \r |
b422b62c | 30 | @retval TRUE Multi-processor is supported.\r |
31 | @retval FALSE Multi-processor is not supported.\r | |
32 | \r | |
33 | **/\r | |
34 | BOOLEAN\r | |
35 | MultiProcessorDebugSupport (\r | |
36 | VOID\r | |
37 | )\r | |
38 | {\r | |
39 | return mMultiProcessorDebugSupport;\r | |
40 | }\r | |
18b144ea | 41 | \r |
b422b62c | 42 | /**\r |
43 | Internal constructor worker function.\r | |
44 | \r | |
45 | It will register one callback function on EFI PCD Protocol.\r | |
46 | It will allocate the NVS memory to store Mailbox and install configuration table\r | |
47 | in system table to store its pointer.\r | |
18b144ea | 48 | \r |
49 | **/\r | |
b422b62c | 50 | VOID\r |
51 | InternalConstructorWorker (\r | |
52 | VOID\r | |
18b144ea | 53 | )\r |
54 | {\r | |
55 | EFI_STATUS Status;\r | |
56 | EFI_PHYSICAL_ADDRESS Address;\r | |
b422b62c | 57 | BOOLEAN DebugTimerInterruptState;\r |
0a488765 | 58 | DEBUG_AGENT_MAILBOX *Mailbox;\r |
59 | DEBUG_AGENT_MAILBOX *NewMailbox;\r | |
8cc26df4 JF |
60 | EFI_HOB_GUID_TYPE *GuidHob;\r |
61 | EFI_VECTOR_HANDOFF_INFO *VectorHandoffInfo;\r | |
62 | \r | |
63 | //\r | |
64 | // Check persisted vector handoff info\r | |
65 | //\r | |
66 | Status = EFI_SUCCESS;\r | |
67 | GuidHob = GetFirstGuidHob (&gEfiVectorHandoffInfoPpiGuid);\r | |
68 | if (GuidHob != NULL && !mDxeCoreFlag) {\r | |
69 | //\r | |
70 | // Check if configuration table is installed or not if GUIDed HOB existed,\r | |
71 | // only when Debug Agent is not linked by DXE Core\r | |
72 | //\r | |
73 | Status = EfiGetSystemConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID **) &VectorHandoffInfo);\r | |
74 | }\r | |
75 | if (GuidHob == NULL || Status != EFI_SUCCESS) {\r | |
76 | //\r | |
77 | // Install configuration table for persisted vector handoff info if GUIDed HOB cannot be found or\r | |
78 | // configuration table does not exist\r | |
79 | //\r | |
80 | Status = gBS->InstallConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID *) &mVectorHandoffInfoDebugAgent[0]);\r | |
81 | if (EFI_ERROR (Status)) {\r | |
82 | DEBUG ((EFI_D_ERROR, "DebugAgent: Cannot install configuration table for persisted vector handoff info!\n"));\r | |
83 | CpuDeadLoop ();\r | |
84 | }\r | |
85 | }\r | |
93c0bdec | 86 | \r |
87 | //\r | |
b422b62c | 88 | // Install EFI Serial IO protocol on debug port\r |
93c0bdec | 89 | //\r |
b422b62c | 90 | InstallSerialIo ();\r |
93c0bdec | 91 | \r |
18b144ea | 92 | Address = 0;\r |
93 | Status = gBS->AllocatePages (\r | |
94 | AllocateAnyPages,\r | |
95 | EfiACPIMemoryNVS,\r | |
0a488765 | 96 | EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + PcdGet16(PcdDebugPortHandleBufferSize)),\r |
18b144ea | 97 | &Address\r |
98 | );\r | |
8cc26df4 JF |
99 | if (EFI_ERROR (Status)) {\r |
100 | DEBUG ((EFI_D_ERROR, "DebugAgent: Cannot install configuration table for mailbox!\n"));\r | |
101 | CpuDeadLoop ();\r | |
102 | }\r | |
18b144ea | 103 | \r |
b422b62c | 104 | DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (FALSE);\r |
18b144ea | 105 | \r |
0a488765 | 106 | NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Address;\r |
107 | //\r | |
108 | // Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox\r | |
109 | // and Debug Port Handle buffer may be free at runtime, SMM debug agent needs to access them\r | |
110 | //\r | |
111 | Mailbox = GetMailboxPointer ();\r | |
112 | CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));\r | |
113 | CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16(PcdDebugPortHandleBufferSize));\r | |
114 | //\r | |
115 | // Update Debug Port Handle in new Mailbox\r | |
116 | //\r | |
117 | UpdateMailboxContent (NewMailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, (UINT64)(UINTN)(NewMailbox + 1));\r | |
118 | mMailboxPointer = NewMailbox;\r | |
119 | \r | |
120 | DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (DebugTimerInterruptState);\r | |
18b144ea | 121 | \r |
93c0bdec | 122 | Status = gBS->InstallConfigurationTable (&gEfiDebugAgentGuid, (VOID *) mMailboxPointer);\r |
8cc26df4 JF |
123 | if (EFI_ERROR (Status)) {\r |
124 | DEBUG ((EFI_D_ERROR, "DebugAgent: Failed to install configuration for mailbox!\n"));\r | |
125 | CpuDeadLoop ();\r | |
126 | }\r | |
b422b62c | 127 | }\r |
128 | \r | |
129 | /**\r | |
130 | Debug Agent constructor function.\r | |
131 | \r | |
132 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r | |
133 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
134 | \r | |
135 | @retval RETURN_SUCCESS When this function completed.\r | |
136 | \r | |
137 | **/\r | |
138 | RETURN_STATUS\r | |
139 | EFIAPI\r | |
140 | DxeDebugAgentLibConstructor (\r | |
141 | IN EFI_HANDLE ImageHandle,\r | |
142 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
143 | )\r | |
144 | {\r | |
145 | if (mDxeCoreFlag) {\r | |
146 | //\r | |
147 | // Invoke internal constructor function only when DXE core links this library instance\r | |
148 | //\r | |
149 | InternalConstructorWorker ();\r | |
150 | }\r | |
151 | \r | |
152 | return RETURN_SUCCESS;\r | |
153 | }\r | |
154 | \r | |
155 | /**\r | |
156 | Get the pointer to Mailbox from the configuration table.\r | |
157 | \r | |
158 | @return Pointer to Mailbox.\r | |
159 | \r | |
160 | **/\r | |
161 | DEBUG_AGENT_MAILBOX *\r | |
162 | GetMailboxFromConfigurationTable (\r | |
163 | VOID\r | |
164 | )\r | |
165 | {\r | |
166 | EFI_STATUS Status;\r | |
167 | DEBUG_AGENT_MAILBOX *Mailbox;\r | |
93c0bdec | 168 | \r |
b422b62c | 169 | Status = EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid, (VOID **) &Mailbox);\r |
170 | if (Status == EFI_SUCCESS && Mailbox != NULL) {\r | |
171 | VerifyMailboxChecksum (Mailbox);\r | |
172 | return Mailbox;\r | |
173 | } else {\r | |
174 | return NULL;\r | |
175 | }\r | |
18b144ea | 176 | }\r |
177 | \r | |
178 | /**\r | |
179 | Get the pointer to Mailbox from the GUIDed HOB.\r | |
180 | \r | |
181 | @param[in] HobStart The starting HOB pointer to search from.\r | |
182 | \r | |
183 | @return Pointer to Mailbox.\r | |
184 | \r | |
185 | **/\r | |
186 | DEBUG_AGENT_MAILBOX *\r | |
187 | GetMailboxFromHob (\r | |
188 | IN VOID *HobStart\r | |
189 | )\r | |
190 | {\r | |
191 | EFI_HOB_GUID_TYPE *GuidHob;\r | |
b422b62c | 192 | UINT64 *MailboxLocation;\r |
193 | DEBUG_AGENT_MAILBOX *Mailbox;\r | |
18b144ea | 194 | \r |
195 | GuidHob = GetNextGuidHob (&gEfiDebugAgentGuid, HobStart);\r | |
196 | if (GuidHob == NULL) {\r | |
197 | return NULL;\r | |
198 | }\r | |
b422b62c | 199 | MailboxLocation = (UINT64 *) (GET_GUID_HOB_DATA(GuidHob));\r |
200 | Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);\r | |
201 | VerifyMailboxChecksum (Mailbox);\r | |
18b144ea | 202 | \r |
b422b62c | 203 | return Mailbox;\r |
18b144ea | 204 | }\r |
205 | \r | |
206 | /**\r | |
207 | Get Debug Agent Mailbox pointer.\r | |
208 | \r | |
209 | @return Mailbox pointer.\r | |
210 | \r | |
211 | **/\r | |
212 | DEBUG_AGENT_MAILBOX *\r | |
213 | GetMailboxPointer (\r | |
214 | VOID\r | |
215 | )\r | |
216 | {\r | |
b422b62c | 217 | AcquireMpSpinLock (&mDebugMpContext.MailboxSpinLock);\r |
218 | VerifyMailboxChecksum (mMailboxPointer);\r | |
219 | ReleaseMpSpinLock (&mDebugMpContext.MailboxSpinLock);\r | |
18b144ea | 220 | return mMailboxPointer;\r |
221 | }\r | |
222 | \r | |
223 | /**\r | |
224 | Get debug port handle.\r | |
225 | \r | |
226 | @return Debug port handle.\r | |
227 | \r | |
228 | **/\r | |
229 | DEBUG_PORT_HANDLE\r | |
230 | GetDebugPortHandle (\r | |
231 | VOID\r | |
232 | )\r | |
233 | {\r | |
b422b62c | 234 | return (DEBUG_PORT_HANDLE) (UINTN)(GetMailboxPointer ()->DebugPortHandle);\r |
235 | }\r | |
236 | \r | |
237 | /**\r | |
238 | Worker function to setup IDT table and initialize the IDT entries.\r | |
239 | \r | |
240 | @param[in] Mailbox Pointer to Mailbox.\r | |
241 | \r | |
242 | **/\r | |
243 | VOID\r | |
244 | SetupDebugAgentEnviroment (\r | |
245 | IN DEBUG_AGENT_MAILBOX *Mailbox\r | |
246 | )\r | |
247 | {\r | |
248 | IA32_DESCRIPTOR Idtr;\r | |
249 | UINT16 IdtEntryCount;\r | |
250 | UINT64 DebugPortHandle;\r | |
251 | \r | |
252 | if (mMultiProcessorDebugSupport) {\r | |
253 | InitializeSpinLock (&mDebugMpContext.MpContextSpinLock);\r | |
254 | InitializeSpinLock (&mDebugMpContext.DebugPortSpinLock);\r | |
255 | InitializeSpinLock (&mDebugMpContext.MailboxSpinLock);\r | |
256 | //\r | |
257 | // Clear Break CPU index value\r | |
258 | //\r | |
259 | mDebugMpContext.BreakAtCpuIndex = (UINT32) -1;\r | |
260 | }\r | |
261 | \r | |
262 | //\r | |
263 | // Get original IDT address and size.\r | |
264 | //\r | |
265 | AsmReadIdtr ((IA32_DESCRIPTOR *) &Idtr);\r | |
266 | IdtEntryCount = (UINT16) ((Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR));\r | |
267 | if (IdtEntryCount < 33) {\r | |
8cc26df4 JF |
268 | ZeroMem (&mIdtEntryTable, sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33);\r |
269 | //\r | |
270 | // Copy original IDT table into new one\r | |
271 | //\r | |
272 | CopyMem (&mIdtEntryTable, (VOID *) Idtr.Base, Idtr.Limit + 1);\r | |
273 | //\r | |
274 | // Load new IDT table\r | |
275 | //\r | |
b422b62c | 276 | Idtr.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33 - 1);\r |
277 | Idtr.Base = (UINTN) &mIdtEntryTable;\r | |
b422b62c | 278 | AsmWriteIdtr ((IA32_DESCRIPTOR *) &Idtr);\r |
279 | }\r | |
280 | \r | |
281 | //\r | |
282 | // Initialize the IDT table entries to support source level debug.\r | |
283 | //\r | |
284 | InitializeDebugIdt ();\r | |
285 | \r | |
3bf04a71 JF |
286 | //\r |
287 | // If mMailboxPointer is not set before, set it\r | |
288 | //\r | |
289 | if (mMailboxPointer == NULL) {\r | |
290 | if (Mailbox != NULL) {\r | |
291 | //\r | |
292 | // If Mailbox exists, copy it into one global variable\r | |
293 | //\r | |
294 | CopyMem (&mMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));\r | |
295 | } else {\r | |
296 | ZeroMem (&mMailbox, sizeof (DEBUG_AGENT_MAILBOX));\r | |
297 | }\r | |
298 | mMailboxPointer = &mMailbox;\r | |
299 | }\r | |
b422b62c | 300 | \r |
b422b62c | 301 | //\r |
302 | // Initialize debug communication port\r | |
303 | //\r | |
304 | DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((VOID *)(UINTN)mMailboxPointer->DebugPortHandle, NULL);\r | |
305 | UpdateMailboxContent (mMailboxPointer, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);\r | |
306 | \r | |
307 | if (Mailbox == NULL) {\r | |
308 | //\r | |
309 | // Trigger one software interrupt to inform HOST\r | |
310 | //\r | |
311 | TriggerSoftInterrupt (SYSTEM_RESET_SIGNATURE);\r | |
312 | SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);\r | |
313 | //\r | |
314 | // Memory has been ready\r | |
315 | //\r | |
316 | if (IsHostAttached ()) {\r | |
317 | //\r | |
318 | // Trigger one software interrupt to inform HOST\r | |
319 | //\r | |
320 | TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);\r | |
321 | }\r | |
322 | }\r | |
18b144ea | 323 | }\r |
324 | \r | |
b422b62c | 325 | \r |
18b144ea | 326 | /**\r |
327 | Initialize debug agent.\r | |
328 | \r | |
329 | This function is used to set up debug enviroment for DXE phase.\r | |
330 | \r | |
331 | If this function is called by DXE Core, Context must be the pointer\r | |
332 | to HOB list which will be used to get GUIDed HOB. It will enable\r | |
333 | interrupt to support break-in feature.\r | |
334 | If this function is called by DXE module, Context must be NULL. It\r | |
335 | will enable interrupt to support break-in feature.\r | |
336 | \r | |
337 | @param[in] InitFlag Init flag is used to decide initialize process.\r | |
338 | @param[in] Context Context needed according to InitFlag.\r | |
339 | @param[in] Function Continue function called by debug agent library; it was\r | |
340 | optional.\r | |
341 | \r | |
342 | **/\r | |
343 | VOID\r | |
344 | EFIAPI\r | |
345 | InitializeDebugAgent (\r | |
346 | IN UINT32 InitFlag,\r | |
347 | IN VOID *Context, OPTIONAL\r | |
348 | IN DEBUG_AGENT_CONTINUE Function OPTIONAL\r | |
349 | )\r | |
350 | {\r | |
b422b62c | 351 | UINT64 *MailboxLocation;\r |
18b144ea | 352 | DEBUG_AGENT_MAILBOX *Mailbox;\r |
18b144ea | 353 | BOOLEAN InterruptStatus;\r |
b422b62c | 354 | VOID *HobList;\r |
355 | IA32_DESCRIPTOR IdtDescriptor;\r | |
356 | IA32_DESCRIPTOR *Ia32Idtr;\r | |
357 | IA32_IDT_ENTRY *Ia32IdtEntry;\r | |
18b144ea | 358 | \r |
b422b62c | 359 | if (InitFlag == DEBUG_AGENT_INIT_DXE_AP) {\r |
360 | //\r | |
361 | // Invoked by AP, enable interrupt to let AP could receive IPI from other processors\r | |
362 | //\r | |
363 | EnableInterrupts ();\r | |
364 | return ;\r | |
18b144ea | 365 | }\r |
366 | \r | |
b422b62c | 367 | // \r |
368 | // Disable Debug Timer interrupt\r | |
369 | //\r | |
370 | SaveAndSetDebugTimerInterrupt (FALSE);\r | |
18b144ea | 371 | //\r |
372 | // Save and disable original interrupt status\r | |
373 | //\r | |
374 | InterruptStatus = SaveAndDisableInterrupts ();\r | |
375 | \r | |
b422b62c | 376 | //\r |
377 | // Try to get mailbox firstly\r | |
378 | //\r | |
379 | HobList = NULL;\r | |
380 | Mailbox = NULL;\r | |
381 | MailboxLocation = NULL;\r | |
382 | \r | |
383 | switch (InitFlag) {\r | |
384 | \r | |
385 | case DEBUG_AGENT_INIT_DXE_LOAD:\r | |
18b144ea | 386 | //\r |
b422b62c | 387 | // Check if Debug Agent has been initialized before\r |
18b144ea | 388 | //\r |
b422b62c | 389 | if (IsDebugAgentInitialzed ()) {\r |
390 | DEBUG ((EFI_D_INFO, "Debug Agent: The former agent will be overwritten by the new one!\n"));\r | |
391 | }\r | |
392 | \r | |
393 | mMultiProcessorDebugSupport = TRUE;\r | |
93c0bdec | 394 | //\r |
b422b62c | 395 | // Save original IDT table\r |
396 | //\r | |
397 | AsmReadIdtr (&IdtDescriptor);\r | |
398 | mSaveIdtTableSize = IdtDescriptor.Limit + 1;\r | |
399 | mSavedIdtTable = AllocateCopyPool (mSaveIdtTableSize, (VOID *) IdtDescriptor.Base);\r | |
400 | //\r | |
401 | // Initialize Debug Timer hardware\r | |
402 | //\r | |
403 | InitializeDebugTimer ();\r | |
404 | //\r | |
405 | // Check if Debug Agent initialized in DXE phase\r | |
406 | //\r | |
407 | Mailbox = GetMailboxFromConfigurationTable ();\r | |
408 | if (Mailbox == NULL) {\r | |
409 | //\r | |
410 | // Try to get mailbox from GUIDed HOB build in PEI \r | |
411 | //\r | |
412 | HobList = GetHobList ();\r | |
413 | Mailbox = GetMailboxFromHob (HobList);\r | |
414 | }\r | |
415 | //\r | |
416 | // Set up IDT table and prepare for IDT entries\r | |
417 | //\r | |
418 | SetupDebugAgentEnviroment (Mailbox);\r | |
419 | //\r | |
420 | // For DEBUG_AGENT_INIT_S3, needn't to install configuration table and EFI Serial IO protocol\r | |
421 | // For DEBUG_AGENT_INIT_DXE_CORE, InternalConstructorWorker() will invoked in Constructor()\r | |
422 | //\r | |
423 | InternalConstructorWorker ();\r | |
424 | //\r | |
425 | // Enable interrupt to receive Debug Timer interrupt\r | |
93c0bdec | 426 | //\r |
18b144ea | 427 | EnableInterrupts ();\r |
428 | \r | |
b422b62c | 429 | mDebugAgentInitialized = TRUE;\r |
430 | FindAndReportModuleImageInfo (SIZE_4KB);\r | |
431 | \r | |
432 | *(EFI_STATUS *)Context = EFI_SUCCESS;\r | |
433 | \r | |
434 | if (gST->ConOut != NULL) {\r | |
435 | Print (L"Debug Agent: Initialized successfully!\r\n");\r | |
436 | Print (L"If the Debug Port is serial port, please make sure this serial port isn't connected by ISA Serial driver\r\n");\r | |
437 | Print (L"You could do the following steps to disconnect the serial port:\r\n");\r | |
438 | Print (L"1: Shell> drivers\r\n");\r | |
439 | Print (L" ...\r\n");\r | |
440 | Print (L" V VERSION E G G #D #C DRIVER NAME IMAGE NAME\r\n");\r | |
441 | Print (L" == ======== = = = == == =================================== ===================\r\n");\r | |
442 | Print (L" 8F 0000000A B - - 1 14 PCI Bus Driver PciBusDxe\r\n");\r | |
443 | Print (L" 91 00000010 ? - - - - ATA Bus Driver AtaBusDxe\r\n");\r | |
444 | Print (L" ...\r\n");\r | |
445 | Print (L" A7 0000000A B - - 1 1 ISA Serial Driver IsaSerialDxe\r\n");\r | |
446 | Print (L" ...\r\n");\r | |
447 | Print (L"2: Shell> dh -d A7\r\n");\r | |
448 | Print (L" A7: Image(IsaSerialDxe) ImageDevPath (..9FB3-11D4-9A3A-0090273FC14D))DriverBinding ComponentName ComponentName2\r\n");\r | |
449 | Print (L" Driver Name : ISA Serial Driver\r\n");\r | |
450 | Print (L" Image Name : FvFile(93B80003-9FB3-11D4-9A3A-0090273FC14D)\r\n");\r | |
451 | Print (L" Driver Version : 0000000A\r\n");\r | |
452 | Print (L" Driver Type : BUS\r\n");\r | |
453 | Print (L" Configuration : NO\r\n");\r | |
454 | Print (L" Diagnostics : NO\r\n");\r | |
455 | Print (L" Managing :\r\n");\r | |
456 | Print (L" Ctrl[EA] : PciRoot(0x0)/Pci(0x1F,0x0)/Serial(0x0)\r\n");\r | |
457 | Print (L" Child[EB] : PciRoot(0x0)/Pci(0x1F,0x0)/Serial(0x0)/Uart(115200,8,N,1)\r\n");\r | |
458 | Print (L"3: Shell> disconnect EA\r\n");\r | |
459 | Print (L"4: Shell> load -nc DebugAgentDxe.efi\r\n\r\n");\r | |
460 | }\r | |
461 | break;\r | |
462 | \r | |
463 | case DEBUG_AGENT_INIT_DXE_UNLOAD:\r | |
464 | if (mDebugAgentInitialized) {\r | |
465 | if (IsHostAttached ()) {\r | |
466 | Print (L"Debug Agent: Host is still connected, please de-attach TARGET firstly!\r\n");\r | |
467 | *(EFI_STATUS *)Context = EFI_ACCESS_DENIED;\r | |
468 | // \r | |
469 | // Enable Debug Timer interrupt again\r | |
470 | //\r | |
471 | SaveAndSetDebugTimerInterrupt (TRUE);\r | |
472 | } else {\r | |
473 | //\r | |
474 | // Restore original IDT table\r | |
475 | //\r | |
476 | AsmReadIdtr (&IdtDescriptor);\r | |
477 | IdtDescriptor.Limit = (UINT16) (mSaveIdtTableSize - 1);\r | |
478 | CopyMem ((VOID *) IdtDescriptor.Base, mSavedIdtTable, mSaveIdtTableSize);\r | |
479 | AsmWriteIdtr (&IdtDescriptor);\r | |
480 | FreePool (mSavedIdtTable);\r | |
481 | mDebugAgentInitialized = FALSE;\r | |
482 | *(EFI_STATUS *)Context = EFI_SUCCESS;\r | |
483 | }\r | |
484 | } else {\r | |
485 | Print (L"Debug Agent: It hasn't been initialized, cannot unload it!\r\n");\r | |
486 | *(EFI_STATUS *)Context = EFI_NOT_STARTED;\r | |
487 | }\r | |
18b144ea | 488 | \r |
18b144ea | 489 | //\r |
b422b62c | 490 | // Restore interrupt state.\r |
18b144ea | 491 | //\r |
b422b62c | 492 | SetInterruptState (InterruptStatus);\r |
493 | break;\r | |
18b144ea | 494 | \r |
b422b62c | 495 | case DEBUG_AGENT_INIT_DXE_CORE:\r |
496 | mDxeCoreFlag = TRUE;\r | |
497 | mMultiProcessorDebugSupport = TRUE;\r | |
18b144ea | 498 | //\r |
b422b62c | 499 | // Initialize Debug Timer hardware\r |
18b144ea | 500 | //\r |
b422b62c | 501 | InitializeDebugTimer ();\r |
18b144ea | 502 | //\r |
b422b62c | 503 | // Try to get mailbox from GUIDed HOB build in PEI \r |
18b144ea | 504 | //\r |
b422b62c | 505 | HobList = Context;\r |
506 | Mailbox = GetMailboxFromHob (HobList);\r | |
507 | //\r | |
508 | // Set up IDT table and prepare for IDT entries\r | |
509 | //\r | |
510 | SetupDebugAgentEnviroment (Mailbox);\r | |
511 | //\r | |
512 | // Enable interrupt to receive Debug Timer interrupt\r | |
513 | //\r | |
514 | EnableInterrupts ();\r | |
18b144ea | 515 | \r |
b422b62c | 516 | break;\r |
18b144ea | 517 | \r |
b422b62c | 518 | case DEBUG_AGENT_INIT_S3:\r |
18b144ea | 519 | \r |
b422b62c | 520 | if (Context != NULL) {\r |
521 | Ia32Idtr = (IA32_DESCRIPTOR *) Context;\r | |
522 | Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);\r | |
523 | MailboxLocation = (UINT64 *) (UINTN) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow + \r | |
524 | (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));\r | |
525 | Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);\r | |
526 | VerifyMailboxChecksum (Mailbox);\r | |
527 | }\r | |
18b144ea | 528 | //\r |
3bf04a71 JF |
529 | // Save Mailbox pointer in global variable\r |
530 | //\r | |
531 | mMailboxPointer = Mailbox;\r | |
532 | //\r | |
b422b62c | 533 | // Set up IDT table and prepare for IDT entries\r |
18b144ea | 534 | //\r |
b422b62c | 535 | SetupDebugAgentEnviroment (Mailbox);\r |
18b144ea | 536 | //\r |
b422b62c | 537 | // Disable interrupt\r |
18b144ea | 538 | //\r |
b422b62c | 539 | DisableInterrupts ();\r |
540 | FindAndReportModuleImageInfo (SIZE_4KB);\r | |
541 | if (GetDebugFlag (DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT) == 1) {\r | |
542 | //\r | |
543 | // If Boot Script entry break is set, code will be break at here.\r | |
544 | //\r | |
545 | CpuBreakpoint ();\r | |
546 | }\r | |
547 | break;\r | |
548 | \r | |
549 | default:\r | |
18b144ea | 550 | //\r |
b422b62c | 551 | // Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this \r |
552 | // Debug Agent library instance.\r | |
18b144ea | 553 | //\r |
b422b62c | 554 | DEBUG ((EFI_D_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));\r |
555 | CpuDeadLoop ();\r | |
556 | break;\r | |
18b144ea | 557 | }\r |
18b144ea | 558 | }\r |