I recommend leaving it in Chipsec project until the port to MdePkg libs can be completed.
Mike > -----Original Message----- > From: Jayaprakash, N <n.jayaprak...@intel.com> > Sent: Tuesday, November 29, 2022 8:22 AM > To: Kinney, Michael D <michael.d.kin...@intel.com>; devel@edk2.groups.io > Cc: Rebecca Cran <rebe...@nuviainc.com>; Kadapathri, Ajay > <ajay.kadapat...@intel.com>; Frinzell, Aaron > <aaron.frinz...@intel.com> > Subject: RE: [edk2-libc Patch 1/1] edk2-libc: migration of edk2module from > chipsec repo > > Hi Mike, > > Thanks Mike for your feedback. I completely agree with your suggestions. > > Having said that, the code in PR is an existing well tested code from Chipsec > git repo and it was probably written quite a > few years ago. > This is probably the reason that it is not following the edk2 conventions are > guidelines with respect to ASM. > Chipsec git repo for reference - > https://github.com/chipsec/chipsec/tree/main/chipsec_tools/edk2/PythonEFI > > Our idea is to bring this code from Chipsec repo as is in the first stage, > enable the Chipsec tool and then make any > additional improvements required. > We shall definitely take up your suggestions early in the next year 2023. > > Let me know if this idea sounds good. > > Regards, > JP > -----Original Message----- > From: Kinney, Michael D <michael.d.kin...@intel.com> > Sent: 29 November 2022 21:23 > To: Jayaprakash, N <n.jayaprak...@intel.com>; devel@edk2.groups.io; Kinney, > Michael D <michael.d.kin...@intel.com> > Cc: Rebecca Cran <rebe...@nuviainc.com> > Subject: RE: [edk2-libc Patch 1/1] edk2-libc: migration of edk2module from > chipsec repo > > Hi JP, > > Many of these APIs are already available from the MdePkg BaseLib, IoLib, and > PciLib. > > Why would we add custom ASM implementations of there here? > > Why ASM and not NASM. edk2 projects have consolidated on NASM for all > IA32/X64 assembly code. > > I think the best approach is to port the Python wrappers around the calls to > these > ASM functions to call MdePkg BaseLib, IoLib, and PciLib and remove the ASM > code > from the patch. > > Thanks, > > Mike > > > -----Original Message----- > > From: Jayaprakash, N <n.jayaprak...@intel.com> > > Sent: Monday, November 21, 2022 6:00 AM > > To: devel@edk2.groups.io > > Cc: Rebecca Cran <rebe...@nuviainc.com>; Kinney, Michael D > > <michael.d.kin...@intel.com>; Jayaprakash, N > > <n.jayaprak...@intel.com> > > Subject: [edk2-libc Patch 1/1] edk2-libc: migration of edk2module from > > chipsec repo > > > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4161 > > > > This patch merges the enhancements done by chipsec > > tool to edk2 module into edk2-libc repo. > > The chipsec enhancements can be used for various > > other Python based tools to access platform registers. > > These enhancements providing a set of APIs to access > > the platform registers directly from the python > > scripts running on UEFI shell. This will benefit the > > Python users on UEFI shell in general and enhances > > it's usability. Python can be used effectively to > > implement tools, scripts required for automation, > > debug from UEFI shell. > > > > Cc: Rebecca Cran <rebe...@nuviainc.com> > > Cc: Michael D Kinney <michael.d.kin...@intel.com> > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Jayaprakash N <n.jayaprak...@intel.com> > > Reviewed-by: Michael D Kinney <michael.d.kin...@intel.com> > > --- > > .../Python-3.6.8/PyMod-3.6.8/Modules/cpu.asm | 519 ++++++++++++++++ > > .../PyMod-3.6.8/Modules/cpu_ia32.asm | 395 ++++++++++++ > > .../PyMod-3.6.8/Modules/edk2module.c | 568 +++++++++++++++++- > > .../Python/Python-3.6.8/Python368.inf | 32 +- > > 4 files changed, 1496 insertions(+), 18 deletions(-) > > create mode 100644 > > AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Modules/cpu.asm > > create mode 100644 > > AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Modules/cpu_ia32.asm > > > > diff --git > > a/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Modules/cpu.asm > > b/AppPkg/Applications/Python/Python- > > 3.6.8/PyMod-3.6.8/Modules/cpu.asm > > new file mode 100644 > > index 0000000..65edc96 > > --- /dev/null > > +++ b/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Modules/cpu.asm > > @@ -0,0 +1,519 @@ > > +TITLE cpu.asm: Assembly code for the x64 resources > > + > > +.CODE cpu_asm_code$__a > > + > > +PUBLIC WritePortDword > > +PUBLIC WritePortWord > > +PUBLIC WritePortByte > > +PUBLIC ReadPortDword > > +PUBLIC ReadPortWord > > +PUBLIC ReadPortByte > > +PUBLIC WriteHighCMOSByte > > +PUBLIC WriteLowCMOSByte > > +PUBLIC SendAPMSMI > > +PUBLIC WritePCIByte > > +PUBLIC WritePCIWord > > +PUBLIC WritePCIDword > > +PUBLIC ReadPCIByte > > +PUBLIC ReadPCIWord > > +PUBLIC ReadPCIDword > > +PUBLIC _rdmsr > > +PUBLIC _wrmsr > > +PUBLIC _load_gdt > > +PUBLIC _rflags > > +PUBLIC _swsmi > > + > > + > > +;------------------------------------------------------------------------------ > > +; UINT64 _rflags() > > +;------------------------------------------------------------------------------ > > +_rflags PROC > > + pushfq > > + pop rax > > + ret > > +_rflags ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void _store_idtr( > > +; unsigned char *address // rcx > > +; ) > > +;------------------------------------------------------------------------------ > > +_store_idtr PROC > > + sidt fword ptr [rcx] > > + ret > > +_store_idtr ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void _load_idtr( > > +; unsigned char *address // rcx > > +; ) > > +;------------------------------------------------------------------------------ > > +_load_idtr PROC > > + lidt fword ptr [rcx] > > + ret > > +_load_idtr ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void _store_gdtr( > > +; unsigned char *address // rcx > > +; ) > > +;------------------------------------------------------------------------------ > > +_store_gdtr PROC > > + sgdt fword ptr [rcx] > > + ret > > +_store_gdtr ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void _load_gdtr( > > +; unsigned char *address // rcx > > +; ) > > +;------------------------------------------------------------------------------ > > +_load_gdtr PROC > > + lgdt fword ptr [rcx] > > + ret > > +_load_gdtr ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void _store_ldtr( > > +; unsigned char *address // rcx > > +; ) > > +;------------------------------------------------------------------------------ > > +_store_ldtr PROC > > + ;sldt fword ptr [rcx] > > + ret > > +_store_ldtr ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void _load_ldtr( > > +; unsigned char *address // rcx > > +; ) > > +;------------------------------------------------------------------------------ > > +_load_ldtr PROC > > + ;lldt fword ptr [rcx] > > + ret > > +_load_ldtr ENDP > > + > > + > > +;------------------------------------------------------------------------------ > > +; void _load_gdt( > > +; unsigned char *value // rcx > > +; ) > > +;------------------------------------------------------------------------------ > > +_load_gdt PROC > > + > > + sgdt fword ptr [rcx] > > + lgdt fword ptr [rcx] > > + > > + ret > > +_load_gdt ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void _rdmsr( > > +; unsigned int msr_num, // rcx > > +; unsigned int* msr_lo, // rdx > > +; unsigned int* msr_hi // r8 > > +; ) > > +;------------------------------------------------------------------------------ > > +_rdmsr PROC > > + push r10 > > + push r11 > > + push rax > > + push rdx > > + > > + mov r10, rdx ; msr_lo > > + mov r11, r8 ; msr_hi > > + > > + ; rcx has msr_num > > + rdmsr > > + > > + ; Write MSR results in edx:eax > > + mov dword ptr [r10], eax > > + mov dword ptr [r11], edx > > + > > + pop rdx > > + pop rax > > + pop r11 > > + pop r10 > > + > > + ret > > +_rdmsr ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void _wrmsr( > > +; unsigned int msr_num, // rcx > > +; unsigned int msr_hi, // rdx > > +; unsigned int msr_lo // r8 > > +; ) > > +;------------------------------------------------------------------------------ > > +_wrmsr PROC > > + push rax > > + > > + ; rcx has msr_num > > + ; rdx has msr_hi > > + ; move msr_lo from r8 to rax > > + mov rax, r8 > > + wrmsr > > + > > + pop rax > > + ret > > +_wrmsr ENDP > > + > > + > > +;------------------------------------------------------------------------------ > > +; void > > +; WritePortDword ( > > +; unsigned int out_value // rcx > > +; unsigned short port_num // rdx > > +; ) > > +;------------------------------------------------------------------------------ > > +WritePortDword PROC > > + push rax > > + > > + mov rax, rcx > > + out dx, rax > > + > > + pop rax > > + ret > > +WritePortDword ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void > > +; WritePortWord ( > > +; unsigned short out_value // rcx > > +; unsigned short port_num // rdx > > +; ) > > +;------------------------------------------------------------------------------ > > +WritePortWord PROC > > + push rax > > + > > + mov rax, rcx > > + out dx, ax > > + > > + pop rax > > + ret > > +WritePortWord ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void > > +; WritePortByte ( > > +; unsigned char out_value // rcx > > +; unsigned short port_num // rdx > > +; ) > > +;------------------------------------------------------------------------------ > > +WritePortByte PROC > > + push rax > > + > > + mov rax, rcx > > + out dx, al > > + > > + pop rax > > + ret > > +WritePortByte ENDP > > + > > +;------------------------------------------------------------------------------ > > +; unsigned int > > +; ReadPortDword ( > > +; unsigned short port_num // rcx > > +; ) > > +;------------------------------------------------------------------------------ > > +ReadPortDword PROC > > + push rdx > > + > > + xor rax, rax > > + mov rdx, rcx > > + in eax, dx > > + > > + pop rdx > > + ret > > +ReadPortDword ENDP > > + > > +;------------------------------------------------------------------------------ > > +; unsigned short > > +; ReadPortWord ( > > +; unsigned short port_num // rcx > > +; ) > > +;------------------------------------------------------------------------------ > > +ReadPortWord PROC > > + push rdx > > + > > + xor rax, rax > > + mov rdx, rcx > > + in ax, dx > > + > > + pop rdx > > + ret > > +ReadPortWord ENDP > > + > > +;------------------------------------------------------------------------------ > > +; unsigned char > > +; ReadPortByte ( > > +; unsigned short port_num // rcx > > +; ) > > +;------------------------------------------------------------------------------ > > +ReadPortByte PROC > > + push rdx > > + > > + xor rax, rax > > + mov rdx, rcx > > + in al, dx > > + > > + pop rdx > > + ret > > +ReadPortByte ENDP > > + > > + > > +;------------------------------------------------------------------------------ > > +; void > > +; WriteHighCMOSByte ( > > +; unsigned char cmos_off // rcx > > +; unsigned char val // rdx > > +; ) > > +;------------------------------------------------------------------------------ > > +WriteHighCMOSByte PROC > > + push rax > > + > > + mov rax, rcx > > + out 72h, al > > + mov rax, rdx > > + out 73h, al > > + > > + pop rax > > + ret > > +WriteHighCMOSByte ENDP > > +;------------------------------------------------------------------------------ > > +; void > > +; WriteLowCMOSByte ( > > +; unsigned char cmos_off // rcx > > +; unsigned char val // rdx > > +; ) > > +;------------------------------------------------------------------------------ > > +WriteLowCMOSByte PROC > > + push rax > > + > > + mov rax, rcx > > + or al, 80h > > + out 70h, al > > + mov rax, rdx > > + out 71h, al > > + > > + pop rax > > + ret > > +WriteLowCMOSByte ENDP > > + > > + > > +; @TODO: looks incorrect > > +;------------------------------------------------------------------------------ > > +; void > > +; SendAPMSMI ( > > +; unsigned int apm_port_value // rcx > > +; IN UINT64 rax_value // rdx > > +; ) > > +;------------------------------------------------------------------------------ > > +SendAPMSMI PROC > > + push rax > > + push rdx > > + > > + mov rax, rcx > > + mov dx, 0B2h > > + out dx, rax > > + > > + pop rdx > > + pop rax > > + ret > > +SendAPMSMI ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void > > +; WritePCIByte ( > > +; unsigned int pci_reg // rcx > > +; unsigned short cfg_data_port // rdx > > +; unsigned char byte_value // r8 > > +; ) > > +;------------------------------------------------------------------------------ > > +WritePCIByte PROC > > + push rax > > + push rdx > > + > > + cli > > + mov rax, rcx ; pci_reg > > + mov dx, 0CF8h > > + out dx, rax > > + > > + mov rax, r8 ; byte_value > > + pop rdx ; cfg_data_port > > + out dx, al > > + sti > > + > > + pop rax > > + ret > > +WritePCIByte ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void > > +; WritePCIWord ( > > +; unsigned int pci_reg // rcx > > +; unsigned short cfg_data_port // rdx > > +; unsigned short word_value // r8 > > +; ) > > +;------------------------------------------------------------------------------ > > +WritePCIWord PROC > > + push rax > > + push rdx > > + > > + cli > > + mov rax, rcx ; pci_reg > > + mov dx, 0CF8h > > + out dx, rax > > + > > + mov rax, r8 ; byte_value > > + pop rdx ; cfg_data_port > > + out dx, ax > > + sti > > + > > + pop rax > > + ret > > +WritePCIWord ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void > > +; WritePCIDword ( > > +; unsigned int pci_reg // rcx > > +; unsigned short cfg_data_port // rdx > > +; unsigned int dword_value // r8 > > +; ) > > +;------------------------------------------------------------------------------ > > +WritePCIDword PROC > > + push rax > > + push rdx > > + > > + cli > > + mov rax, rcx ; pci_reg > > + mov dx, 0CF8h > > + out dx, rax > > + > > + mov rax, r8 ; byte_value > > + pop rdx ; cfg_data_port > > + out dx, eax > > + sti > > + > > + pop rax > > + ret > > +WritePCIDword ENDP > > + > > + > > + > > +;------------------------------------------------------------------------------ > > +; unsigned char > > +; ReadPCIByte ( > > +; unsigned int pci_reg // rcx > > +; unsigned short cfg_data_port // rdx > > +; ) > > +;------------------------------------------------------------------------------ > > +ReadPCIByte PROC > > + push rdx > > + > > + cli > > + mov rax, rcx ; pci_reg > > + mov dx, 0CF8h > > + out dx, rax > > + > > + xor rax, rax > > + pop rdx ; cfg_data_port > > + in al, dx > > + sti > > + > > + ret > > +ReadPCIByte ENDP > > + > > +;------------------------------------------------------------------------------ > > +; unsigned short > > +; ReadPCIWord ( > > +; unsigned int pci_reg // rcx > > +; unsigned short cfg_data_port // rdx > > +; ) > > +;------------------------------------------------------------------------------ > > +ReadPCIWord PROC > > + push rdx > > + > > + cli > > + mov rax, rcx ; pci_reg > > + mov dx, 0CF8h > > + out dx, rax > > + > > + xor rax, rax > > + pop rdx ; cfg_data_port > > + in ax, dx > > + sti > > + > > + ret > > +ReadPCIWord ENDP > > + > > +;------------------------------------------------------------------------------ > > +; unsigned int > > +; ReadPCIDword ( > > +; unsigned int pci_reg // rcx > > +; unsigned short cfg_data_port // rdx > > +; ) > > +;------------------------------------------------------------------------------ > > +ReadPCIDword PROC > > + push rdx > > + > > + cli > > + mov rax, rcx ; pci_reg > > + mov dx, 0CF8h > > + out dx, rax > > + > > + xor rax, rax > > + pop rdx ; cfg_data_port > > + in eax, dx > > + sti > > + > > + ret > > +ReadPCIDword ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void > > +; _swsmi ( > > +; unsigned int smi_code_data // rcx > > +; IN UINT64 rax_value // rdx > > +; IN UINT64 rbx_value // r8 > > +; IN UINT64 rcx_value // r9 > > +; IN UINT64 rdx_value // rsp + 0x28 > > +; IN UINT64 rsi_value // rsp + 0x30 > > +; IN UINT64 rdi_value // rsp + 0x38 > > +; ) > > +;------------------------------------------------------------------------------ > > +_swsmi PROC > > + push rbx > > + push rsi > > + push rdi > > + > > + ; rsp - 0x18 > > + > > + ; setting up GPR (arguments) to SMI handler call > > + ; notes: > > + ; RAX will get partially overwritten (AX) by _smi_code_data (which > > is passed in RCX) > > + ; RDX will get partially overwritten (DX) by the value of APMC port > > (= 0x00B2) > > + mov rax, rdx ; rax_value > > + mov ax, cx ; smi_code_data > > + mov rdx, r10 ; rdx_value > > + mov rdx, [rsp + 040h] ; rsp + 0x28 + 0x18 > > + > > + mov rbx, r8 ; rbx_value > > + mov rcx, r9 ; rcx_value > > + mov rsi, [rsp + 048h] ; rsi_value > > + mov rdi, [rsp + 050h] ; rdi_value > > + > > + ; this OUT instruction will write WORD value (smi_code_data) to ports > > 0xB2 and 0xB3 (SW SMI control and data ports) > > + out 0B2h, ax > > + > > + ; @TODO: some SM handlers return data/errorcode in GPRs, need to > > return this to the caller > > + > > + pop rdi > > + pop rsi > > + pop rbx > > + ret > > +_swsmi ENDP > > + > > + > > +END > > diff --git > > a/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Modules/cpu_ia32.asm > b/AppPkg/Applications/Python/Python- > > 3.6.8/PyMod-3.6.8/Modules/cpu_ia32.asm > > new file mode 100644 > > index 0000000..0b6fc6d > > --- /dev/null > > +++ > > b/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Modules/cpu_ia32.asm > > @@ -0,0 +1,395 @@ > > +TITLE cpu.asm: Assembly code for the i386 resources > > + > > +PUBLIC WritePortDword > > +PUBLIC WritePortWord > > +PUBLIC WritePortByte > > +PUBLIC ReadPortDword > > +PUBLIC ReadPortWord > > +PUBLIC ReadPortByte > > +PUBLIC WriteHighCMOSByte > > +PUBLIC WriteLowCMOSByte > > +PUBLIC SendAPMSMI > > +PUBLIC WritePCIByte > > +PUBLIC WritePCIWord > > +PUBLIC WritePCIDword > > +PUBLIC ReadPCIByte > > +PUBLIC ReadPCIWord > > +PUBLIC ReadPCIDword > > +PUBLIC _rdmsr > > +PUBLIC _wrmsr > > + > > + > > + .586p > > + .model flat,C > > + .code > > + > > +;------------------------------------------------------------------------------ > > +; void _store_idtr( > > +; unsigned char *address // rcx > > +; ) > > +;------------------------------------------------------------------------------ > > +_store_idtr PROC > > + mov ecx, dword ptr [esp+4] > > + sidt dword ptr [ecx] > > + ret > > +_store_idtr ENDP > > + > > + > > +;------------------------------------------------------------------------------ > > +; void _load_idtr( > > +; unsigned char *address // rcx > > +; ) > > +;------------------------------------------------------------------------------ > > +_load_idtr PROC > > + mov ecx, dword ptr [esp+4] > > + lidt fword ptr [ecx] > > + ret > > +_load_idtr ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void _store_gdtr( > > +; unsigned char *address // rcx > > +; ) > > +;------------------------------------------------------------------------------ > > +_store_gdtr PROC > > + mov ecx, dword ptr [esp+4] > > + sgdt dword ptr [ecx] > > + ret > > +_store_gdtr ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void _store_ldtr( > > +; unsigned char *address // rcx > > +; ) > > +;------------------------------------------------------------------------------ > > +_store_ldtr PROC > > + mov ecx, dword ptr [esp+4] > > + sldt word ptr [ecx] > > + ret > > +_store_ldtr ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void __stdcall _rdmsr( > > +; IN UINT32 msr, > > +; OUT UINT32* msrlo, > > +; OUT UINT32* msrhi > > +; ) > > +;------------------------------------------------------------------------------ > > +_rdmsr PROC > > + mov ecx, dword ptr [esp + 4] ; msr > > + > > + rdmsr > > + > > + mov ecx, dword ptr [esp + 8] > > + mov dword ptr [ecx], eax ; msrlo > > + mov ecx, dword ptr [esp + 12] > > + mov dword ptr [ecx], edx ; msrhi > > + > > + ret > > +_rdmsr ENDP > > + > > +;------------------------------------------------------------------------------ > > +; VOID __stdcall _wrmsr( > > +; IN UINT32 msr, > > +; IN UINT32 msrlo, > > +; IN UINT32 msrhi > > +; ) > > +;------------------------------------------------------------------------------ > > +_wrmsr PROC > > + mov ecx, dword ptr [esp + 4] ; msr > > + mov eax, dword ptr [esp + 8] ; msrlo > > + mov edx, dword ptr [esp + 12] ; msrhi > > + > > + wrmsr > > + > > + ret > > +_wrmsr ENDP > > + > > +;------------------------------------------------------------------------------ > > +;UINT32 _eflags() > > +;------------------------------------------------------------------------------ > > +eflags PROC > > + pushfd > > + pop eax > > + ret > > +eflags ENDP > > + > > +;------------------------------------------------------------------------------ > > +; VOID > > +; WritePortDword ( > > +; IN UINT32 out_value > > +; IN UINT16 port_num > > +; ) > > +;------------------------------------------------------------------------------ > > +WritePortDword PROC > > + mov eax, dword ptr [esp + 4] ; out_value > > + mov edx, dword ptr [esp + 8] ; port_num > > + out dx, eax > > + > > + ret > > +WritePortDword ENDP > > + > > +;------------------------------------------------------------------------------ > > +; VOID > > +; WritePortWord ( > > +; IN UINT16 out_value > > +; IN UINT16 port_num > > +; ) > > +;------------------------------------------------------------------------------ > > +WritePortWord PROC > > + mov eax, dword ptr [esp + 4] ; out_value > > + mov edx, dword ptr [esp + 8] ; port_num > > + out dx, ax > > + > > + ret > > +WritePortWord ENDP > > + > > +;------------------------------------------------------------------------------ > > +; VOID > > +; WritePortByte ( > > +; IN UINT8 out_value > > +; IN UINT16 port_num > > +; ) > > +;------------------------------------------------------------------------------ > > +WritePortByte PROC > > + mov eax, dword ptr [esp + 4] ; out_value > > + mov edx, dword ptr [esp + 8] ; port_num > > + out dx, al > > + > > + ret > > +WritePortByte ENDP > > + > > +;------------------------------------------------------------------------------ > > +; UINT32 > > +; ReadPortDword ( > > +; IN UINT16 port_num > > +; ) > > +;------------------------------------------------------------------------------ > > +ReadPortDword PROC > > + xor eax, eax > > + mov edx, dword ptr [esp + 4] ; port_num > > + in eax, dx > > + > > + ret > > +ReadPortDword ENDP > > + > > +;------------------------------------------------------------------------------ > > +; UINT16 > > +; ReadPortWord ( > > +; IN UINT16 port_num > > +; ) > > +;------------------------------------------------------------------------------ > > +ReadPortWord PROC > > + xor eax, eax > > + mov edx, dword ptr [esp + 4] ; port_num > > + in ax, dx > > + > > + ret > > +ReadPortWord ENDP > > + > > +;------------------------------------------------------------------------------ > > +; UINT8 > > +; ReadPortByte ( > > +; IN UINT16 port_num > > +; ) > > +;------------------------------------------------------------------------------ > > +ReadPortByte PROC > > + xor eax, eax > > + mov edx, dword ptr [esp + 4] ; port_num > > + in al, dx > > + > > + ret > > +ReadPortByte ENDP > > + > > +;------------------------------------------------------------------------------ > > +; VOID > > +; WriteHighCMOSByte ( > > +; IN UINT8 cmos_off > > +; IN UINT8 val > > +; ) > > +;------------------------------------------------------------------------------ > > +WriteHighCMOSByte PROC > > + mov eax, dword ptr [esp + 4] ; cmos_off > > + out 72h, al > > + mov eax, dword ptr [esp + 8] ; val > > + out 73h, al > > + > > + ret > > +WriteHighCMOSByte ENDP > > + > > +;------------------------------------------------------------------------------ > > +; VOID > > +; WriteLowCMOSByte ( > > +; IN UINT8 cmos_off > > +; IN UINT8 val > > +; ) > > +;------------------------------------------------------------------------------ > > +WriteLowCMOSByte PROC > > + mov eax, dword ptr [esp + 4] ; cmos_off > > + or al, 80h > > + out 70h, al > > + mov eax, dword ptr [esp + 8] ; val > > + out 71h, al > > + > > + ret > > +WriteLowCMOSByte ENDP > > + > > + > > +;------------------------------------------------------------------------------ > > +; VOID > > +; SendAPMSMI ( > > +; IN UINT32 apm_port_value > > +; IN UINT64 rax_value // NOT USED??? > > +; ) > > +;------------------------------------------------------------------------------ > > +SendAPMSMI PROC > > + mov eax, dword ptr [esp + 4] ; apm_port_value > > + mov dx, 0B2h > > + out dx, eax > > + > > + ret > > +SendAPMSMI ENDP > > + > > +;------------------------------------------------------------------------------ > > +; VOID > > +; WritePCIByte ( > > +; IN UINT32 pci_reg > > +; IN UINT16 cfg_data_port > > +; IN UINT8 byte_value > > +; ) > > +;------------------------------------------------------------------------------ > > +WritePCIByte PROC > > + mov eax, dword ptr [esp + 4] ; pci_reg > > + mov dx, 0CF8h > > + out dx, eax > > + > > + mov eax, dword ptr [esp + 12] ; word_value > > + mov edx, dword ptr [esp + 8] ; cfg_data_port > > + out dx, al > > + > > + ret > > +WritePCIByte ENDP > > + > > +;------------------------------------------------------------------------------ > > +; VOID > > +; WritePCIWord ( > > +; IN UINT32 pci_reg > > +; IN UINT16 cfg_data_port > > +; IN UINT16 word_value > > +; ) > > +;------------------------------------------------------------------------------ > > +WritePCIWord PROC > > + mov eax, dword ptr [esp + 4] ; pci_reg > > + mov dx, 0CF8h > > + out dx, eax > > + > > + mov eax, dword ptr [esp + 12] ; word_value > > + mov edx, dword ptr [esp + 8] ; cfg_data_port > > + out dx, ax > > + > > + ret > > +WritePCIWord ENDP > > + > > +;------------------------------------------------------------------------------ > > +; VOID > > +; WritePCIDword ( > > +; IN UINT32 pci_reg > > +; IN UINT16 cfg_data_port // rdx > > +; IN UINT32 dword_value // r8 > > +; ) > > +;------------------------------------------------------------------------------ > > +WritePCIDword PROC > > + > > + mov eax, dword ptr [esp + 4] ; pci_reg > > + mov dx, 0CF8h > > + out dx, eax > > + > > + mov eax, dword ptr [esp + 12] ; dword_value > > + mov edx, dword ptr [esp + 8] ; cfg_data_port > > + out dx, eax > > + > > + ret > > +WritePCIDword ENDP > > + > > + > > +;------------------------------------------------------------------------------ > > +; unsigned char > > +; ReadPCIByte ( > > +; unsigned int pci_reg // rcx > > +; unsigned short cfg_data_port // rdx > > +; ) > > +;------------------------------------------------------------------------------ > > +ReadPCIByte PROC > > + cli > > + mov eax, dword ptr [esp + 4] ; pci_reg > > + mov dx, 0CF8h > > + out dx, eax > > + > > + xor eax, eax > > + mov edx, dword ptr [esp + 8] ; cfg_data_port > > + in al, dx > > + sti > > + > > + ret > > +ReadPCIByte ENDP > > + > > +;------------------------------------------------------------------------------ > > +; unsigned short > > +; ReadPCIWord ( > > +; unsigned int pci_reg // rcx > > +; unsigned short cfg_data_port // rdx > > +; ) > > +;------------------------------------------------------------------------------ > > +ReadPCIWord PROC > > + cli > > + mov eax, dword ptr [esp + 4] ; pci_reg > > + mov dx, 0CF8h > > + out dx, eax > > + > > + xor eax, eax > > + mov edx, dword ptr [esp + 8] ; cfg_data_port > > + in ax, dx > > + sti > > + > > + ret > > +ReadPCIWord ENDP > > + > > +;------------------------------------------------------------------------------ > > +; unsigned int > > +; ReadPCIDword ( > > +; unsigned int pci_reg // rcx > > +; unsigned short cfg_data_port // rdx > > +; ) > > +;------------------------------------------------------------------------------ > > +ReadPCIDword PROC > > + cli > > + mov eax, dword ptr [esp + 4] ; pci_reg > > + mov dx, 0CF8h > > + out dx, eax > > + > > + xor eax, eax > > + mov edx, dword ptr [esp + 8] ; cfg_data_port > > + in eax, dx > > + sti > > + > > + ret > > +ReadPCIDword ENDP > > + > > +;------------------------------------------------------------------------------ > > +; void > > +; _swsmi ( > > +; unsigned int smi_code_data // rcx > > +; IN UINT32 rax_value // rdx > > +; IN UINT32 rbx_value // r8 > > +; IN UINT32 rcx_value // r9 > > +; IN UINT32 rdx_value // r10 > > +; IN UINT32 rsi_value // r11 > > +; IN UINT32 rdi_value // r12 > > +; ) > > +;------------------------------------------------------------------------------ > > +_swsmi PROC > > + xor eax, eax > > + ret > > +_swsmi ENDP > > + > > +END > > diff --git > > a/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Modules/edk2module.c > b/AppPkg/Applications/Python/Python- > > 3.6.8/PyMod-3.6.8/Modules/edk2module.c > > index 0501a2b..4dd4b7c 100644 > > --- > > a/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Modules/edk2module.c > > +++ > > b/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Modules/edk2module.c > > @@ -3,7 +3,7 @@ > > Derived from posixmodule.c in Python 2.7.2. > > > > Copyright (c) 2015, Daryl McDaniel. All rights reserved.<BR> > > - Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.<BR> > > + Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.<BR> > > This program and the accompanying materials are licensed and made > > available under > > the terms and conditions of the BSD License that accompanies this > > distribution. > > The full text of the license may be found at > > @@ -29,6 +29,45 @@ > > extern "C" { > > #endif > > > > +#if defined(UEFI_MSVC_32) || defined(UEFI_MSVC_64) > > +// > > +// CHIPSEC extension for edk2 module of Python 3.6.8 > > +// build support available for > > +// VS Tool chains x86 and x64 bit builds only. > > +// > > + PyTypeObject EfiGuidType; > > + > > + // -- Access to CPU MSRs > > + extern void _rdmsr( unsigned int msr_num, unsigned int* msr_lo, unsigned > > int* msr_hi ); > > + extern void _wrmsr( unsigned int msr_num, unsigned int msr_hi, unsigned > > int msr_lo ); > > + extern void _swsmi( unsigned int smi_code_data, unsigned int rax_value, > > unsigned int rbx_value, unsigned int > rcx_value, > > unsigned int rdx_value, unsigned int rsi_value, unsigned int rdi_value ); > > + extern unsigned int AsmCpuidEx( unsigned int RegisterInEax, unsigned > > int RegisterInEcx, unsigned int* > > RegisterOutEax, unsigned int* RegisterOutEbx, unsigned int* RegisterOutEcx, > > unsigned int* RegisterOutEdx); > > + // -- Access to PCI CFG space > > + extern void WritePCIByte ( unsigned int pci_reg, unsigned short > > cfg_data_port, unsigned char byte_value ); > > + extern void WritePCIWord ( unsigned int pci_reg, unsigned short > > cfg_data_port, unsigned short word_value ); > > + extern void WritePCIDword ( unsigned int pci_reg, unsigned short > > cfg_data_port, unsigned int dword_value ); > > + extern unsigned char ReadPCIByte ( unsigned int pci_reg, unsigned short > > cfg_data_port ); > > + extern unsigned short ReadPCIWord ( unsigned int pci_reg, unsigned short > > cfg_data_port ); > > + extern unsigned int ReadPCIDword( unsigned int pci_reg, unsigned short > > cfg_data_port ); > > + // -- Access to Port I/O > > + extern unsigned int ReadPortDword ( unsigned short port_num ); > > + extern unsigned short ReadPortWord ( unsigned short port_num ); > > + extern unsigned char ReadPortByte ( unsigned short port_num ); > > + extern void WritePortDword( unsigned int out_value, unsigned > > short port_num ); > > + extern void WritePortWord ( unsigned short out_value, unsigned > > short port_num ); > > + extern void WritePortByte ( unsigned char out_value, unsigned > > short port_num ); > > + // -- Access to CPU Descriptor tables > > + extern void _store_idtr( void* desc_address ); > > + extern void _load_idtr ( void* desc_address ); > > + extern void _store_gdtr( void* desc_address ); > > + extern void _store_ldtr( void* desc_address ); > > + > > + // -- Support routines > > + EFI_STATUS GuidToStr( IN EFI_GUID *guid, IN OUT UINT8 *str_buffer ); > > + > > +#endif > > + > > + > > PyDoc_STRVAR(edk2__doc__, > > "This module provides access to UEFI firmware functionality > > that is\n\ > > standardized by the C Standard and the POSIX standard (a > > thinly\n\ > > @@ -3784,7 +3823,7 @@ edk2_tmpnam(PyObject *self, PyObject *noargs) > > return PyUnicode_FromString(buffer); > > } > > #endif > > -#endif > > +#endif > > > > PyDoc_STRVAR(edk2_abort__doc__, > > "abort() -> does not return!\n\n\ > > @@ -3800,6 +3839,509 @@ edk2_abort(PyObject *self, PyObject *noargs) > > return NULL; > > } > > > > + > > +#if defined(UEFI_MSVC_32) || defined(UEFI_MSVC_64) > > +/*code merged from > > https://github.com/chipsec/chipsec/tree/main/chipsec_tools/edk2/PythonEFI */ > > +/* ######################### START ############################ */ > > + > > +unsigned int ReadPCICfg( > > + unsigned char bus, > > + unsigned char dev, > > + unsigned char fun, > > + unsigned char off, > > + unsigned char len // 1, 2, 4 bytes > > + ) > > +{ > > + unsigned int result = 0; > > + unsigned int pci_addr = (0x80000000 | (bus << 16) | (dev << 11) | (fun > > << 8) | (off & ~3)); > > + unsigned short cfg_data_port = (unsigned short)(0xCFC + ( off & 0x3 )); > > + if ( 1 == len ) result = (ReadPCIByte ( pci_addr, cfg_data_port ) & > > 0xFF); > > + else if( 2 == len ) result = (ReadPCIWord ( pci_addr, cfg_data_port ) & > > 0xFFFF); > > + else if( 4 == len ) result = ReadPCIDword( pci_addr, cfg_data_port ); > > + return result; > > +} > > + > > +void WritePCICfg( > > + unsigned char bus, > > + unsigned char dev, > > + unsigned char fun, > > + unsigned char off, > > + unsigned char len, // 1, 2, 4 bytes > > + unsigned int val > > + ) > > +{ > > + unsigned int pci_addr = (0x80000000 | (bus << 16) | (dev << 11) | (fun > > << 8) | (off & ~3)); > > + unsigned short cfg_data_port = (unsigned short)(0xCFC + ( off & 0x3 )); > > + if ( 1 == len ) WritePCIByte ( pci_addr, cfg_data_port, (unsigned > > char)(val&0xFF) ); > > + else if( 2 == len ) WritePCIWord ( pci_addr, cfg_data_port, (unsigned > > short)(val&0xFFFF) ); > > + else if( 4 == len ) WritePCIDword( pci_addr, cfg_data_port, val ); > > +} > > + > > +PyDoc_STRVAR(efi_rdmsr__doc__, > > +"rdmsr(ecx) -> (eax,edx)\n\ > > +Read the given MSR."); > > + > > +static PyObject * > > +posix_rdmsr(PyObject *self, PyObject *args) > > +{ > > + unsigned int vecx, veax, vedx; > > + if (!PyArg_ParseTuple(args, "I", &vecx)) > > + return NULL; > > + Py_BEGIN_ALLOW_THREADS > > + _rdmsr( vecx, &veax, &vedx ); > > + Py_END_ALLOW_THREADS > > + return Py_BuildValue("(II)", (unsigned long)veax, (unsigned long)vedx); > > +} > > + > > +PyDoc_STRVAR(efi_wrmsr__doc__, > > +"wrmsr(ecx, eax, edx) -> None\n\ > > +Write edx:eax to the given MSR."); > > + > > +static PyObject * > > +posix_wrmsr(PyObject *self, PyObject *args) > > +{ > > + unsigned int vecx, veax, vedx; > > + if (!PyArg_ParseTuple(args, "III", &vecx, &veax, &vedx)) > > + return NULL; > > + Py_BEGIN_ALLOW_THREADS > > + _wrmsr( vecx, vedx, veax ); > > + Py_END_ALLOW_THREADS > > + Py_INCREF(Py_None); > > + return Py_None; > > +} > > + > > +PyDoc_STRVAR(efi_swsmi__doc__, > > +"swsmi(smi_code_data, rax_value, rbx_value, rcx_value, rdx_value, > > rsi_value, rdi_value) -> None\n\ > > +Triggering Software SMI"); > > + > > +static PyObject * > > +posix_swsmi(PyObject *self, PyObject *args) > > +{ > > + unsigned int smi_code_data, rax_value, rbx_value, rcx_value, rdx_value, > > rsi_value, rdi_value; > > + if (!PyArg_Parse(args, "(IIIIIII)", &smi_code_data, &rax_value, > > &rbx_value, &rcx_value, &rdx_value, &rsi_value, > > &rdi_value)) > > + return NULL; > > + Py_BEGIN_ALLOW_THREADS > > + _swsmi( smi_code_data, rax_value, rbx_value, rcx_value, rdx_value, > > rsi_value, rdi_value ); > > + Py_END_ALLOW_THREADS > > + Py_INCREF(Py_None); > > + return Py_None; > > +} > > + > > +PyDoc_STRVAR(efi_cpuid__doc__, > > +"cpuid(eax, ecx) -> (eax:ebx:ecx:edx)\n\ > > +Read the CPUID.";); > > + > > +static PyObject * > > +posix_cpuid(PyObject *self, PyObject *args) > > +{ > > + UINT32 eax, ecx, rax_value, rbx_value, rcx_value, rdx_value; > > + if (!PyArg_ParseTuple(args, "II", &eax, &ecx)) > > + return NULL; > > + Py_BEGIN_ALLOW_THREADS > > + AsmCpuidEx( eax, ecx, &rax_value, &rbx_value, &rcx_value, &rdx_value); > > + Py_END_ALLOW_THREADS > > + return Py_BuildValue("(IIII))", (unsigned long)rax_value, (unsigned > > long)rbx_value, (unsigned long)rcx_value, > > (unsigned long)rdx_value); > > +} > > + > > +PyDoc_STRVAR(efi_allocphysmem__doc__, > > +"allocphysmem(length, max_pa) -> (va)\n\ > > +Use malloc to allocate space in memory.";); > > + > > +static PyObject * > > +posix_allocphysmem(PyObject *self, PyObject *args) > > +{ > > + unsigned int length, max_pa; > > + void *va; > > + if (!PyArg_ParseTuple(args, "II", &length, &max_pa)) > > + return NULL; > > + > > + Py_BEGIN_ALLOW_THREADS > > + va = malloc(length); > > + Py_END_ALLOW_THREADS > > + > > + // return Py_BuildValue("(K)", (unsigned long)va); > > + return Py_BuildValue("(I)", (unsigned long)va); > > +} > > + > > +PyDoc_STRVAR(efi_readio__doc__, > > +"readio(addr, size) -> (int)\n\ > > +Read the value (size == 1, 2, or 4 bytes) of the specified IO port."); > > + > > +static PyObject * > > +posix_readio(PyObject *self, PyObject *args) > > +{ > > + unsigned int addr, sz, result; > > + short addrs; > > + > > + if (!PyArg_ParseTuple(args, "II", &addr, &sz)) > > + return NULL; > > + > > + Py_BEGIN_ALLOW_THREADS > > + result = 0; > > + addrs = (short)(addr & 0xffff); > > + if ( 1 == sz ) result = (ReadPortByte( addrs ) & 0xFF); > > + else if( 2 == sz ) result = (ReadPortWord( addrs ) & 0xFFFF); > > + else if( 4 == sz ) result = ReadPortDword( addrs ); > > + Py_END_ALLOW_THREADS > > + return PyLong_FromUnsignedLong((unsigned long)result); > > +} > > + > > +PyDoc_STRVAR(efi_writeio__doc__, > > +"writeio(addr, size, value) -> None\n\ > > +Write the value (size == 1, 2, or 4 bytes) of the specified IO port."); > > + > > +static PyObject * > > +posix_writeio(PyObject *self, PyObject *args) > > +{ > > + unsigned int addr, sz, value; > > + short addrs; > > + > > + if (!PyArg_ParseTuple(args, "III", &addr, &sz, &value)) > > + return NULL; > > + > > + Py_BEGIN_ALLOW_THREADS > > + addrs = (short)(addr & 0xffff); > > + if ( 1 == sz ) WritePortByte ( (unsigned char)(value&0xFF), addrs ); > > + else if( 2 == sz ) WritePortWord ( (unsigned short)(value&0xFFFF), addrs > > ); > > + else if( 4 == sz ) WritePortDword( value, addrs ); > > + Py_END_ALLOW_THREADS > > + > > + Py_INCREF(Py_None); > > + return Py_None; > > +} > > + > > +PyDoc_STRVAR(efi_readpci__doc__, > > +"readpci(bus,dev,func,addr,size) -> (int)\n\ > > +Read the value (size == 1, 2, or 4 bytes) of the specified PCI b/d/f."); > > + > > +static PyObject * > > +posix_readpci(PyObject *self, PyObject *args) > > +{ > > + unsigned int bus, dev, func, addr, sz, result; > > + > > + if (!PyArg_ParseTuple(args, "IIIII", &bus, &dev, &func, &addr, &sz)) > > + return NULL; > > + > > + Py_BEGIN_ALLOW_THREADS > > + result = ReadPCICfg( bus, dev, func, addr, sz ); > > + Py_END_ALLOW_THREADS > > + > > + return PyLong_FromUnsignedLong((unsigned long)result); > > +} > > + > > +PyDoc_STRVAR(efi_writepci__doc__, > > +"writepci(bus,dev,func,addr,value,len) -> None\n\ > > +Write the value to the specified PCI b/d/f. Len is value size (either 1, > > 2, or 4 bytes)."); > > + > > +static PyObject * > > +posix_writepci(PyObject *self, PyObject *args) > > +{ > > + unsigned int bus, dev, func, addr, val, len; > > + > > + if (!PyArg_ParseTuple(args, "IIIIII", &bus, &dev, &func, &addr, &val, > > &len)) > > + return NULL; > > + > > + Py_BEGIN_ALLOW_THREADS > > + WritePCICfg( bus, dev, func, addr, len, val ); > > + Py_END_ALLOW_THREADS > > + > > + Py_INCREF(Py_None); > > + return Py_None; > > +} > > + > > +PyDoc_STRVAR(efi_readmem__doc__, > > +"readmem(addr_lo, addr_hi, len) -> ByteString\n\ > > +Read the given memory address."); > > + > > +static PyObject * > > +posix_readmem(PyObject *self, PyObject *args) > > +{ > > + PyObject *data; > > + UINT32 addr_lo, addr_hi; > > + char *buffer, *cbuffer, *addr; > > + int len, index; > > + > > + if (!PyArg_ParseTuple(args, "III", &addr_lo, &addr_hi, &len)) > > + return NULL; > > + > > +#ifdef MDE_CPU_X64 > > + addr = (unsigned char*)((UINT64)addr_lo | ((UINT64)addr_hi << 32)); > > +#else > > + addr = (unsigned char*)addr_lo; > > +#endif > > + > > + buffer = malloc(len); > > + if (buffer == NULL) > > + return NULL; > > + > > + cbuffer = buffer; > > + index = len; > > + > > + Py_BEGIN_ALLOW_THREADS > > + > > + while(index--){ > > + *cbuffer = *addr; > > + cbuffer++; > > + addr++; > > + } > > + > > + Py_END_ALLOW_THREADS > > + > > + data = Py_BuildValue("y#", buffer, len); > > + free(buffer); > > + > > + return data; > > +} > > + > > +PyDoc_STRVAR(efi_readmem_dword__doc__, > > +"readmem_dword(addr_lo, addr_hi) -> (int32)\n\ > > +Read the given memory address and return 32-bit value."); > > + > > +static PyObject * > > +posix_readmem_dword(PyObject *self, PyObject *args) > > +{ > > + unsigned int result, *addr; > > + UINT32 addr_lo, addr_hi; > > + > > + if (!PyArg_ParseTuple(args, "II", &addr_lo, &addr_hi)) > > + return NULL; > > + > > +#ifdef MDE_CPU_X64 > > + addr = (unsigned int*)((UINT64)addr_lo | ((UINT64)addr_hi << 32)); > > +#else > > + addr = (unsigned int*)addr_lo; > > +#endif > > + > > + Py_BEGIN_ALLOW_THREADS > > + result = *addr; > > + Py_END_ALLOW_THREADS > > + > > + return PyLong_FromUnsignedLong((unsigned long)result); > > +} > > + > > +PyDoc_STRVAR(efi_writemem__doc__, > > +"writemem(addr_lo, addr_hi, buf, len) -> None\n\ > > +Write the buf (PyString) to the given memory address."); > > + > > +static PyObject * > > +posix_writemem(PyObject *self, PyObject *args) > > +{ > > + char *buf, *addr; > > + int len; > > + UINT32 addr_lo, addr_hi; > > + > > + if (!PyArg_ParseTuple(args, "IIs#", &addr_lo, &addr_hi, &buf, &len)) > > + return NULL; > > + > > +#ifdef MDE_CPU_X64 > > + addr = (unsigned char*)((UINT64)addr_lo | ((UINT64)addr_hi << 32)); > > +#else > > + addr = (unsigned char*)addr_lo; > > +#endif > > + > > + Py_BEGIN_ALLOW_THREADS > > + while(len--){ > > + *addr = *buf; > > + buf++; > > + addr++; > > + } > > + Py_END_ALLOW_THREADS > > + > > + Py_INCREF(Py_None); > > + return Py_None; > > +} > > + > > +PyDoc_STRVAR(efi_writemem_dword__doc__, > > +"writemem_dword(addr_lo, addr_hi, val) -> None\n\ > > +Write the 32-bit value to the given memory address."); > > + > > +static PyObject * > > +posix_writemem_dword(PyObject *self, PyObject *args) > > +{ > > + unsigned int *addr, val; > > + UINT32 addr_lo, addr_hi; > > + > > + if (!PyArg_ParseTuple(args, "III", &addr_lo, &addr_hi, &val)) > > + return NULL; > > + > > +#ifdef MDE_CPU_X64 > > + addr = (unsigned int*)((UINT64)addr_lo | ((UINT64)addr_hi << 32)); > > +#else > > + addr = (unsigned int*)addr_lo; > > +#endif > > + > > + Py_BEGIN_ALLOW_THREADS > > + *addr = val; > > + Py_END_ALLOW_THREADS > > + > > + Py_INCREF(Py_None); > > + return Py_None; > > +} > > + > > +PyDoc_STRVAR(MiscRT_GetVariable__doc__, > > +"(Status, Attributes, Data, DataSize) = GetVariable(VariableName, GUID, > > DataSize)\n\n\ > > +Returns the value of a variable."); > > + > > +static > > +PyObject * > > +MiscRT_GetVariable(PyObject *self, PyObject *args) > > +{ > > + PyObject *data_out; > > + CHAR16 *VariableName; > > + EFI_GUID VendorGuid; > > + UINT32 GuidSize; > > + UINT32 Attributes; > > + UINT64 DataSize; > > + char *Data; > > + const CHAR16 *GuidIn; > > + EFI_STATUS Status; > > + > > + if(!PyArg_ParseTuple(args, "uu#K", &VariableName, &GuidIn, &GuidSize, > > &DataSize)) > > + { > > + return NULL; > > + } > > + > > + StrToGuid(GuidIn, &VendorGuid); > > + > > + Data = malloc(DataSize); > > + if (!Data) > > + return NULL; > > + > > + Py_BEGIN_ALLOW_THREADS > > + Status = gRT->GetVariable(VariableName, &VendorGuid, &Attributes, (UINTN > > *)&DataSize, (void*)Data); > > + Py_END_ALLOW_THREADS > > + > > + data_out = Py_BuildValue("(IIy#K)", (UINT32)Status, Attributes, Data, > > DataSize, DataSize); > > + free(Data); > > + > > + return data_out; > > +} > > + > > +PyDoc_STRVAR(MiscRT_GetNextVariableName__doc__, > > +"(Status, VariableNameSize, VariableName, VendorGuid) = > > GetNextVariableName(NameSize, VariableName, GUID)\n\n\ > > +Enumerates the current variable names."); > > + > > +static > > +PyObject * > > +MiscRT_GetNextVariableName(PyObject *self, PyObject *args) > > +{ > > + UINT64 NameSize; > > + CHAR16 *VariableName, *NameIn; > > + UINT32 GuidSize, VariableNameSize, i; > > + EFI_GUID VendorGuid; > > + EFI_STATUS Status; > > + const char *GuidIn; > > + char *VendorGuidPtr, *GuidOut[37]; > > + > > + if(!PyArg_ParseTuple(args, "Ky#s#", &NameSize, &NameIn, > > &VariableNameSize, &GuidIn, &GuidSize)) > > + { > > + return NULL; > > + } > > + > > + VendorGuidPtr = (char *)&VendorGuid; > > + for (i=0; i<sizeof(VendorGuid); i++) > > + VendorGuidPtr[i] = GuidIn[i]; > > + > > + for (i=0; i<NameSize && NameIn[i] != (CHAR16)0; i++) > > + VariableName[i] = NameIn[i]; > > + VariableName[i] = NameIn[i]; > > + > > + Py_BEGIN_ALLOW_THREADS > > + Status = gRT->GetNextVariableName((UINTN *)&NameSize, (CHAR16 > > *)VariableName, &VendorGuid); > > + Py_END_ALLOW_THREADS > > + > > + GuidToStr((EFI_GUID *)&VendorGuid, (UINT8 *)GuidOut); > > + > > + return Py_BuildValue("(IuKs)", (UINT32) Status, VariableName, NameSize, > > &GuidOut); > > +} > > + > > +PyDoc_STRVAR(MiscRT_SetVariable__doc__, > > +"(Status, DataSize, GUID) = SetVariable(VariableName, GUID, Attributes, > > Data, DataSize)\n\n\ > > +Sets the value of a variable."); > > + > > +static > > +PyObject * > > +MiscRT_SetVariable(PyObject *self, PyObject *args) > > +{ > > + CHAR16 *VariableName; > > + UINT64 DataSize; > > + char *Data, *guidptr, *VendorGuidPtr; > > + char *GuidOut[37]; > > + EFI_STATUS Status; > > + EFI_GUID VendorGuid; > > + UINT32 Attributes; > > + UINT32 GuidSize, strDataSize; > > + const CHAR16 *GuidIn; > > + > > + if(!PyArg_ParseTuple(args, "uu#Is#I", &VariableName, &GuidIn, &GuidSize, > > &Attributes, &Data, &strDataSize, > &DataSize)) > > + { > > + return NULL; > > + } > > + > > + StrToGuid(GuidIn, &VendorGuid); > > + > > + Py_BEGIN_ALLOW_THREADS > > + Status = gRT->SetVariable(VariableName, &VendorGuid, Attributes, > > (UINTN)DataSize, (void*)Data); > > + Py_END_ALLOW_THREADS > > + > > + GuidToStr((EFI_GUID *)&VendorGuid, (UINT8 *)GuidOut); > > + > > +// return Py_BuildValue("(IKu#)", (UINT32) Status, DataSize, > > &VendorGuid, sizeof(VendorGuid)); > > + return Py_BuildValue("(IKs)", (UINT32) Status, DataSize, &GuidOut); > > +} > > + > > + > > + > > +EFI_STATUS > > +GuidToStr ( > > + IN EFI_GUID *guid, > > + IN OUT UINT8 *str_buffer > > + ) > > +/*++ > > + > > +Routine Description: > > + This function prints a GUID to a buffer > > + > > +Arguments: > > + guid - Pointer to a GUID > > + str_buffer - Pointer to a str buffer > > + > > +Returns: > > + EFI_SUCCESS GUID was printed > > + EFI_INVALID_PARAMETER GUID was NULL > > + > > +--*/ > > +{ > > + if (guid == NULL) { > > + return EFI_INVALID_PARAMETER; > > + } > > + > > + sprintf ( > > + (CHAR8 *)str_buffer, > > + "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", > > + (unsigned) guid->Data1, > > + guid->Data2, > > + guid->Data3, > > + guid->Data4[0], > > + guid->Data4[1], > > + guid->Data4[2], > > + guid->Data4[3], > > + guid->Data4[4], > > + guid->Data4[5], > > + guid->Data4[6], > > + guid->Data4[7] > > + ); > > + > > + return EFI_SUCCESS; > > +} > > + > > + > > + > > +/*code merged from > > https://github.com/chipsec/chipsec/tree/main/chipsec_tools/edk2/PythonEFI */ > > +/* ######################### END ############################ */ > > +#endif > > + > > + > > static PyMethodDef edk2_methods[] = { > > {"access", edk2_access, METH_VARARGS, edk2_access__doc__}, > > #ifdef HAVE_TTYNAME > > @@ -4044,7 +4586,7 @@ static PyMethodDef edk2_methods[] = { > > #ifdef HAVE_TMPNAM > > {"tmpnam", edk2_tmpnam, METH_NOARGS, edk2_tmpnam__doc__}, > > #endif > > -#endif > > +#endif > > #ifdef HAVE_CONFSTR > > {"confstr", edk2_confstr, METH_VARARGS, edk2_confstr__doc__}, > > #endif > > @@ -4058,6 +4600,26 @@ static PyMethodDef edk2_methods[] = { > > {"pathconf", edk2_pathconf, METH_VARARGS, edk2_pathconf__doc__}, > > #endif > > {"abort", edk2_abort, METH_NOARGS, edk2_abort__doc__}, > > + > > +#if defined(UEFI_MSVC_32) || defined(UEFI_MSVC_64) > > + {"rdmsr", posix_rdmsr, METH_VARARGS, > > efi_rdmsr__doc__}, > > + {"wrmsr", posix_wrmsr, METH_VARARGS, > > efi_wrmsr__doc__}, > > + {"readpci", posix_readpci, METH_VARARGS, > > efi_readpci__doc__}, > > + {"writepci", posix_writepci, METH_VARARGS, > > efi_writepci__doc__}, > > + {"readmem", posix_readmem, METH_VARARGS, > > efi_readmem__doc__}, > > + {"readmem_dword", posix_readmem_dword, METH_VARARGS, > > efi_readmem_dword__doc__}, > > + {"writemem", posix_writemem, METH_VARARGS, > > efi_writemem__doc__}, > > + {"writemem_dword", posix_writemem_dword, METH_VARARGS, > > efi_writemem_dword__doc__}, > > + {"writeio", posix_writeio, METH_VARARGS, > > efi_writeio__doc__}, > > + {"readio", posix_readio, METH_VARARGS, > > efi_readio__doc__}, > > + {"swsmi", posix_swsmi, METH_VARARGS, > > efi_swsmi__doc__}, > > + {"allocphysmem", posix_allocphysmem, METH_VARARGS, > > efi_allocphysmem__doc__}, > > + {"cpuid", posix_cpuid, METH_VARARGS, > > efi_cpuid__doc__}, > > + {"GetVariable", MiscRT_GetVariable, METH_VARARGS, > > MiscRT_GetVariable__doc__}, > > + {"GetNextVariableName", MiscRT_GetNextVariableName, METH_VARARGS, > > MiscRT_GetNextVariableName__doc__}, > > + {"SetVariable", MiscRT_SetVariable, METH_VARARGS, > > MiscRT_SetVariable__doc__}, > > +#endif > > + > > {NULL, NULL} /* Sentinel */ > > }; > > > > diff --git a/AppPkg/Applications/Python/Python-3.6.8/Python368.inf > > b/AppPkg/Applications/Python/Python- > 3.6.8/Python368.inf > > index 121d4a9..d3ccb6a 100644 > > --- a/AppPkg/Applications/Python/Python-3.6.8/Python368.inf > > +++ b/AppPkg/Applications/Python/Python-3.6.8/Python368.inf > > @@ -14,7 +14,7 @@ > > > > [Defines] > > INF_VERSION = 0x00010016 > > - BASE_NAME = Python > > + BASE_NAME = Python > > FILE_GUID = 9DA30E98-094C-4FF0-94CB-81C10E69F750 > > MODULE_TYPE = UEFI_APPLICATION > > VERSION_STRING = 0.1 > > @@ -201,8 +201,8 @@ > > Modules/_blake2/blake2b_impl.c # > > Modules/_blake2/blake2s_impl.c # > > Modules/_sha3/sha3module.c # > > - Modules/signalmodule.c # > > - #Modules/socketmodule.c # > > + Modules/signalmodule.c # > > + #Modules/socketmodule.c # > > Modules/symtablemodule.c # > > Modules/unicodedata.c # > > Modules/xxsubtype.c # > > @@ -215,7 +215,7 @@ > > Modules/_io/iobase.c # > > Modules/_io/stringio.c # > > Modules/_io/textio.c # > > - Modules/atexitmodule.c # > > + Modules/atexitmodule.c # > > > > #Modules/cjkcodecs > > Modules/cjkcodecs/multibytecodec.c # > > @@ -251,24 +251,26 @@ Modules/zlib > > Modules/zlib/zutil.c # > > > > #Modules/ctypes > > - PyMod-$(PYTHON_VERSION)/Modules/_ctypes/_ctypes.c | MSFT # > > - Modules/_ctypes/stgdict.c | MSFT # > > - Modules/_ctypes/libffi_msvc/prep_cif.c | MSFT# > > - PyMod-$(PYTHON_VERSION)/Modules/_ctypes/malloc_closure.c | MSFT # > > - PyMod-$(PYTHON_VERSION)/Modules/_ctypes/libffi_msvc/ffi.c | MSFT # > > - Modules/_ctypes/cfield.c | MSFT # > > - PyMod-$(PYTHON_VERSION)/Modules/_ctypes/callproc.c | MSFT # > > - Modules/_ctypes/callbacks.c | MSFT # > > + PyMod-$(PYTHON_VERSION)/Modules/_ctypes/_ctypes.c | MSFT # > > + Modules/_ctypes/stgdict.c | MSFT # > > + Modules/_ctypes/libffi_msvc/prep_cif.c | MSFT# > > + PyMod-$(PYTHON_VERSION)/Modules/_ctypes/malloc_closure.c | MSFT # > > + PyMod-$(PYTHON_VERSION)/Modules/_ctypes/libffi_msvc/ffi.c | MSFT # > > + Modules/_ctypes/cfield.c | MSFT # > > + PyMod-$(PYTHON_VERSION)/Modules/_ctypes/callproc.c | MSFT # > > + Modules/_ctypes/callbacks.c | MSFT # > > > > [Sources.IA32] > > - Modules/_ctypes/libffi_msvc/win32.c | MSFT # > > + Modules/_ctypes/libffi_msvc/win32.c | MSFT # > > + PyMod-$(PYTHON_VERSION)/Modules/cpu_ia32.asm | MSFT # > > > > [Sources.X64] > > - Modules/_ctypes/libffi_msvc/win64.asm | MSFT # > > + Modules/_ctypes/libffi_msvc/win64.asm | MSFT # > > + PyMod-$(PYTHON_VERSION)/Modules/cpu.asm | MSFT # > > > > [BuildOptions] > > MSFT:*_*_*_CC_FLAGS = /GL- /Oi- /wd4018 /wd4054 /wd4055 /wd4101 /wd4131 > > /wd4152 /wd4204 /wd4210 /wd4244 /wd4267 > /wd4305 > > /wd4310 /wd4389 /wd4701 /wd4702 /wd4706 /wd4456 /wd4312 /wd4457 /wd4459 > > /wd4474 /wd4476 > > /I$(WORKSPACE)\AppPkg\Applications\Python\Python-3.6.8\Include > > /DHAVE_MEMMOVE /DUSE_PYEXPAT_CAPI /DXML_STATIC -D UEFI > /WX- > > /DXML_POOR_ENTROPY /DUEFI_C_SOURCE > > - GCC:*_*_*_CC_FLAGS = -Wno-unused-function -Wno-format -Wno-error > > -fno-strict-aliasing - > > I$(WORKSPACE)/AppPkg/Applications/Python/Python-3.6.8/Include > > -DHAVE_MEMMOVE -DUSE_PYEXPAT_CAPI -DXML_STATIC - > > DXML_POOR_ENTROPY > > + GCC:*_*_*_CC_FLAGS = -Wno-unused-function -Wno-format -Wno-error > > -fno-strict-aliasing - > > I$(WORKSPACE)/AppPkg/Applications/Python/Python-3.6.8/Include > > -DHAVE_MEMMOVE -DUSE_PYEXPAT_CAPI -DXML_STATIC - > > DXML_POOR_ENTROPY > > > > [BuildOptions.IA32] > > MSFT:*_*_*_CC_FLAGS = /DUEFI_MSVC_32 > > -- > > 2.33.0.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#96701): https://edk2.groups.io/g/devel/message/96701 Mute This Topic: https://groups.io/mt/95172081/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-