2 Debug Agent library implementition for Dxe Core and Dxr modules.
4 Copyright (c) 2010, 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.
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.
15 #include "DxeDebugAgentLib.h"
17 DEBUG_AGENT_MAILBOX mMailbox
;
19 DEBUG_AGENT_MAILBOX
*mMailboxPointer
;
21 IA32_IDT_GATE_DESCRIPTOR mIdtEntryTable
[33];
23 BOOLEAN mConfigurationTableNeeded
= FALSE
;
25 CONST BOOLEAN MultiProcessorDebugSupport
= TRUE
;
28 Constructor allocates the NVS memory to store Mailbox and install configuration table
29 in system table to store its pointer.
31 @param[in] ImageHandle The firmware allocated handle for the EFI image.
32 @param[in] SystemTable A pointer to the EFI System Table.
34 @retval RETURN_SUCCESS Allocate the global memory space to store guid and function tables.
35 @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated.
40 DxeDebugAgentLibConstructor (
41 IN EFI_HANDLE ImageHandle
,
42 IN EFI_SYSTEM_TABLE
*SystemTable
46 EFI_PHYSICAL_ADDRESS Address
;
48 if (!mConfigurationTableNeeded
) {
49 return RETURN_SUCCESS
;
53 Status
= gBS
->AllocatePages (
56 EFI_SIZE_TO_PAGES (sizeof (DEBUG_AGENT_MAILBOX
)),
59 if (EFI_ERROR (Status
)) {
64 (UINT8
*) (UINTN
) Address
,
65 (UINT8
*) (UINTN
) mMailboxPointer
,
66 sizeof (DEBUG_AGENT_MAILBOX
)
69 mMailboxPointer
= (DEBUG_AGENT_MAILBOX
*) (UINTN
) Address
;
71 return gBS
->InstallConfigurationTable (&gEfiDebugAgentGuid
, (VOID
*) mMailboxPointer
);
75 Get the pointer to Mailbox from the GUIDed HOB.
77 @param[in] HobStart The starting HOB pointer to search from.
79 @return Pointer to Mailbox.
87 EFI_HOB_GUID_TYPE
*GuidHob
;
89 GuidHob
= GetNextGuidHob (&gEfiDebugAgentGuid
, HobStart
);
90 if (GuidHob
== NULL
) {
94 return (DEBUG_AGENT_MAILBOX
*) (GET_GUID_HOB_DATA(GuidHob
));
98 Get Debug Agent Mailbox pointer.
100 @return Mailbox pointer.
103 DEBUG_AGENT_MAILBOX
*
108 return mMailboxPointer
;
112 Get debug port handle.
114 @return Debug port handle.
122 return (DEBUG_PORT_HANDLE
) (UINTN
)(mMailboxPointer
->DebugPortHandle
);
127 Initialize debug agent.
129 This function is used to set up debug enviroment for DXE phase.
131 If this function is called by DXE Core, Context must be the pointer
132 to HOB list which will be used to get GUIDed HOB. It will enable
133 interrupt to support break-in feature.
134 If this function is called by DXE module, Context must be NULL. It
135 will enable interrupt to support break-in feature.
137 @param[in] InitFlag Init flag is used to decide initialize process.
138 @param[in] Context Context needed according to InitFlag.
139 @param[in] Function Continue function called by debug agent library; it was
145 InitializeDebugAgent (
147 IN VOID
*Context
, OPTIONAL
148 IN DEBUG_AGENT_CONTINUE Function OPTIONAL
151 DEBUG_AGENT_MAILBOX
*Mailbox
;
152 IA32_DESCRIPTOR Idtr
;
153 UINT16 IdtEntryCount
;
154 BOOLEAN InterruptStatus
;
156 if (InitFlag
!= DEBUG_AGENT_INIT_DXE_CORE
&&
157 InitFlag
!= DEBUG_AGENT_INIT_S3
&&
158 InitFlag
!= DEBUG_AGENT_INIT_DXE_AP
) {
163 // Save and disable original interrupt status
165 InterruptStatus
= SaveAndDisableInterrupts ();
167 if (InitFlag
== DEBUG_AGENT_INIT_DXE_CORE
) {
169 // Try to get Mailbox from GUIDed HOB.
171 mConfigurationTableNeeded
= TRUE
;
172 Mailbox
= GetMailboxFromHob (Context
);
174 } else if (InitFlag
== DEBUG_AGENT_INIT_DXE_AP
) {
182 // If it is in S3 path, needn't to install configuration table.
187 if (Mailbox
!= NULL
) {
189 // If Mailbox exists, copy it into one global variable.
191 CopyMem (&mMailbox
, Mailbox
, sizeof (DEBUG_AGENT_MAILBOX
));
192 mMailbox
.DebugPortHandle
= 0;
195 // If Mailbox not exists, used the local Mailbox.
197 ZeroMem (&mMailbox
, sizeof (DEBUG_AGENT_MAILBOX
));
200 mMailboxPointer
= &mMailbox
;
203 // Get original IDT address and size.
205 AsmReadIdtr ((IA32_DESCRIPTOR
*) &Idtr
);
206 IdtEntryCount
= (UINT16
) ((Idtr
.Limit
+ 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR
));
207 if (IdtEntryCount
< 33) {
208 Idtr
.Limit
= (UINT16
) (sizeof (IA32_IDT_GATE_DESCRIPTOR
) * 33 - 1);
209 Idtr
.Base
= (UINTN
) &mIdtEntryTable
;
210 AsmWriteIdtr ((IA32_DESCRIPTOR
*) &Idtr
);
214 // Initialize the IDT table entries to support source level debug.
216 InitializeDebugIdt ();
219 // Initialize debug communication port
221 mMailboxPointer
->DebugPortHandle
= (UINT64
) (UINTN
)DebugPortInitialize (NULL
, NULL
);
223 InitializeSpinLock (&mDebugMpContext
.MpContextSpinLock
);
224 InitializeSpinLock (&mDebugMpContext
.DebugPortSpinLock
);
226 if (InitFlag
== DEBUG_AGENT_INIT_DXE_CORE
) {
228 // Initialize Debug Timer hardware and enable interrupt.
230 InitializeDebugTimer ();
236 // Disable Debug Timer interrupt in S3 path.
238 SaveAndSetDebugTimerInterrupt (FALSE
);
241 // Restore interrupt state.
243 SetInterruptState (InterruptStatus
);