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 934A6AC064A for ; Wed, 3 Jan 2024 03:26:04 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=SBT+vuLv+g0WuxhAJwIhdYiXE8LtUD2Qkdky/Jj59k0=; 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=1704252363; v=1; b=I4i4DQcUKgovuVJFpkLxreah0QUdWs+bl18uovZQMy8pFhogcJvD000Q4f/1rObNge4VDhoU hH7DpoMhttMY0iCPSl6BfEyqOiD116qCiQqzNlQlS2oKazclWXq8wcLpOeaCqIsCAYeHabSuPS+ POtaX6VggBoF/OSSxMP1BGZM= X-Received: by 127.0.0.2 with SMTP id IkxGYY7687511x4MK58DQD2W; Tue, 02 Jan 2024 19:26:03 -0800 X-Received: from out203-205-221-190.mail.qq.com (out203-205-221-190.mail.qq.com [203.205.221.190]) by mx.groups.io with SMTP id smtpd.web11.8296.1704252360631359680 for ; Tue, 02 Jan 2024 19:26:02 -0800 X-Received: from yc-vm.taila82bd.ts.net ([118.116.127.82]) by newxmesmtplogicsvrszc5-1.qq.com (NewEsmtp) with SMTP id 67612CA9; Wed, 03 Jan 2024 11:25:54 +0800 X-QQ-mid: xmsmtpt1704252354tu2mq05fk Message-ID: X-QQ-XMAILINFO: NMGzQWUSIfvTwT0IhcI2cr5ybUzVbeii6+Qb1aRTJ38dvzb6JXGaeM1xZ0GT4e qAPBEmy3jTOmORdnajjnvI1V3buIdJqBYCKPO7Fz4TexvY3CGIFILgqhgMQKvINdQ+cWr9UJLgdA d1gFJC8Cdm1vd2ipZ7cvrN8vGBZZu9z5S6gnLa9z6SuES1/AbHMskQYvaFipDToQXB46aIAfNwjG wVMDNn+UACpWt/4OErQR8N+cm/6bTAOGHWH6c9+cSNmV3hFjbzWrRek2g3Qyej1y8mnIRaSnOz99 h+WaJGRxbCKngiSo3UTMpWa6vS/mTIrI9uOa71oF3cyHyahvrWZzkRenAhVulgepX7eXr0A0qVnd kLuRjLs5z2kZuVwwtmSYSAScUu8uXHa/BP5YJ92DHqlBmsKQI3XCW/DDx1TJ0/XMt6Ws2YSQmWkK GJnp0DwIgs8/dvhG+DONcyJJ9KDsqv2peJrcKr9bBbmIgUDX9Udekvf6yz8K2rNIPcr6SVTk5bMA zscGVMrZ5Q5KQUCF2XS3gOxwz5dVW80a6T1i05Bf1Z6XOatxIvi4kSSCJ5y4iPvCGXlVmCBYRFog eXTZ0ds4HiWiFdpBbue1h5+qixQjqr+IWuIbjkUfGr8vynAI/w33XsBm9Q6vGbSN+w7pK8sH0Uvh M/InCINR6xj7ylCJaQ3jRZcH7obfM3txpuPkbQIKMaTjq7WFEqHER6XmaTJTfU7QcrHHNenqzIV4 UvN/Akso0Ur5udNV6fsCkWO2NJXlrBGGwKTjEzdE6/yIrFEYDQ81EeAi4PGdyMSIYWhOdMAgEzxU x5QivjVYl2LYRciPj8MxRyMqoT/2JjPUlsDpyr2ZPvcVPSPX+3huS4LQQIwo4NL4PIt2HWVjOH94 TdaNLLTgqk6NEEkRxwXnOq78LtaTwPFS7HXbhx13yvhvFUSz+pJ4F1jW4GUrXgDzG9AGVJbINn5N YzDeBoz6t4JF0PEZaAx4IaBMk54yAUTijBdzju+J0vTkejk2Xhr52BZysxkVFY3W2ffX7kE8k= X-QQ-XMRINFO: MPJ6Tf5t3I/ycC2BItcBVIA= From: "yorange" To: devel@edk2.groups.io Cc: gaoliming@byosoft.com.cn, yorange Subject: [edk2-devel] [PATCH] MdePkg/BaseLib: Fix InternalSwitchStack bug for RISCV64. Date: Wed, 3 Jan 2024 11:25:40 +0800 X-OQ-MSGID: <200892891489754b78715d8e15331564e3916c5b.1704252263.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: DcCuSUgk2uxrPwgpF5rR34xAx7686176AA= 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=I4i4DQcU; 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: yorange 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: yorange --- 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 (#113057): https://edk2.groups.io/g/devel/message/113057 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] -=-=-=-=-=-=-=-=-=-=-=-