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 A660AAC13DB for ; Tue, 26 Dec 2023 14:29:08 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=osxCsC7V40ggbV+zs6SRCW1Bkyed7gyAzJMSlnT2eOw=; c=relaxed/simple; d=groups.io; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Transfer-Encoding; s=20140610; t=1703600947; v=1; b=WJKUD4WnNingrTzL5j2QgB3nKFccss3XqmXZMtEIb0RyTDkcl2aRzHp3u9XF1jy7DLJ55k+4 SpNZjmXzIrn8OAaGW/COUxmhsAgsiEsV8q0t/BWwY5/bb5bROJhDpXse6QhNl1j1OodtMBBEYt1 p+obMaFRT5OiU0qDhHi6/+xY= X-Received: by 127.0.0.2 with SMTP id fNXgYY7687511xWQVx0Ng4DO; Tue, 26 Dec 2023 06:29:07 -0800 X-Received: from mail-vk1-f180.google.com (mail-vk1-f180.google.com [209.85.221.180]) by mx.groups.io with SMTP id smtpd.web10.82461.1703600946693439171 for ; Tue, 26 Dec 2023 06:29:06 -0800 X-Received: by mail-vk1-f180.google.com with SMTP id 71dfb90a1353d-4b73593f37dso125478e0c.1 for ; Tue, 26 Dec 2023 06:29:06 -0800 (PST) X-Gm-Message-State: 58ItdpD3Hnsh0dpJTwZ9Yl4fx7686176AA= X-Google-Smtp-Source: AGHT+IEkv5rfPDEZoePubpWsDH5wirvefNODAIm7KZPTFnKNsd0gxaBchDFyO0phMV/jMcPxdBjFPL5xf9YMRNEiTJA= X-Received: by 2002:ac5:cfda:0:b0:4b6:e424:754 with SMTP id m26-20020ac5cfda000000b004b6e4240754mr2203067vkf.27.1703600945274; Tue, 26 Dec 2023 06:29:05 -0800 (PST) MIME-Version: 1.0 References: <462e947d.8a.18c8b64da71.Coremail.wangyang@bosc.ac.cn> In-Reply-To: <462e947d.8a.18c8b64da71.Coremail.wangyang@bosc.ac.cn> From: "Pedro Falcato" Date: Tue, 26 Dec 2023 14:28:53 +0000 Message-ID: Subject: Re: [edk2-devel] [PATCH] MdePkg/BaseLib:Fix boot DxeCore hang on riscv platform To: devel@edk2.groups.io, wangyang@bosc.ac.cn Cc: sunilvl@ventanamicro.com, zhiguang.liu@intel.com, michael.d.kinney@intel.com, gaoliming@byosoft.com.cn, andrei.warkentin@intel.com, wangran@bosc.ac.cn 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,pedro.falcato@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: text/plain; charset="UTF-8" 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=WJKUD4Wn; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.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 On Tue, Dec 26, 2023 at 2:14=E2=80=AFPM =E7=8E=8B=E6=B4=8B wrote: > > From f15d405067860a8087c5eb4080bc3e08ca5e0e21 Mon Sep 17 00:00:00 2001 > From: wangyang > Date: Wed, 20 Dec 2023 20:27:42 +0800 > Subject: [PATCH] MdePkg/BaseLib:Fix boot DxeCore hang on riscv platform > > 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: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/MdePk= g/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 @@ > > #include "BaseLibInternals.h" > > +UINTN > +EFIAPI > +InternalSwitchStackAsm ( > + IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer > + ); > /** > Transfers control to a function starting with a new stack. > > @@ -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/Librar= y/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 p= oint > + > + @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 > -- > 2.25.1 Please use git send-email, as per https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Development-Pr= ocess Thanks, Pedro -=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 (#112925): https://edk2.groups.io/g/devel/message/112925 Mute This Topic: https://groups.io/mt/103369616/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-