From nobody Wed Dec 25 13:35:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1507751148937999.6674655298651; Wed, 11 Oct 2017 12:45:48 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4E01221DF9690; Wed, 11 Oct 2017 12:42:18 -0700 (PDT) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0076.outbound.protection.outlook.com [104.47.38.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 445A62095E51F for ; Wed, 11 Oct 2017 12:42:16 -0700 (PDT) Received: from leduran-Precision-WorkStation-T5400.amd.com (165.204.77.1) by DM5PR12MB1243.namprd12.prod.outlook.com (10.168.237.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Wed, 11 Oct 2017 19:45:42 +0000 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=helo; client-ip=104.47.38.76; helo=nam02-bl2-obe.outbound.protection.outlook.com; envelope-from=leo.duran@amd.com; receiver=edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=2vaAcTaRbJXNXQiuChxFduL9/00M1tzgHVSWsC6GLxA=; b=0TCKoZ7ux/T0HcwkPBEC/+IoVAJaTTMQK0/+EYsc0JXhcU8kWMEu8iL9iozMDwAudYbQMmf9KfxJGTgX6Fd7dIDMa+Pg28GjXWB6UxJx/kQCMmRhvL29v/CuKksKndTg+XLvw/rZnBjN1G2EZBEwNDgOZUPgqKDGrL9kNCT35pk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=leo.duran@amd.com; From: Leo Duran To: edk2-devel@lists.01.org Date: Wed, 11 Oct 2017 14:45:30 -0500 Message-Id: <1507751131-32404-2-git-send-email-leo.duran@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507751131-32404-1-git-send-email-leo.duran@amd.com> References: <1507751131-32404-1-git-send-email-leo.duran@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CO2PR05CA0063.namprd05.prod.outlook.com (10.166.88.159) To DM5PR12MB1243.namprd12.prod.outlook.com (10.168.237.22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d18b1a7e-54f4-48d3-5d80-08d510e0a8de X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(48565401081)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:DM5PR12MB1243; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1243; 3:gySAfSVynwY7bJwivQ9ZNG9/ELH+MZ2JhmX0v0MRogEnrjuI+X+JVUyA1VXhjhcW2s+as+fCqMUohRxA2ir6w3TwMaTX7kQTvxMgqZtkACB9z6I9ajlF+wdeHTjZ7CCX0Dgw+u+Az4DbP8/yPaF6KmsaxFb2UitMK/vPKuJsLvvLV68PNOHib7xWr2fZaEVk+A+9fnjudfwTf0cL5p0B8H6dXxvEuCz8Zr4mdRp6wwwxCQDWK9aBEjWbVRVRlmbq; 25:sjib999+W5EUGzVlO4+Y9PhA8Sc+spkz0GxrH96xJaTIpolWz844NyETQ+aaGwsnY9vR61dgiYRsRbnGcYShIQ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G+; 4:InxB7LfmD4lElqT7M27FZuMrIs4oA7Dirz5g6vWnSn2Y4wf9IzN5YhYy5wM9uTnp2ayx5IqiC/e+wiyn8TsCBZQr/Wue5Zv/o/6ugOw/SBwYrLkH2ZrpUPjerwGZQMAz+h7Jp6Ko55V5P5iw2+V9k2eu+WFPFK6DIrTQ87ruBquMw/wpkFglNM7DXDw+hE4o3wOF6N6L9gVVnwHA/0PUcd36t45mMtUfQpHcL082S8F4ftwdPVu7Bh6kRddJPZkWmwczak8SJ4/7rIjo37m5HZ+IYumZlGbR30tusVrBA9VuZxMu1gikzYg+mJ+N8jscu0KxUVLk8Cd/7Jn0/7J7I+b1RkVMAldBkiq+yCQciag= X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(788757137089)(228905959029699); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(6055026)(6041248)(20161123564025)(20161123555025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM5PR12MB1243; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM5PR12MB1243; X-Forefront-PRVS: 0457F11EAF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(376002)(346002)(199003)(189002)(36756003)(68736007)(189998001)(16526018)(53936002)(16586007)(50466002)(966005)(2906002)(81156014)(3846002)(48376002)(316002)(6306002)(305945005)(81166006)(8676002)(53946003)(86362001)(6116002)(97736004)(478600001)(8936002)(7736002)(2351001)(5003940100001)(2361001)(53376002)(53416004)(6666003)(50986999)(6486002)(25786009)(76176999)(106356001)(16799955002)(4326008)(5660300001)(105586002)(575784001)(66066001)(50226002)(15188155005)(54906003)(47776003)(33646002)(101416001)(6916009)(2950100002)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1243; H:leduran-Precision-WorkStation-T5400.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR12MB1243; 23:6UIy2K23wBm6kBpA11aNCZ/YMgUvvklwPbYf0jdIX?= =?us-ascii?Q?2NO9KNVPzKVDXeyGDkqVhFue1hYOlswngD3GVPcKRMGL2xWCD9gsSOenOuEq?= =?us-ascii?Q?mO50Bqx4ij8I2y3MPJ1bZ+9EShCgL7Q2AoVT/hNY+Kb0ob1vVO8uyeIgcpbA?= =?us-ascii?Q?BD/m6eo17atwfYKONdZbKziGEju5CE70Hqy0A9oJiKw0AqkM1tb2f6O6Ygez?= =?us-ascii?Q?PmVzao8I6D/xkWT5aQkUtOu0Nkq4z+3UVKN0kABcWVJ6EOaYzvWzzIt4EL7+?= =?us-ascii?Q?ollW5E4XPqv8h1ssEa/ZabEwTebUUNNNxllLscaZhcxxApp/DgZlfb4oPKuk?= =?us-ascii?Q?k5I089A/RqU/B80d/2wnSkB6z2f7pQNdGjIbgfedcLIAK1ZGaiYcT6Y0kc5w?= =?us-ascii?Q?eiqP1KC6aJFP0Ix0ravQUlDn++G36Qik/LiypwugvdH7G78wcYA1rhaW9HYR?= =?us-ascii?Q?GSJORKHLKAB7i6i8x8/ez5xHE44IsSn8VgTiFW4e25T2i0zqd+KlroYqoOPd?= =?us-ascii?Q?9fa23JmdiYgJTZLo2qCESgyriXMjXrEhNH79SdGR0bIyXi8WRx8rbvlwMPVJ?= =?us-ascii?Q?dtjO+r0IQ/vzM97/BqCTkNzfwOqLyeiscHBoWtmwFSf8LZwZS8W05RsR0Jtm?= =?us-ascii?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RryqNOrfbY8LiA3iKMC1HvYKu/V25zG2350Z3VXvxTZUNsnyMGLnH2Y2toTy48ex9vW6ddxfY7AYdFtsDF0jcxF6p+ZP2tv6xOwbBtQ37ouddZ5x0tqdSKqIu5rT647fg4bsGBNammNEG5lzllo2bXWvCO8a8aA==; 5:sAmKCQnuIcRBtvBiWFBzkYcGsbR3Gvd06EYZVvVeiwQPKmKEjTTzmpIvGTFkRnzZwxwVp8P3Pq3mRq6gIahpOObIIdClCnKithfReSic5ghp2+rz2rPM8BGBj3cKf4MwbhPizGJqWKbPQfzvPKd2ng==; 24:AW9isGMl5AQmgdSMTS6WWrYqTZy/3tONZNi/tfJ9hfoZfEewjFwQK4b6cTadXrmC0Aen3p4n9bJfaMHfFZJncAnZW5/giykJnQakYJwZuEg=; 7:4pl96V5bNL9/kpsDk9F2iyaAFaABeyGvCAZ+VT7hpnldV2bgIupP3cT3GSijKE/cwcQnhC5RBXblJAn7KwJwk1neU57MGkSWDk8yOLDxxTm20Te4rImNLkL3Jmb2smXYI9ugob7K391CqEuhSOOLFM7+9NAxKdrWHBMqj7pNkK01LaBqrnot84VhwQV3/SJNSr8w6gEBugifay1CFHK5Pb7oyS1P1m5as4Nb9Gf9NM4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1243; 20:Qdc/5jjcg8USap0fYs5CU4RuvfXOVpn5/EHbmACtne0W9WHUSy3qTTf5GNXCKnu1EEh58vOuKGLMX8rh2XeOVdX99UIg7wE7iKSUWy06TQKkLztg7lcGx05O6yira3QfF8wG4HY4AT7zs/Od8W2uHP1+tryi99nu790O94uNUtN7kw2pfoavIRFuEpitF/K44gDxCR6Rthr1rDUZXo/2ODUrzl0kLHXZl3SgGgr/XppeAZmR5Op9RzJ+cP+Pwye+ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2017 19:45:42.6688 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1243 Subject: [edk2] [PATCH v5 1/2] UefiCpuPkg/SmmCpuFeaturesLib: Use global variables to replace macros X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Jordan Justen , Liming Gao , Jiewen Yao , Michael D Kinney Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Set global variables on Constructor function based on CPUID checks. The variables replace Intel macros to allow support on AMD x86 systems. Specifically, the replaced macros are: 1) SRAM_SAVE_STATE_MAP_OFFSET 2) TXT_SMM_PSD_OFFSET Cc: Jiewen Yao Cc: Ruiyu Ni Cc: Michael D Kinney Cc: Jordan Justen Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Leo Duran --- .../Library/SmmCpuFeaturesLib/Ia32/SmiEntry.S | 28 ++++++---- .../Library/SmmCpuFeaturesLib/Ia32/SmiEntry.asm | 29 +++++++---- .../Library/SmmCpuFeaturesLib/Ia32/SmiEntry.nasm | 43 ++++++++++++---- UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCommon.h | 48 ++++++++++++++++++ .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 59 ++++++++++++++++++= ---- .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf | 3 ++ .../SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf | 3 ++ UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c | 39 ++++++++++++-- .../Library/SmmCpuFeaturesLib/X64/SmiEntry.S | 28 ++++++---- .../Library/SmmCpuFeaturesLib/X64/SmiEntry.asm | 30 +++++++---- .../Library/SmmCpuFeaturesLib/X64/SmiEntry.nasm | 47 ++++++++++++----- 11 files changed, 282 insertions(+), 75 deletions(-) create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCommon.h diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.S b/UefiCpu= Pkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.S index 4c0f8c8..c7b49d7 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.S +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.S @@ -1,6 +1,8 @@ #-------------------------------------------------------------------------= ----- # # Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2017, AMD Incorporated. All rights reserved.
+# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BS= D License # which accompanies this distribution. The full text of the license may b= e found at @@ -28,6 +30,9 @@ ASM_GLOBAL ASM_PFX(gStmSmbase) ASM_GLOBAL ASM_PFX(gStmXdSupported) ASM_GLOBAL ASM_PFX(FeaturePcdGet (PcdCpuSmmStackGuard)) ASM_GLOBAL ASM_PFX(gStmSmiHandlerIdtr) +ASM_GLOBAL ASM_PFX(gStmPsdOffset) +ASM_GLOBAL ASM_PFX(gStmGdtSize) +ASM_GLOBAL ASM_PFX(gStmGdtPtr) =20 .equ MSR_IA32_MISC_ENABLE, 0x1A0 .equ MSR_EFER, 0xc0000080 @@ -36,12 +41,13 @@ ASM_GLOBAL ASM_PFX(gStmSmiHandlerIdtr) # # Constants relating to TXT_PROCESSOR_SMM_DESCRIPTOR # -.equ DSC_OFFSET, 0xfb00 -.equ DSC_GDTPTR, 0x48 -.equ DSC_GDTSIZ, 0x50 -.equ DSC_CS, 0x14 -.equ DSC_DS, 0x16 -.equ DSC_SS, 0x18 +# .equ DSC_OFFSET, 0xfb00 +# .equ DSC_GDTPTR, 0x48 +# .equ DSC_GDTSIZ, 0x50 +# +.equ DSC_CS, 0x14 +.equ DSC_DS, 0x16 +.equ DSC_SS, 0x18 .equ DSC_OTHERSEG, 0x1A =20 .equ PROTECT_MODE_CS, 0x08 @@ -55,11 +61,11 @@ _StmSmiEntryPoint: .byte 0xbb # mov bx, imm16 .word _StmGdtDesc - _StmSmiEntryPoint + 0x8000 .byte 0x2e,0xa1 # mov ax, cs:[offset16] - .word DSC_OFFSET + DSC_GDTSIZ +ASM_PFX(gStmGdtSize): .space 2 # .word DSC_OFFSET + DSC_GDTSIZ decl %eax movl %eax, %cs:(%edi) # mov cs:[bx], ax .byte 0x66,0x2e,0xa1 # mov eax, cs:[offset16] - .word DSC_OFFSET + DSC_GDTPTR +ASM_PFX(gStmGdtPtr): .space 2 # .word DSC_OFFSET + DSC_GDTPTR movw %ax, %cs:2(%edi) movw %ax, %bp # ebp =3D GDT base .byte 0x66 @@ -167,7 +173,11 @@ XdDone: movl %cr0, %ebx orl $0x080010023, %ebx # enable paging + WP + NE + MP = + PE movl %ebx, %cr0 - leal DSC_OFFSET(%edi),%ebx + + movl $ASM_PFX(gStmPsdOffset), %ebx # leal DSC_OFFSET(%edi), %ebx + movzxw (%ebx), %esi + leal (%edi, %esi), %ebx + movw DSC_DS(%ebx),%ax movl %eax, %ds movw DSC_OTHERSEG(%ebx),%ax diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.asm b/UefiC= puPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.asm index 91dc1eb..4dbe276 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.asm +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.asm @@ -1,5 +1,7 @@ ;-------------------------------------------------------------------------= ----- ; ; Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
+; Copyright (c) 2017, AMD Incorporated. All rights reserved.
+; ; This program and the accompanying materials ; are licensed and made available under the terms and conditions of the BS= D License ; which accompanies this distribution. The full text of the license may b= e found at @@ -29,13 +31,14 @@ MSR_EFER_XD EQU 0800h ; ; Constants relating to TXT_PROCESSOR_SMM_DESCRIPTOR ; -DSC_OFFSET EQU 0fb00h -DSC_GDTPTR EQU 48h -DSC_GDTSIZ EQU 50h -DSC_CS EQU 14h -DSC_DS EQU 16h -DSC_SS EQU 18h -DSC_OTHERSEG EQU 1Ah +; DSC_OFFSET EQU 0fb00h +; DSC_GDTPTR EQU 48h +; DSC_GDTSIZ EQU 50h +; +DSC_CS EQU 14h +DSC_DS EQU 16h +DSC_SS EQU 18h +DSC_OTHERSEG EQU 1Ah =20 PROTECT_MODE_CS EQU 08h PROTECT_MODE_DS EQU 20h @@ -54,6 +57,9 @@ EXTERNDEF gStmSmbase:DWORD EXTERNDEF gStmXdSupported:BYTE EXTERNDEF FeaturePcdGet (PcdCpuSmmStackGuard):BYTE EXTERNDEF gStmSmiHandlerIdtr:FWORD +EXTERNDEF gStmPsdOffset:WORD +EXTERNDEF gStmGdtSize:WORD +EXTERNDEF gStmGdtPtr:WORD =20 .code =20 @@ -63,11 +69,11 @@ _StmSmiEntryPoint: DB 0bbh ; mov bx, imm16 DW offset _StmGdtDesc - _StmSmiEntryPoint + 8000h DB 2eh, 0a1h ; mov ax, cs:[offset16] - DW DSC_OFFSET + DSC_GDTSIZ +gStmGdtSize DW ? ; DSC_OFFSET + DSC_GDTSIZ dec eax mov cs:[edi], eax ; mov cs:[bx], ax DB 66h, 2eh, 0a1h ; mov eax, cs:[offset16] - DW DSC_OFFSET + DSC_GDTPTR +gStmGdtPtr DW ? ; DSC_OFFSET + DSC_GDTPTR mov cs:[edi + 2], ax ; mov cs:[bx + 2], eax mov bp, ax ; ebp =3D GDT base DB 66h @@ -174,7 +180,10 @@ gStmXdSupported DB 1 mov ebx, cr0 or ebx, 080010023h ; enable paging + WP + NE + MP + PE mov cr0, ebx - lea ebx, [edi + DSC_OFFSET] + + movzx esi, word ptr [gStmPsdOffset] ; lea ebx, [edi + DSC_OFFS= ET] + lea ebx, [edi + esi] ; + mov ax, [ebx + DSC_DS] mov ds, eax mov ax, [ebx + DSC_OTHERSEG] diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.nasm b/Uefi= CpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.nasm index 00c0f067..023923a 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.nasm +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.nasm @@ -1,5 +1,7 @@ ;-------------------------------------------------------------------------= ----- ; ; Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
+; Copyright (c) 2017, AMD Incorporated. All rights reserved.
+; ; This program and the accompanying materials ; are licensed and made available under the terms and conditions of the BS= D License ; which accompanies this distribution. The full text of the license may b= e found at @@ -25,17 +27,18 @@ ; ; Constants relating to TXT_PROCESSOR_SMM_DESCRIPTOR ; -%define DSC_OFFSET 0xfb00 -%define DSC_GDTPTR 0x48 -%define DSC_GDTSIZ 0x50 -%define DSC_CS 0x14 -%define DSC_DS 0x16 -%define DSC_SS 0x18 -%define DSC_OTHERSEG 0x1a +; %define DSC_OFFSET 0xfb00 +; %define DSC_GDTPTR 0x48 +; %define DSC_GDTSIZ 0x50 +; +%define DSC_CS 0x14 +%define DSC_DS 0x16 +%define DSC_SS 0x18 +%define DSC_OTHERSEG 0x1a =20 %define PROTECT_MODE_CS 0x8 %define PROTECT_MODE_DS 0x20 -%define TSS_SEGMENT 0x40 +%define TSS_SEGMENT 0x40 =20 extern ASM_PFX(SmiRendezvous) extern ASM_PFX(FeaturePcdGet (PcdCpuSmmStackGuard)) @@ -51,6 +54,10 @@ global ASM_PFX(gStmSmbase) global ASM_PFX(gStmXdSupported) extern ASM_PFX(gStmSmiHandlerIdtr) =20 +extern ASM_PFX(gStmPsdOffset) +global ASM_PFX(gStmGdtSize) +global ASM_PFX(gStmGdtPtr) + ASM_PFX(gStmSmiCr3) EQU StmSmiCr3Patch - 4 ASM_PFX(gStmSmiStack) EQU StmSmiStackPatch - 4 ASM_PFX(gStmSmbase) EQU StmSmbasePatch - 4 @@ -62,10 +69,18 @@ BITS 16 ASM_PFX(gcStmSmiHandlerTemplate): _StmSmiEntryPoint: mov bx, _StmGdtDesc - _StmSmiEntryPoint + 0x8000 - mov ax,[cs:DSC_OFFSET + DSC_GDTSIZ] + + mov eax, ASM_PFX(gStmGdtSize) ; mov ax, [cs:DSC_OFFSET + D= SC_GDTSIZ] + mov si, [cs:eax] ; + mov ax, [cs:si] ; + dec ax mov [cs:bx], ax - mov eax, [cs:DSC_OFFSET + DSC_GDTPTR] + + mov eax, ASM_PFX(gStmGdtPtr) ; mov eax, [cs:DSC_OFFSET + = DSC_GDTPTR] + mov si, [cs:eax] ; + mov eax, [cs:si] ; + mov [cs:bx + 2], eax mov ebp, eax ; ebp =3D GDT base o32 lgdt [cs:bx] ; lgdt fword ptr cs:[bx] @@ -166,7 +181,10 @@ StmXdSupportedPatch: mov ebx, cr0 or ebx, 0x80010023 ; enable paging + WP + NE + MP + PE mov cr0, ebx - lea ebx, [edi + DSC_OFFSET] + + movzx esi, word [ASM_PFX(gStmPsdOffset)] ; lea ebx, [edi + DSC_= OFFSET] + lea ebx, [edi + esi] ; + mov ax, [ebx + DSC_DS] mov ds, eax mov ax, [ebx + DSC_OTHERSEG] @@ -271,5 +289,8 @@ _StmSmiHandler: ; STM init finish jmp CommonHandler =20 +ASM_PFX(gStmGdtSize) : RESW 1 +ASM_PFX(gStmGdtPtr) : RESW 1 + ASM_PFX(gcStmSmiHandlerSize) : DW $ - _StmSmiEntryPoint ASM_PFX(gcStmSmiHandlerOffset) : DW _StmSmiHandler - _StmSmiEntryPo= int diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCommon.h b/UefiCpuPkg/= Library/SmmCpuFeaturesLib/SmmCommon.h new file mode 100644 index 0000000..78b3a5b --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCommon.h @@ -0,0 +1,48 @@ +/** @file + Common declarations + + Copyright (c) 2017, AMD Incorporated. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#ifndef _SMM_COMMON_H_ +#define _SMM_COMMON_H_ + +#include + +// +// Definitions for AMD systems are based on contents of the +// AMD64 Architecture Programmer's Manual +// Volume 2: System Programming, Section 10 System-Management Mode +// +#define AMD_SMRAM_SAVE_STATE_MAP_OFFSET 0xfe00 +#define AMD_SMM_PSD_OFFSET 0xfc00 + +// +// External global variables for SMRAM offsets +// +extern UINT16 gSmramStateMapOffset; +extern UINT16 gSmmPsdOffset; + + +/** + Determine if the standard CPU signature is "AuthenticAMD". + + @retval TRUE The CPU signature matches. + @retval FALSE The CPU signature does not match. + +**/ +BOOLEAN +SmmStandardSignatureIsAuthenticAMD ( + VOID + ); + +#endif diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/Uef= iCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c index 2d2bc6d..1c12095 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c @@ -1,14 +1,16 @@ /** @file -The CPU specific programming for PiSmmCpuDxeSmm module. + The CPU specific programming for PiSmmCpuDxeSmm module. =20 -Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
-This program and the accompanying materials -are licensed and made available under the terms and conditions of the BSD = License -which accompanies this distribution. The full text of the license may be = found at -http://opensource.org/licenses/bsd-license.php + Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2017, AMD Incorporated. All rights reserved.
=20 -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLI= ED. + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. =20 **/ =20 @@ -22,6 +24,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER= EXPRESS OR IMPLIED. #include #include =20 +#include "SmmCommon.h" + // // Machine Specific Registers (MSRs) // @@ -41,6 +45,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER= EXPRESS OR IMPLIED. #define SMM_FEATURES_LIB_IA32_MCA_CAP 0x17D #define SMM_CODE_ACCESS_CHK_BIT BIT58 =20 + /** Internal worker function that is called to complete CPU initialization a= t the end of SmmCpuFeaturesInitializeProcessor(). @@ -77,6 +82,13 @@ BOOLEAN mNeedConfigureMtrrs =3D TRUE; // BOOLEAN *mSmrrEnabled; =20 +// +// Set default value for SMRAM offset +// from +// +UINT16 gSmramStateMapOffset =3D SMRAM_SAVE_STATE_MAP_OFFSET; + + /** The constructor function =20 @@ -99,6 +111,13 @@ SmmCpuFeaturesLibConstructor ( UINTN ModelId; =20 // + // Override SMRAM offset for AMD + // + if (SmmStandardSignatureIsAuthenticAMD ()) { + gSmramStateMapOffset =3D AMD_SMRAM_SAVE_STATE_MAP_OFFSET; + } + + // // Retrieve CPU Family and Model // AsmCpuid (CPUID_VERSION_INFO, &RegEax, NULL, NULL, &RegEdx); @@ -224,7 +243,7 @@ SmmCpuFeaturesInitializeProcessor ( // // Configure SMBASE. // - CpuState =3D (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_= SAVE_STATE_MAP_OFFSET); + CpuState =3D (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + gSmram= StateMapOffset); CpuState->x86.SMBASE =3D (UINT32)CpuHotPlugData->SmBase[CpuIndex]; =20 // @@ -630,3 +649,25 @@ SmmCpuFeaturesAllocatePageTableMemory ( return NULL; } =20 + +/** + Determine if the standard CPU signature is "AuthenticAMD". + + @retval TRUE The CPU signature matches. + @retval FALSE The CPU signature does not match. + +**/ +BOOLEAN +SmmStandardSignatureIsAuthenticAMD ( + VOID + ) +{ + UINT32 RegEbx; + UINT32 RegEcx; + UINT32 RegEdx; + + AsmCpuid (CPUID_SIGNATURE, NULL, &RegEbx, &RegEcx, &RegEdx); + return (RegEbx =3D=3D CPUID_SIGNATURE_AUTHENTIC_AMD_EBX && + RegEcx =3D=3D CPUID_SIGNATURE_AUTHENTIC_AMD_ECX && + RegEdx =3D=3D CPUID_SIGNATURE_AUTHENTIC_AMD_EDX); +} diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf b/U= efiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf index 77908b0..6a39d4b 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf @@ -2,6 +2,8 @@ # The CPU specific programming for PiSmmCpuDxeSmm module. # # Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2017, AMD Incorporated. All rights reserved.
+# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the B= SD License # which accompanies this distribution. The full text of the license may = be found at @@ -24,6 +26,7 @@ =20 [Sources] SmmCpuFeaturesLib.c + SmmCommon.h SmmCpuFeaturesLibNoStm.c =20 [Packages] diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf = b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf index db8dcdc..a76bed6 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf @@ -3,6 +3,8 @@ # is included. # # Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2017, AMD Incorporated. All rights reserved.
+# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the B= SD License # which accompanies this distribution. The full text of the license may = be found at @@ -25,6 +27,7 @@ =20 [Sources] SmmCpuFeaturesLib.c + SmmCommon.h SmmStm.c SmmStm.h =20 diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c b/UefiCpuPkg/Lib= rary/SmmCpuFeaturesLib/SmmStm.c index 45015b8..5f7c3db 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c @@ -2,6 +2,8 @@ SMM STM support functions =20 Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2017, AMD Incorporated. All rights reserved.
+ This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -28,6 +30,8 @@ #include =20 #include "SmmStm.h" +#include "SmmCommon.h" + =20 #define TXT_EVTYPE_BASE 0x400 #define TXT_EVTYPE_STM_HASH (TXT_EVTYPE_BASE + 14) @@ -97,6 +101,20 @@ extern volatile UINT8 gcStmSmiHand= lerTemplate[]; extern CONST UINT16 gcStmSmiHandlerSize; extern UINT16 gcStmSmiHandlerOffset; extern BOOLEAN gStmXdSupported; +extern UINT16 gStmGdtSize; +extern UINT16 gStmGdtPtr; + +// +// Constants relating to TXT_PROCESSOR_SMM_DESCRIPTOR +// +#define TXT_PSD_GDTPTR 0x48 +#define TXT_PSD_GDTSIZE 0x50 + +// +// Set default value for PSD offset in SMRAM +// from +// +UINT16 gStmPsdOffset =3D TXT_SMM_PSD_OFFSET; =20 // // Variables used by SMI Handler @@ -145,6 +163,19 @@ SmmCpuFeaturesLibStmConstructor ( ASSERT_EFI_ERROR (Status); =20 // + // Override PSD offset for AMD + // + if (SmmStandardSignatureIsAuthenticAMD ()) { + gStmPsdOffset =3D AMD_SMM_PSD_OFFSET; + } + + // + // Initialize STM global variables associated with SMI Handler + // + gStmGdtSize =3D gStmPsdOffset + TXT_PSD_GDTSIZE; + gStmGdtPtr =3D gStmPsdOffset + TXT_PSD_GDTPTR; + + // // Lookup the MP Services Protocol // Status =3D gBS->LocateProtocol ( @@ -276,8 +307,8 @@ SmmCpuFeaturesInstallSmiHandler ( UINT32 RegEdx; EFI_PROCESSOR_INFORMATION ProcessorInfo; =20 - CopyMem ((VOID *)((UINTN)SmBase + TXT_SMM_PSD_OFFSET), &gcStmPsd, sizeof= (gcStmPsd)); - Psd =3D (TXT_PROCESSOR_SMM_DESCRIPTOR *)(VOID *)((UINTN)SmBase + TXT_SMM= _PSD_OFFSET); + CopyMem ((VOID *)((UINTN)SmBase + gStmPsdOffset), &gcStmPsd, sizeof (gcS= tmPsd)); + Psd =3D (TXT_PROCESSOR_SMM_DESCRIPTOR *)(VOID *)((UINTN)SmBase + gStmPsd= Offset); Psd->SmmGdtPtr =3D GdtBase; Psd->SmmGdtSize =3D (UINT32)GdtSize; =20 @@ -416,7 +447,7 @@ SmmEndOfDxeEventNotify ( } =20 for (Index =3D 0; Index < gSmst->NumberOfCpus; Index++) { - Psd =3D (TXT_PROCESSOR_SMM_DESCRIPTOR *)((UINTN)gSmst->CpuSaveState[In= dex] - SMRAM_SAVE_STATE_MAP_OFFSET + TXT_SMM_PSD_OFFSET); + Psd =3D (TXT_PROCESSOR_SMM_DESCRIPTOR *)((UINTN)gSmst->CpuSaveState[In= dex] - gSmramStateMapOffset + gStmPsdOffset); DEBUG ((DEBUG_INFO, "Index=3D%d Psd=3D%p Rsdp=3D%p\n", Index, Psd, R= sdp)); Psd->AcpiRsdp =3D (UINT64)(UINTN)Rsdp; } @@ -1266,7 +1297,7 @@ NotifyStmResourceChange ( TXT_PROCESSOR_SMM_DESCRIPTOR *Psd; =20 for (Index =3D 0; Index < gSmst->NumberOfCpus; Index++) { - Psd =3D (TXT_PROCESSOR_SMM_DESCRIPTOR *)((UINTN)gSmst->CpuSaveState[In= dex] - SMRAM_SAVE_STATE_MAP_OFFSET + TXT_SMM_PSD_OFFSET); + Psd =3D (TXT_PROCESSOR_SMM_DESCRIPTOR *)((UINTN)gSmst->CpuSaveState[In= dex] - gSmramStateMapOffset + gStmPsdOffset); Psd->BiosHwResourceRequirementsPtr =3D (UINT64)(UINTN)StmResource; } return ; diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.S b/UefiCpuP= kg/Library/SmmCpuFeaturesLib/X64/SmiEntry.S index 1f9f91c..5f3386a 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.S +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.S @@ -1,6 +1,8 @@ #-------------------------------------------------------------------------= ----- # # Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2017, AMD Incorporated. All rights reserved.
+# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BS= D License # which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +29,9 @@ ASM_GLOBAL ASM_PFX(gStmSmiStack) ASM_GLOBAL ASM_PFX(gStmSmbase) ASM_GLOBAL ASM_PFX(gStmXdSupported) ASM_GLOBAL ASM_PFX(gStmSmiHandlerIdtr) +ASM_GLOBAL ASM_PFX(gStmPsdOffset) +ASM_GLOBAL ASM_PFX(gStmGdtSize) +ASM_GLOBAL ASM_PFX(gStmGdtPtr) =20 .equ MSR_IA32_MISC_ENABLE, 0x1A0 .equ MSR_EFER, 0xc0000080 @@ -35,12 +40,13 @@ ASM_GLOBAL ASM_PFX(gStmSmiHandlerIdtr) # # Constants relating to TXT_PROCESSOR_SMM_DESCRIPTOR # -.equ DSC_OFFSET, 0xfb00 -.equ DSC_GDTPTR, 0x48 -.equ DSC_GDTSIZ, 0x50 -.equ DSC_CS, 0x14 -.equ DSC_DS, 0x16 -.equ DSC_SS, 0x18 +# .equ DSC_OFFSET, 0xfb00 +# .equ DSC_GDTPTR, 0x48 +# .equ DSC_GDTSIZ, 0x50 +# +.equ DSC_CS, 0x14 +.equ DSC_DS, 0x16 +.equ DSC_SS, 0x18 .equ DSC_OTHERSEG, 0x1a # # Constants relating to CPU State Save Area @@ -71,12 +77,12 @@ _StmSmiEntryPoint: # fix GDT descriptor # .byte 0x2e,0xa1 # mov ax, cs:[offset16] - .word DSC_OFFSET + DSC_GDTSIZ +ASM_PFX(gStmGdtSize): .space 2 # .word DSC_OFFSET + DSC_GDTSIZ .byte 0x48 # dec ax .byte 0x2e movl %eax, (%rdi) # mov cs:[bx], ax .byte 0x66,0x2e,0xa1 # mov eax, cs:[offset16] - .word DSC_OFFSET + DSC_GDTPTR +ASM_PFX(gStmGdtPtr): .space 2 # .word DSC_OFFSET + DSC_GDTPTR .byte 0x2e movw %ax, 2(%rdi) .byte 0x66,0x2e @@ -183,7 +189,11 @@ Base: LongMode: # long mode (64-bit code) starts h= ere movabsq $ASM_PFX(gStmSmiHandlerIdtr), %rax lidt (%rax) - lea (DSC_OFFSET)(%rdi), %ebx + + movl $ASM_PFX(gStmPsdOffset), %ebx # lea (DSC_OFFSET)(%rdi), %= ebx + movzxw (%ebx), %rsi + leal (%rdi, %rsi), %ebx + movw DSC_DS(%rbx), %ax movl %eax,%ds movw DSC_OTHERSEG(%rbx), %ax diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.asm b/UefiCp= uPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.asm index ad51e07..10913df 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.asm +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.asm @@ -1,5 +1,7 @@ ;-------------------------------------------------------------------------= ----- ; ; Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+; Copyright (c) 2017, AMD Incorporated. All rights reserved.
+; ; This program and the accompanying materials ; are licensed and made available under the terms and conditions of the BS= D License ; which accompanies this distribution. The full text of the license may b= e found at @@ -32,6 +34,10 @@ EXTERNDEF gStmSmiStack:DWORD EXTERNDEF gStmSmbase:DWORD EXTERNDEF gStmXdSupported:BYTE EXTERNDEF gStmSmiHandlerIdtr:FWORD +EXTERNDEF gStmPsdOffset:WORD +EXTERNDEF gStmGdtSize:WORD +EXTERNDEF gStmGdtPtr:WORD + =20 MSR_IA32_MISC_ENABLE EQU 1A0h MSR_EFER EQU 0c0000080h @@ -40,13 +46,14 @@ MSR_EFER_XD EQU 0800h ; ; Constants relating to TXT_PROCESSOR_SMM_DESCRIPTOR ; -DSC_OFFSET EQU 0fb00h -DSC_GDTPTR EQU 48h -DSC_GDTSIZ EQU 50h -DSC_CS EQU 14h -DSC_DS EQU 16h -DSC_SS EQU 18h -DSC_OTHERSEG EQU 1ah +; DSC_OFFSET EQU 0fb00h +; DSC_GDTPTR EQU 48h +; DSC_GDTSIZ EQU 50h +; +DSC_CS EQU 14h +DSC_DS EQU 16h +DSC_SS EQU 18h +DSC_OTHERSEG EQU 1ah ; ; Constants relating to CPU State Save Area ; @@ -74,12 +81,12 @@ _StmSmiEntryPoint: DW offset _StmGdtDesc - _StmSmiEntryPoint + 8000h ; bx =3D GdtDe= sc offset ; fix GDT descriptor DB 2eh, 0a1h ; mov ax, cs:[offset16] - DW DSC_OFFSET + DSC_GDTSIZ +gStmGdtSize DW ? ; DSC_OFFSET + DSC_GDTSIZ DB 48h ; dec ax DB 2eh mov [rdi], eax ; mov cs:[bx], ax DB 66h, 2eh, 0a1h ; mov eax, cs:[offset16] - DW DSC_OFFSET + DSC_GDTPTR +gStmGdtPtr DW ? ; DSC_OFFSET + DSC_GDTPTR DB 2eh mov [rdi + 2], ax ; mov cs:[bx + 2], eax DB 66h, 2eh @@ -178,7 +185,10 @@ Base: @LongMode: ; long mode (64-bit code) starts h= ere mov rax, offset gStmSmiHandlerIdtr lidt fword ptr [rax] - lea ebx, [rdi + DSC_OFFSET] + + movzx rsi, word ptr [gStmPsdOffset] ; lea ebx, [rdi + DSC_OFFS= ET] + lea ebx, [rdi + rsi] ; + mov ax, [rbx + DSC_DS] mov ds, eax mov ax, [rbx + DSC_OTHERSEG] diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.nasm b/UefiC= puPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.nasm index bcac643..df4c5a2 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.nasm +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.nasm @@ -1,5 +1,7 @@ ;-------------------------------------------------------------------------= ----- ; ; Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
+; Copyright (c) 2017, AMD Incorporated. All rights reserved.
+; ; This program and the accompanying materials ; are licensed and made available under the terms and conditions of the BS= D License ; which accompanies this distribution. The full text of the license may b= e found at @@ -29,13 +31,14 @@ ; ; Constants relating to TXT_PROCESSOR_SMM_DESCRIPTOR ; -%define DSC_OFFSET 0xfb00 -%define DSC_GDTPTR 0x48 -%define DSC_GDTSIZ 0x50 -%define DSC_CS 0x14 -%define DSC_DS 0x16 -%define DSC_SS 0x18 -%define DSC_OTHERSEG 0x1a +; %define DSC_OFFSET 0xfb00 +; %define DSC_GDTPTR 0x48 +; %define DSC_GDTSIZ 0x50 +; +%define DSC_CS 0x14 +%define DSC_DS 0x16 +%define DSC_SS 0x18 +%define DSC_OTHERSEG 0x1a ; ; Constants relating to CPU State Save Area ; @@ -44,9 +47,9 @@ =20 %define PROTECT_MODE_CS 0x8 %define PROTECT_MODE_DS 0x20 -%define LONG_MODE_CS 0x38 -%define TSS_SEGMENT 0x40 -%define GDT_SIZE 0x50 +%define LONG_MODE_CS 0x38 +%define TSS_SEGMENT 0x40 +%define GDT_SIZE 0x50 =20 extern ASM_PFX(SmiRendezvous) extern ASM_PFX(gStmSmiHandlerIdtr) @@ -61,6 +64,10 @@ global ASM_PFX(gcStmSmiHandlerTemplate) global ASM_PFX(gcStmSmiHandlerSize) global ASM_PFX(gcStmSmiHandlerOffset) =20 +extern ASM_PFX(gStmPsdOffset) +global ASM_PFX(gStmGdtSize) +global ASM_PFX(gStmGdtPtr) + ASM_PFX(gStmSmbase) EQU StmSmbasePatch - 4 ASM_PFX(gStmSmiStack) EQU StmSmiStackPatch - 4 ASM_PFX(gStmSmiCr3) EQU StmSmiCr3Patch - 4 @@ -73,10 +80,18 @@ BITS 16 ASM_PFX(gcStmSmiHandlerTemplate): _StmSmiEntryPoint: mov bx, _StmGdtDesc - _StmSmiEntryPoint + 0x8000 - mov ax,[cs:DSC_OFFSET + DSC_GDTSIZ] + + mov eax, ASM_PFX(gStmGdtSize) ; mov ax, [cs:DSC_OFFSET + D= SC_GDTSIZ] + mov si, [cs:eax] ; + mov ax, [cs:si] ; + dec ax mov [cs:bx], ax - mov eax, [cs:DSC_OFFSET + DSC_GDTPTR] + + mov eax, ASM_PFX(gStmGdtPtr) ; mov eax, [cs:DSC_OFFSET + = DSC_GDTPTR] + mov si, [cs:eax] ; + mov eax, [cs:si] ; + mov [cs:bx + 2], eax o32 lgdt [cs:bx] ; lgdt fword ptr cs:[bx] mov ax, PROTECT_MODE_CS @@ -166,7 +181,10 @@ Base: @LongMode: ; long mode (64-bit code) starts h= ere mov rax, ASM_PFX(gStmSmiHandlerIdtr) lidt [rax] - lea ebx, [rdi + DSC_OFFSET] + + movzx rsi, word [ASM_PFX(gStmPsdOffset)] ; lea ebx, [rdi + DSC_= OFFSET] + lea ebx, [rdi + rsi] ; + mov ax, [rbx + DSC_DS] mov ds, eax mov ax, [rbx + DSC_OTHERSEG] @@ -262,5 +280,8 @@ _StmSmiHandler: ; STM init finish jmp CommonHandler =20 +ASM_PFX(gStmGdtSize) : RESW 1 +ASM_PFX(gStmGdtPtr) : RESW 1 + ASM_PFX(gcStmSmiHandlerSize) : DW $ - _StmSmiEntryPoint ASM_PFX(gcStmSmiHandlerOffset) : DW _StmSmiHandler - _StmSmiEntryPoint --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Wed Dec 25 13:35:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1507751151566725.3071657389585; Wed, 11 Oct 2017 12:45:51 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 96FA521E781F3; Wed, 11 Oct 2017 12:42:20 -0700 (PDT) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0076.outbound.protection.outlook.com [104.47.38.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8D2B22095E51F for ; Wed, 11 Oct 2017 12:42:17 -0700 (PDT) Received: from leduran-Precision-WorkStation-T5400.amd.com (165.204.77.1) by DM5PR12MB1243.namprd12.prod.outlook.com (10.168.237.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Wed, 11 Oct 2017 19:45:43 +0000 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=helo; client-ip=104.47.38.76; helo=nam02-bl2-obe.outbound.protection.outlook.com; envelope-from=leo.duran@amd.com; receiver=edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=g8qG0EzVRgKePvBKaxtRX7q6wGl4JfJ7Fvkbx0JcizQ=; b=0zUM4QsptLqOhGnIXZETGU5cPODnmY90sjVAQ5w/DeRUU/Ds8y1219MtepP4ZER5/y1pYAJdKfjc7259slooe8e2mwdvA7fwJqZmM5mGGN5YKWQDfAIPNI2oJ332YtqpEiUuhCb3B7/ARu5yrJGRsQkz1k48cVz9Ffqu7M3sUZ0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=leo.duran@amd.com; From: Leo Duran To: edk2-devel@lists.01.org Date: Wed, 11 Oct 2017 14:45:31 -0500 Message-Id: <1507751131-32404-3-git-send-email-leo.duran@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507751131-32404-1-git-send-email-leo.duran@amd.com> References: <1507751131-32404-1-git-send-email-leo.duran@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CO2PR05CA0063.namprd05.prod.outlook.com (10.166.88.159) To DM5PR12MB1243.namprd12.prod.outlook.com (10.168.237.22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 76547387-2531-43c4-6726-08d510e0a9ca X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(48565401081)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:DM5PR12MB1243; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1243; 3:blQFJPa3UYFwS2dbgKTTH4qDzau3DgnnqCNEi1ftJPxMNR/QGFMs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TXC+NJEVnChFuXeyGgG6I79aXj4gYk0E3iynnQ01NI2ai43fzh0BWjVrnKiwnUjzN885M3xPXPxT3zOKHobJk+fgQ2fmNkfq+5yMGZ0RpxU+EZSbk1Dm1Cldcvf+zAlvV8mcn863FQV7H9tSKIeieoSdLOEvD+ybiTVDLZN5/tRg3VdY4zMsa3Z8loOMWvp0Lh2wfrVbUx8Wn0s4EbBIT5MR3oWqsQVBUL1I0WG+VNeYoTtXQBKxdioIrG/5/SQPYDSPLkwOL/FRV3d9jtyNI2qa5PMZujsWUF7/xzN7bgj; 4:W3D//i6LxMoJ7wcR5JmBR5/RS/iNDBI00w2dDmeatLiQVTU6T/iyBDJ+EYMqQqM4Q1EbnQUdJKWfsJKlyGme1VYVutjYdWGUwIGOy+UJ2oP1qGpLE8gNuknn7PEuobsgappb8c+GRfFpcfgsgt9x48PpXiL4sSUfFj+aNO0fdtjYW1IdbhUqaEgCn6eAlAIkBsTdjoP9CS2v8Ips0XI/2yrfBLL3dkm/OukQixl9XFxNJ38NyKdCpOYMRzl9zFvj0S+BA8ox9AVaOKL35JKOlPdgqoFGU1IgGTbFuQQdRThZNlmx8vTS/SFPuKowu4HfPeRBf7a4oK5aDSimp0hueexwms3Icim+WZSXPa7jp2w= X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(788757137089)(228905959029699); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(6055026)(6041248)(20161123564025)(20161123555025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM5PR12MB1243; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM5PR12MB1243; X-Forefront-PRVS: 0457F11EAF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(979002)(6029001)(6009001)(39860400002)(376002)(346002)(199003)(189002)(36756003)(68736007)(189998001)(16526018)(53936002)(16586007)(50466002)(966005)(2906002)(81156014)(3846002)(48376002)(316002)(6306002)(305945005)(81166006)(8676002)(53946003)(86362001)(6116002)(97736004)(478600001)(8936002)(7736002)(2351001)(5003940100001)(2361001)(53376002)(53416004)(6666003)(50986999)(6486002)(25786009)(76176999)(106356001)(16799955002)(4326008)(5660300001)(105586002)(575784001)(66066001)(50226002)(15188155005)(54906003)(47776003)(33646002)(101416001)(6916009)(2950100002)(19627235001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1243; H:leduran-Precision-WorkStation-T5400.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR12MB1243; 23:p6wYWI0nfg48O5ozh8WU0S9MKOr4NHr+wWb0jt1ZT?= =?us-ascii?Q?+s9lIZeOLegWqlwQC7bhrUdtPnVWHb6jYb/td9V6TqgjUPwhvB040HXcR0AG?= =?us-ascii?Q?iG6dp6JNS2hrdqTC3XifEs7kZfiiM54/rIE63Ms9zoNPnngqt3EfLWfhnoDD?= =?us-ascii?Q?kYjN9qZ4rk0+JFvFbCaWR7D/3HCmGMwdOYh1lVsdwwNSCqDI8MFXVICdsPXB?= =?us-ascii?Q?igTZet3Bx/eHBiRSiQ6a1nbpoFSnqyCs1u4Bbk1j/dZ3FZKh4SiKmqCfH3Y0?= =?us-ascii?Q?JxzKK62N0M2cufVfHz6YKVcxqgBqTm94QqD2izuoZdrqZuu7WGs7DaPncyEj?= =?us-ascii?Q?v7/KT2gdkIEQAlOsBlVj5QfTq/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oS7e1HIPJoijQWHibBjKkgdXtkEL7wWy0C6J27j2uuEtoT8SZ7t52wj0+EiMFIQF7UNXa5tK7X68cHYdmbk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1243; 20:sTrLwXCQexldhYGC0BCacvTWu2pm59bTu6RtxyPbBhxdKSbrRir2W01ov2HYQj9OamRXWopZKwcRGNioo1EfK5lfntGalDBR0KO9h2Ae77S/663Y424KGUJM8WoqFWtOWYGSOGcrWal3H+Jg6YN3bxRdJd6GdyQt8qTOaT/DrfaQuaJWVtrAwHFNH5JPxuMLD6kg1zTM21fX9/HU1f9AY27QYuMvC2JLgZaZ9vgo4plgki2JlSgl0qEO0C9fUZb1 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2017 19:45:43.9032 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1243 Subject: [edk2] [PATCH v5 2/2] UefiCpuPkg/PiSmmCpuDxeSmm: Use global variables to replace macros X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Jordan Justen , Liming Gao , Jiewen Yao , Michael D Kinney Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Set global variables on Entry function based on CPUID checks. The variables replace Intel macros to allow support on AMD x86 systems. Specifically, the replaced macros are: 1) SRAM_SAVE_STATE_MAP_OFFSET 2) SMM_PSD_OFFSET Cc: Jiewen Yao Cc: Ruiyu Ni Cc: Michael D Kinney Cc: Jordan Justen Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Leo Duran --- UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c | 22 ++++--- UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.S | 28 ++++++--- UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.asm | 21 +++++-- UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm | 43 +++++++++---- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 72 ++++++++++++++++++= ++-- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 17 ++++- UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c | 18 +++--- UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 20 +++--- UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c | 22 ++++--- UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.S | 34 ++++++---- UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.asm | 22 +++++-- UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm | 45 ++++++++++---- 12 files changed, 265 insertions(+), 99 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c b/UefiCpuPkg/PiSmmC= puDxeSmm/Ia32/Semaphore.c index 02a866b..7b2e5fb 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c @@ -1,15 +1,17 @@ /** @file -Semaphore mechanism to indicate to the BSP that an AP has exited SMM -after SMBASE relocation. + Semaphore mechanism to indicate to the BSP that an AP has exited SMM + after SMBASE relocation. =20 -Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
-This program and the accompanying materials -are licensed and made available under the terms and conditions of the BSD = License -which accompanies this distribution. The full text of the license may be = found at -http://opensource.org/licenses/bsd-license.php + Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2017, AMD Incorporated. All rights reserved.
=20 -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLI= ED. + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. =20 **/ =20 @@ -38,7 +40,7 @@ SemaphoreHook ( =20 mRebasedFlag =3D RebasedFlag; =20 - CpuState =3D (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_= SAVE_STATE_MAP_OFFSET); + CpuState =3D (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + gSmmSm= ramStateMapOffset); mSmmRelocationOriginalAddress =3D (UINTN)HookReturnFromSmm ( CpuIndex, CpuState, diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.S b/UefiCpuPkg/PiSmmCp= uDxeSmm/Ia32/SmiEntry.S index 3243a91..d25c099 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.S +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.S @@ -1,6 +1,8 @@ #-------------------------------------------------------------------------= ----- # # Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2017, AMD Incorporated. All rights reserved.
+# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BS= D License # which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +29,9 @@ ASM_GLOBAL ASM_PFX(gSmbase) ASM_GLOBAL ASM_PFX(mXdSupported) ASM_GLOBAL ASM_PFX(FeaturePcdGet (PcdCpuSmmStackGuard)) ASM_GLOBAL ASM_PFX(gSmiHandlerIdtr) +ASM_GLOBAL ASM_PFX(gSmmPsdOffset) +ASM_GLOBAL ASM_PFX(gPsdGdtSize) +ASM_GLOBAL ASM_PFX(gPsdGdtPtr) =20 .equ MSR_IA32_MISC_ENABLE, 0x1A0 .equ MSR_EFER, 0xc0000080 @@ -35,12 +40,13 @@ ASM_GLOBAL ASM_PFX(gSmiHandlerIdtr) # # Constants relating to PROCESSOR_SMM_DESCRIPTOR # -.equ DSC_OFFSET, 0xfb00 -.equ DSC_GDTPTR, 0x30 -.equ DSC_GDTSIZ, 0x38 -.equ DSC_CS, 14 -.equ DSC_DS, 16 -.equ DSC_SS, 18 +# .equ DSC_OFFSET, 0xfb00 +# .equ DSC_GDTPTR, 0x30 +# .equ DSC_GDTSIZ, 0x38 +# +.equ DSC_CS, 14 +.equ DSC_DS, 16 +.equ DSC_SS, 18 .equ DSC_OTHERSEG, 20 =20 .equ PROTECT_MODE_CS, 0x08 @@ -55,11 +61,11 @@ _SmiEntryPoint: .byte 0xbb # mov bx, imm16 .word _GdtDesc - _SmiEntryPoint + 0x8000 .byte 0x2e,0xa1 # mov ax, cs:[offset16] - .word DSC_OFFSET + DSC_GDTSIZ +ASM_PFX(gPsdGdtSize): .space 2 # .word DSC_OFFSET + DSC_GDTSIZ decl %eax movl %eax, %cs:(%edi) # mov cs:[bx], ax .byte 0x66,0x2e,0xa1 # mov eax, cs:[offset16] - .word DSC_OFFSET + DSC_GDTPTR +ASM_PFX(gPsdGdtPtr): .space 2 # .word DSC_OFFSET + DSC_GDTPTR movw %ax, %cs:2(%edi) movw %ax, %bp # ebp =3D GDT base .byte 0x66 @@ -167,7 +173,11 @@ NxeDone: movl %cr0, %ebx orl $0x080010023, %ebx # enable paging + WP + NE + MP = + PE movl %ebx, %cr0 - leal DSC_OFFSET(%edi),%ebx + + movl $ASM_PFX(gSmmPsdOffset), %ebx # leal DSC_OFFSET(%edi), %ebx + movzxw (%ebx), %esi + leal (%edi, %esi), %ebx + movw DSC_DS(%ebx),%ax movl %eax, %ds movw DSC_OTHERSEG(%ebx),%ax diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.asm b/UefiCpuPkg/PiSmm= CpuDxeSmm/Ia32/SmiEntry.asm index 8296f36..c9c471f 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.asm +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.asm @@ -1,5 +1,7 @@ ;-------------------------------------------------------------------------= ----- ; ; Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+; Copyright (c) 2017, AMD Incorporated. All rights reserved.
+; ; This program and the accompanying materials ; are licensed and made available under the terms and conditions of the BS= D License ; which accompanies this distribution. The full text of the license may b= e found at @@ -29,9 +31,10 @@ MSR_EFER_XD EQU 0800h ; ; Constants relating to PROCESSOR_SMM_DESCRIPTOR ; -DSC_OFFSET EQU 0fb00h -DSC_GDTPTR EQU 30h -DSC_GDTSIZ EQU 38h +; DSC_OFFSET EQU 0fb00h +; DSC_GDTPTR EQU 30h +; DSC_GDTSIZ EQU 38h +; DSC_CS EQU 14 DSC_DS EQU 16 DSC_SS EQU 18 @@ -53,6 +56,9 @@ EXTERNDEF gSmbase:DWORD EXTERNDEF mXdSupported:BYTE EXTERNDEF FeaturePcdGet (PcdCpuSmmStackGuard):BYTE EXTERNDEF gSmiHandlerIdtr:FWORD +EXTERNDEF gSmmPsdOffset:WORD +EXTERNDEF gPsdGdtSize:WORD +EXTERNDEF gPsdGdtPtr:WORD =20 .code =20 @@ -62,11 +68,11 @@ _SmiEntryPoint: DB 0bbh ; mov bx, imm16 DW offset _GdtDesc - _SmiEntryPoint + 8000h DB 2eh, 0a1h ; mov ax, cs:[offset16] - DW DSC_OFFSET + DSC_GDTSIZ +gPsdGdtSize DW ? ; DSC_OFFSET + DSC_GDTSIZ dec eax mov cs:[edi], eax ; mov cs:[bx], ax DB 66h, 2eh, 0a1h ; mov eax, cs:[offset16] - DW DSC_OFFSET + DSC_GDTPTR +gPsdGdtPtr DW ? ; DSC_OFFSET + DSC_GDTPTR mov cs:[edi + 2], ax ; mov cs:[bx + 2], eax mov bp, ax ; ebp =3D GDT base DB 66h @@ -173,7 +179,10 @@ mXdSupported DB 1 mov ebx, cr0 or ebx, 080010023h ; enable paging + WP + NE + MP + PE mov cr0, ebx - lea ebx, [edi + DSC_OFFSET] + + movzx esi, word ptr [gSmmPsdOffset] ; lea ebx, [edi + DSC_OFFS= ET] + lea ebx, [edi + esi] + mov ax, [ebx + DSC_DS] mov ds, eax mov ax, [ebx + DSC_OTHERSEG] diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm b/UefiCpuPkg/PiSm= mCpuDxeSmm/Ia32/SmiEntry.nasm index 4d2383f..666233b 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm @@ -1,5 +1,7 @@ ;-------------------------------------------------------------------------= ----- ; ; Copyright (c) 2016, Intel Corporation. All rights reserved.
+; Copyright (c) 2017, AMD Incorporated. All rights reserved.
+; ; This program and the accompanying materials ; are licensed and made available under the terms and conditions of the BS= D License ; which accompanies this distribution. The full text of the license may b= e found at @@ -25,17 +27,18 @@ ; ; Constants relating to PROCESSOR_SMM_DESCRIPTOR ; -%define DSC_OFFSET 0xfb00 -%define DSC_GDTPTR 0x30 -%define DSC_GDTSIZ 0x38 -%define DSC_CS 14 -%define DSC_DS 16 -%define DSC_SS 18 -%define DSC_OTHERSEG 20 +; %define DSC_OFFSET 0xfb00 +; %define DSC_GDTPTR 0x30 +; %define DSC_GDTSIZ 0x38 +; +%define DSC_CS 14 +%define DSC_DS 16 +%define DSC_SS 18 +%define DSC_OTHERSEG 20 =20 %define PROTECT_MODE_CS 0x8 %define PROTECT_MODE_DS 0x20 -%define TSS_SEGMENT 0x40 +%define TSS_SEGMENT 0x40 =20 extern ASM_PFX(SmiRendezvous) extern ASM_PFX(FeaturePcdGet (PcdCpuSmmStackGuard)) @@ -50,16 +53,28 @@ global ASM_PFX(gSmbase) global ASM_PFX(mXdSupported) extern ASM_PFX(gSmiHandlerIdtr) =20 +extern ASM_PFX(gSmmPsdOffset) +global ASM_PFX(gPsdGdtSize) +global ASM_PFX(gPsdGdtPtr) + SECTION .text =20 BITS 16 ASM_PFX(gcSmiHandlerTemplate): _SmiEntryPoint: mov bx, _GdtDesc - _SmiEntryPoint + 0x8000 - mov ax,[cs:DSC_OFFSET + DSC_GDTSIZ] + + mov eax, ASM_PFX(gPsdGdtSize) ; mov ax, [cs:DSC_OFFSET + D= SC_GDTSIZ] + mov si, [cs:eax] ; + mov ax, [cs:si] ; + dec ax mov [cs:bx], ax - mov eax, [cs:DSC_OFFSET + DSC_GDTPTR] + + mov eax, ASM_PFX(gPsdGdtPtr) ; mov eax, [cs:DSC_OFFSET + = DSC_GDTPTR] + mov si, [cs:eax] ; + mov eax, [cs:si] ; + mov [cs:bx + 2], eax mov ebp, eax ; ebp =3D GDT base o32 lgdt [cs:bx] ; lgdt fword ptr cs:[bx] @@ -160,7 +175,10 @@ ASM_PFX(mXdSupported): DB 1 mov ebx, cr0 or ebx, 0x80010023 ; enable paging + WP + NE + MP + PE mov cr0, ebx - lea ebx, [edi + DSC_OFFSET] + + movzx esi, word [ASM_PFX(gSmmPsdOffset)] ; lea ebx, [edi + DSC_= OFFSET] + lea ebx, [edi + esi] ; + mov ax, [ebx + DSC_DS] mov ds, eax mov ax, [ebx + DSC_OTHERSEG] @@ -205,5 +223,8 @@ ASM_PFX(SmiHandler): .7: rsm =20 +ASM_PFX(gPsdGdtSize): RESW 1 +ASM_PFX(gPsdGdtPtr) : RESW 1 + ASM_PFX(gcSmiHandlerSize): DW $ - _SmiEntryPoint =20 diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.c index 282d2e6..ad7c811 100755 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -116,6 +116,31 @@ UINTN mSmmCpuSmramRangeCount; =20 UINT8 mPhysicalAddressBits; =20 +// +// Set default value for SMRAM offset +// from +// +UINT16 gSmmSmramStateMapOffset =3D SMRAM_SAVE_STATE_MAP_OFFSET; + +// +// Set default value for PSD offset in SMRAM +// +UINT16 gSmmPsdOffset =3D INTEL_SMM_PSD_OFFSET; + +// +// Constants relating to PROCESSOR_SMM_DESCRIPTOR +// +#define SMM_PSD_GDTPTR 0x30 +#define SMM_PSD_GDTSIZE 0x38 + + +// +// External global variables associated with SMI Handler Template +// +extern UINT16 gPsdGdtSize; +extern UINT16 gPsdGdtPtr; + + /** Initialize IDT to setup exception handlers for SMM. =20 @@ -407,7 +432,7 @@ SmmRelocateBases ( gcSmiInitGdtr.Limit =3D gcSmiGdtr.Limit; =20 U8Ptr =3D (UINT8*)(UINTN)(SMM_DEFAULT_SMBASE + SMM_HANDLER_OFFSET); - CpuStatePtr =3D (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMR= AM_SAVE_STATE_MAP_OFFSET); + CpuStatePtr =3D (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + gSm= mSmramStateMapOffset); =20 // // Backup original contents at address 0x38000 @@ -500,6 +525,29 @@ SmmReadyToLockEventNotify ( } =20 /** + Determine if the standard CPU signature is "AuthenticAMD". + + @retval TRUE The CPU signature matches. + @retval FALSE The CPU signature does not match. + +**/ +STATIC +BOOLEAN +StandardSignatureIsAuthenticAMD ( + VOID + ) +{ + UINT32 RegEbx; + UINT32 RegEcx; + UINT32 RegEdx; + + AsmCpuid (CPUID_SIGNATURE, NULL, &RegEbx, &RegEcx, &RegEdx); + return (RegEbx =3D=3D CPUID_SIGNATURE_AUTHENTIC_AMD_EBX && + RegEcx =3D=3D CPUID_SIGNATURE_AUTHENTIC_AMD_ECX && + RegEdx =3D=3D CPUID_SIGNATURE_AUTHENTIC_AMD_EDX); +} + +/** The module Entry Point of the CPU SMM driver. =20 @param ImageHandle The firmware allocated handle for the EFI image. @@ -547,6 +595,20 @@ PiCpuSmmEntry ( ); =20 // + // Override SMRAM offsets for AMD + // + if (StandardSignatureIsAuthenticAMD ()) { + gSmmSmramStateMapOffset =3D AMD_SMRAM_SAVE_STATE_MAP_OFFSET; + gSmmPsdOffset =3D AMD_SMM_PSD_OFFSET; + } + + // + // Initialize PSD global variables associated with SMI Handler + // + gPsdGdtSize =3D gSmmPsdOffset + SMM_PSD_GDTSIZE; + gPsdGdtPtr =3D gSmmPsdOffset + SMM_PSD_GDTPTR; + + // // Fix segment address of the long-mode-switch jump // if (sizeof (UINTN) =3D=3D sizeof (UINT64)) { @@ -707,12 +769,12 @@ PiCpuSmmEntry ( =20 // // Compute tile size of buffer required to hold the CPU SMRAM Save State= Map, extra CPU - // specific context start starts at SMBASE + SMM_PSD_OFFSET, and the SMI= entry point. + // specific context start starts at SMBASE + gSmmPsdOffset, and the SMI = entry point. // This size is rounded up to nearest power of 2. // TileCodeSize =3D GetSmiHandlerSize (); TileCodeSize =3D ALIGN_VALUE(TileCodeSize, SIZE_4KB); - TileDataSize =3D (SMRAM_SAVE_STATE_MAP_OFFSET - SMM_PSD_OFFSET) + sizeof= (SMRAM_SAVE_STATE_MAP); + TileDataSize =3D (gSmmSmramStateMapOffset - gSmmPsdOffset) + sizeof (SMR= AM_SAVE_STATE_MAP); TileDataSize =3D ALIGN_VALUE(TileDataSize, SIZE_4KB); TileSize =3D TileDataSize + TileCodeSize - 1; TileSize =3D 2 * GetPowerOfTwo32 ((UINT32)TileSize); @@ -725,7 +787,7 @@ PiCpuSmmEntry ( // the SMI Handler size must be reduced or the size of the extra CPU spe= cific // context must be reduced. // - ASSERT (TileSize <=3D (SMRAM_SAVE_STATE_MAP_OFFSET + sizeof (SMRAM_SAVE_= STATE_MAP) - SMM_HANDLER_OFFSET)); + ASSERT (TileSize <=3D (gSmmSmramStateMapOffset + sizeof (SMRAM_SAVE_STAT= E_MAP) - SMM_HANDLER_OFFSET)); =20 // // Allocate buffer for all of the tiles. @@ -783,7 +845,7 @@ PiCpuSmmEntry ( for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) { mCpuHotPlugData.SmBase[Index] =3D (UINTN)Buffer + Index * Til= eSize - SMM_HANDLER_OFFSET; gSmmCpuPrivate->CpuSaveStateSize[Index] =3D sizeof(SMRAM_SAVE_STATE_MA= P); - gSmmCpuPrivate->CpuSaveState[Index] =3D (VOID *)(mCpuHotPlugData.S= mBase[Index] + SMRAM_SAVE_STATE_MAP_OFFSET); + gSmmCpuPrivate->CpuSaveState[Index] =3D (VOID *)(mCpuHotPlugData.S= mBase[Index] + gSmmSmramStateMapOffset); gSmmCpuPrivate->Operation[Index] =3D SmmCpuNone; =20 if (Index < mNumberOfCpus) { diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.h index 1cf85c1..8ad9d56 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -56,6 +56,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER= EXPRESS OR IMPLIED. #include =20 #include +#include #include =20 #include "CpuService.h" @@ -360,7 +361,21 @@ typedef struct { UINT32 MsrIndex; } MP_MSR_LOCK; =20 -#define SMM_PSD_OFFSET 0xfb00 +#define INTEL_SMM_PSD_OFFSET 0xfb00 + +// +// Definitions for AMD systems are based on contents of the +// AMD64 Architecture Programmer's Manual +// Volume 2: System Programming, Section 10 System-Management Mode +// +#define AMD_SMRAM_SAVE_STATE_MAP_OFFSET 0xfe00 +#define AMD_SMM_PSD_OFFSET 0xfc00 + +// +// External global variables for SMRAM offsets +// +extern UINT16 gSmmSmramStateMapOffset; +extern UINT16 gSmmPsdOffset; =20 /// /// All global semaphores' pointer diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c b/UefiCpuPk= g/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c index 3ad5256..8707424 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c @@ -1,13 +1,15 @@ /** @file =20 -Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
-This program and the accompanying materials -are licensed and made available under the terms and conditions of the BSD = License -which accompanies this distribution. The full text of the license may be = found at -http://opensource.org/licenses/bsd-license.php + Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2017, AMD Incorporated. All rights reserved.
=20 -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLI= ED. + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. =20 **/ =20 @@ -703,7 +705,7 @@ PatchSmmSaveStateMap ( =20 TileCodeSize =3D GetSmiHandlerSize (); TileCodeSize =3D ALIGN_VALUE(TileCodeSize, SIZE_4KB); - TileDataSize =3D (SMRAM_SAVE_STATE_MAP_OFFSET - SMM_PSD_OFFSET) + sizeof= (SMRAM_SAVE_STATE_MAP); + TileDataSize =3D (gSmmSmramStateMapOffset - gSmmPsdOffset) + sizeof (SMR= AM_SAVE_STATE_MAP); TileDataSize =3D ALIGN_VALUE(TileDataSize, SIZE_4KB); TileSize =3D TileDataSize + TileCodeSize - 1; TileSize =3D 2 * GetPowerOfTwo32 ((UINT32)TileSize); diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c b/UefiCpuPkg/PiSmmC= puDxeSmm/SmramSaveState.c index 3188d43..1f460b7 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c @@ -1,14 +1,16 @@ /** @file -Provides services to access SMRAM Save State Map + Provides services to access SMRAM Save State Map =20 -Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
-This program and the accompanying materials -are licensed and made available under the terms and conditions of the BSD = License -which accompanies this distribution. The full text of the license may be = found at -http://opensource.org/licenses/bsd-license.php + Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2017, AMD Incorporated. All rights reserved.
=20 -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLI= ED. + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. =20 **/ =20 @@ -690,7 +692,7 @@ InstallSmiHandler ( // // Initialize PROCESSOR_SMM_DESCRIPTOR // - Psd =3D (PROCESSOR_SMM_DESCRIPTOR *)(VOID *)((UINTN)SmBase + SMM_PSD_OFF= SET); + Psd =3D (PROCESSOR_SMM_DESCRIPTOR *)(VOID *)((UINTN)SmBase + gSmmPsdOffs= et); CopyMem (Psd, &gcPsd, sizeof (gcPsd)); Psd->SmmGdtPtr =3D (UINT64)GdtBase; Psd->SmmGdtSize =3D (UINT32)GdtSize; diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c b/UefiCpuPkg/PiSmmCp= uDxeSmm/X64/Semaphore.c index 6dbcb08..3f52c7a 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/Semaphore.c @@ -1,15 +1,17 @@ /** @file -Semaphore mechanism to indicate to the BSP that an AP has exited SMM -after SMBASE relocation. + Semaphore mechanism to indicate to the BSP that an AP has exited SMM + after SMBASE relocation. =20 -Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
-This program and the accompanying materials -are licensed and made available under the terms and conditions of the BSD = License -which accompanies this distribution. The full text of the license may be = found at -http://opensource.org/licenses/bsd-license.php + Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2017, AMD Incorporated. All rights reserved.
=20 -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLI= ED. + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. =20 **/ =20 @@ -51,7 +53,7 @@ SemaphoreHook ( mRebasedFlag =3D RebasedFlag; mRebasedFlagAddr32 =3D (UINT32)(UINTN)mRebasedFlag; =20 - CpuState =3D (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_= SAVE_STATE_MAP_OFFSET); + CpuState =3D (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + gSmmSm= ramStateMapOffset); mSmmRelocationOriginalAddress =3D HookReturnFromSmm ( CpuIndex, CpuState, diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.S b/UefiCpuPkg/PiSmmCpu= DxeSmm/X64/SmiEntry.S index 600d862..c3405ec 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.S +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.S @@ -1,6 +1,8 @@ #-------------------------------------------------------------------------= ----- # # Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2017, AMD Incorporated. All rights reserved.
+# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BS= D License # which accompanies this distribution. The full text of the license may b= e found at @@ -26,6 +28,9 @@ ASM_GLOBAL ASM_PFX(gSmiStack) ASM_GLOBAL ASM_PFX(gSmbase) ASM_GLOBAL ASM_PFX(mXdSupported) ASM_GLOBAL ASM_PFX(gSmiHandlerIdtr) +ASM_GLOBAL ASM_PFX(gSmmPsdOffset) +ASM_GLOBAL ASM_PFX(gPsdGdtSize) +ASM_GLOBAL ASM_PFX(gPsdGdtPtr) =20 .equ MSR_IA32_MISC_ENABLE, 0x1A0 .equ MSR_EFER, 0xc0000080 @@ -34,12 +39,13 @@ ASM_GLOBAL ASM_PFX(gSmiHandlerIdtr) # # Constants relating to PROCESSOR_SMM_DESCRIPTOR # -.equ DSC_OFFSET, 0xfb00 -.equ DSC_GDTPTR, 0x30 -.equ DSC_GDTSIZ, 0x38 -.equ DSC_CS, 14 -.equ DSC_DS, 16 -.equ DSC_SS, 18 +# .equ DSC_OFFSET, 0xfb00 +# .equ DSC_GDTPTR, 0x30 +# .equ DSC_GDTSIZ, 0x38 +# +.equ DSC_CS, 14 +.equ DSC_DS, 16 +.equ DSC_SS, 18 .equ DSC_OTHERSEG, 20 # # Constants relating to CPU State Save Area @@ -49,9 +55,9 @@ ASM_GLOBAL ASM_PFX(gSmiHandlerIdtr) =20 .equ PROTECT_MODE_CS, 0x08 .equ PROTECT_MODE_DS, 0x20 -.equ LONG_MODE_CS, 0x38 -.equ TSS_SEGMENT, 0x40 -.equ GDT_SIZE, 0x50 +.equ LONG_MODE_CS, 0x38 +.equ TSS_SEGMENT, 0x40 +.equ GDT_SIZE, 0x50 =20 .text =20 @@ -70,12 +76,12 @@ _SmiEntryPoint: # fix GDT descriptor # .byte 0x2e,0xa1 # mov ax, cs:[offset16] - .word DSC_OFFSET + DSC_GDTSIZ +ASM_PFX(gPsdGdtSize): .space 2 # .word DSC_OFFSET + DSC_GDTSIZ .byte 0x48 # dec ax .byte 0x2e movl %eax, (%rdi) # mov cs:[bx], ax .byte 0x66,0x2e,0xa1 # mov eax, cs:[offset16] - .word DSC_OFFSET + DSC_GDTPTR +ASM_PFX(gPsdGdtPtr): .space 2 # .word DSC_OFFSET + DSC_GDTPTR .byte 0x2e movw %ax, 2(%rdi) .byte 0x66,0x2e @@ -182,7 +188,11 @@ Base: LongMode: # long mode (64-bit code) starts h= ere movabsq $ASM_PFX(gSmiHandlerIdtr), %rax lidt (%rax) - lea (DSC_OFFSET)(%rdi), %ebx + + movl $ASM_PFX(gSmmPsdOffset), %ebx # lea (DSC_OFFSET)(%rdi), %= ebx + movzxw (%ebx), %rsi + leal (%rdi, %rsi), %ebx + movw DSC_DS(%rbx), %ax movl %eax,%ds movw DSC_OTHERSEG(%rbx), %ax diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.asm b/UefiCpuPkg/PiSmmC= puDxeSmm/X64/SmiEntry.asm index c74f82a..72eeb1a 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.asm +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.asm @@ -1,5 +1,7 @@ ;-------------------------------------------------------------------------= ----- ; ; Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+; Copyright (c) 2017, AMD Incorporated. All rights reserved.
+; ; This program and the accompanying materials ; are licensed and made available under the terms and conditions of the BS= D License ; which accompanies this distribution. The full text of the license may b= e found at @@ -31,6 +33,10 @@ EXTERNDEF gSmiStack:DWORD EXTERNDEF gSmbase:DWORD EXTERNDEF mXdSupported:BYTE EXTERNDEF gSmiHandlerIdtr:FWORD +EXTERNDEF gSmmPsdOffset:WORD +EXTERNDEF gPsdGdtSize:WORD +EXTERNDEF gPsdGdtPtr:WORD + =20 MSR_IA32_MISC_ENABLE EQU 1A0h MSR_EFER EQU 0c0000080h @@ -39,9 +45,10 @@ MSR_EFER_XD EQU 0800h ; ; Constants relating to PROCESSOR_SMM_DESCRIPTOR ; -DSC_OFFSET EQU 0fb00h -DSC_GDTPTR EQU 30h -DSC_GDTSIZ EQU 38h +: DSC_OFFSET EQU 0fb00h +; DSC_GDTPTR EQU 30h +; DSC_GDTSIZ EQU 38h +; DSC_CS EQU 14 DSC_DS EQU 16 DSC_SS EQU 18 @@ -73,12 +80,12 @@ _SmiEntryPoint: DW offset _GdtDesc - _SmiEntryPoint + 8000h ; bx =3D GdtDesc off= set ; fix GDT descriptor DB 2eh, 0a1h ; mov ax, cs:[offset16] - DW DSC_OFFSET + DSC_GDTSIZ +gPsdGdtSize DW ? ; DSC_OFFSET + DSC_GDTSIZ DB 48h ; dec ax DB 2eh mov [rdi], eax ; mov cs:[bx], ax DB 66h, 2eh, 0a1h ; mov eax, cs:[offset16] - DW DSC_OFFSET + DSC_GDTPTR +gPsdGdtPtr DW ? ; DSC_OFFSET + DSC_GDTPTR DB 2eh mov [rdi + 2], ax ; mov cs:[bx + 2], eax DB 66h, 2eh @@ -177,7 +184,10 @@ Base: @LongMode: ; long mode (64-bit code) starts h= ere mov rax, offset gSmiHandlerIdtr lidt fword ptr [rax] - lea ebx, [rdi + DSC_OFFSET] + + movzx rsi, word ptr [gSmmPsdOffset] ; lea ebx, [rdi + DSC_OFFS= ET] + lea ebx, [rdi + rsi] ; + mov ax, [rbx + DSC_DS] mov ds, eax mov ax, [rbx + DSC_OTHERSEG] diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm b/UefiCpuPkg/PiSmm= CpuDxeSmm/X64/SmiEntry.nasm index c3c094f..3a841c9 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm @@ -1,5 +1,7 @@ ;-------------------------------------------------------------------------= ----- ; ; Copyright (c) 2016, Intel Corporation. All rights reserved.
+; Copyright (c) 2017, AMD Incorporated. All rights reserved.
+; ; This program and the accompanying materials ; are licensed and made available under the terms and conditions of the BS= D License ; which accompanies this distribution. The full text of the license may b= e found at @@ -29,12 +31,13 @@ ; ; Constants relating to PROCESSOR_SMM_DESCRIPTOR ; -%define DSC_OFFSET 0xfb00 -%define DSC_GDTPTR 0x30 -%define DSC_GDTSIZ 0x38 -%define DSC_CS 14 -%define DSC_DS 16 -%define DSC_SS 18 +; %define DSC_OFFSET 0xfb00 +; %define DSC_GDTPTR 0x30 +; %define DSC_GDTSIZ 0x38 +; +%define DSC_CS 14 +%define DSC_DS 16 +%define DSC_SS 18 %define DSC_OTHERSEG 20 ; ; Constants relating to CPU State Save Area @@ -44,9 +47,9 @@ =20 %define PROTECT_MODE_CS 0x8 %define PROTECT_MODE_DS 0x20 -%define LONG_MODE_CS 0x38 -%define TSS_SEGMENT 0x40 -%define GDT_SIZE 0x50 +%define LONG_MODE_CS 0x38 +%define TSS_SEGMENT 0x40 +%define GDT_SIZE 0x50 =20 extern ASM_PFX(SmiRendezvous) extern ASM_PFX(gSmiHandlerIdtr) @@ -60,6 +63,10 @@ global ASM_PFX(gSmiCr3) global ASM_PFX(gcSmiHandlerTemplate) global ASM_PFX(gcSmiHandlerSize) =20 +extern ASM_PFX(gSmmPsdOffset) +global ASM_PFX(gPsdGdtSize) +global ASM_PFX(gPsdGdtPtr) + DEFAULT REL SECTION .text =20 @@ -67,10 +74,18 @@ BITS 16 ASM_PFX(gcSmiHandlerTemplate): _SmiEntryPoint: mov bx, _GdtDesc - _SmiEntryPoint + 0x8000 - mov ax,[cs:DSC_OFFSET + DSC_GDTSIZ] + + mov eax, ASM_PFX(gPsdGdtSize) ; mov ax, [cs:DSC_OFFSET + D= SC_GDTSIZ] + mov si, [cs:eax] ; + mov ax, [cs:si] ; + dec ax mov [cs:bx], ax - mov eax, [cs:DSC_OFFSET + DSC_GDTPTR] + + mov eax, ASM_PFX(gPsdGdtPtr) ; mov eax, [cs:DSC_OFFSET + = DSC_GDTPTR] + mov si, [cs:eax] ; + mov eax, [cs:si] ; + mov [cs:bx + 2], eax o32 lgdt [cs:bx] ; lgdt fword ptr cs:[bx] mov ax, PROTECT_MODE_CS @@ -160,7 +175,10 @@ Base: @LongMode: ; long mode (64-bit code) starts h= ere mov rax, ASM_PFX(gSmiHandlerIdtr) lidt [rax] - lea ebx, [rdi + DSC_OFFSET] + + movzx rsi, word [ASM_PFX(gSmmPsdOffset)] ; lea ebx, [rdi + DSC_= OFFSET] + lea ebx, [rdi + rsi] + mov ax, [rbx + DSC_DS] mov ds, eax mov ax, [rbx + DSC_OTHERSEG] @@ -220,5 +238,8 @@ _SmiHandler: .1: rsm =20 +ASM_PFX(gPsdGdtSize): RESW 1 +ASM_PFX(gPsdGdtPtr) : RESW 1 + gcSmiHandlerSize DW $ - _SmiEntryPoint =20 --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel