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
;
18 DEBUG_AGENT_MAILBOX mLocalMailbox
;
19 UINTN mSavedDebugRegisters
[6];
20 CONST BOOLEAN MultiProcessorDebugSupport
= FALSE
;
24 Get Debug Agent Mailbox pointer.
26 @return Mailbox pointer.
34 return mMailboxPointer
;
38 Get debug port handle.
40 @return Debug port handle.
48 return (DEBUG_PORT_HANDLE
) (UINTN
)(mMailboxPointer
->DebugPortHandle
);
52 Store debug register when SMI exit.
60 mSavedDebugRegisters
[0] = AsmReadDr0 ();
61 mSavedDebugRegisters
[1] = AsmReadDr1 ();
62 mSavedDebugRegisters
[2] = AsmReadDr2 ();
63 mSavedDebugRegisters
[3] = AsmReadDr3 ();
64 mSavedDebugRegisters
[4] = AsmReadDr6 ();
65 mSavedDebugRegisters
[5] = AsmReadDr7 ();
69 Restore debug register when SMI exit.
73 RestoreDebugRegister (
78 AsmWriteDr0 (mSavedDebugRegisters
[0]);
79 AsmWriteDr1 (mSavedDebugRegisters
[1]);
80 AsmWriteDr2 (mSavedDebugRegisters
[2]);
81 AsmWriteDr3 (mSavedDebugRegisters
[3]);
82 AsmWriteDr6 (mSavedDebugRegisters
[4]);
83 AsmWriteDr7 (mSavedDebugRegisters
[5]);
87 Initialize debug agent.
89 This function is used to set up debug enviroment for source level debug
92 If InitFlag is DEBUG_AGENT_INIT_SMM, it will overirde IDT table entries
93 and initialize debug port. It will get debug agent Mailbox from GUIDed HOB,
94 it it exists, debug agent wiil copied it into the local Mailbox in SMM space.
95 it will overirde IDT table entries and initialize debug port. Context will be
97 If InitFlag is DEBUG_AGENT_INIT_ENTER_SMI, debug agent will save Debug
98 Registers and get local Mailbox in SMM space. Context will be NULL.
99 If InitFlag is DEBUG_AGENT_INIT_EXIT_SMI, debug agent will restore Debug
100 Registers. Context will be NULL.
102 @param[in] InitFlag Init flag is used to decide initialize process.
103 @param[in] Context Context needed according to InitFlag.
104 @param[in] Function Continue function called by debug agent library; it was
110 InitializeDebugAgent (
112 IN VOID
*Context
, OPTIONAL
113 IN DEBUG_AGENT_CONTINUE Function OPTIONAL
117 UINT64 DebugPortHandle
;
120 case DEBUG_AGENT_INIT_SMM
:
121 Status
= EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid
, (VOID
**) &mMailboxPointer
);
122 if (EFI_ERROR (Status
) || mMailboxPointer
== NULL
) {
123 ZeroMem (&mLocalMailbox
, sizeof (DEBUG_AGENT_MAILBOX
));
124 mMailboxPointer
= &mLocalMailbox
;
129 case DEBUG_AGENT_INIT_ENTER_SMI
:
130 SaveDebugRegister ();
131 InitializeDebugIdt ();
133 if (mMailboxPointer
!= NULL
) {
135 // Initialize debug communication port
137 DebugPortHandle
= (UINT64
) (UINTN
)DebugPortInitialize ((DEBUG_PORT_HANDLE
) (UINTN
)mMailboxPointer
->DebugPortHandle
, NULL
);
138 mMailboxPointer
->DebugPortHandle
= DebugPortHandle
;
140 if (mMailboxPointer
->DebugFlag
.Bits
.BreakOnNextSmi
== 1) {
142 // If SMM entry break is set, SMM code will be break at here.
149 case DEBUG_AGENT_INIT_EXIT_SMI
:
150 RestoreDebugRegister ();