From nobody Fri Apr 19 18:18:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+96517+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96517+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1669039262; cv=none; d=zohomail.com; s=zohoarc; b=J7QxKkleUzoHDDr42mIDL64hh0Pka/n9IzqYbHfITlbyM1/G6bBJXf2nF5sxue1GInNww3glfdaj+6dVEXK/wVbt6E5zj0jQ81EqjU0XUJ1fc8IxOrhZYWk/Xyil2SgfptSLldnT/U+UfVUs9rLpLsZ65l3nYXUWK9jHyCC9W+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669039262; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=cpZ4XSsdqhlnxv1NoQTx9/FasRk4rh6tzDjck89TwB4=; b=kw3Z0zy6YrN2H6m/eKJatwACIRHegRolzPf1ROA6r0t6Z5Q2ndFn6fbcSnL7Y+kXRbl+CRad348FglS25YPJwTnzBpoG1iv3zcc7KzzMUvEjeZhYgRGopwpG5xkSx5khx8P1TUGZvlD52alBvaPuRoc93wMcwd1fF0ggWVncqIU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96517+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1669039262651647.5893939784445; Mon, 21 Nov 2022 06:01:02 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3sZDYY1788612xrzM2KjuDYx; Mon, 21 Nov 2022 06:01:02 -0800 X-Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web10.38870.1669039261165859356 for ; Mon, 21 Nov 2022 06:01:01 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10538"; a="312262355" X-IronPort-AV: E=Sophos;i="5.96,181,1665471600"; d="scan'208";a="312262355" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2022 06:00:59 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10538"; a="783457225" X-IronPort-AV: E=Sophos;i="5.96,181,1665471600"; d="scan'208";a="783457225" X-Received: from sanirban-mobl1.gar.corp.intel.com (HELO njayapra-MOBL1.gar.corp.intel.com) ([10.213.69.19]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2022 06:00:55 -0800 From: "Jayaprakash, N" To: devel@edk2.groups.io Cc: Rebecca Cran , Michael D Kinney , Jayaprakash N Subject: [edk2-devel] [edk2-libc Patch 1/1] edk2-libc: migration of edk2module from chipsec repo Date: Mon, 21 Nov 2022 19:30:26 +0530 Message-Id: <20221121140026.1931-2-n.jayaprakash@intel.com> In-Reply-To: <20221121140026.1931-1-n.jayaprakash@intel.com> References: <20221121140026.1931-1-n.jayaprakash@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,n.jayaprakash@intel.com X-Gm-Message-State: nXjnRWvRniY5P0rP35MaMtTbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1669039262; bh=rzi+OAhVqJxzVE2l5rfPn/edQzX78sB7NVOudMAMTf8=; h=Cc:Date:From:Reply-To:Subject:To; b=PnUBJxBOrVFs22peD1LmSpKHE8fr5F5muuYOFANvWs85CJFg6nckzCzsRbBsUcqXYuX twdwM+ZRsfoCu9ujNgi2+LnUtTBL6sC2qA6vONgsTWNxphNw/OY4ol0sYXoYL5D498h1D kK/WoCe+OtgcTSU1DL7uz60eAk07P0IF0cA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1669039270289100001 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4161 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 Cc: Michael D Kinney Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jayaprakash N Reviewed-by: Michael D Kinney --- .../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/Mod= ules/cpu.asm create mode 100644 AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Mod= ules/cpu_ia32.asm diff --git a/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Modules/cp= u.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 =20 + 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 =20 + 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 =20 + 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 =20 + 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 =20 + 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 =20 + 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 +=09 + xor rax, rax=09 + 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=09 + 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=09 + 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 i= s passed in RCX) + ; RDX will get partially overwritten (DX) by the value of APMC port = (=3D 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 retur= n 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/cp= u_ia32.asm b/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Modules/cp= u_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=20 +; ) +;-------------------------------------------------------------------------= ----- +_rdmsr PROC + mov ecx, dword ptr [esp + 4] ; msr + + rdmsr + + mov ecx, dword ptr [esp + 8]=20 + mov dword ptr [ecx], eax ; msrlo + mov ecx, dword ptr [esp + 12]=20 + mov dword ptr [ecx], edx ; msrhi + + ret +_rdmsr ENDP + +;-------------------------------------------------------------------------= ----- +; VOID __stdcall _wrmsr( +; IN UINT32 msr, +; IN UINT32 msrlo, +; IN UINT32 msrhi=20 +; ) +;-------------------------------------------------------------------------= ----- +_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 =20 + 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 =20 + 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=09 + 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=09 + 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/ed= k2module.c b/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Modules/ed= k2module.c index 0501a2b..4dd4b7c 100644 --- a/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Modules/edk2modul= e.c +++ b/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Modules/edk2modul= e.c @@ -3,7 +3,7 @@ Derived from posixmodule.c in Python 2.7.2. =20 Copyright (c) 2015, Daryl McDaniel. All rights reserved.
- Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.
+ Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made avai= lable under the terms and conditions of the BSD License that accompanies this dist= ribution. The full text of the license may be found at @@ -29,6 +29,45 @@ extern "C" { #endif =20 +#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, uns= igned int rsi_value, unsigned int rdi_value ); + extern unsigned int AsmCpuidEx( unsigned int RegisterInEax, unsigned i= nt RegisterInEcx, unsigned int* RegisterOutEax, unsigned int* RegisterOutE= bx, 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 t= hat is\n\ standardized by the C Standard and the POSIX standard (a thin= ly\n\ @@ -3784,7 +3823,7 @@ edk2_tmpnam(PyObject *self, PyObject *noargs) return PyUnicode_FromString(buffer); } #endif -#endif=20 +#endif =20 PyDoc_STRVAR(edk2_abort__doc__, "abort() -> does not return!\n\n\ @@ -3800,6 +3839,509 @@ edk2_abort(PyObject *self, PyObject *noargs) return NULL; } =20 + +#if defined(UEFI_MSVC_32) || defined(UEFI_MSVC_64) +/*code merged from https://github.com/chipsec/chipsec/tree/main/chipsec_to= ols/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 =3D 0; + unsigned int pci_addr =3D (0x80000000 | (bus << 16) | (dev << 11) | (fun= << 8) | (off & ~3)); + unsigned short cfg_data_port =3D (unsigned short)(0xCFC + ( off & 0x3 )); + if ( 1 =3D=3D len ) result =3D (ReadPCIByte ( pci_addr, cfg_data_por= t ) & 0xFF); + else if( 2 =3D=3D len ) result =3D (ReadPCIWord ( pci_addr, cfg_data_por= t ) & 0xFFFF); + else if( 4 =3D=3D len ) result =3D ReadPCIDword( pci_addr, cfg_data_por= t ); + 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 =3D (0x80000000 | (bus << 16) | (dev << 11) | (fun= << 8) | (off & ~3)); + unsigned short cfg_data_port =3D (unsigned short)(0xCFC + ( off & 0x3 )); + if ( 1 =3D=3D len ) WritePCIByte ( pci_addr, cfg_data_port, (unsigne= d char)(val&0xFF) ); + else if( 2 =3D=3D len ) WritePCIWord ( pci_addr, cfg_data_port, (unsigne= d short)(val&0xFFFF) ); + else if( 4 =3D=3D 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_valu= e, 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_val= ue, &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_v= alue, 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 =3D 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 =3D=3D 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 =3D 0; + addrs =3D (short)(addr & 0xffff); + if ( 1 =3D=3D sz ) result =3D (ReadPortByte( addrs ) & 0xFF); + else if( 2 =3D=3D sz ) result =3D (ReadPortWord( addrs ) & 0xFFFF); + else if( 4 =3D=3D sz ) result =3D 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 =3D=3D 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 =3D (short)(addr & 0xffff); + if ( 1 =3D=3D sz ) WritePortByte ( (unsigned char)(value&0xFF), addr= s ); + else if( 2 =3D=3D sz ) WritePortWord ( (unsigned short)(value&0xFFFF), a= ddrs ); + else if( 4 =3D=3D 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 =3D=3D 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 =3D 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, &l= en)) + 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 =3D (unsigned char*)((UINT64)addr_lo | ((UINT64)addr_hi << 32)); +#else + addr =3D (unsigned char*)addr_lo; +#endif + + buffer =3D malloc(len); + if (buffer =3D=3D NULL) + return NULL; + + cbuffer =3D buffer; + index =3D len; + + Py_BEGIN_ALLOW_THREADS + + while(index--){ + *cbuffer =3D *addr; + cbuffer++; + addr++; + } + + Py_END_ALLOW_THREADS + + data =3D 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 =3D (unsigned int*)((UINT64)addr_lo | ((UINT64)addr_hi << 32)); +#else + addr =3D (unsigned int*)addr_lo; +#endif + + Py_BEGIN_ALLOW_THREADS + result =3D *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 =3D (unsigned char*)((UINT64)addr_lo | ((UINT64)addr_hi << 32)); +#else + addr =3D (unsigned char*)addr_lo; +#endif + + Py_BEGIN_ALLOW_THREADS + while(len--){ + *addr =3D *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 =3D (unsigned int*)((UINT64)addr_lo | ((UINT64)addr_hi << 32)); +#else + addr =3D (unsigned int*)addr_lo; +#endif + + Py_BEGIN_ALLOW_THREADS + *addr =3D val; + Py_END_ALLOW_THREADS + + Py_INCREF(Py_None); + return Py_None; +} + +PyDoc_STRVAR(MiscRT_GetVariable__doc__, +"(Status, Attributes, Data, DataSize) =3D 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, &D= ataSize)) + { + return NULL; + } + + StrToGuid(GuidIn, &VendorGuid); + + Data =3D malloc(DataSize); + if (!Data) + return NULL; + + Py_BEGIN_ALLOW_THREADS + Status =3D gRT->GetVariable(VariableName, &VendorGuid, &Attributes, (UIN= TN *)&DataSize, (void*)Data); + Py_END_ALLOW_THREADS + + data_out =3D Py_BuildValue("(IIy#K)", (UINT32)Status, Attributes, Data, = DataSize, DataSize); + free(Data); + + return data_out; +} + +PyDoc_STRVAR(MiscRT_GetNextVariableName__doc__, +"(Status, VariableNameSize, VariableName, VendorGuid) =3D GetNextVariableN= ame(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, &VariableNameSiz= e, &GuidIn, &GuidSize)) + { + return NULL; + } + + VendorGuidPtr =3D (char *)&VendorGuid; + for (i=3D0; iGetNextVariableName((UINTN *)&NameSize, (CHAR16 *)Variab= leName, &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) =3D 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 =3D gRT->SetVariable(VariableName, &VendorGuid, Attributes, (UINT= N)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 =3D=3D 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_to= ols/edk2/PythonEFI */ +/* ######################### END ############################ */ +#endif + + static PyMethodDef edk2_methods[] =3D { {"access", edk2_access, METH_VARARGS, edk2_access__doc__}, #ifdef HAVE_TTYNAME @@ -4044,7 +4586,7 @@ static PyMethodDef edk2_methods[] =3D { #ifdef HAVE_TMPNAM {"tmpnam", edk2_tmpnam, METH_NOARGS, edk2_tmpnam__doc__}, #endif -#endif=20 +#endif #ifdef HAVE_CONFSTR {"confstr", edk2_confstr, METH_VARARGS, edk2_confstr__doc__}, #endif @@ -4058,6 +4600,26 @@ static PyMethodDef edk2_methods[] =3D { {"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, Mis= cRT_GetVariable__doc__}, + {"GetNextVariableName", MiscRT_GetNextVariableName, METH_VARARGS, Mis= cRT_GetNextVariableName__doc__}, + {"SetVariable", MiscRT_SetVariable, METH_VARARGS, Mis= cRT_SetVariable__doc__}, +#endif + {NULL, NULL} /* Sentinel */ }; =20 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 @@ =20 [Defines] INF_VERSION =3D 0x00010016 - BASE_NAME =3D Python + BASE_NAME =3D Python FILE_GUID =3D 9DA30E98-094C-4FF0-94CB-81C10E69F750 MODULE_TYPE =3D UEFI_APPLICATION VERSION_STRING =3D 0.1 @@ -201,8 +201,8 @@ Modules/_blake2/blake2b_impl.c # Modules/_blake2/blake2s_impl.c # Modules/_sha3/sha3module.c # - Modules/signalmodule.c #=20 - #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 # =20 #Modules/cjkcodecs Modules/cjkcodecs/multibytecodec.c # @@ -251,24 +251,26 @@ Modules/zlib Modules/zlib/zutil.c # =20 #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 # =20 [Sources.IA32] - Modules/_ctypes/libffi_msvc/win32.c | MSFT # + Modules/_ctypes/libffi_msvc/win32.c | MSFT # + PyMod-$(PYTHON_VERSION)/Modules/cpu_ia32.asm | MSFT # =20 [Sources.X64] - Modules/_ctypes/libffi_msvc/win64.asm | MSFT # + Modules/_ctypes/libffi_msvc/win64.asm | MSFT # + PyMod-$(PYTHON_VERSION)/Modules/cpu.asm | MSFT # =20 [BuildOptions] MSFT:*_*_*_CC_FLAGS =3D /GL- /Oi- /wd4018 /wd4054 /wd4055 /wd4101 /wd413= 1 /wd4152 /wd4204 /wd4210 /wd4244 /wd4267 /wd4305 /wd4310 /wd4389 /wd4701 /= wd4702 /wd4706 /wd4456 /wd4312 /wd4457 /wd4459 /wd4474 /wd4476 /I$(WORKSPAC= E)\AppPkg\Applications\Python\Python-3.6.8\Include /DHAVE_MEMMOVE /DUSE_PYE= XPAT_CAPI /DXML_STATIC -D UEFI /WX- /DXML_POOR_ENTROPY /DUEFI_C_SOURCE - GCC:*_*_*_CC_FLAGS =3D -Wno-unused-function -Wno-format -Wno-error -fno-= strict-aliasing -I$(WORKSPACE)/AppPkg/Applications/Python/Python-3.6.8/Incl= ude -DHAVE_MEMMOVE -DUSE_PYEXPAT_CAPI -DXML_STATIC -DXML_POOR_ENTROPY + GCC:*_*_*_CC_FLAGS =3D -Wno-unused-function -Wno-format -Wno-error -fno-= strict-aliasing -I$(WORKSPACE)/AppPkg/Applications/Python/Python-3.6.8/Incl= ude -DHAVE_MEMMOVE -DUSE_PYEXPAT_CAPI -DXML_STATIC -DXML_POOR_ENTROPY =20 [BuildOptions.IA32] MSFT:*_*_*_CC_FLAGS =3D /DUEFI_MSVC_32 --=20 2.33.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#96517): https://edk2.groups.io/g/devel/message/96517 Mute This Topic: https://groups.io/mt/95172081/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-