ReadSaveStateRegister/WriteSaveStateRegister functions

Laszlo Ersek

On 06/24/20 10:53, mzktsn@... wrote:

I have noticed some functions that provide access
in the CPU Saved State Registers (ReadSaveStateRegister/WriteSaveStateRegister() etc.)
Would like to ask if it is possible to use their functionality from code
inside /MdeModulePkg/Core/PiSmmCore/PiSmmCore.c file? And what modifications should be
made in order to achieve it if is viable?
Not sure *why* you'd like to access specific registers from the SMM save
state map in PiSmmCore.

But, these functions are exposed though a standard interface too; see
EFI_SMM_CPU_PROTOCOL (or rather "EFI_MM_CPU_PROTOCOL") in the PI spec,
volume 4, section "4.3 CPU Save State Access Services".

In edk2, PiSmmCpuDxeSmm provides the protocol; the member functions are
delegated to the platform's SmmCpuFeaturesLib instance, and there are
general fallback implementations too.

See for example SmmReadSaveState() in

Status = SmmCpuFeaturesReadSaveStateRegister (CpuIndex, Register,
Width, Buffer);
if (Status == EFI_UNSUPPORTED) {
Status = ReadSaveStateRegister (CpuIndex, Register, Width, Buffer);
return Status;

where SmmCpuFeaturesReadSaveStateRegister() comes from the platform's
library instance, and ReadSaveStateRegister() is the generic/fallback
code, from "UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c".

Generally speaking, in a module that's different from PiSmmCpuDxeSmm,
you could introduce a depex or a protocol notify on
EFI_SMM_CPU_PROTOCOL, and use its member functions.

Whether that applies *specifically* to PiSmmCore, I can't say. (Again I
don't know *why* you need that functionality there.)

Probably best to address the PiSmmCore owners directly; run the
following command in edk2:

$ python BaseTools/Scripts/ \
-l MdeModulePkg/Core/PiSmmCore/PiSmmCore.c

Jian J Wang <>
Hao A Wu <hao.a.wu@...>
Eric Dong <eric.dong@...>
Ray Ni <>

I've added those people to the CC list now.

General hint: when posting a query (to any technical mailing list,
really), always include the "why", not just the "what" / "how".