Skip to content

Commit

Permalink
UefiCpuPkg: SmmProfile: Use public Architectural MSRs from MdePkg
Browse files Browse the repository at this point in the history
Replaced local Msr defines with inclusion of Register/Amd/Msr.h.

Signed-off-by: Vivian Nowka-Keane <[email protected]>
  • Loading branch information
VivianNK authored and mergify[bot] committed Nov 12, 2024
1 parent 5a73776 commit f1674e6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
44 changes: 31 additions & 13 deletions UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@ DisableBTS (
VOID
)
{
AsmMsrAnd64 (MSR_DEBUG_CTL, ~((UINT64)(MSR_DEBUG_CTL_BTS | MSR_DEBUG_CTL_TR)));
MSR_IA32_DEBUGCTL_REGISTER DebugCtl;

DebugCtl.Uint64 = AsmReadMsr64 (MSR_IA32_DEBUGCTL);
DebugCtl.Bits.BTS = 0;
DebugCtl.Bits.TR = 0;

AsmWriteMsr64 (MSR_IA32_DEBUGCTL, DebugCtl.Uint64);
}

/**
Expand All @@ -143,7 +149,13 @@ EnableBTS (
VOID
)
{
AsmMsrOr64 (MSR_DEBUG_CTL, (MSR_DEBUG_CTL_BTS | MSR_DEBUG_CTL_TR));
MSR_IA32_DEBUGCTL_REGISTER DebugCtl;

DebugCtl.Uint64 = AsmReadMsr64 (MSR_IA32_DEBUGCTL);
DebugCtl.Bits.BTS = 1;
DebugCtl.Bits.TR = 1;

AsmWriteMsr64 (MSR_IA32_DEBUGCTL, DebugCtl.Uint64);
}

/**
Expand Down Expand Up @@ -930,15 +942,15 @@ ActivateLBR (
VOID
)
{
UINT64 DebugCtl;
MSR_IA32_DEBUGCTL_REGISTER DebugCtl;

DebugCtl = AsmReadMsr64 (MSR_DEBUG_CTL);
if ((DebugCtl & MSR_DEBUG_CTL_LBR) != 0) {
DebugCtl.Uint64 = AsmReadMsr64 (MSR_IA32_DEBUGCTL);
if (DebugCtl.Bits.LBR) {
return;
}

DebugCtl |= MSR_DEBUG_CTL_LBR;
AsmWriteMsr64 (MSR_DEBUG_CTL, DebugCtl);
DebugCtl.Bits.LBR = 1;
AsmWriteMsr64 (MSR_IA32_DEBUGCTL, DebugCtl.Uint64);
}

/**
Expand All @@ -952,17 +964,23 @@ ActivateBTS (
IN UINTN CpuIndex
)
{
UINT64 DebugCtl;
MSR_IA32_DEBUGCTL_REGISTER DebugCtl;

DebugCtl = AsmReadMsr64 (MSR_DEBUG_CTL);
if ((DebugCtl & MSR_DEBUG_CTL_BTS) != 0) {
DebugCtl.Uint64 = AsmReadMsr64 (MSR_IA32_DEBUGCTL);
if ((DebugCtl.Bits.BTS)) {
return;
}

AsmWriteMsr64 (MSR_DS_AREA, (UINT64)(UINTN)mMsrDsArea[CpuIndex]);
DebugCtl |= (UINT64)(MSR_DEBUG_CTL_BTS | MSR_DEBUG_CTL_TR);
DebugCtl &= ~((UINT64)MSR_DEBUG_CTL_BTINT);
AsmWriteMsr64 (MSR_DEBUG_CTL, DebugCtl);

//
// Enable BTS
//
DebugCtl.Bits.BTS = 1;
DebugCtl.Bits.TR = 1;

DebugCtl.Bits.BTINT = 0;
AsmWriteMsr64 (MSR_IA32_DEBUGCTL, DebugCtl.Uint64);
}

/**
Expand Down
15 changes: 4 additions & 11 deletions UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// CPU generic definition
//
#define MSR_EFER 0xc0000080
#define MSR_EFER_XD 0x800
#define MSR_EFER_XD 0x800

#define CPUID1_EDX_BTS_AVAILABLE 0x200000
#define CPUID1_EDX_BTS_AVAILABLE 0x200000

#define DR6_SINGLE_STEP 0x4000
#define RFLAG_TF 0x100
#define DR6_SINGLE_STEP 0x4000

#define MSR_DEBUG_CTL 0x1D9
#define MSR_DEBUG_CTL_LBR 0x1
#define MSR_DEBUG_CTL_TR 0x40
#define MSR_DEBUG_CTL_BTS 0x80
#define MSR_DEBUG_CTL_BTINT 0x100
#define MSR_DS_AREA 0x600
#define MSR_DS_AREA 0x600

#define HEAP_GUARD_NONSTOP_MODE \
((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT6|BIT3|BIT2)) > BIT6)
Expand Down

0 comments on commit f1674e6

Please sign in to comment.