From patchwork Sun Feb 11 16:11:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1897476 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=ufl+Ws5a; 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=HYHF49tv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::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 [IPv6:2607:7c80:54:3::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 4TXszz5TW2z23hb for ; Mon, 12 Feb 2024 03:12:14 +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=iRZSDV+woEnaEWkpqanr7cnq/Im5gbYQOmGUFUe01lY=; b=ufl+Ws5aFggAiB Pn6bxIZFczemi7njuj/bldAOLMUytPDz6pVJwsBs6/Pzj4DH732Rq4IWq9yP5/awbuZydWIoiNaYr ldvV4NACQCSSolguo5aLuCysFtTS+jKR7se/sCHQLrdFdd81k/eovT+XROmj2rm06SItwKsNzGsGR bDG+tCu5Nz3GHk55j4p2Qvg5DLmB+m+I7qBQz82CivL4ry2gdq4vnCHQL1iOrBRK27BTYLyDRuv+s nxFN3SpA45DmCQgtjuJNSP78+4LVgOmRnI1sdVecrrv6SH7mcM7oKVdNho8ba1S3DrTN308EW/gek YIMtYHlRmK8IruRZcxUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCQy-00000002zby-2a3M; Sun, 11 Feb 2024 16:12:00 +0000 Received: from m16.mail.126.com ([220.197.31.9]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCQv-00000002zaJ-3BEU for opensbi@lists.infradead.org; Sun, 11 Feb 2024 16:11:59 +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=cFanE SNgxnnF2lgpZD67AXJtvlMhR4QgciBhzcF+MQw=; b=HYHF49tvcIfTOUfOkVPyu AcPKxNbzVMsuIofbQp2x/dnimqe2npqeA/87Eo6bj04zNI91JLo8JWQlSsLAlhD6 4Tmakby6UnuiBguopyR7YADj+lY8Ilzate6APc87viU3Tbd8qFDZw7VXx1ip+bDo nEYE+LnP/+FLpp/SnuLe/g= Received: from T490.lan (unknown [36.153.54.93]) by gzga-smtp-mta-g1-1 (Coremail) with SMTP id _____wDXf23B8chlw7Q2Ag--.15450S3; Mon, 12 Feb 2024 00:11:47 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org Subject: [PATCH v4 1/8] firmware: remove copy-base relocation Date: Mon, 12 Feb 2024 00:11:25 +0800 Message-ID: <20240211161138.2538981-2-wxjstz@126.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240211161138.2538981-1-wxjstz@126.com> References: <20240211161138.2538981-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wDXf23B8chlw7Q2Ag--.15450S3 X-Coremail-Antispam: 1Uf129KBjvJXoW3JF43uw4kKry8KF47JFyUtrb_yoW3CrW7pF 4fGa47trs5G34rXr97u3Wrur4jgw4DXrWxurW29FyrA34fZrn3Za48trZ5Ja4kJ34xJw4U uFy2yr17A3W5Ar7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piG-erUUUUU= X-Originating-IP: [36.153.54.93] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBcwaBOmSQAkkjsAAAsi X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240211_081158_201275_BE4C90C9 X-CRM114-Status: GOOD ( 14.41 ) 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: Remove copy-base relocations that are no longer needed. Signed-off-by: Xiang W --- Makefile | 8 +++- README.md | 5 -- docs/firmware/fw.md | 6 --- firmware/fw_base.S | 110 ++ firmware/objects.mk | 11 ----- 5 files [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [220.197.31.9 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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_AU Message has a valid DKIM or DK signature from author's domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz(at)126.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 Remove copy-base relocations that are no longer needed. Signed-off-by: Xiang W --- Makefile | 8 +++- README.md | 5 -- docs/firmware/fw.md | 6 --- firmware/fw_base.S | 110 ++------------------------------------------ firmware/objects.mk | 11 ----- 5 files changed, 10 insertions(+), 130 deletions(-) diff --git a/Makefile b/Makefile index 680c19a..d8cffa6 100644 --- a/Makefile +++ b/Makefile @@ -179,6 +179,10 @@ CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib # Check whether the assembler and the compiler support the Zicsr and Zifencei extensions CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep "zicsr\|zifencei" > /dev/null && echo n || echo y) +ifneq ($(OPENSBI_LD_PIE),y) +$(error Your linker does not support creating PIEs, opensbi requires this.) +endif + # Build Info: # OPENSBI_BUILD_TIME_STAMP -- the compilation time stamp # OPENSBI_BUILD_COMPILER_VERSION -- the compiler version info @@ -356,7 +360,7 @@ CFLAGS += -mcmodel=$(PLATFORM_RISCV_CODE_MODEL) CFLAGS += $(RELAX_FLAG) CFLAGS += $(GENFLAGS) CFLAGS += $(platform-cflags-y) -CFLAGS += -fno-pie -no-pie +CFLAGS += -fPIE -pie CFLAGS += $(firmware-cflags-y) CPPFLAGS += $(GENFLAGS) @@ -365,6 +369,7 @@ CPPFLAGS += $(firmware-cppflags-y) ASFLAGS = -g -Wall -nostdlib ASFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls +ASFLAGS += -fpic # Optionally supported flags ifeq ($(CC_SUPPORT_SAVE_RESTORE),y) ASFLAGS += -mno-save-restore @@ -391,6 +396,7 @@ ifeq ($(OPENSBI_LD_EXCLUDE_LIBS),y) ELFFLAGS += -Wl,--exclude-libs,ALL endif ELFFLAGS += -Wl,--build-id=none +ELFFLAGS += -Wl,--no-dynamic-linker -Wl,-pie ELFFLAGS += $(platform-ldflags-y) ELFFLAGS += $(firmware-ldflags-y) diff --git a/README.md b/README.md index 73de8ea..7a24801 100644 --- a/README.md +++ b/README.md @@ -274,11 +274,6 @@ make CC=riscv64-linux-gnu-gcc LLVM=1 These variables must be passed for all the make invocations described in this document. -NOTE: Using Clang with a `riscv*-linux-gnu` GNU binutils linker has been seen -to produce broken binaries with missing relocations; it is therefore currently -recommended that this combination be avoided or *FW_PIC=n* be used to disable -building OpenSBI as a position-independent binary. - Building with timestamp and compiler info ----------------------------------------- diff --git a/docs/firmware/fw.md b/docs/firmware/fw.md index 38351c8..2f4deb5 100644 --- a/docs/firmware/fw.md +++ b/docs/firmware/fw.md @@ -69,12 +69,6 @@ parameters: argument by the prior booting stage. * **FW_FDT_PADDING** - Optional zero bytes padding to the embedded flattened device tree binary file specified by **FW_FDT_PATH** option. -* **FW_PIC** - "FW_PIC=y" generates position independent executable firmware - images. OpenSBI can run at arbitrary address with appropriate alignment. - Therefore, the original relocation mechanism ("FW_PIC=n") will be skipped. - In other words, OpenSBI will directly run at the load address without any - code movement. This option requires a toolchain with PIE support, and it - is on by default. Additionally, each firmware type as a set of type specific configuration parameters. Detailed information for each firmware type can be found in the diff --git a/firmware/fw_base.S b/firmware/fw_base.S index 09894e6..cd94f15 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -14,8 +14,7 @@ #include #include -#define BOOT_STATUS_RELOCATE_DONE 1 -#define BOOT_STATUS_BOOT_HART_DONE 2 +#define BOOT_STATUS_BOOT_HART_DONE 1 .macro MOV_3R __d0, __s0, __d1, __s1, __d2, __s2 add \__d0, \__s0, zero @@ -31,16 +30,6 @@ add \__d4, \__s4, zero .endm -/* - * If __start_reg <= __check_reg and __check_reg < __end_reg then - * jump to __pass - */ -.macro BRANGE __start_reg, __end_reg, __check_reg, __jump_lable - blt \__check_reg, \__start_reg, 999f - bge \__check_reg, \__end_reg, 999f - j \__jump_lable -999: -.endm .section .entry, "ax", %progbits .align 3 @@ -55,20 +44,19 @@ _start: li a7, -1 beq a6, a7, _try_lottery /* Jump to relocation wait loop if we are not boot hart */ - bne a0, a6, _wait_relocate_copy_done + bne a0, a6, _wait_for_boot_hart _try_lottery: /* Jump to relocation wait loop if we don't get relocation lottery */ lla a6, _relocate_lottery li a7, 1 amoadd.w a6, a7, (a6) - bnez a6, _wait_relocate_copy_done + bnez a6, _wait_for_boot_hart /* Save load address */ lla t0, _load_start lla t1, _fw_start REG_S t1, 0(t0) -#ifdef FW_PIC /* relocate the global table content */ lla t0, _link_start REG_L t0, 0(t0) @@ -90,100 +78,8 @@ _try_lottery: 3: addi t0, t0, (REGBYTES * 3) blt t0, t1, 2b - j _relocate_done -_wait_relocate_copy_done: - j _wait_for_boot_hart -#else - /* Relocate if load address != link address */ -_relocate: - lla t0, _link_start - REG_L t0, 0(t0) - lla t1, _link_end - REG_L t1, 0(t1) - lla t2, _load_start - REG_L t2, 0(t2) - beq t0, t2, _relocate_done - sub t3, t1, t0 - add t3, t3, t2 - lla t4, _relocate_done - sub t4, t4, t2 - add t4, t4, t0 - blt t2, t0, _relocate_copy_to_upper -_relocate_copy_to_lower: - ble t1, t2, _relocate_copy_to_lower_loop - lla t3, _relocate_lottery - BRANGE t2, t1, t3, _start_hang - lla t3, _boot_status - BRANGE t2, t1, t3, _start_hang - lla t3, _relocate - lla t5, _relocate_done - BRANGE t2, t1, t3, _start_hang - BRANGE t2, t1, t5, _start_hang - BRANGE t3, t5, t2, _start_hang -_relocate_copy_to_lower_loop: - REG_L t3, 0(t2) - REG_S t3, 0(t0) - add t0, t0, __SIZEOF_POINTER__ - add t2, t2, __SIZEOF_POINTER__ - blt t0, t1, _relocate_copy_to_lower_loop - jr t4 -_relocate_copy_to_upper: - ble t3, t0, _relocate_copy_to_upper_loop - lla t2, _relocate_lottery - BRANGE t0, t3, t2, _start_hang - lla t2, _boot_status - BRANGE t0, t3, t2, _start_hang - lla t2, _relocate - lla t5, _relocate_done - BRANGE t0, t3, t2, _start_hang - BRANGE t0, t3, t5, _start_hang - BRANGE t2, t5, t0, _start_hang -_relocate_copy_to_upper_loop: - add t3, t3, -__SIZEOF_POINTER__ - add t1, t1, -__SIZEOF_POINTER__ - REG_L t2, 0(t3) - REG_S t2, 0(t1) - blt t0, t1, _relocate_copy_to_upper_loop - jr t4 -_wait_relocate_copy_done: - lla t0, _fw_start - lla t1, _link_start - REG_L t1, 0(t1) - beq t0, t1, _wait_for_boot_hart - lla t2, _boot_status - lla t3, _wait_for_boot_hart - sub t3, t3, t0 - add t3, t3, t1 -1: - /* waitting for relocate copy done (_boot_status == 1) */ - li t4, BOOT_STATUS_RELOCATE_DONE - REG_L t5, 0(t2) - /* Reduce the bus traffic so that boot hart may proceed faster */ - nop - nop - nop - bgt t4, t5, 1b - jr t3 -#endif _relocate_done: - /* - * Mark relocate copy done - * Use _boot_status copy relative to the load address - */ - lla t0, _boot_status -#ifndef FW_PIC - lla t1, _link_start - REG_L t1, 0(t1) - lla t2, _load_start - REG_L t2, 0(t2) - sub t0, t0, t1 - add t0, t0, t2 -#endif - li t1, BOOT_STATUS_RELOCATE_DONE - REG_S t1, 0(t0) - fence rw, rw - /* At this point we are running from link address */ /* Reset all registers except ra, a0, a1 and a2 for boot HART */ diff --git a/firmware/objects.mk b/firmware/objects.mk index a1704c4..b2ace75 100644 --- a/firmware/objects.mk +++ b/firmware/objects.mk @@ -13,17 +13,6 @@ firmware-cflags-y += firmware-asflags-y += firmware-ldflags-y += -ifndef FW_PIC -FW_PIC := $(OPENSBI_LD_PIE) -endif - -ifeq ($(FW_PIC),y) -firmware-genflags-y += -DFW_PIC -firmware-asflags-y += -fpic -firmware-cflags-y += -fPIE -pie -firmware-ldflags-y += -Wl,--no-dynamic-linker -Wl,-pie -endif - ifdef FW_TEXT_START firmware-genflags-y += -DFW_TEXT_START=$(FW_TEXT_START) endif From patchwork Sun Feb 11 16:11:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1897479 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=D3IjtmEJ; 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=kbabVCY7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::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 [IPv6:2607:7c80:54:3::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 4TXszz55GMz23fR for ; Mon, 12 Feb 2024 03:12:14 +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=SAteDvMv34qna3fwzcuOgnXRP6cobDryNq4pnFKJwkI=; b=D3IjtmEJRTOyOV MGn646Piv1BVcSZNSJnKUzApCd40JXNNfv78bAZVVJ5ii1OQsQg1WNCroOj7Id3Zt4LJyTPEJzQR/ b2YuvzSWazTWL5AitAjtXaRS9tgqyG0Evpaz9UbD+7KwmjOFbAw70gyjQZ2nZVckZx0GFOo+lbg1y hEt2KHal0r3gWErw38lMD0CmM+hdZ9i2eqWV/4iOTg+xc+KMpjjX9MfZnrEXHv88pbX0PEsDH2bbB uaYlZM8AhE4paNDKCpKg4mNVO5pZCjtxwVDae5YO1CGy1I/oFutAgaDzG6EO6Dxu8HDObKpIoy/iQ 4O+qu5nmr47YFrPvYxzg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCR2-00000002zdl-0IY5; Sun, 11 Feb 2024 16:12:04 +0000 Received: from m16.mail.126.com ([220.197.31.6]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCQw-00000002zaT-2Jiv for opensbi@lists.infradead.org; Sun, 11 Feb 2024 16:12:01 +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=ICkMx s17k4ULtB9IlIGkUtV6O9lEtQYzm4HxnZOr+Zw=; b=kbabVCY7DS2fyQsCF7WOc 3e9kBHLdYci/4O46AERlZU9COGU6sW8QP5RQGjqokmQpChvyEFFESQvRTgqNXZqK yKY1aiW8wYq80RfDkdbDZIdxTPd+yepALISvY5eE4ooc6/v5ABRAPvDC7wyRdev5 1za29cC7qRsrev4Z1V3Z8Y= Received: from T490.lan (unknown [36.153.54.93]) by gzga-smtp-mta-g1-1 (Coremail) with SMTP id _____wDXf23B8chlw7Q2Ag--.15450S4; Mon, 12 Feb 2024 00:11:48 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org Subject: [PATCH v4 2/8] firmware: fw_base.S: Simplify address get Date: Mon, 12 Feb 2024 00:11:26 +0800 Message-ID: <20240211161138.2538981-3-wxjstz@126.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240211161138.2538981-1-wxjstz@126.com> References: <20240211161138.2538981-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wDXf23B8chlw7Q2Ag--.15450S4 X-Coremail-Antispam: 1Uf129KBjvdXoWruF4kXF17Jr1rCF47ur4rZrb_yoWDWwc_AF WIkFyxG3WFvr45Ww1xGr1fJr1YyrW8Wa40vF4fA3yxJr17CayjqF4UZF4DXr9FqF43KrZr ZFnrJFs7Kwn29jkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7sRCHq2PUUUUU== X-Originating-IP: [36.153.54.93] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBcwaBOmSQAkkjsQAAsj X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240211_081158_952610_B316FA6F X-CRM114-Status: UNSURE ( 5.38 ) 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: Simplify address get. Remove _link_start _link_end _load_start. Signed-off-by: Xiang W --- firmware/fw_base.S | 16 ++ 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index cd94f15..d418041 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -52,15 +52,9 @@ _try_lottery: amoadd.w a6, a7, (a6) bnez a6, _wa [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [220.197.31.6 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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_AU Message has a valid DKIM or DK signature from author's domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz(at)126.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 Simplify address get. Remove _link_start _link_end _load_start. Signed-off-by: Xiang W --- firmware/fw_base.S | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index cd94f15..d418041 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -52,15 +52,9 @@ _try_lottery: amoadd.w a6, a7, (a6) bnez a6, _wait_for_boot_hart - /* Save load address */ - lla t0, _load_start - lla t1, _fw_start - REG_S t1, 0(t0) - /* relocate the global table content */ - lla t0, _link_start - REG_L t0, 0(t0) - /* t1 shall has the address of _fw_start */ + li t0, FW_TEXT_START + lla t1, _fw_start sub t2, t1, t0 lla t0, __rel_dyn_start lla t1, __rel_dyn_end @@ -398,12 +392,6 @@ _relocate_lottery: RISCV_PTR 0 _boot_status: RISCV_PTR 0 -_load_start: - RISCV_PTR _fw_start -_link_start: - RISCV_PTR FW_TEXT_START -_link_end: - RISCV_PTR _fw_reloc_end .section .entry, "ax", %progbits .align 3 From patchwork Sun Feb 11 16:11:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1897477 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=flP8tUQm; 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=dLm1TdQw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::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 [IPv6:2607:7c80:54:3::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 4TXszz5x2Jz23yd for ; Mon, 12 Feb 2024 03:12:14 +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=oCGtJZq+SQTdQmZ3TaZhwdBWBr3Tc06lWCL6FJY/5ow=; b=flP8tUQmdCx9p7 +MCOcxbnLzjN6supbHdNcqfzUkLfrYC+N8BWPsODs3MUxc+i4UE6HZJ1Xyf6EIWgp2cAPfo0ZKSgT ALvpxr8kDGxo6+95QkzvdjDlZeNgj+UjkVGbdoZyM66g/lwgnb/KemJe1lABuI0QpVffuVeWwYNfy 12MRxabtLgTwTA9cQ8GEc4KeZl8Ew/tAj01ooctBmwais/Xuf5ROVlJtwuh0JEWCOkpk7hSjshvfq kcU96bPyQ75W/CQC8Q79nEaTFzXMSe4E9aDO0oCEgyu0NA7cIhQpEbqNJQVf1Y1mv9WRFIHwXNd2R wktUqw6ugt/EbfrsbNxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCR1-00000002zdG-1v4M; Sun, 11 Feb 2024 16:12:03 +0000 Received: from m16.mail.126.com ([220.197.31.6]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCQw-00000002zaQ-2JeV for opensbi@lists.infradead.org; Sun, 11 Feb 2024 16:12:01 +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=NOe+z 5GsUh8h4ceV/9bSVUeeJCnHpQW39ylJahuuIDc=; b=dLm1TdQwqeiOzvB9pHiGj jS413EX45ZfykhyaYCJrsnoHTQtSBWZhCGrGmJLZj8LlnHe/cYJlXutJPsWKABdD 3+CTwblX8Pn5wOhblBeTCWF9cvUCFGhlVGbc3VKYYGBx+97vCoF50KqDyGosOnge 5VQj8expf1NiVcd5zTZWCc= Received: from T490.lan (unknown [36.153.54.93]) by gzga-smtp-mta-g1-1 (Coremail) with SMTP id _____wDXf23B8chlw7Q2Ag--.15450S5; Mon, 12 Feb 2024 00:11:48 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org Subject: [PATCH v4 3/8] firmware: fw_base: Simplified setup trap handler Date: Mon, 12 Feb 2024 00:11:27 +0800 Message-ID: <20240211161138.2538981-4-wxjstz@126.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240211161138.2538981-1-wxjstz@126.com> References: <20240211161138.2538981-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wDXf23B8chlw7Q2Ag--.15450S5 X-Coremail-Antispam: 1Uf129KBjvdXoW7Xw4fZFWUKF18XF13Kr4kZwb_yoWkCFg_XF WDua4Iqr4qvrZ5X3y0kFW3Wwn5WrWF9FWFgw4DCr4jyr13tFWYgr9rJw47W3yrZ34vgryD AF4DJrZrJr92vjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRiaZX5UUUUU== X-Originating-IP: [36.153.54.93] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBcwaBOmSQAkkjsgABsh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240211_081158_999305_99623E4C X-CRM114-Status: UNSURE ( 5.26 ) 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 same detection was done twice when setting mtvec and trap_exit. Merging can reduce code size. Signed-off-by: Xiang W Reviewed-by: Anup Patel --- firmware/fw_base.S | 16 ++++ 1 file changed, 4 insertions(+), 12 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [220.197.31.6 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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_AU Message has a valid DKIM or DK signature from author's domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz(at)126.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 same detection was done twice when setting mtvec and trap_exit. Merging can reduce code size. Signed-off-by: Xiang W Reviewed-by: Anup Patel --- firmware/fw_base.S | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index d418041..f0dd0da 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -362,22 +362,14 @@ _start_warm: srli a5, a5, ('H' - 'A') andi a5, a5, 0x1 beq a5, zero, _skip_trap_handler_rv32_hyp - lla a4, _trap_handler_rv32_hyp -_skip_trap_handler_rv32_hyp: -#endif - csrw CSR_MTVEC, a4 - -#if __riscv_xlen == 32 /* Override trap exit for H-extension */ - csrr a5, CSR_MISA - srli a5, a5, ('H' - 'A') - andi a5, a5, 0x1 - beq a5, zero, _skip_trap_exit_rv32_hyp - lla a4, _trap_exit_rv32_hyp csrr a5, CSR_MSCRATCH + lla a4, _trap_exit_rv32_hyp REG_S a4, SBI_SCRATCH_TRAP_EXIT_OFFSET(a5) -_skip_trap_exit_rv32_hyp: + lla a4, _trap_handler_rv32_hyp +_skip_trap_handler_rv32_hyp: #endif + csrw CSR_MTVEC, a4 /* Initialize SBI runtime */ csrr a0, CSR_MSCRATCH From patchwork Sun Feb 11 16:11:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1897481 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=ndCHUESz; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=c1dp2DBH; 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=iHX2yq/2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::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 [IPv6:2607:7c80:54:3::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 4TXt031FLJz23nM for ; Mon, 12 Feb 2024 03:12:19 +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=g4ALKiScGEcaqo3Zq2G483qdlRT77+M5+nQ61EnwtL0=; b=ndCHUESzPByeBg 4aDbNjNlniOuUCdWowKpb7j19FeIWPCSrYQEH+HdzjXFFKXshrC+y4XWyZDvN5wBwSN6bfTyjkFYP NwojG1Gr1lGeK4E+DPOJ1GOysQMXVYB+zZjRC0V/AP0yhLVw9X5vdlv1obD7gbuS0gi21Vgr+T2eL F+tVjggxnXv85wQvSVNTRVwWJwx2DiWXEdXDFP0H4zVc+PUL58g8L+/349ZRTqISrYlTcThm9vMLH mX3T/HShcoVuqcNG3AAsWa3THQJlyf9UwA/XYCL1GASgp8OIa03kAbUgZ8rHHLVUtH6DBPm3uE2x4 Bo+NazyrcdMZSzF/wnAA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCR9-00000002ziu-3pfj; Sun, 11 Feb 2024 16:12:11 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCR6-00000002zge-3v2Q for opensbi@bombadil.infradead.org; Sun, 11 Feb 2024 16:12:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=sZHWapsaM2AZosz4o9OgWfrec+EioHB4imdxRCoCOYw=; b=c1dp2DBHHK/Nmw+2yLKA+RJ0oV vbzkfJBMDC/HW54RuKOjEcVjmW0bh7oT55Ia/PGs7msZsRddUizodpDTDkv0xCb+EJYeoHyHcv9OG wu4fipEwFh1RomyZIj7u96gflYsmQK66h4RfDp6IOMao/YDsjulD9DvhRnVnGQhSosJ08TncmegPU n1SV/BLFRRO1u+O59AmowZ9Zudsp0AT3rTYTqbCW6IDNdtwuj4EEFB/dnWQjX+mucs96U+PGonbmN GCLLH0wGkWh9v5TUO3fI/VSlYc3uxnd4lOlzMDdgmoWjSs2pfwTAHZGf+Cz3lU6D8X4WlAP8fwtGo ZZNzmzhQ==; Received: from m16.mail.126.com ([117.135.210.8]) by desiato.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCR2-0000000EsTR-4BVL for opensbi@lists.infradead.org; Sun, 11 Feb 2024 16:12:07 +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=sZHWa psaM2AZosz4o9OgWfrec+EioHB4imdxRCoCOYw=; b=iHX2yq/2rshamBaN7mFXj 6f8raQ3jECkpNdgCjjhuUc2hjfmVKBK/HjgKV5T7i0Qvc/jarEaHKvfBYab+r9GT Xtv9uwu2sVplAHW7zmvqU80K/PaQ3fMNQNTpJnU51UffiXd9ovBORrL1Uspx5YuQ 9rjhpVagbivULdn30+y7Q4= Received: from T490.lan (unknown [36.153.54.93]) by gzga-smtp-mta-g1-1 (Coremail) with SMTP id _____wDXf23B8chlw7Q2Ag--.15450S6; Mon, 12 Feb 2024 00:11:49 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org Subject: [PATCH v4 4/8] firmware: fw_dynamic.S: Remove _bad_dynamic_info Date: Mon, 12 Feb 2024 00:11:28 +0800 Message-ID: <20240211161138.2538981-5-wxjstz@126.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240211161138.2538981-1-wxjstz@126.com> References: <20240211161138.2538981-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wDXf23B8chlw7Q2Ag--.15450S6 X-Coremail-Antispam: 1Uf129KBjvdXoWrZw17uw1rJF1Dur1ruryrCrg_yoWDCrc_AF y3uFnxCr4FvrWrta109r1rCw1xZF97ua1qg3WxCw4UXr13J343Xrn5CFW2qr4v9a10kr45 AF17CrnIyFn7ujkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7sRAMa07UUUUU== X-Originating-IP: [36.153.54.93] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBdRSBOmSdLxQBHwABsH X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240211_161205_860949_0D60F531 X-CRM114-Status: UNSURE ( 5.48 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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: _bad_dynamic_info is same as _start_hang, so remove it. Signed-off-by: Xiang W Reviewed-by: Anup Patel --- firmware/fw_dynamic.S | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/firmware/fw_dynamic.S b/firmware/fw_dynamic.S index 7ff1c6a..5ee2883 100644 --- a/firmware/fw_dynamic.S +++ b/firmware/fw_dynamic.S @@ -11,12 +11,6 @@ Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz(at)126.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 _bad_dynamic_info is same as _start_hang, so remove it. Signed-off-by: Xiang W Reviewed-by: Anup Patel --- firmware/fw_dynamic.S | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/firmware/fw_dynamic.S b/firmware/fw_dynamic.S index 7ff1c6a..5ee2883 100644 --- a/firmware/fw_dynamic.S +++ b/firmware/fw_dynamic.S @@ -11,12 +11,6 @@ #include "fw_base.S" - .section .entry, "ax", %progbits - .align 3 -_bad_dynamic_info: - wfi - j _bad_dynamic_info - .section .entry, "ax", %progbits .align 3 .global fw_boot_hart @@ -30,10 +24,10 @@ fw_boot_hart: /* Sanity checks */ li a1, FW_DYNAMIC_INFO_MAGIC_VALUE REG_L a0, FW_DYNAMIC_INFO_MAGIC_OFFSET(a2) - bne a0, a1, _bad_dynamic_info + bne a0, a1, _start_hang li a1, FW_DYNAMIC_INFO_VERSION_MAX REG_L a0, FW_DYNAMIC_INFO_VERSION_OFFSET(a2) - bgt a0, a1, _bad_dynamic_info + bgt a0, a1, _start_hang /* Read boot HART id */ li a1, FW_DYNAMIC_INFO_VERSION_2 From patchwork Sun Feb 11 16:11:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1897482 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=Y6evReGA; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=AORx0/1e; 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=W9dpWBXF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::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 [IPv6:2607:7c80:54:3::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 4TXt030Jr2z23hb for ; Mon, 12 Feb 2024 03:12:18 +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=wG6AKSAe/id0Ei9GrUix9g805LO0jAz36rKZv9X7mJk=; b=Y6evReGAIQsk/o /GiccFqfKWlYCFHKN5syijSoV50szqCKOBqmIIHH+FYr2gNlz32puFxnauDjwgobjZ7TwyKR2PRjA XPihk6yGXe7CgdXr/O9MEtEea9KHID7tNnKrg+L0Vqilk/4M2hOzytgBFH5k6uMClCwe6rUlRzcO3 q3b6SlJ0POH2Ca5QugAzj0rDBwKNbpAzg1+6njgLmYq5QCt/yrRS0nHNOXpBLgNErmwaKg2EKYFpd v8ZyaHBUT4a+VCIj001U0RLo/7o1oiqQOB1OKzOqLF32lE/V97OSqmivpo+Kj3AHXUbkQfaga2bLx ZTebwjg4HXur1xXy/h5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCR9-00000002zi1-0PxW; Sun, 11 Feb 2024 16:12:11 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCR6-00000002zgV-3XaA for opensbi@bombadil.infradead.org; Sun, 11 Feb 2024 16:12:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=3N24zVmfsYL+LkGDz8crnpExC9qrRLAbwSZilN/vREs=; b=AORx0/1emjOHG15ZBh42FNVYCQ JJlP3LqzgEfALPZyInw3puhNoRprPeBUXidgeagbhucJwzioBPLJyp/CCPAEZWFmhUtv8SgZyvSdq yxRGBgmkmdkHc7BarAk8P/R+0v5EcddIAiyh1dLOLkBONXW4C0k+rrhYcOAPPYmMyRjdLGAxR+TNW Pd7v1p899QKxf524+ziUr4KBE0iQHw6U+2DJuNS5KkcsG4tnjefWw0WV5iOWoQM4TrtcEHSTjB+PZ khFTmZ8e79lcMNnUfLTn4eig2MmWXY4QpNoyenpc43FTLrUnPE0faYYRJqLt0B2cm9PmdkxA4mtvm Zv2ebg9Q==; Received: from m16.mail.126.com ([220.197.31.6]) by desiato.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCR3-0000000EsTQ-020g for opensbi@lists.infradead.org; Sun, 11 Feb 2024 16:12:07 +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=3N24z VmfsYL+LkGDz8crnpExC9qrRLAbwSZilN/vREs=; b=W9dpWBXFU6ZtncKz8sohN YCNVQP8KtoEzDptlu/EZyIdc9BFJVvotDdEemS6RsaHUmLm/394ViJDG//hmEyAx PBbB31Si8kp5RiUao4cQzmJeSf4m2bRmjpcw1tcf2Z236eGGuoIB6axBRejBjeD9 hXitUFJ2HthYpa9gvqP5zU= Received: from T490.lan (unknown [36.153.54.93]) by gzga-smtp-mta-g1-1 (Coremail) with SMTP id _____wDXf23B8chlw7Q2Ag--.15450S7; Mon, 12 Feb 2024 00:11:50 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org Subject: [PATCH v4 5/8] firmware: fw_base.S: Remove _relocate_lottery Date: Mon, 12 Feb 2024 00:11:29 +0800 Message-ID: <20240211161138.2538981-6-wxjstz@126.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240211161138.2538981-1-wxjstz@126.com> References: <20240211161138.2538981-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wDXf23B8chlw7Q2Ag--.15450S7 X-Coremail-Antispam: 1Uf129KBjvdXoWrKFyUZw1fuFykJFW7WFWxZwb_yoWDZFX_A3 W2ka4kGFWkXFZ8tr4rCr1fJr1YkrZ5u3WfuFsrA39IyF17C3yfuF4UZ3yDX395WFsFgFZ0 vFZ7trsrZw1I9jkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7sRKID7PUUUUU== X-Originating-IP: [36.153.54.93] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBdQaBOmSdLxQKIAAAsg X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240211_161205_845594_A0A2B586 X-CRM114-Status: UNSURE ( 6.17 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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: Remove _relocate_lottery and use _boot_status instead Signed-off-by: Xiang W --- firmware/fw_base.S | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index f0dd0da..10fee4f 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -14,7 +14,8 @@ #include #include List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Remove _relocate_lottery and use _boot_status instead Signed-off-by: Xiang W --- firmware/fw_base.S | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index f0dd0da..10fee4f 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -14,7 +14,8 @@ #include #include -#define BOOT_STATUS_BOOT_HART_DONE 1 +#define BOOT_STATUS_LOTTERY_DONE 1 +#define BOOT_STATUS_BOOT_HART_DONE 2 .macro MOV_3R __d0, __s0, __d1, __s1, __d2, __s2 add \__d0, \__s0, zero @@ -47,8 +48,8 @@ _start: bne a0, a6, _wait_for_boot_hart _try_lottery: /* Jump to relocation wait loop if we don't get relocation lottery */ - lla a6, _relocate_lottery - li a7, 1 + lla a6, _boot_status + li a7, BOOT_STATUS_LOTTERY_DONE amoadd.w a6, a7, (a6) bnez a6, _wait_for_boot_hart @@ -380,8 +381,6 @@ _skip_trap_handler_rv32_hyp: .data .align 3 -_relocate_lottery: - RISCV_PTR 0 _boot_status: RISCV_PTR 0 From patchwork Sun Feb 11 16:11:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1897475 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=k/5/quIL; 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=hwxyrMA1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::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 [IPv6:2607:7c80:54:3::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 4TXszz5p7cz23nM for ; Mon, 12 Feb 2024 03:12:14 +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=6qnw0p4HCnFb/S0ld6wU4pD8gQtWAoW22IJa/bjzKzY=; b=k/5/quILyK8UuJ D8NqspvVgeN7Wh/vkpeJ2x6xUVQJVTv1WV2yXChAL2xm7mGSgOKk2RPZAHVH8dgT6PPsOQcga0oKY HWYvzUivr3qO3gQACh/kuOKEAhRzVt9ZTC7sjWhLMJXOvcYQl0szhYTmnMtHm6QKacfNVCfsvEuHX C0VjgndqX8b4Ftg6jZiyQwnPXJzPTu30PsmgzBJzjyUaMyZlP2Fe07zzpQf3bt0i570iuGEfV8LrO 75dC3UqzipVqC6yNeDivS45OstRZVj6tj9OPgMaB3zVsJHe8SBjZjF6dVsZo0jhXJLhJWYkTBFvgS vO0bTdXiL1j8fLSbi8DQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCR0-00000002zcb-3Io5; Sun, 11 Feb 2024 16:12:02 +0000 Received: from m16.mail.126.com ([220.197.31.9]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCQw-00000002zaU-1Xds for opensbi@lists.infradead.org; Sun, 11 Feb 2024 16:12:00 +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=mYqWn o6WXU73mTDMXo+vAoLKAOcLfiLkZzl/Zn6p2yM=; b=hwxyrMA16BOG2B497LyWo Aq+89t12/9w6tqn6beSzwy/8/xkUuKEafZ5BBP79Mlvwok3Y6i0ZjrJnHW9MFUJW Xe6lA22pIo5jRv689QxR4jx/yjxRXDsrkLIY94Hll6pMx4lQPK5LrTs0ZjMQC6PV s2emlNGqtR8hRCu1RUqq3A= Received: from T490.lan (unknown [36.153.54.93]) by gzga-smtp-mta-g1-1 (Coremail) with SMTP id _____wDXf23B8chlw7Q2Ag--.15450S8; Mon, 12 Feb 2024 00:11:50 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org Subject: [PATCH v4 6/8] firmware: fw_base.S: fix _reset_regs Date: Mon, 12 Feb 2024 00:11:30 +0800 Message-ID: <20240211161138.2538981-7-wxjstz@126.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240211161138.2538981-1-wxjstz@126.com> References: <20240211161138.2538981-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wDXf23B8chlw7Q2Ag--.15450S8 X-Coremail-Antispam: 1Uf129KBjvdXoW7Gr4xWF15KrykJr43AF1DJrb_yoWkCrXEvF WIyryqyrsrtFyagw1DGr1akr9Y9rWUC3yS9w4rJFZFyrWxWa18trWkur47Aa4UXw43KrWr AFy7JrZ3u3s7ujkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7sRKID7PUUUUU== X-Originating-IP: [36.153.54.93] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBdAeBOmSdLvQLxAAAsk X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240211_081158_800985_6B176F8E X-CRM114-Status: UNSURE ( 6.70 ) 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: a3 and a4 cannot be reset because used in fw_platform_init. Signed-off-by: Xiang W --- firmware/fw_base.S | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index 10fee4f..30fd616 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -77,7 +77,7 @@ _relocate_done: Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [220.197.31.9 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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_AU Message has a valid DKIM or DK signature from author's domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz(at)126.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 a3 and a4 cannot be reset because used in fw_platform_init. Signed-off-by: Xiang W --- firmware/fw_base.S | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index 10fee4f..30fd616 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -77,7 +77,7 @@ _relocate_done: /* At this point we are running from link address */ - /* Reset all registers except ra, a0, a1 and a2 for boot HART */ + /* Reset all registers except ra, a0, a1, a2, a3 and a4 for boot HART */ li ra, 0 call _reset_regs @@ -304,7 +304,7 @@ _wait_for_boot_hart: bne t0, t1, _wait_for_boot_hart _start_warm: - /* Reset all registers except ra, a0, a1 and a2 for non-boot HARTs */ + /* Reset all registers except ra, a0, a1, a2, a3 and a4 for non-boot HART */ li ra, 0 call _reset_regs @@ -655,7 +655,7 @@ _reset_regs: /* flush the instruction cache */ fence.i - /* Reset all registers except ra, a0, a1 and a2 */ + /* Reset all registers except ra, a0, a1, a2, a3 and a4 */ li sp, 0 li gp, 0 li tp, 0 @@ -664,8 +664,6 @@ _reset_regs: li t2, 0 li s0, 0 li s1, 0 - li a3, 0 - li a4, 0 li a5, 0 li a6, 0 li a7, 0 From patchwork Sun Feb 11 16:11:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1897478 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=ErezGu+N; 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=pj1GxCyA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::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 [IPv6:2607:7c80:54:3::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 4TXszz5Nnhz23fm for ; Mon, 12 Feb 2024 03:12:14 +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=zk/xVPqzv0sCVhm8zjkrhKk/8axoAnDylA1Q7kVDMUk=; b=ErezGu+N1luttd LXqB0gMT2qROUA8lnQw01dLXIur/LtBcAcUiGF7ZD5CkN61BCL8ZXxZFu7+ie+TtUGSxw+J1OjsKd DXe1K/UbsaBrlWKURTWNP+9Nla/gVH9jT4EOTwaBE6pLikuXESc4PkwdVsUUojXGMVItkZjbpjmIN 5PhP3Epb8UZNzI+FOg9SrA9B6FRTpB2NTX82WXJwnT3n6OwvnnqJ5t0C72nezs+UjdvycXCC3VuiE dGHaa+5fShHUi1UBT6c5f5Yc0k5Cz2WwbxHNZwFw6eRLxz9CS6HgkKnrRH4VsW/FrOk7mHDRnNL0O /sGDxXdzKJmNVHo6ozTg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCR3-00000002zej-44p2; Sun, 11 Feb 2024 16:12:05 +0000 Received: from m16.mail.126.com ([117.135.210.7]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCR0-00000002zbm-1JlS for opensbi@lists.infradead.org; Sun, 11 Feb 2024 16:12:04 +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=0owT+ Kno5Y6lFCMysYweXqIohX8Ufqa2oBZT44+snlQ=; b=pj1GxCyAeVrA+6DZF21jZ ZNJwozxHW4l48hjLzwfyIUad5mI/kZUlTWuFrv35/nJJMn1gSFDjReA7faysGYTs m//27jbmeAKdjkCtuIcP2+cFTttj8R1wDTbDWpVlTp1yGCwjWDAPNGOv+o1gjHDl Y7H8+DBHX+Lu+rec5Hs1iU= Received: from T490.lan (unknown [36.153.54.93]) by gzga-smtp-mta-g1-1 (Coremail) with SMTP id _____wDXf23B8chlw7Q2Ag--.15450S9; Mon, 12 Feb 2024 00:11:51 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org Subject: [PATCH v4 7/8] firmware: Improve fw_boot_hart Date: Mon, 12 Feb 2024 00:11:31 +0800 Message-ID: <20240211161138.2538981-8-wxjstz@126.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240211161138.2538981-1-wxjstz@126.com> References: <20240211161138.2538981-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wDXf23B8chlw7Q2Ag--.15450S9 X-Coremail-Antispam: 1Uf129KBjvJXoWxZF4fAryrAFW5WF48Gr1kGrg_yoW5ZFW3pr 13Gay2vw4vg34rXrnrGFWUuFW5uF1SyFZrW3y2kF1kAry7Arn5JayDKFs5t343JFykAw4f XFyIyF4jkF12krJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piqg4-UUUUU= X-Originating-IP: [36.153.54.93] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBdQmBOmSdLxQKIgAAst X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240211_081202_891695_2A6536F0 X-CRM114-Status: UNSURE ( 7.31 ) 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: Improve fw_boot_hart to reduce parameter saving and restoration. Signed-off-by: Xiang W --- firmware/fw_base.S | 7 ++----- firmware/fw_dynamic.S | 24 ++++++++++++ firmware/fw_jump.S | 6 +++--- firmware/fw_payload.S | 6 +++--- 4 files changed, 20 inser [...] 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.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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_AU Message has a valid DKIM or DK signature from author's domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz(at)126.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 Improve fw_boot_hart to reduce parameter saving and restoration. Signed-off-by: Xiang W --- firmware/fw_base.S | 7 ++----- firmware/fw_dynamic.S | 24 ++++++++++++------------ firmware/fw_jump.S | 6 +++--- firmware/fw_payload.S | 6 +++--- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index 30fd616..4de053f 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -38,14 +38,11 @@ .globl _start_warm _start: /* 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 li a7, -1 - beq a6, a7, _try_lottery + beq t0, a7, _try_lottery /* Jump to relocation wait loop if we are not boot hart */ - bne a0, a6, _wait_for_boot_hart + bne a0, t0, _wait_for_boot_hart _try_lottery: /* Jump to relocation wait loop if we don't get relocation lottery */ lla a6, _boot_status diff --git a/firmware/fw_dynamic.S b/firmware/fw_dynamic.S index 5ee2883..52ef320 100644 --- a/firmware/fw_dynamic.S +++ b/firmware/fw_dynamic.S @@ -17,24 +17,24 @@ /* * This function is called very early even before * fw_save_info() is called. - * We can only use a0, a1, and a2 registers here. - * The boot HART id should be returned in 'a0'. + * We can only use t0, t1, and t2 registers here. + * The boot HART id should be returned in 't0'. */ fw_boot_hart: /* Sanity checks */ - li a1, FW_DYNAMIC_INFO_MAGIC_VALUE - REG_L a0, FW_DYNAMIC_INFO_MAGIC_OFFSET(a2) - bne a0, a1, _start_hang - li a1, FW_DYNAMIC_INFO_VERSION_MAX - REG_L a0, FW_DYNAMIC_INFO_VERSION_OFFSET(a2) - bgt a0, a1, _start_hang + li t1, FW_DYNAMIC_INFO_MAGIC_VALUE + REG_L t0, FW_DYNAMIC_INFO_MAGIC_OFFSET(a2) + bne t0, t1, _start_hang + li t1, FW_DYNAMIC_INFO_VERSION_MAX + REG_L t0, FW_DYNAMIC_INFO_VERSION_OFFSET(a2) + bgt t0, t1, _start_hang /* Read boot HART id */ - li a1, FW_DYNAMIC_INFO_VERSION_2 - blt a0, a1, 2f - REG_L a0, FW_DYNAMIC_INFO_BOOT_HART_OFFSET(a2) + li t1, FW_DYNAMIC_INFO_VERSION_2 + blt t0, t1, 2f + REG_L t0, FW_DYNAMIC_INFO_BOOT_HART_OFFSET(a2) ret -2: li a0, -1 +2: li t0, -1 ret .section .entry, "ax", %progbits diff --git a/firmware/fw_jump.S b/firmware/fw_jump.S index ac74dc6..1775fcd 100644 --- a/firmware/fw_jump.S +++ b/firmware/fw_jump.S @@ -15,11 +15,11 @@ /* * This function is called very early even before * fw_save_info() is called. - * We can only use a0, a1, and a2 registers here. - * The boot HART id should be returned in 'a0'. + * We can only use t0, t1, and t2 registers here. + * The boot HART id should be returned in 't0'. */ fw_boot_hart: - li a0, -1 + li t0, -1 ret .section .entry, "ax", %progbits diff --git a/firmware/fw_payload.S b/firmware/fw_payload.S index c53a3bb..985f833 100644 --- a/firmware/fw_payload.S +++ b/firmware/fw_payload.S @@ -15,11 +15,11 @@ /* * This function is called very early even before * fw_save_info() is called. - * We can only use a0, a1, and a2 registers here. - * The boot HART id should be returned in 'a0'. + * We can only use t0, t1, and t2 registers here. + * The boot HART id should be returned in 't0'. */ fw_boot_hart: - li a0, -1 + li t0, -1 ret .section .entry, "ax", %progbits From patchwork Sun Feb 11 16:11:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1897483 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=n55aMrA6; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=BoWtBK1A; 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=J3cJ5y7V; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::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 [IPv6:2607:7c80:54:3::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 4TXt050Zgfz23f7 for ; Mon, 12 Feb 2024 03:12:21 +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=xWM7uqK3TYA+CnzlMXdKTUWWrLUeRoaJBQLXam7dBww=; b=n55aMrA6THRDIR U0hdKyXHBcbPHcVlVkeV3DZccH5+4Dwz0K7KMfuuHtRqLFFTLvgaJ6WJ11l5Y9YHd5Cxnr8ySO15l TYVdmoCIyIgi46Q7AvJnAjpgsTb31xwJsvKWuHPghBERxu/94QYTKRWTtPFtI00s/Xc6Alhi7OOVt LOwkJQKfBmnsb4fIojHfQRUzTyFE9lmDsdgtMuwsMiWB/zSMg2+T3HQMyqF413dCG2HEAZO8fRJR2 nkAwtB5JMvGGmnP57i0mA66VSmJbuznBNe2902Clz9maB0gAEpTA/7Od2R1s1pY27l8Ri9QRAGA/h kPJfTckGXP5WGVsIVsgg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCRB-00000002zkL-1zco; Sun, 11 Feb 2024 16:12:13 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCR8-00000002zhS-1eRW for opensbi@bombadil.infradead.org; Sun, 11 Feb 2024 16:12:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=0ktkXyTteCUOcFWQgUCqrObwfVKSVkZdF0i9QCltC8s=; b=BoWtBK1AIGq+tcnhW7KTot+PX1 PcX+44TtWjeceqizCZfTyMFi+fUXWb2CJxxcEzay9mll4tPKYKdZrWNzLOYA/tOohfNa7n0OiaZ22 ISWjJxgZHiHFYUtW/V+hqrgsyT05bIxfbnuHWp2004v5X6l8z3AEZLgqDavhBVU9SX6sQlDrYiO8i D4Qj6hjG4U5mh85N1fAfUF+HNxyEuCi3rERPFxUmyNm8Ji7kSAKz1YQlKpzh6ICW9AGeWWJlGAzHi cKtA5XUq9IJne1r6bHw2lh2okgTpgSHhCzbDppeIxpFdMngOIEdxZIypChJy8JokTb1QkysMZbZkA xUKUS1Bw==; Received: from m16.mail.126.com ([220.197.31.8]) by desiato.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZCR2-0000000EsTS-40UF for opensbi@lists.infradead.org; Sun, 11 Feb 2024 16:12:09 +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=0ktkX yTteCUOcFWQgUCqrObwfVKSVkZdF0i9QCltC8s=; b=J3cJ5y7Vsczr04choo1RG vLed6g4zPufHCmQWNXh0v4XANFNiLsY4VSl+CN9VT40xwhxRHJ9oPECRAq9IqU/D wNOVYyXB8lj7X98SjhV31s6EfU1uJy/psM+W2dYrX2GU/01yLINmGeBQfyzjYAg7 rgIbLAeP9JzUPteKuhoiqU= Received: from T490.lan (unknown [36.153.54.93]) by gzga-smtp-mta-g1-1 (Coremail) with SMTP id _____wDXf23B8chlw7Q2Ag--.15450S10; Mon, 12 Feb 2024 00:11:51 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org Subject: [PATCH v4 8/8] firmware: Use C if possible Date: Mon, 12 Feb 2024 00:11:32 +0800 Message-ID: <20240211161138.2538981-9-wxjstz@126.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240211161138.2538981-1-wxjstz@126.com> References: <20240211161138.2538981-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wDXf23B8chlw7Q2Ag--.15450S10 X-Coremail-Antispam: 1Uf129KBjvAXoWfGr18Xr1DKrW5Ww18urykXwb_yoW8CrW5Ko Wavan7C3WkKws3Wws0yr18WFy7XFWUWrn3Ar4xZw13CFyqqa4293Wrtwn3WFsIyF15Kryk XryIy3WkGa1xtFyfn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjTRP3kZDUUUU X-Originating-IP: [36.153.54.93] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBdQmBOmSdLxQKIgABss X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240211_161205_956384_97EBA13E X-CRM114-Status: GOOD ( 19.89 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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: Use C as soon as possible after setting up the stack. Signed-off-by: Xiang W --- Makefile | 10 +- firmware/fw.c | 101 +++++++++++++++++++ firmware/fw_base.S | 209 + firmware/fw_dynamic.S | 25 ++--- firmware/fw_jum [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz(at)126.com] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [220.197.31.8 listed in list.dnswl.org] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 Use C as soon as possible after setting up the stack. Signed-off-by: Xiang W --- Makefile | 10 +- firmware/fw.c | 101 +++++++++++++++++++ firmware/fw_base.S | 209 +--------------------------------------- firmware/fw_dynamic.S | 25 ++--- firmware/fw_jump.S | 25 ++--- firmware/fw_payload.S | 25 ++--- firmware/objects.mk | 2 + include/sbi/sbi_types.h | 1 + 8 files changed, 142 insertions(+), 256 deletions(-) create mode 100644 firmware/fw.c diff --git a/Makefile b/Makefile index d8cffa6..dfd2554 100644 --- a/Makefile +++ b/Makefile @@ -257,13 +257,14 @@ platform-objs-path-y=$(foreach obj,$(platform-objs-y),$(platform_build_dir)/$(ob firmware-bins-path-y=$(foreach bin,$(firmware-bins-y),$(platform_build_dir)/firmware/$(bin)) endif firmware-elfs-path-y=$(firmware-bins-path-y:.bin=.elf) -firmware-objs-path-y=$(firmware-bins-path-y:.bin=.o) +firmware-objs-path-y=$(foreach obj,$(firmware-objs-y),$(platform_build_dir)/firmware/$(obj)) # Setup list of deps files for objects deps-y=$(platform-objs-path-y:.o=.dep) deps-y+=$(libsbi-objs-path-y:.o=.dep) deps-y+=$(libsbiutils-objs-path-y:.o=.dep) deps-y+=$(firmware-objs-path-y:.o=.dep) +deps-y+=$(firmware-bins-path-y:.bin=.dep) deps-y+=$(firmware-elfs-path-y:=.dep) # Setup platform ABI, ISA and Code Model @@ -510,6 +511,9 @@ $(build_dir)/lib/libsbi.a: $(libsbi-objs-path-y) $(platform_build_dir)/lib/libplatsbi.a: $(libsbi-objs-path-y) $(libsbiutils-objs-path-y) $(platform-objs-path-y) $(call compile_ar,$@,$^) +$(platform_build_dir)/firmware/libfw.a: $(firmware-objs-path-y) + $(call compile_ar,$@,$^) + $(build_dir)/%.dep: $(src_dir)/%.carray $(KCONFIG_CONFIG) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_CONFIG)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) @@ -572,8 +576,8 @@ $(platform_build_dir)/%.dtb: $(platform_src_dir)/%.dts $(platform_build_dir)/%.bin: $(platform_build_dir)/%.elf $(call compile_objcopy,$@,$<) -$(platform_build_dir)/%.elf: $(platform_build_dir)/%.o $(platform_build_dir)/%.elf.ld $(platform_build_dir)/lib/libplatsbi.a - $(call compile_elf,$@,$@.ld,$< $(platform_build_dir)/lib/libplatsbi.a) +$(platform_build_dir)/%.elf: $(platform_build_dir)/%.o $(platform_build_dir)/%.elf.ld $(platform_build_dir)/lib/libplatsbi.a $(platform_build_dir)/firmware/libfw.a + $(call compile_elf,$@,$@.ld,$< $(platform_build_dir)/lib/libplatsbi.a) $(platform_build_dir)/firmware/libfw.a $(platform_build_dir)/%.dep: $(src_dir)/%.ldS $(KCONFIG_CONFIG) $(call compile_cpp_dep,$@,.ld,$<) diff --git a/firmware/fw.c b/firmware/fw.c new file mode 100644 index 0000000..5f5ce30 --- /dev/null +++ b/firmware/fw.c @@ -0,0 +1,101 @@ +#include +#include +#include +#include +#include + +extern struct sbi_platform platform; + +extern char _fw_start[]; +extern char _fw_end[]; +extern char _fw_rw_start[]; +extern char _start_warm[]; +extern char fw_fdt_bin[]; +extern char _hartid_to_scratch[]; + +extern void fw_save_info(unsigned long arg0, + unsigned long arg1,unsigned long arg2); +extern unsigned long fw_next_arg1(void); +extern unsigned long fw_next_addr(void); +extern unsigned long fw_next_mode(void); +extern unsigned long fw_options(void); + +__weak unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1, + unsigned long arg2, unsigned long arg3, unsigned long arg4) +{ + return arg1; +} + +void fw_coldboot_init(unsigned long arg0, unsigned long arg1, + unsigned long arg2, unsigned long arg3, unsigned long arg4) +{ + unsigned long top; + unsigned long fw_start; + unsigned long fw_rw_offset; + unsigned long fw_heap_size; + unsigned long fw_heap_offset; + unsigned long fw_size; + unsigned long warmboot_addr; + unsigned long platform_addr; + unsigned long hartid_to_scratch; + unsigned long next_addr; + unsigned long next_arg1; + unsigned long next_mode; + unsigned long options; + + const void * fdt; + void *target_fdt; + + fw_save_info(arg0, arg1, arg2); +#ifdef FW_FDT_PATH + arg1 = (unsigned long)fw_fdt_bin; +#endif + + /* initialization platform */ + arg1 = fw_platform_init(arg0, arg1, arg2, arg3, arg4); + + /* relocate fdt */ + fdt = (const void*)arg1; + target_fdt = (void*)fw_next_arg1(); + fdt_move(fdt, target_fdt, fdt_totalsize(fdt)); + + /* initialization scratch for all harts */ + next_addr = fw_next_addr(); + next_arg1 = fw_next_arg1(); + next_mode = fw_next_mode(); +#ifdef FW_OPTIONS + options = FW_OPTIONS +#else + options = fw_options(); +#endif + top = (unsigned long)_fw_end + + platform.hart_stack_size * platform.hart_count; + fw_start = (unsigned long)_fw_start; + fw_rw_offset = (unsigned long)_fw_rw_start - fw_start; + fw_heap_size = platform.heap_size; + fw_heap_offset = top - fw_start; + fw_size = top + fw_heap_size - fw_start; + warmboot_addr = (unsigned long)_start_warm; + platform_addr = (unsigned long)&platform; + hartid_to_scratch = (unsigned long)_hartid_to_scratch; + + for (u32 i = 0; i < platform.hart_count; i++) { + struct sbi_scratch *scratch = (struct sbi_scratch *)(top + - i * platform.hart_stack_size - SBI_SCRATCH_SIZE); + + scratch->fw_start = fw_start; + scratch->fw_size = fw_size; + scratch->fw_rw_offset = fw_rw_offset; + scratch->fw_heap_size = fw_heap_size; + scratch->fw_heap_offset = fw_heap_offset; + scratch->warmboot_addr = warmboot_addr; + scratch->platform_addr = platform_addr; + scratch->hartid_to_scratch = hartid_to_scratch; + scratch->next_addr = next_addr; + scratch->next_arg1 = next_arg1; + scratch->next_mode = next_mode; + scratch->options = options; + scratch->tmp0 = 0; + } +} + diff --git a/firmware/fw_base.S b/firmware/fw_base.S index 4de053f..6ff93ea 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -17,21 +17,6 @@ #define BOOT_STATUS_LOTTERY_DONE 1 #define BOOT_STATUS_BOOT_HART_DONE 2 -.macro MOV_3R __d0, __s0, __d1, __s1, __d2, __s2 - add \__d0, \__s0, zero - add \__d1, \__s1, zero - add \__d2, \__s2, zero -.endm - -.macro MOV_5R __d0, __s0, __d1, __s1, __d2, __s2, __d3, __s3, __d4, __s4 - add \__d0, \__s0, zero - add \__d1, \__s1, zero - add \__d2, \__s2, zero - add \__d3, \__s3, zero - add \__d4, \__s4, zero -.endm - - .section .entry, "ax", %progbits .align 3 .globl _start @@ -95,192 +80,7 @@ _bss_zero: li s5, (SBI_SCRATCH_SIZE * 2) add sp, s4, s5 - /* Allow main firmware to save info */ - MOV_5R s0, a0, s1, a1, s2, a2, s3, a3, s4, a4 - call fw_save_info - MOV_5R a0, s0, a1, s1, a2, s2, a3, s3, a4, s4 - -#ifdef FW_FDT_PATH - /* Override previous arg1 */ - lla a1, fw_fdt_bin -#endif - - /* - * Initialize platform - * Note: The a0 to a4 registers passed to the - * firmware are parameters to this function. - */ - MOV_5R s0, a0, s1, a1, s2, a2, s3, a3, s4, a4 - call fw_platform_init - add t0, a0, zero - MOV_5R a0, s0, a1, s1, a2, s2, a3, s3, a4, s4 - add a1, t0, zero - - /* Preload HART details - * s7 -> HART Count - * s8 -> HART Stack Size - * s9 -> Heap Size - * s10 -> Heap Offset - */ - lla a4, platform -#if __riscv_xlen > 32 - lwu s7, SBI_PLATFORM_HART_COUNT_OFFSET(a4) - lwu s8, SBI_PLATFORM_HART_STACK_SIZE_OFFSET(a4) - lwu s9, SBI_PLATFORM_HEAP_SIZE_OFFSET(a4) -#else - lw s7, SBI_PLATFORM_HART_COUNT_OFFSET(a4) - lw s8, SBI_PLATFORM_HART_STACK_SIZE_OFFSET(a4) - lw s9, SBI_PLATFORM_HEAP_SIZE_OFFSET(a4) -#endif - - /* Setup scratch space for all the HARTs*/ - lla tp, _fw_end - mul a5, s7, s8 - add tp, tp, a5 - /* Setup heap base address */ - lla s10, _fw_start - sub s10, tp, s10 - add tp, tp, s9 - /* Keep a copy of tp */ - add t3, tp, zero - /* Counter */ - li t2, 1 - /* hartid 0 is mandated by ISA */ - li t1, 0 -_scratch_init: - /* - * The following registers hold values that are computed before - * entering this block, and should remain unchanged. - * - * t3 -> the firmware end address - * s7 -> HART count - * s8 -> HART stack size - * s9 -> Heap Size - * s10 -> Heap Offset - */ - add tp, t3, zero - sub tp, tp, s9 - mul a5, s8, t1 - sub tp, tp, a5 - li a5, SBI_SCRATCH_SIZE - sub tp, tp, a5 - - /* Initialize scratch space */ - /* Store fw_start and fw_size in scratch space */ - lla a4, _fw_start - sub a5, t3, a4 - REG_S a4, SBI_SCRATCH_FW_START_OFFSET(tp) - REG_S a5, SBI_SCRATCH_FW_SIZE_OFFSET(tp) - - /* Store R/W section's offset in scratch space */ - lla a5, _fw_rw_start - sub a5, a5, a4 - REG_S a5, SBI_SCRATCH_FW_RW_OFFSET(tp) - - /* Store fw_heap_offset and fw_heap_size in scratch space */ - REG_S s10, SBI_SCRATCH_FW_HEAP_OFFSET(tp) - REG_S s9, SBI_SCRATCH_FW_HEAP_SIZE_OFFSET(tp) - - /* Store next arg1 in scratch space */ - MOV_3R s0, a0, s1, a1, s2, a2 - call fw_next_arg1 - REG_S a0, SBI_SCRATCH_NEXT_ARG1_OFFSET(tp) - MOV_3R a0, s0, a1, s1, a2, s2 - /* Store next address in scratch space */ - MOV_3R s0, a0, s1, a1, s2, a2 - call fw_next_addr - REG_S a0, SBI_SCRATCH_NEXT_ADDR_OFFSET(tp) - MOV_3R a0, s0, a1, s1, a2, s2 - /* Store next mode in scratch space */ - MOV_3R s0, a0, s1, a1, s2, a2 - call fw_next_mode - REG_S a0, SBI_SCRATCH_NEXT_MODE_OFFSET(tp) - MOV_3R a0, s0, a1, s1, a2, s2 - /* Store warm_boot address in scratch space */ - lla a4, _start_warm - REG_S a4, SBI_SCRATCH_WARMBOOT_ADDR_OFFSET(tp) - /* Store platform address in scratch space */ - lla a4, platform - REG_S a4, SBI_SCRATCH_PLATFORM_ADDR_OFFSET(tp) - /* Store hartid-to-scratch function address in scratch space */ - lla a4, _hartid_to_scratch - REG_S a4, SBI_SCRATCH_HARTID_TO_SCRATCH_OFFSET(tp) - /* Store trap-exit function address in scratch space */ - lla a4, _trap_exit - REG_S a4, SBI_SCRATCH_TRAP_EXIT_OFFSET(tp) - /* Clear tmp0 in scratch space */ - REG_S zero, SBI_SCRATCH_TMP0_OFFSET(tp) - /* Store firmware options in scratch space */ - MOV_3R s0, a0, s1, a1, s2, a2 -#ifdef FW_OPTIONS - li a0, FW_OPTIONS -#else - call fw_options -#endif - REG_S a0, SBI_SCRATCH_OPTIONS_OFFSET(tp) - MOV_3R a0, s0, a1, s1, a2, s2 - /* Move to next scratch space */ - add t1, t1, t2 - blt t1, s7, _scratch_init - - /* - * Relocate Flatened Device Tree (FDT) - * source FDT address = previous arg1 - * destination FDT address = next arg1 - * - * Note: We will preserve a0 and a1 passed by - * previous booting stage. - */ - beqz a1, _fdt_reloc_done - /* Mask values in a4 */ - li a4, 0xff - /* t1 = destination FDT start address */ - MOV_3R s0, a0, s1, a1, s2, a2 - call fw_next_arg1 - add t1, a0, zero - MOV_3R a0, s0, a1, s1, a2, s2 - beqz t1, _fdt_reloc_done - beq t1, a1, _fdt_reloc_done - /* t0 = source FDT start address */ - add t0, a1, zero - /* t2 = source FDT size in big-endian */ -#if __riscv_xlen > 32 - lwu t2, 4(t0) -#else - lw t2, 4(t0) -#endif - /* t3 = bit[15:8] of FDT size */ - add t3, t2, zero - srli t3, t3, 16 - and t3, t3, a4 - slli t3, t3, 8 - /* t4 = bit[23:16] of FDT size */ - add t4, t2, zero - srli t4, t4, 8 - and t4, t4, a4 - slli t4, t4, 16 - /* t5 = bit[31:24] of FDT size */ - add t5, t2, zero - and t5, t5, a4 - slli t5, t5, 24 - /* t2 = bit[7:0] of FDT size */ - srli t2, t2, 24 - and t2, t2, a4 - /* t2 = FDT size in little-endian */ - or t2, t2, t3 - or t2, t2, t4 - or t2, t2, t5 - /* t2 = destination FDT end address */ - add t2, t1, t2 - /* FDT copy loop */ - ble t2, t1, _fdt_reloc_done -_fdt_reloc_again: - REG_L t3, 0(t0) - REG_S t3, 0(t1) - add t0, t0, __SIZEOF_POINTER__ - add t1, t1, __SIZEOF_POINTER__ - blt t1, t2, _fdt_reloc_again -_fdt_reloc_done: + call fw_coldboot_init /* mark boot hart done */ li t0, BOOT_STATUS_BOOT_HART_DONE @@ -415,13 +215,6 @@ _start_hang: wfi j _start_hang - .section .entry, "ax", %progbits - .align 3 - .weak fw_platform_init -fw_platform_init: - add a0, a1, zero - ret - /* Map implicit memcpy() added by compiler to sbi_memcpy() */ .section .text .align 3 diff --git a/firmware/fw_dynamic.S b/firmware/fw_dynamic.S index 52ef320..f8cb3d1 100644 --- a/firmware/fw_dynamic.S +++ b/firmware/fw_dynamic.S @@ -41,10 +41,8 @@ fw_boot_hart: .align 3 .global fw_save_info /* - * We can only use a0, a1, a2, a3, and a4 registers here. - * The a0, a1, and a2 registers will be same as passed by - * previous booting stage. - * Nothing to be returned here. + * This function will be called in a C function, and the implementation + * needs to meet the calling constraints of RISC-V */ fw_save_info: /* Save next arg1 in 'a1' */ @@ -76,10 +74,8 @@ fw_save_info: .align 3 .global fw_next_arg1 /* - * We can only use a0, a1, and a2 registers here. - * The a0, a1, and a2 registers will be same as passed by - * previous booting stage. - * The next arg1 should be returned in 'a0'. + * This function will be called in a C function, and the implementation + * needs to meet the calling constraints of RISC-V */ fw_next_arg1: lla a0, _dynamic_next_arg1 @@ -90,8 +86,8 @@ fw_next_arg1: .align 3 .global fw_next_addr /* - * We can only use a0, a1, and a2 registers here. - * The next address should be returned in 'a0'. + * This function will be called in a C function, and the implementation + * needs to meet the calling constraints of RISC-V */ fw_next_addr: lla a0, _dynamic_next_addr @@ -102,8 +98,8 @@ fw_next_addr: .align 3 .global fw_next_mode /* - * We can only use a0, a1, and a2 registers here. - * The next address should be returned in 'a0' + * This function will be called in a C function, and the implementation + * needs to meet the calling constraints of RISC-V */ fw_next_mode: lla a0, _dynamic_next_mode @@ -114,9 +110,8 @@ fw_next_mode: .align 3 .global fw_options /* - * We can only use a0, a1, and a2 registers here. - * The 'a4' register will have default options. - * The next address should be returned in 'a0'. + * This function will be called in a C function, and the implementation + * needs to meet the calling constraints of RISC-V */ fw_options: lla a0, _dynamic_options diff --git a/firmware/fw_jump.S b/firmware/fw_jump.S index 1775fcd..0af0cab 100644 --- a/firmware/fw_jump.S +++ b/firmware/fw_jump.S @@ -26,10 +26,8 @@ fw_boot_hart: .align 3 .global fw_save_info /* - * We can only use a0, a1, a2, a3, and a4 registers here. - * The a0, a1, and a2 registers will be same as passed by - * previous booting stage. - * Nothing to be returned here. + * This function will be called in a C function, and the implementation + * needs to meet the calling constraints of RISC-V */ fw_save_info: ret @@ -38,10 +36,8 @@ fw_save_info: .align 3 .global fw_next_arg1 /* - * We can only use a0, a1, and a2 registers here. - * The a0, a1, and a2 registers will be same as passed by - * previous booting stage. - * The next arg1 should be returned in 'a0'. + * This function will be called in a C function, and the implementation + * needs to meet the calling constraints of RISC-V */ fw_next_arg1: #ifdef FW_JUMP_FDT_ADDR @@ -55,8 +51,8 @@ fw_next_arg1: .align 3 .global fw_next_addr /* - * We can only use a0, a1, and a2 registers here. - * The next address should be returned in 'a0'. + * This function will be called in a C function, and the implementation + * needs to meet the calling constraints of RISC-V */ fw_next_addr: lla a0, _jump_addr @@ -67,8 +63,8 @@ fw_next_addr: .align 3 .global fw_next_mode /* - * We can only use a0, a1, and a2 registers here. - * The next address should be returned in 'a0' + * This function will be called in a C function, and the implementation + * needs to meet the calling constraints of RISC-V */ fw_next_mode: li a0, PRV_S @@ -78,9 +74,8 @@ fw_next_mode: .align 3 .global fw_options /* - * We can only use a0, a1, and a2 registers here. - * The 'a4' register will have default options. - * The next address should be returned in 'a0'. + * This function will be called in a C function, and the implementation + * needs to meet the calling constraints of RISC-V */ fw_options: add a0, zero, zero diff --git a/firmware/fw_payload.S b/firmware/fw_payload.S index 985f833..a9f4720 100644 --- a/firmware/fw_payload.S +++ b/firmware/fw_payload.S @@ -26,10 +26,8 @@ fw_boot_hart: .align 3 .global fw_save_info /* - * We can only use a0, a1, a2, a3, and a4 registers here. - * The a0, a1, and a2 registers will be same as passed by - * previous booting stage. - * Nothing to be returned here. + * This function will be called in a C function, and the implementation + * needs to meet the calling constraints of RISC-V */ fw_save_info: ret @@ -38,10 +36,8 @@ fw_save_info: .align 3 .global fw_next_arg1 /* - * We can only use a0, a1, and a2 registers here. - * The a0, a1, and a2 registers will be same as passed by - * previous booting stage. - * The next arg1 should be returned in 'a0'. + * This function will be called in a C function, and the implementation + * needs to meet the calling constraints of RISC-V */ fw_next_arg1: #ifdef FW_PAYLOAD_FDT_ADDR @@ -55,8 +51,8 @@ fw_next_arg1: .align 3 .global fw_next_addr /* - * We can only use a0, a1, and a2 registers here. - * The next address should be returned in 'a0'. + * This function will be called in a C function, and the implementation + * needs to meet the calling constraints of RISC-V */ fw_next_addr: lla a0, payload_bin @@ -66,8 +62,8 @@ fw_next_addr: .align 3 .global fw_next_mode /* - * We can only use a0, a1, and a2 registers here. - * The next address should be returned in 'a0'. + * This function will be called in a C function, and the implementation + * needs to meet the calling constraints of RISC-V */ fw_next_mode: li a0, PRV_S @@ -77,9 +73,8 @@ fw_next_mode: .align 3 .global fw_options /* - * We can only use a0, a1, and a2 registers here. - * The 'a4' register will have default options. - * The next address should be returned in 'a0'. + * This function will be called in a C function, and the implementation + * needs to meet the calling constraints of RISC-V */ fw_options: add a0, zero, zero diff --git a/firmware/objects.mk b/firmware/objects.mk index b2ace75..efe44fa 100644 --- a/firmware/objects.mk +++ b/firmware/objects.mk @@ -55,3 +55,5 @@ endif ifdef FW_OPTIONS firmware-genflags-y += -DFW_OPTIONS=$(FW_OPTIONS) endif + +firmware-objs-y += fw.o diff --git a/include/sbi/sbi_types.h b/include/sbi/sbi_types.h index def88bb..76f86f4 100644 --- a/include/sbi/sbi_types.h +++ b/include/sbi/sbi_types.h @@ -66,6 +66,7 @@ typedef uint64_t be64_t; #define NULL ((void *)0) +#define __weak __attribute__((weak)) #define __packed __attribute__((packed)) #define __noreturn __attribute__((noreturn)) #define __aligned(x) __attribute__((aligned(x)))