Skip to content

Commit f1674e6

Browse files
VivianNKmergify[bot]
authored andcommitted
UefiCpuPkg: SmmProfile: Use public Architectural MSRs from MdePkg
Replaced local Msr defines with inclusion of Register/Amd/Msr.h. Signed-off-by: Vivian Nowka-Keane <vnowkakeane@linux.microsoft.com>
1 parent 5a73776 commit f1674e6

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,13 @@ DisableBTS (
131131
VOID
132132
)
133133
{
134-
AsmMsrAnd64 (MSR_DEBUG_CTL, ~((UINT64)(MSR_DEBUG_CTL_BTS | MSR_DEBUG_CTL_TR)));
134+
MSR_IA32_DEBUGCTL_REGISTER DebugCtl;
135+
136+
DebugCtl.Uint64 = AsmReadMsr64 (MSR_IA32_DEBUGCTL);
137+
DebugCtl.Bits.BTS = 0;
138+
DebugCtl.Bits.TR = 0;
139+
140+
AsmWriteMsr64 (MSR_IA32_DEBUGCTL, DebugCtl.Uint64);
135141
}
136142

137143
/**
@@ -143,7 +149,13 @@ EnableBTS (
143149
VOID
144150
)
145151
{
146-
AsmMsrOr64 (MSR_DEBUG_CTL, (MSR_DEBUG_CTL_BTS | MSR_DEBUG_CTL_TR));
152+
MSR_IA32_DEBUGCTL_REGISTER DebugCtl;
153+
154+
DebugCtl.Uint64 = AsmReadMsr64 (MSR_IA32_DEBUGCTL);
155+
DebugCtl.Bits.BTS = 1;
156+
DebugCtl.Bits.TR = 1;
157+
158+
AsmWriteMsr64 (MSR_IA32_DEBUGCTL, DebugCtl.Uint64);
147159
}
148160

149161
/**
@@ -930,15 +942,15 @@ ActivateLBR (
930942
VOID
931943
)
932944
{
933-
UINT64 DebugCtl;
945+
MSR_IA32_DEBUGCTL_REGISTER DebugCtl;
934946

935-
DebugCtl = AsmReadMsr64 (MSR_DEBUG_CTL);
936-
if ((DebugCtl & MSR_DEBUG_CTL_LBR) != 0) {
947+
DebugCtl.Uint64 = AsmReadMsr64 (MSR_IA32_DEBUGCTL);
948+
if (DebugCtl.Bits.LBR) {
937949
return;
938950
}
939951

940-
DebugCtl |= MSR_DEBUG_CTL_LBR;
941-
AsmWriteMsr64 (MSR_DEBUG_CTL, DebugCtl);
952+
DebugCtl.Bits.LBR = 1;
953+
AsmWriteMsr64 (MSR_IA32_DEBUGCTL, DebugCtl.Uint64);
942954
}
943955

944956
/**
@@ -952,17 +964,23 @@ ActivateBTS (
952964
IN UINTN CpuIndex
953965
)
954966
{
955-
UINT64 DebugCtl;
967+
MSR_IA32_DEBUGCTL_REGISTER DebugCtl;
956968

957-
DebugCtl = AsmReadMsr64 (MSR_DEBUG_CTL);
958-
if ((DebugCtl & MSR_DEBUG_CTL_BTS) != 0) {
969+
DebugCtl.Uint64 = AsmReadMsr64 (MSR_IA32_DEBUGCTL);
970+
if ((DebugCtl.Bits.BTS)) {
959971
return;
960972
}
961973

962974
AsmWriteMsr64 (MSR_DS_AREA, (UINT64)(UINTN)mMsrDsArea[CpuIndex]);
963-
DebugCtl |= (UINT64)(MSR_DEBUG_CTL_BTS | MSR_DEBUG_CTL_TR);
964-
DebugCtl &= ~((UINT64)MSR_DEBUG_CTL_BTINT);
965-
AsmWriteMsr64 (MSR_DEBUG_CTL, DebugCtl);
975+
976+
//
977+
// Enable BTS
978+
//
979+
DebugCtl.Bits.BTS = 1;
980+
DebugCtl.Bits.TR = 1;
981+
982+
DebugCtl.Bits.BTINT = 0;
983+
AsmWriteMsr64 (MSR_IA32_DEBUGCTL, DebugCtl.Uint64);
966984
}
967985

968986
/**

UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
3939
//
4040
// CPU generic definition
4141
//
42-
#define MSR_EFER 0xc0000080
43-
#define MSR_EFER_XD 0x800
42+
#define MSR_EFER_XD 0x800
4443

45-
#define CPUID1_EDX_BTS_AVAILABLE 0x200000
44+
#define CPUID1_EDX_BTS_AVAILABLE 0x200000
4645

47-
#define DR6_SINGLE_STEP 0x4000
48-
#define RFLAG_TF 0x100
46+
#define DR6_SINGLE_STEP 0x4000
4947

50-
#define MSR_DEBUG_CTL 0x1D9
51-
#define MSR_DEBUG_CTL_LBR 0x1
52-
#define MSR_DEBUG_CTL_TR 0x40
53-
#define MSR_DEBUG_CTL_BTS 0x80
54-
#define MSR_DEBUG_CTL_BTINT 0x100
55-
#define MSR_DS_AREA 0x600
48+
#define MSR_DS_AREA 0x600
5649

5750
#define HEAP_GUARD_NONSTOP_MODE \
5851
((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT6|BIT3|BIT2)) > BIT6)

0 commit comments

Comments
 (0)