From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 6818D74003A for ; Wed, 3 Jan 2024 00:59:26 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=3a4HVeQlQJp177dOO1JKZ+IPRDsE3eTb879ZxFkDRZo=; 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=ktJD/VfpWGaRm52acW4Kv6g8utPwA0UK1fafkPcvSLMDA64Xb58qhzigvCp5L7Cy+vjDwhcg MTnwajc4ipCDbaEXRtHNfGwSL76RWs+Y5eNlv+MYaUVtDKc4rqKiE8b66X99dKrQyW3ZsvAsSmc yhyiTu2vC9W+nEft2SvpiHjU= X-Received: by 127.0.0.2 with SMTP id EF3UYY7687511x4l8FL7WdqX; 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: JwnrYkYQNFXJd95fmH7Z9j3ex7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="ktJD/Vfp"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=foxmail.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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=0D RiscV64/RiscVMmu.S | GCC=0D RiscV64/SpeculationBarrier.S | GCC=0D + RiscV64/RiscVSwitchStack.S | GCC=0D =0D [Sources.LOONGARCH64]=0D Math64.c=0D 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 @@ =0D #include "BaseLibInternals.h"=0D =0D +/**=0D + Transfers control to a function starting with a new stack.=0D +=0D + This internal worker function transfers control to the function=0D + specified by EntryPoint using the new stack specified by NewStack,=0D + and passes in the parameters specified by Context1 and Context2.=0D + Context1 and Context2 are optional and may be NULL.=0D + The function EntryPoint must never return.=0D +=0D + @param EntryPoint The pointer to the function to enter.=0D + @param Context1 The first parameter to pass in.=0D + @param Context2 The second Parameter to pass in=0D + @param NewStack The new Location of the stack=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +InternalSwitchStackAsm (=0D + IN SWITCH_STACK_ENTRY_POINT EntryPoint,=0D + IN VOID *Context1 OPTIONAL,=0D + IN VOID *Context2 OPTIONAL,=0D + IN VOID *NewStack=0D + );=0D +=0D /**=0D Transfers control to a function starting with a new stack.=0D =0D @@ -42,12 +66,7 @@ InternalSwitchStack ( IN VA_LIST Marker=0D )=0D {=0D - BASE_LIBRARY_JUMP_BUFFER JumpBuffer;=0D + InternalSwitchStackAsm(EntryPoint, Context1, Context2, (void *)(UINTN)Ne= wStack - sizeof (VOID *));=0D =0D - JumpBuffer.RA =3D (UINTN)EntryPoint;=0D - JumpBuffer.SP =3D (UINTN)NewStack - sizeof (VOID *);=0D - JumpBuffer.S0 =3D (UINT64)(UINTN)Context1;=0D - JumpBuffer.S1 =3D (UINT64)(UINTN)Context2;=0D - LongJump (&JumpBuffer, (UINTN)-1);=0D ASSERT (FALSE);=0D }=0D 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 @@ +//------------------------------------------------------------------------= ------=0D +//=0D +// Switch Stack for RISC-V=0D +//=0D +// SPDX-License-Identifier: BSD-2-Clause-Patent=0D +//=0D +//------------------------------------------------------------------------= ------=0D +=0D +/**=0D +//=0D +// This allows the caller to switch the stack and goes to the new entry p= oint=0D +//=0D +// @param EntryPoint The pointer to the location to enter=0D +// @param Context Parameter to pass in=0D +// @param Context2 Parameter2 to pass in=0D +// @param NewStack New Location of the stack=0D +//=0D +// @return Nothing. Goes to the Entry Point passing in the new paramet= ers=0D +//=0D +VOID=0D +EFIAPI=0D +InternalSwitchStackAsm (=0D + SWITCH_STACK_ENTRY_POINT EntryPoint,=0D + VOID *Context,=0D + VOID *Context2,=0D + VOID *NewStack=0D + );=0D +**/=0D +=0D +.align 3=0D + .globl InternalSwitchStackAsm=0D +InternalSwitchStackAsm:=0D + mv ra, a0=0D + mv a0, a1=0D + mv a1, a2=0D + mv sp, a3=0D +=0D + ret=0D --=20 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- 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/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-