From nobody Sat May 18 04:13:24 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+113050+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+113050+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=foxmail.com ARC-Seal: i=1; a=rsa-sha256; t=1704243565; cv=none; d=zohomail.com; s=zohoarc; b=OxrxDQivd13rtUhS2gvyIBjWMPlKUfZvpLMUzAEMhZI2P6ZwOMLrxbwNPnwqmCJFHF04f8sqqOkYE/g+CAuX3W5DkFsMM8rXW93Ou3E126D6wpTvol6xl2JUTT/A3iTkp83zlk0eIHnjyHXHOZw5iyeEb4UdcdS+pWfoG8/rnIk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704243565; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=VkSKJ/Ru1Cz94k5diHA65nr/PdiZlmOmFjfcDA8Yfkc=; b=NKVCM21zXnpTgNWV3rFVRAeuh6YqLc+u/3RI/OIVs5OqWajb3f+PPAwrtB65Uv7+I6//p/bi4RuhYlxe0UobdojUYXdmPBYFxRbzSfPuvMK6+fZt0Or8YCrON39ZhVuFbG8XOF3QLgwaq2P/rSQY8vVBCAw+fva/x3NLiD0GRJs= 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+113050+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 1704243565375189.6608130389336; Tue, 2 Jan 2024 16:59:25 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=KzTe0JmnJ7Ayzi272dnANeyMDzF7OhhQAO5e7YAhEhM=; c=relaxed/simple; d=groups.io; h=Message-ID:From:To:Cc:Subject:Date:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1704243564; v=1; b=WKWzRqCatzTSSJDyIdSuVD+yyb1tZ3JftsXgcx+/KV0Qfz5xDQ10V/chSskaPUoK7CPatyGG oA16wztYnmSi9z5PasvnL00qR79uIxPiRsgZZb1TADu0idX8vtk5lRNzSnpHV2EZ3GmBvkygoi7 kReu/zI169U3DhxUMMid0g/c= X-Received: by 127.0.0.2 with SMTP id 6tURYY1788612xBVFWRCz1Ie; Tue, 02 Jan 2024 16:59:24 -0800 X-Received: from out203-205-221-209.mail.qq.com (out203-205-221-209.mail.qq.com [203.205.221.209]) by mx.groups.io with SMTP id smtpd.web11.117159.1703736979158609597 for ; Wed, 27 Dec 2023 20:16:20 -0800 X-Received: from yc-vm.localdomain ([222.212.185.241]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id 40D182A6; Thu, 28 Dec 2023 12:16:13 +0800 X-QQ-mid: xmsmtpt1703736973tv8hysi7r Message-ID: X-QQ-XMAILINFO: NafziRg7Bx694wDfbk/6l7QUDqlWCz4xcbaAF+i2FRcpuq2HghLWLENs/0uAxt R9A076sSR87PHS8By37zx9TBQMrot2WqKnFj15VOxk57hbAxevbGwS9HHdCWOb8NGn4pfd9DlXXB vsxszP2yvtewh+SKZaYnJqWvU4Sf9Y0lBGXXE2gHztpkO2DIuG2YIXGZWFbjTgye/QKHh3hl6Oxb BFcEljjFfdE3jAPELwj7fScAuVwkyBDjX2zYAtllcsvEmH7dkwwfIdfsEVyV5eWx3j14XN6p8GgJ Hir5ExJ0q3Y8hW6ISS2cVKNLdhu2I7lkF9gXUtroZsJ1JJe9rzqRwNJRg1LnvrfOGXHMtOUfOUHq 4YLs6ss0NmPg2byuU5mAHQBfU5TwZKHv0W+iExmsc2hY8yzHlV4/2bY9/RTxiUzHPAIRbsaweEl+ 8Y3i9xMu2+9QXY8icqGGe8gtayqPHIRzW1g2iOeE5Jv5vgxp+JWbIlTyTKK6O2k81Cet2Y5yINcy jjw7VQvVlVfk0zEsEbXZdD5gz6mnfJYiNr2z8Lf6ADUkfu+d7SiqFWkBelx3C4Wnsmue7wda1SrC /sz7jy7EqI1tfpnxPToGZIOabE4/eOe5DMELtlA4t0F5rCfusaXp+zanUo/o7Rr0FmqRAZTjIPSv htqzqnta8wzf9b/XRN9rhN95HkQfyfTJIQm0DfoSS0Yn7ICF+TBE0wGLMINaKGseChWGigspN+UZ gJyAh4+c8zI7/LhVQRkrEkoqu6DpccVaH21d6ebGy7z4TSunNFG9yKO76Q5GiZgW8zdB//Wu9XJH 0QLiMo/+g2ai87D7uQbw4XFHY+kE6zmYFHJPZ/uVgvLUyvW9577TRS+SzYN3h1bfjNNvqq+gxeCn aMIAVsv7h9nr7YKmEWOoHvffmLiyQkLVfqKeOyrCFwaArWnABqXSYmMmsND8vWOOPOWmCNWidYDP fq2Hk72aCbjRoS2Fu/4XeGV/jlUQXCtCAV+hQwQTXBdD5KASdzcjGJGSyA9I9q X-QQ-XMRINFO: NyFYKkN4Ny6FSmKK/uo/jdU= From: "yorange" To: devel@edk2.groups.io Cc: yorange1 Subject: [edk2-devel] [PATCH] MdePkg/BaseLib: Fix InternalSwitchStack bug for RISCV64. Date: Thu, 28 Dec 2023 12:16:09 +0800 X-OQ-MSGID: <977200758335a325524d875b69ebfa80e2134967.1703734291.git.yangcheng.work@foxmail.com> MIME-Version: 1.0 Precedence: Bulk 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,yangcheng.work@foxmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: ZXiHjYoO3b0o0SGT2l3Ezyznx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1704243566518100002 Content-Type: text/plain; charset="utf-8" From: yorange1 REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D4611 Fixed the InternalSwitchStack error of RISCV64. LongJump is no longer used for stack switch. Refer to Arm and AArch64 and use InternalSwitchStackAsm instead. Signed-off-by: yorange1 --- MdePkg/Library/BaseLib/BaseLib.inf | 1 + .../BaseLib/RiscV64/InternalSwitchStack.c | 31 ++++++++++++--- .../BaseLib/RiscV64/RiscVSwitchStack.S | 38 +++++++++++++++++++ 3 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVSwitchStack.S diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index 5338938944..10382111ef 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -405,6 +405,7 @@ RiscV64/ReadTimer.S | GCC RiscV64/RiscVMmu.S | GCC RiscV64/SpeculationBarrier.S | GCC + RiscV64/RiscVSwitchStack.S | GCC =20 [Sources.LOONGARCH64] Math64.c diff --git a/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c b/MdePkg/= Library/BaseLib/RiscV64/InternalSwitchStack.c index b78424c163..c9d92920df 100644 --- a/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c +++ b/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c @@ -8,6 +8,30 @@ =20 #include "BaseLibInternals.h" =20 +/** + Transfers control to a function starting with a new stack. + + This internal worker function transfers control to the function + specified by EntryPoint using the new stack specified by NewStack, + and passes in the parameters specified by Context1 and Context2. + Context1 and Context2 are optional and may be NULL. + The function EntryPoint must never return. + + @param EntryPoint The pointer to the function to enter. + @param Context1 The first parameter to pass in. + @param Context2 The second Parameter to pass in + @param NewStack The new Location of the stack + +**/ +VOID +EFIAPI +InternalSwitchStackAsm ( + IN SWITCH_STACK_ENTRY_POINT EntryPoint, + IN VOID *Context1 OPTIONAL, + IN VOID *Context2 OPTIONAL, + IN VOID *NewStack + ); + /** Transfers control to a function starting with a new stack. =20 @@ -42,12 +66,7 @@ InternalSwitchStack ( IN VA_LIST Marker ) { - BASE_LIBRARY_JUMP_BUFFER JumpBuffer; + InternalSwitchStackAsm(EntryPoint, Context1, Context2, (void *)(UINTN)Ne= wStack - sizeof (VOID *)); =20 - JumpBuffer.RA =3D (UINTN)EntryPoint; - JumpBuffer.SP =3D (UINTN)NewStack - sizeof (VOID *); - JumpBuffer.S0 =3D (UINT64)(UINTN)Context1; - JumpBuffer.S1 =3D (UINT64)(UINTN)Context2; - LongJump (&JumpBuffer, (UINTN)-1); ASSERT (FALSE); } diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVSwitchStack.S b/MdePkg/Lib= rary/BaseLib/RiscV64/RiscVSwitchStack.S new file mode 100644 index 0000000000..7b316dd5e5 --- /dev/null +++ b/MdePkg/Library/BaseLib/RiscV64/RiscVSwitchStack.S @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------= ------ +// +// Switch Stack for RISC-V +// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +//------------------------------------------------------------------------= ------ + +/** +// +// This allows the caller to switch the stack and goes to the new entry p= oint +// +// @param EntryPoint The pointer to the location to enter +// @param Context Parameter to pass in +// @param Context2 Parameter2 to pass in +// @param NewStack New Location of the stack +// +// @return Nothing. Goes to the Entry Point passing in the new paramet= ers +// +VOID +EFIAPI +InternalSwitchStackAsm ( + SWITCH_STACK_ENTRY_POINT EntryPoint, + VOID *Context, + VOID *Context2, + VOID *NewStack + ); +**/ + +.align 3 + .globl InternalSwitchStackAsm +InternalSwitchStackAsm: + mv ra, a0 + mv a0, a1 + mv a1, a2 + mv sp, a3 + + ret --=20 2.34.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 (#113050): https://edk2.groups.io/g/devel/message/113050 Mute This Topic: https://groups.io/mt/103494172/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-