https://github.com/EfiPy/EfiPy2/blob/main/Efi/Apps/EfiPy2Sample/CpuIdBasic.py
Description
In this demo, the sample script shows how to uses x86 instruction CPUID with CorePy/EfiPy2.
We have put CpuId module in EfiPy2.Lib in EfiPy2, that is the re-usable CpuId module need to be import as
from EfiPy2.Lib import CpuId
In CpuId module, it has class named "CpuIdClass". and create object as
CpuIdObj = CpuId.CpuIdClass()
CpuId module also provide generic register suit for CPUID instruction operation by CorePy.
CpuIdReg = CpuId.CPUID_GENERIC_REGISTERs()
CpuIdClass has two member functions... GetId () and GetId2 (). Both functions take three parameters. The first two parameters are EAX and ECX by instruction CPUID. But the third parameter is memory address by GetId (), CPUID_GENERIC_REGISTERs object for GetId2 ().
Also, user can create its own register with pack structure type for CPUID, for example...
import EfiPy2.MdePkg.Register.Intel.Cpuid as CpuidRegs
class CpuIdRegisters (EfiPy.Structure):
_pack_ = 1
_fields_ = [
('EAX', CpuidRegs.CPUID_VERSION_INFO_EAX),
('EBX', CpuidRegs.CPUID_VERSION_INFO_EBX),
('ECX', CpuidRegs.CPUID_VERSION_INFO_ECX),
('EDX', CpuidRegs.CPUID_VERSION_INFO_EDX)
]
CpuIdReg = CpuIdRegisters()
rax = CpuIdObj.GetId2 (CpuidRegs.CPUID_VERSION_INFO, 0, CpuIdReg)
Due to CpuidRegs.CPUID_VERSION_INFO_EAX, CpuidRegs.CPUID_VERSION_INFO_EBX, CpuidRegs.CPUID_VERSION_INFO_ECX and CpuidRegs.CPUID_VERSION_INFO_EDX are union type including each bit field, Python script can also dump version information detail.
No comments:
Post a Comment