From nobody Wed May 15 07:52:52 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+112923+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+112923+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1703600068; cv=none; d=zohomail.com; s=zohoarc; b=BLlGdVXypeoCWj2jdQzuI6QXZyNcvQkjzkSdh1om9M8OoUG+CMOkvtZgRAvUomy57Grp8OJ+LhntkF4qnr4SyI7R8qb08FNtLghoc9EXhuOHbGRe82CNnyRqQ7jQe7uIm1BdGDzRHkxsndMuQeZARZjV41teGP0VNeOc+nbZqW4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703600068; 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=1GlD9gpr6nVb7VO9qtztb4wgudRSW/8WoGjMWj1GLlM=; b=do3UJmfjtEEvc8MYVgGmcaAc7qqOf79xE5Y0C9bdChg3QYYGyeytwy/6wYEep019Pvl9yBoZlB3YUOQAKN/+B2dC90FzcDAjhkTzaGs0uCI72rsajJV0ebXVUGZiAiP8hVGw2e8VXlk+FFuO3ki5RbfXNSO2sAO/QMuQHA6IaTg= 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+112923+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 17036000680771011.6987782119797; Tue, 26 Dec 2023 06:14:28 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=WxM+NiYyxERs9R3SDUfRlk7oMATXm9A7lR8Wd1Fmgt4=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id: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=1703600067; v=1; b=hk9UvokLP+C3U4kkj7QOnG+eNveRIIafve6+godQqBt+mmWicDGq7Zu+f/jFl+NIdqFHpCe9 0c8wCxfjdBYTAeP7AUangaqjqYUrD+HV1cONW5zIyiUm7dYg7uU/YyFK27286jrus8XtZvtjU5b UelSnaXuYckq5eBE4spLnhR8= X-Received: by 127.0.0.2 with SMTP id kGi0YY1788612x3pV2yOghR5; Tue, 26 Dec 2023 06:14:27 -0800 X-Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [52.229.168.213]) by mx.groups.io with SMTP id smtpd.web10.57558.1703495370482544576 for ; Mon, 25 Dec 2023 01:09:32 -0800 X-Received: from localhost.localdomain (unknown [123.114.53.210]) by mail (Coremail) with SMTP id AQAAfwDHr9nCRollyflSAA--.3525S2; Mon, 25 Dec 2023 17:09:23 +0800 (CST) From: =?UTF-8?B?546L5rSL?= To: devel@edk2.groups.io, sunilvl@ventanamicro.com Cc: Yang Wang , Ran Wang , Bamvor Jian ZHANG , Andrei Warkentin , Liming Gao , Michael D Kinney , Zhiguang Liu Subject: [edk2-devel] [Resend][PATCH] MdePkg/BaseLib:Fix boot DxeCore hang on riscv platform Date: Mon, 25 Dec 2023 17:09:20 +0800 Message-Id: MIME-Version: 1.0 X-CM-TRANSID: AQAAfwDHr9nCRollyflSAA--.3525S2 X-Coremail-Antispam: 1UD129KBjvJXoWxuryrWr4UAFyxZF1fZw1fZwb_yoW5tr4rpr WfC343trnxGr4avw13Xa15tr93tFsYqw1DGrs0yr1rtr1qyF9agw4Utr1rXryYkryxGw45 Ar4UKw4v9as3A37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkS14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r1j6r1xM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4j6r 4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE14v_GFWl 42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJV WUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAK I48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F 4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY 6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUOOzVUUUUU X-CM-SenderInfo: 5zdqw5hdqjquxrvfhtffof0/ 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,wangyang@bosc.ac.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: iLIwgNTFpsimuC2IJVTBfM31x1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1703600068932100025 Content-Type: text/plain; charset="utf-8" For scene of HandOffToDxeCore()->SwitchStack(DxeCoreEntryPoint)-> InternalSwitchStack()->LongJump(),Variable HobList.Raw will be passed (from *Context1 to register a0) to DxeMain() in parameter *HobStart. However, meanwhile the function LongJump() overrides register a0 with a1 (-1) due to commit (ea628f28e5 "RISCV: Fix InternalLongJump to return correct value"), then cause hang. Replacing calling LongJump() with new InternalSwitchStackAsm() to pass addres data in register s0 to register a0 could fix this issue (just like the solution in MdePkg/Library/BaseLib/LoongArch64/SwitchStack.S) Signed-off-by: Yang Wang Reviewed-by: Ran Wang Cc: Bamvor Jian ZHANG Cc: Andrei Warkentin Cc: Liming Gao Cc: Michael D Kinney Cc: Sunil V L Cc: Zhiguang Liu --- .../BaseLib/RiscV64/InternalSwitchStack.c | 7 +++- MdePkg/Library/BaseLib/RiscV64/SwitchStack.S | 40 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 MdePkg/Library/BaseLib/RiscV64/SwitchStack.S diff --git a/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c b/MdePkg/= Library/BaseLib/RiscV64/InternalSwitchStack.c index b78424c163..c60fbdb896 100644 --- a/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c +++ b/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c @@ -8,6 +8,11 @@ =20 #include "BaseLibInternals.h" =20 +UINTN +EFIAPI +InternalSwitchStackAsm ( + IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer + ); /** Transfers control to a function starting with a new stack. =20 @@ -48,6 +53,6 @@ InternalSwitchStack ( JumpBuffer.SP =3D (UINTN)NewStack - sizeof (VOID *); JumpBuffer.S0 =3D (UINT64)(UINTN)Context1; JumpBuffer.S1 =3D (UINT64)(UINTN)Context2; - LongJump (&JumpBuffer, (UINTN)-1); + InternalSwitchStackAsm (&JumpBuffer); ASSERT (FALSE); } diff --git a/MdePkg/Library/BaseLib/RiscV64/SwitchStack.S b/MdePkg/Library/= BaseLib/RiscV64/SwitchStack.S new file mode 100644 index 0000000000..59b8d60e7e --- /dev/null +++ b/MdePkg/Library/BaseLib/RiscV64/SwitchStack.S @@ -0,0 +1,40 @@ +//------------------------------------------------------------------------= ------ +// +// InternalSwitchStackAsm for RISC-V +// +// Copyright (c) 2023, Bosc Corporation. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +//------------------------------------------------------------------------= ------ +# define REG_S sd +# define REG_L ld +# define SZREG 8 +.align 3 + +/** + This allows the caller to switch the stack and goes to the new entry poi= nt + + @param JumpBuffer A pointer to CPU context buffer. +**/ + + .globl InternalSwitchStackAsm +InternalSwitchStackAsm: + REG_L ra, 0*SZREG(a0) + REG_L s0, 1*SZREG(a0) + REG_L s1, 2*SZREG(a0) + REG_L s2, 3*SZREG(a0) + REG_L s3, 4*SZREG(a0) + REG_L s4, 5*SZREG(a0) + REG_L s5, 6*SZREG(a0) + REG_L s6, 7*SZREG(a0) + REG_L s7, 8*SZREG(a0) + REG_L s8, 9*SZREG(a0) + REG_L s9, 10*SZREG(a0) + REG_L s10, 11*SZREG(a0) + REG_L s11, 12*SZREG(a0) + REG_L sp, 13*SZREG(a0) + + add a0, s0, 0 + add a1, s1, 0 + ret --=20 2.25.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 (#112923): https://edk2.groups.io/g/devel/message/112923 Mute This Topic: https://groups.io/mt/103369620/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-