2 Debug Agent library implementition.
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 "SmmDebugAgentLib.h"
17 DEBUG_AGENT_MAILBOX
*mMailboxPointer
= NULL
;
19 GLOBAL_REMOVE_IF_UNREFERENCED DEBUG_AGENT_MAILBOX mLocalMailbox
;
21 GLOBAL_REMOVE_IF_UNREFERENCED UINTN mSavedDebugRegisters
[6];
23 CONST BOOLEAN MultiProcessorDebugSupport
= FALSE
;
27 Get Debug Agent Mailbox pointer.
29 @return Mailbox pointer.
37 return mMailboxPointer
;
41 Get debug port handle.
43 @return Debug port handle.
51 return (DEBUG_PORT_HANDLE
) (UINTN
)(mMailboxPointer
->DebugPortHandle
);
55 Store debug register when SMI exit.
63 mSavedDebugRegisters
[0] = AsmReadDr0 ();
64 mSavedDebugRegisters
[1] = AsmReadDr1 ();
65 mSavedDebugRegisters
[2] = AsmReadDr2 ();
66 mSavedDebugRegisters
[3] = AsmReadDr3 ();
67 mSavedDebugRegisters
[4] = AsmReadDr6 ();
68 mSavedDebugRegisters
[5] = AsmReadDr7 ();
72 Restore debug register when SMI exit.
76 RestoreDebugRegister (
81 AsmWriteDr0 (mSavedDebugRegisters
[0]);
82 AsmWriteDr1 (mSavedDebugRegisters
[1]);
83 AsmWriteDr2 (mSavedDebugRegisters
[2]);
84 AsmWriteDr3 (mSavedDebugRegisters
[3]);
85 AsmWriteDr6 (mSavedDebugRegisters
[4]);
86 AsmWriteDr7 (mSavedDebugRegisters
[5]);
90 Initialize debug agent.
92 This function is used to set up debug enviroment for source level debug
95 If InitFlag is DEBUG_AGENT_INIT_SMM, it will overirde IDT table entries
96 and initialize debug port. It will get debug agent Mailbox from GUIDed HOB,
97 it it exists, debug agent wiil copied it into the local Mailbox in SMM space.
98 it will overirde IDT table entries and initialize debug port. Context will be
100 If InitFlag is DEBUG_AGENT_INIT_ENTER_SMI, debug agent will save Debug
101 Registers and get local Mailbox in SMM space. Context will be NULL.
102 If InitFlag is DEBUG_AGENT_INIT_EXIT_SMI, debug agent will restore Debug
103 Registers. Context will be NULL.
105 @param[in] InitFlag Init flag is used to decide initialize process.
106 @param[in] Context Context needed according to InitFlag.
107 @param[in] Function Continue function called by debug agent library; it was
113 InitializeDebugAgent (
115 IN VOID
*Context
, OPTIONAL
116 IN DEBUG_AGENT_CONTINUE Function OPTIONAL
120 UINT64 DebugPortHandle
;
123 case DEBUG_AGENT_INIT_SMM
:
124 Status
= EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid
, (VOID
**) &mMailboxPointer
);
125 if (EFI_ERROR (Status
) || mMailboxPointer
== NULL
) {
126 ZeroMem (&mLocalMailbox
, sizeof (DEBUG_AGENT_MAILBOX
));
127 mMailboxPointer
= &mLocalMailbox
;
132 case DEBUG_AGENT_INIT_ENTER_SMI
:
133 SaveDebugRegister ();
134 InitializeDebugIdt ();
136 if (mMailboxPointer
!= NULL
) {
138 // Initialize debug communication port
140 DebugPortHandle
= (UINT64
) (UINTN
)DebugPortInitialize ((DEBUG_PORT_HANDLE
) (UINTN
)mMailboxPointer
->DebugPortHandle
, NULL
);
141 mMailboxPointer
->DebugPortHandle
= DebugPortHandle
;
143 if (mMailboxPointer
->DebugFlag
.Bits
.BreakOnNextSmi
== 1) {
145 // If SMM entry break is set, SMM code will be break at here.
152 case DEBUG_AGENT_INIT_EXIT_SMI
:
153 RestoreDebugRegister ();