From patchwork Wed Jan 17 10:42:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1887358 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=PWuGSC6y; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=PmhbsBXl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=198.137.202.133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TFMsV2jffz23f5 for ; Wed, 17 Jan 2024 21:42:53 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FAql4z1IdBPu/2AHfL1jeIbnvznUvdzN925GzjiPylM=; b=PWuGSC6yLezRDe ZDYEtxOLVOL3Dw1gp3YvsphIxhyt9VhASNy1yu330/03blxuDEvRZ6E2eDKFKtnk5jHBLECj5OcAi 2EPp7Kl512D23xf81n1ly2H45RvXMkfLyUMQsGLQ7PH4X+kU6zlIFDvlvYlde1o4ccKUhoRCuWzbt 77wB5/y/Y5U/fGwjfKaCpe5Q91XRblTUhdxWVsegmRMwCtHdcJ9C5f4joApxQEaO25EwDiVKNkT6f 2/RVMG4WfYFwct4poj/u9pc+bJDTGGh59MxjrcEaC5sgEQBwJcpkJJpt8M4hB/YL6M1YB0d1mxP5U 2m4BjBVtL1fs/zXYLH1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rQ3NV-00FJps-26; Wed, 17 Jan 2024 10:42:37 +0000 Received: from m16.mail.126.com ([220.197.31.8]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rQ3NN-00FJkM-1E for opensbi@lists.infradead.org; Wed, 17 Jan 2024 10:42:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=fKTHd FUg9pdH8f80yBLV+HIOtuR/rZq1Y6XY3cdbdqY=; b=PmhbsBXlnXC5CxIuWbi1B s9D6iDaJa9GE3k/PytYLu7otOj1J/kJudGkjmGCVdGaLxwWFksKUa/HY4Dw/dfyi ssAORptvuQI6Atc9dY21czBkQMlQoI5i5KkG9ZZCO4Gd/eOSpmOKGQToHhJnj5k/ OdyakWSBw050A0LwFsSPoY= Received: from T490.lan (unknown [112.83.182.118]) by gzga-smtp-mta-g0-0 (Coremail) with SMTP id _____wC3_5cLr6dlF6RgAQ--.42458S12; Wed, 17 Jan 2024 18:42:24 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W Subject: [PATCH v3 10/10] firmware: fw_base.S: Fix arguments passing Date: Wed, 17 Jan 2024 18:42:07 +0800 Message-ID: <20240117104212.1055737-11-wxjstz@126.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240117104212.1055737-1-wxjstz@126.com> References: <20240117104212.1055737-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wC3_5cLr6dlF6RgAQ--.42458S12 X-Coremail-Antispam: 1Uf129KBjvJXoWxXF4rCr4kZw4xAr1DAF1UWrg_yoW5GrWxpF 13Ga43Kwn8J34xXa4fJF45uw4YgayrJFyvgFW2qrs3Aw17ur1fAa4rJF9Yy3yUJ34Yyw4r WF1Iyr1UC390krJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pi4CJLUUUUU= X-Originating-IP: [112.83.182.118] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBcxBoOmSQAhyLpAAAs0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240117_024229_843614_1A81BC15 X-CRM114-Status: UNSURE ( 8.32 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The previous code backed up and restored arguments many times. Now back up the arguments to s0-s4 at the entry. Calling functions that conform to the riscv calling convention will not destroy the call [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The previous code backed up and restored arguments many times. Now back up the arguments to s0-s4 at the entry. Calling functions that conform to the riscv calling convention will not destroy the callee save register. As long as s0-s4 is not used in assembly, the arguments can be guaranteed not to be destroyed. Signed-off-by: Xiang W --- firmware/fw_base.S | 51 +++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index aec683b..8117e08 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -47,27 +47,27 @@ .globl _start .globl _start_warm _start: + /* save previous arguments */ + MOV_5R s0, a0, s1, a1, s2, a2, s3, a3, s4, a4 + /* Find preferred boot HART id */ - MOV_3R s0, a0, s1, a1, s2, a2 call fw_boot_hart - add a6, a0, zero - MOV_3R a0, s0, a1, s1, a2, s2 lla t2, _fw_start /* load start */ lla t0, _link_start REG_L t0, 0(t0) /* link start */ sub t6, t2, t0 /* runtime offset */ - li a7, -1 - beq a6, a7, _try_lottery + li t1, -1 + beq a0, t1, _try_lottery /* Jump to relocation wait loop if we are not boot hart */ - bne a0, a6, _wait_relocate_copy_done + bne s0, a0, _wait_relocate_copy_done _try_lottery: /* Jump to relocation wait loop if we don't get relocation lottery */ - lla a6, _boot_status - li a7, 1 - amoswap.w a6, a7, (a6) - bnez a6, _wait_relocate_copy_done + lla a0, _boot_status + li t1, 1 + amoswap.w a0, t1, (a0) + bnez a0, _wait_relocate_copy_done #ifdef FW_PIC lla t0, __rel_dyn_start @@ -167,22 +167,23 @@ _relocate_done: call _reset_regs /* Zero-out BSS */ - lla s4, _bss_start - lla s5, _bss_end + lla t0, _bss_start + lla t1, _bss_end _bss_zero: - REG_S zero, (s4) - add s4, s4, __SIZEOF_POINTER__ - blt s4, s5, _bss_zero + REG_S zero, (t0) + add t0, t0, __SIZEOF_POINTER__ + blt t0, t1, _bss_zero /* Setup temporary trap handler */ - lla s4, _start_hang - csrw CSR_MTVEC, s4 + lla t0, _start_hang + csrw CSR_MTVEC, t0 /* Setup temporary stack */ - lla s4, _fw_end - li s5, (SBI_SCRATCH_SIZE * 2) - add sp, s4, s5 + lla t0, _fw_end + li t1, (SBI_SCRATCH_SIZE * 2) + add sp, t0, t1 + MOV_5R a0, s0, a1, s1, a2, s2, a3, s3, a4, s4 call fw_coldboot_init /* mark boot hart done */ @@ -543,23 +544,21 @@ _reset_regs: /* flush the instruction cache */ fence.i - /* Reset all registers except ra, a0, a1 and a2 */ + /* Reset all registers except ra, s0-s4 */ li sp, 0 li gp, 0 li tp, 0 li t0, 0 li t1, 0 li t2, 0 - li s0, 0 - li s1, 0 + li a0, 0 + li a1, 0 + li a2, 0 li a3, 0 li a4, 0 li a5, 0 li a6, 0 li a7, 0 - li s2, 0 - li s3, 0 - li s4, 0 li s5, 0 li s6, 0 li s7, 0