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