2 SEC Core Debug Agent Library instance implementition.
4 Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "SecPeiDebugAgentLib.h"
11 GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSkipBreakpoint
= FALSE
;
14 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_VECTOR_HANDOFF_INFO_PPI mVectorHandoffInfoPpi
= {
15 &mVectorHandoffInfoDebugAgent
[0]
19 // Ppis to be installed
21 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mVectorHandoffInfoPpiList
[] = {
23 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
24 &gEfiVectorHandoffInfoPpiGuid
,
25 &mVectorHandoffInfoPpi
29 GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mDebugAgentMemoryDiscoveredNotifyList
[1] = {
31 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
32 &gEfiPeiMemoryDiscoveredPpiGuid
,
33 DebugAgentCallbackMemoryDiscoveredPpi
38 Check if debug agent support multi-processor.
40 @retval TRUE Multi-processor is supported.
41 @retval FALSE Multi-processor is not supported.
45 MultiProcessorDebugSupport (
53 Read the Attach/Break-in symbols from the debug port.
55 @param[in] Handle Pointer to Debug Port handle.
56 @param[out] BreakSymbol Returned break symbol.
58 @retval EFI_SUCCESS Read the symbol in BreakSymbol.
59 @retval EFI_NOT_FOUND No read the break symbol.
63 DebugReadBreakSymbol (
64 IN DEBUG_PORT_HANDLE Handle
,
65 OUT UINT8
*BreakSymbol
69 DEBUG_PACKET_HEADER DebugHeader
;
74 // If Debug Port buffer has data, read it till it was break symbol or Debug Port buffer empty.
76 Data8
= (UINT8
*) &DebugHeader
;
79 // If start symbol is not received
81 if (!DebugPortPollBuffer (Handle
)) {
83 // If no data in Debug Port, exit
88 // Try to read the start symbol
90 DebugAgentReadBuffer (Handle
, Data8
, 1, 0);
91 if (*Data8
== DEBUG_STARTING_SYMBOL_ATTACH
) {
92 *BreakSymbol
= *Data8
;
93 DebugAgentMsgPrint (DEBUG_AGENT_INFO
, "Debug Timer attach symbol received %x", *BreakSymbol
);
96 if (*Data8
== DEBUG_STARTING_SYMBOL_NORMAL
) {
97 Status
= ReadRemainingBreakPacket (Handle
, &DebugHeader
);
98 if (Status
== EFI_SUCCESS
) {
99 *BreakSymbol
= DebugHeader
.Command
;
100 DebugAgentMsgPrint (DEBUG_AGENT_INFO
, "Debug Timer break symbol received %x", *BreakSymbol
);
103 if (Status
== EFI_TIMEOUT
) {
109 return EFI_NOT_FOUND
;
113 Get the pointer to location saved Mailbox pointer from IDT entry.
117 GetLocationSavedMailboxPointerInIdtEntry (
121 UINTN
*MailboxLocation
;
123 MailboxLocation
= (UINTN
*) GetExceptionHandlerInIdtEntry (DEBUG_MAILBOX_VECTOR
);
125 // *MailboxLocation is the pointer to Mailbox
127 VerifyMailboxChecksum ((DEBUG_AGENT_MAILBOX
*) (*MailboxLocation
));
128 return MailboxLocation
;
132 Set the pointer of Mailbox into IDT entry before memory is ready.
134 @param[in] MailboxLocation Pointer to location saved Mailbox pointer.
138 SetLocationSavedMailboxPointerInIdtEntry (
139 IN VOID
*MailboxLocation
142 SetExceptionHandlerInIdtEntry (DEBUG_MAILBOX_VECTOR
, MailboxLocation
);
146 Get the location of Mailbox pointer from the GUIDed HOB.
148 @return Pointer to the location saved Mailbox pointer.
152 GetMailboxLocationFromHob (
156 EFI_HOB_GUID_TYPE
*GuidHob
;
158 GuidHob
= GetFirstGuidHob (&gEfiDebugAgentGuid
);
159 if (GuidHob
== NULL
) {
162 return (UINT64
*) (GET_GUID_HOB_DATA(GuidHob
));
166 Get Debug Agent Mailbox pointer.
168 @return Mailbox pointer.
171 DEBUG_AGENT_MAILBOX
*
176 UINT64 DebugPortHandle
;
177 UINT64
*MailboxLocationInIdt
;
178 UINT64
*MailboxLocationInHob
;
179 DEBUG_AGENT_MAILBOX
*Mailbox
;
182 // Get mailbox from IDT entry firstly
184 MailboxLocationInIdt
= GetLocationSavedMailboxPointerInIdtEntry ();
185 Mailbox
= (DEBUG_AGENT_MAILBOX
*)(UINTN
)(*MailboxLocationInIdt
);
187 // Cannot used GetDebugFlag() to get Debug Flag to avoid GetMailboxPointer() nested
189 if (Mailbox
->DebugFlag
.Bits
.CheckMailboxInHob
!= 1 ||
190 Mailbox
->DebugFlag
.Bits
.InitArch
!= DEBUG_ARCH_SYMBOL
) {
192 // If mailbox was setup in SEC or the current CPU arch is different from the init arch
193 // Debug Agent initialized, return the mailbox from IDT entry directly.
194 // Otherwise, we need to check the mailbox location saved in GUIDed HOB further.
199 MailboxLocationInHob
= GetMailboxLocationFromHob ();
201 // Compare mailbox in IDT enry with mailbox in HOB,
202 // need to fix mailbox location if HOB moved by PEI CORE
204 if (MailboxLocationInHob
!= MailboxLocationInIdt
&& MailboxLocationInHob
!= NULL
) {
205 Mailbox
= (DEBUG_AGENT_MAILBOX
*)(UINTN
)(*MailboxLocationInHob
);
207 // Fix up Debug Port handler and save new mailbox in IDT entry
209 Mailbox
= (DEBUG_AGENT_MAILBOX
*)((UINTN
)Mailbox
+ ((UINTN
)(MailboxLocationInHob
) - (UINTN
)MailboxLocationInIdt
));
210 DebugPortHandle
= (UINTN
)Mailbox
->DebugPortHandle
+ ((UINTN
)(MailboxLocationInHob
) - (UINTN
)MailboxLocationInIdt
);
211 UpdateMailboxContent (Mailbox
, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX
, DebugPortHandle
);
212 *MailboxLocationInHob
= (UINT64
)(UINTN
)Mailbox
;
213 SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationInHob
);
215 // Clean CheckMailboxInHob flag
217 Mailbox
->DebugFlag
.Bits
.CheckMailboxInHob
= 0;
218 UpdateMailboxChecksum (Mailbox
);
225 Get debug port handle.
227 @return Debug port handle.
235 DEBUG_AGENT_MAILBOX
*DebugAgentMailbox
;
237 DebugAgentMailbox
= GetMailboxPointer ();
239 return (DEBUG_PORT_HANDLE
) (UINTN
)(DebugAgentMailbox
->DebugPortHandle
);
243 Debug Agent provided notify callback function on Memory Discovered PPI.
245 @param[in] PeiServices Indirect reference to the PEI Services Table.
246 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
247 @param[in] Ppi Address of the PPI that was installed.
249 @retval EFI_SUCCESS If the function completed successfully.
254 DebugAgentCallbackMemoryDiscoveredPpi (
255 IN EFI_PEI_SERVICES
**PeiServices
,
256 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
261 DEBUG_AGENT_MAILBOX
*Mailbox
;
262 BOOLEAN InterruptStatus
;
263 EFI_PHYSICAL_ADDRESS Address
;
264 DEBUG_AGENT_MAILBOX
*NewMailbox
;
265 UINT64
*MailboxLocationInHob
;
268 // Save and disable original interrupt status
270 InterruptStatus
= SaveAndDisableInterrupts ();
273 // Allocate ACPI NVS memory for new Mailbox and Debug Port Handle buffer
275 Status
= PeiServicesAllocatePages (
277 EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX
) + PcdGet16(PcdDebugPortHandleBufferSize
)),
280 ASSERT_EFI_ERROR (Status
);
281 NewMailbox
= (DEBUG_AGENT_MAILBOX
*) (UINTN
) Address
;
283 // Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox
284 // and Debug Port Handle buffer in the allocated pool that may be marked as free by DXE Core after DXE Core
285 // reallocates the HOB.
287 Mailbox
= GetMailboxPointer ();
288 CopyMem (NewMailbox
, Mailbox
, sizeof (DEBUG_AGENT_MAILBOX
));
289 CopyMem (NewMailbox
+ 1, (VOID
*)(UINTN
)Mailbox
->DebugPortHandle
, PcdGet16(PcdDebugPortHandleBufferSize
));
291 // Update Mailbox Location pointer in GUIDed HOB and IDT entry with new one
293 MailboxLocationInHob
= GetMailboxLocationFromHob ();
294 ASSERT (MailboxLocationInHob
!= NULL
);
295 *MailboxLocationInHob
= (UINT64
)(UINTN
)NewMailbox
;
296 SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationInHob
);
298 // Update Debug Port Handle in new Mailbox
300 UpdateMailboxContent (NewMailbox
, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX
, (UINT64
)(UINTN
)(NewMailbox
+ 1));
302 // Set physical memory ready flag
304 SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY
, 1);
306 if (IsHostAttached ()) {
308 // Trigger one software interrupt to inform HOST
310 TriggerSoftInterrupt (MEMORY_READY_SIGNATURE
);
314 // Restore interrupt state.
316 SetInterruptState (InterruptStatus
);
322 Initialize debug agent.
324 This function is used to set up debug environment for SEC and PEI phase.
326 If InitFlag is DEBUG_AGENT_INIT_PREMEM_SEC, it will overirde IDT table entries
327 and initialize debug port. It will enable interrupt to support break-in feature.
328 It will set up debug agent Mailbox in cache-as-ramfrom. It will be called before
329 physical memory is ready.
330 If InitFlag is DEBUG_AGENT_INIT_POSTMEM_SEC, debug agent will build one GUIDed
331 HOB to copy debug agent Mailbox. It will be called after physical memory is ready.
333 This function is used to set up debug environment to support source level debugging.
334 If certain Debug Agent Library instance has to save some private data in the stack,
335 this function must work on the mode that doesn't return to the caller, then
336 the caller needs to wrap up all rest of logic after InitializeDebugAgent() into one
337 function and pass it into InitializeDebugAgent(). InitializeDebugAgent() is
338 responsible to invoke the passing-in function at the end of InitializeDebugAgent().
340 If the parameter Function is not NULL, Debug Agent Library instance will invoke it by
341 passing in the Context to be its parameter.
343 If Function() is NULL, Debug Agent Library instance will return after setup debug
346 @param[in] InitFlag Init flag is used to decide the initialize process.
347 @param[in] Context Context needed according to InitFlag; it was optional.
348 @param[in] Function Continue function called by debug agent library; it was
354 InitializeDebugAgent (
356 IN VOID
*Context
, OPTIONAL
357 IN DEBUG_AGENT_CONTINUE Function OPTIONAL
360 DEBUG_AGENT_MAILBOX
*Mailbox
;
361 DEBUG_AGENT_MAILBOX
*NewMailbox
;
362 DEBUG_AGENT_MAILBOX MailboxInStack
;
363 DEBUG_AGENT_PHASE2_CONTEXT Phase2Context
;
364 DEBUG_AGENT_CONTEXT_POSTMEM_SEC
*DebugAgentContext
;
366 IA32_DESCRIPTOR
*Ia32Idtr
;
367 IA32_IDT_ENTRY
*Ia32IdtEntry
;
368 UINT64 DebugPortHandle
;
369 UINT64 MailboxLocation
;
370 UINT64
*MailboxLocationPointer
;
371 EFI_PHYSICAL_ADDRESS Address
;
372 UINT32 DebugTimerFrequency
;
373 BOOLEAN CpuInterruptState
;
376 // Disable interrupts and save current interrupt state
378 CpuInterruptState
= SaveAndDisableInterrupts();
382 case DEBUG_AGENT_INIT_PREMEM_SEC
:
384 InitializeDebugIdt ();
386 MailboxLocation
= (UINT64
)(UINTN
)&MailboxInStack
;
387 Mailbox
= &MailboxInStack
;
388 ZeroMem ((VOID
*) Mailbox
, sizeof (DEBUG_AGENT_MAILBOX
));
390 // Get and save debug port handle and set the length of memory block.
392 SetLocationSavedMailboxPointerInIdtEntry (&MailboxLocation
);
394 // Force error message could be printed during the first shakehand between Target/HOST.
396 SetDebugFlag (DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL
, DEBUG_AGENT_ERROR
);
398 // Save init arch type when debug agent initialized
400 SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH
, DEBUG_ARCH_SYMBOL
);
402 // Initialize Debug Timer hardware and save its frequency
404 InitializeDebugTimer (&DebugTimerFrequency
, TRUE
);
405 UpdateMailboxContent (Mailbox
, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY
, DebugTimerFrequency
);
407 Phase2Context
.InitFlag
= InitFlag
;
408 Phase2Context
.Context
= Context
;
409 Phase2Context
.Function
= Function
;
410 DebugPortInitialize ((VOID
*) &Phase2Context
, InitializeDebugAgentPhase2
);
412 // If reaches here, it means Debug Port initialization failed.
414 DEBUG ((EFI_D_ERROR
, "Debug Agent: Debug port initialization failed.\n"));
418 case DEBUG_AGENT_INIT_POSTMEM_SEC
:
419 Mailbox
= GetMailboxPointer ();
421 // Memory has been ready
423 SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY
, 1);
424 if (IsHostAttached ()) {
426 // Trigger one software interrupt to inform HOST
428 TriggerSoftInterrupt (MEMORY_READY_SIGNATURE
);
431 // Install Vector Handoff Info PPI to persist vectors used by Debug Agent
433 Status
= PeiServicesInstallPpi (&mVectorHandoffInfoPpiList
[0]);
434 if (EFI_ERROR (Status
)) {
435 DEBUG ((EFI_D_ERROR
, "DebugAgent: Failed to install Vector Handoff Info PPI!\n"));
439 // Fix up Debug Port handle address and mailbox address
441 DebugAgentContext
= (DEBUG_AGENT_CONTEXT_POSTMEM_SEC
*) Context
;
442 if (DebugAgentContext
!= NULL
) {
443 DebugPortHandle
= (UINT64
)(UINT32
)(Mailbox
->DebugPortHandle
+ DebugAgentContext
->StackMigrateOffset
);
444 UpdateMailboxContent (Mailbox
, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX
, DebugPortHandle
);
445 Mailbox
= (DEBUG_AGENT_MAILBOX
*) ((UINTN
) Mailbox
+ DebugAgentContext
->StackMigrateOffset
);
446 MailboxLocation
= (UINT64
)(UINTN
)Mailbox
;
448 // Build mailbox location in HOB and fix-up its address
450 MailboxLocationPointer
= BuildGuidDataHob (
455 MailboxLocationPointer
= (UINT64
*) ((UINTN
) MailboxLocationPointer
+ DebugAgentContext
->HeapMigrateOffset
);
458 // DebugAgentContext is NULL. Then, Mailbox can directly be copied into memory.
459 // Allocate ACPI NVS memory for new Mailbox and Debug Port Handle buffer
461 Status
= PeiServicesAllocatePages (
463 EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX
) + PcdGet16(PcdDebugPortHandleBufferSize
)),
466 if (EFI_ERROR (Status
)) {
467 DEBUG ((EFI_D_ERROR
, "DebugAgent: Failed to allocate pages!\n"));
470 NewMailbox
= (DEBUG_AGENT_MAILBOX
*) (UINTN
) Address
;
472 // Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox
473 // and Debug Port Handle buffer in the allocated pool that may be marked as free by DXE Core after DXE Core
474 // reallocates the HOB.
476 CopyMem (NewMailbox
, Mailbox
, sizeof (DEBUG_AGENT_MAILBOX
));
477 CopyMem (NewMailbox
+ 1, (VOID
*)(UINTN
)Mailbox
->DebugPortHandle
, PcdGet16(PcdDebugPortHandleBufferSize
));
478 UpdateMailboxContent (NewMailbox
, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX
, (UINT64
)(UINTN
)(NewMailbox
+ 1));
479 MailboxLocation
= (UINT64
)(UINTN
)NewMailbox
;
481 // Build mailbox location in HOB
483 MailboxLocationPointer
= BuildGuidDataHob (
490 // Update IDT entry to save the location saved mailbox pointer
492 SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer
);
495 case DEBUG_AGENT_INIT_PEI
:
496 if (Context
== NULL
) {
497 DEBUG ((EFI_D_ERROR
, "DebugAgent: Input parameter Context cannot be NULL!\n"));
501 // Check if Debug Agent has initialized before
503 if (IsDebugAgentInitialzed()) {
504 DEBUG ((EFI_D_WARN
, "Debug Agent: It has already initialized in SEC Core!\n"));
508 // Install Vector Handoff Info PPI to persist vectors used by Debug Agent
510 Status
= PeiServicesInstallPpi (&mVectorHandoffInfoPpiList
[0]);
511 if (EFI_ERROR (Status
)) {
512 DEBUG ((EFI_D_ERROR
, "DebugAgent: Failed to install Vector Handoff Info PPI!\n"));
516 // Set up IDT entries
518 InitializeDebugIdt ();
520 // Build mailbox in HOB and setup Mailbox Set In Pei flag
522 Mailbox
= AllocateZeroPool (sizeof (DEBUG_AGENT_MAILBOX
));
523 if (Mailbox
== NULL
) {
524 DEBUG ((EFI_D_ERROR
, "DebugAgent: Failed to allocate memory!\n"));
527 MailboxLocation
= (UINT64
)(UINTN
)Mailbox
;
528 MailboxLocationPointer
= BuildGuidDataHob (
534 // Initialize Debug Timer hardware and save its frequency
536 InitializeDebugTimer (&DebugTimerFrequency
, TRUE
);
537 UpdateMailboxContent (Mailbox
, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY
, DebugTimerFrequency
);
539 // Update IDT entry to save the location pointer saved mailbox pointer
541 SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer
);
544 // Save init arch type when debug agent initialized
546 SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH
, DEBUG_ARCH_SYMBOL
);
548 // Register for a callback once memory has been initialized.
549 // If memery has been ready, the callback funtion will be invoked immediately
551 Status
= PeiServicesNotifyPpi (&mDebugAgentMemoryDiscoveredNotifyList
[0]);
552 if (EFI_ERROR (Status
)) {
553 DEBUG ((EFI_D_ERROR
, "DebugAgent: Failed to register memory discovered callback function!\n"));
557 // Set HOB check flag if memory has not been ready yet
559 if (GetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY
) == 0) {
560 SetDebugFlag (DEBUG_AGENT_FLAG_CHECK_MAILBOX_IN_HOB
, 1);
563 Phase2Context
.InitFlag
= InitFlag
;
564 Phase2Context
.Context
= Context
;
565 Phase2Context
.Function
= Function
;
566 DebugPortInitialize ((VOID
*) &Phase2Context
, InitializeDebugAgentPhase2
);
568 FindAndReportModuleImageInfo (4);
572 case DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64
:
573 if (Context
== NULL
) {
574 DEBUG ((EFI_D_ERROR
, "DebugAgent: Input parameter Context cannot be NULL!\n"));
577 Ia32Idtr
= (IA32_DESCRIPTOR
*) Context
;
578 Ia32IdtEntry
= (IA32_IDT_ENTRY
*)(Ia32Idtr
->Base
);
579 MailboxLocationPointer
= (UINT64
*) ((UINTN
) Ia32IdtEntry
[DEBUG_MAILBOX_VECTOR
].Bits
.OffsetLow
+
580 ((UINTN
) Ia32IdtEntry
[DEBUG_MAILBOX_VECTOR
].Bits
.OffsetHigh
<< 16));
581 Mailbox
= (DEBUG_AGENT_MAILBOX
*) (UINTN
)(*MailboxLocationPointer
);
583 // Mailbox should valid and setup before executing thunk code
585 VerifyMailboxChecksum (Mailbox
);
587 DebugPortHandle
= (UINT64
) (UINTN
)DebugPortInitialize ((VOID
*)(UINTN
)Mailbox
->DebugPortHandle
, NULL
);
588 UpdateMailboxContent (Mailbox
, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX
, DebugPortHandle
);
590 // Set up IDT entries
592 InitializeDebugIdt ();
594 // Update IDT entry to save location pointer saved the mailbox pointer
596 SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer
);
598 FindAndReportModuleImageInfo (4);
604 // Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this
605 // Debug Agent library instance.
607 DEBUG ((EFI_D_ERROR
, "Debug Agent: The InitFlag value is not allowed!\n"));
612 if (InitFlag
== DEBUG_AGENT_INIT_POSTMEM_SEC
) {
614 // Restore CPU Interrupt state and keep debug timer interrupt state as is
615 // in DEBUG_AGENT_INIT_POSTMEM_SEC case
617 SetInterruptState (CpuInterruptState
);
620 // Enable Debug Timer interrupt
622 SaveAndSetDebugTimerInterrupt (TRUE
);
624 // Enable CPU interrupts so debug timer interrupts can be delivered
629 // If Function is not NULL, invoke it always whatever debug agent was initialized sucesssfully or not.
631 if (Function
!= NULL
) {
635 // Set return status for DEBUG_AGENT_INIT_PEI
637 if (InitFlag
== DEBUG_AGENT_INIT_PEI
&& Context
!= NULL
) {
638 *(EFI_STATUS
*)Context
= EFI_SUCCESS
;
643 Caller provided function to be invoked at the end of DebugPortInitialize().
645 Refer to the description for DebugPortInitialize() for more details.
647 @param[in] Context The first input argument of DebugPortInitialize().
648 @param[in] DebugPortHandle Debug port handle created by Debug Communication Library.
653 InitializeDebugAgentPhase2 (
655 IN DEBUG_PORT_HANDLE DebugPortHandle
658 DEBUG_AGENT_PHASE2_CONTEXT
*Phase2Context
;
659 UINT64
*MailboxLocation
;
660 DEBUG_AGENT_MAILBOX
*Mailbox
;
661 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
663 UINT64 NewDebugPortHandle
;
665 Phase2Context
= (DEBUG_AGENT_PHASE2_CONTEXT
*) Context
;
666 MailboxLocation
= GetLocationSavedMailboxPointerInIdtEntry ();
667 Mailbox
= (DEBUG_AGENT_MAILBOX
*)(UINTN
)(*MailboxLocation
);
668 BufferSize
= PcdGet16(PcdDebugPortHandleBufferSize
);
669 if (Phase2Context
->InitFlag
== DEBUG_AGENT_INIT_PEI
&& BufferSize
!= 0) {
670 NewDebugPortHandle
= (UINT64
)(UINTN
)AllocateCopyPool (BufferSize
, DebugPortHandle
);
672 NewDebugPortHandle
= (UINT64
)(UINTN
)DebugPortHandle
;
674 UpdateMailboxContent (Mailbox
, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX
, NewDebugPortHandle
);
677 // Trigger one software interrupt to inform HOST
679 TriggerSoftInterrupt (SYSTEM_RESET_SIGNATURE
);
681 if (Phase2Context
->InitFlag
== DEBUG_AGENT_INIT_PREMEM_SEC
) {
683 // If Temporary RAM region is below 128 MB, then send message to
684 // host to disable low memory filtering.
686 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*)Phase2Context
->Context
;
687 if ((UINTN
)SecCoreData
->TemporaryRamBase
< BASE_128MB
&& IsHostAttached ()) {
688 SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY
, 1);
689 TriggerSoftInterrupt (MEMORY_READY_SIGNATURE
);
692 // Enable Debug Timer interrupt
694 SaveAndSetDebugTimerInterrupt (TRUE
);
696 // Enable CPU interrupts so debug timer interrupts can be delivered
700 // Call continuation function if it is not NULL.
702 Phase2Context
->Function (Phase2Context
->Context
);