From patchwork Thu Nov 9 08:25:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1861882 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=xnK8P/B+; 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=QImfgVBy; 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 4SQw5t3gdVz1yQl for ; Thu, 9 Nov 2023 19:26:26 +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: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:In-Reply-To:References: List-Owner; bh=0y9Kg+U4Wvhcb5bjTAq8FKWdvQuDQ65LtutVL14qXz8=; b=xnK8P/B+0nJTvs N8VRNYFJnhts8RTg23VjkdAPnvmkPCSjuYYUjXzCcaEMnx0f20suh3T7ThDnmYINBxUXE/iaRKrwY iElxTipvoXhDxVw2/Rvady/d3IQ2yyox33diXHw15aiVJ3UYEmJoR1Rz1K00zgkyUwAJAfrgExtCy IAYpgksdli8oT6GCYA7SyrHs9aVUZRUy4DqyRk5W+flR8bUO/Aqkq9uMmK5wXwV/4+rITOVRbADyv j+a3cd0hizaBm/ti2VN59i4lG9ozeSAEk85oTjaf/xb+Tx/Vcc85qx5A3ff1kVN2eGfOWTA+96Hbh XLw9lF7X4C1FedcB5jdA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r10Mg-005cPz-2O; Thu, 09 Nov 2023 08:26:14 +0000 Received: from m15.mail.126.com ([45.254.50.224]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r10Md-005cNA-1L for opensbi@lists.infradead.org; Thu, 09 Nov 2023 08:26:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=kPL8OEgj2HvbJbYNMHmIiIGbVO9JVvjLUeWC3pBYGuc=; b=QImfgVByRK6etRYa3d5//5vVcDXRGuFywZd3Ur0XdAcAivwCarkOPrme8OlFjt rLTo0DRtec8X/bJowKg7bwZv8F1qa5vbEEYi3Q5C9j5CzuVDUpkQGeIGOdIbVGAP wP0Qsf/9jgXZ+v7gZmSgi67cpB5Tl8yJayxWfOVTE4j9o= Received: from T490.lan (unknown [112.83.183.252]) by zwqz-smtp-mta-g2-0 (Coremail) with SMTP id _____wDnb7+Kl0xl9p41Cg--.7810S2; Thu, 09 Nov 2023 16:25:48 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: bjorn@kernel.org, schwab@linux-m68k.org, jrtc27@jrtc27.com, inochiama@outlook.com, Xiang W , =?utf-8?b?QmrDtnJuIFTDtnBl?= =?utf-8?b?bA==?= Subject: [PATCH] lib: sbi_illegal_insn: Emulate c.li Date: Thu, 9 Nov 2023 16:25:17 +0800 Message-ID: <20231109082540.52144-1-wxjstz@126.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-CM-TRANSID: _____wDnb7+Kl0xl9p41Cg--.7810S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ww47Aw48tF13Wr4fWF1ftFb_yoW8Wr4DpF Z8GF18Kr40q34xuFZxJrn8uFyrAa1xK3yxA3WIyrZakr4UAwn5XFy5tr1jqF1rKryUGw4U XF4jyryUCF15XrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziX_-AUUUUU= X-Originating-IP: [112.83.183.252] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBdA8jOmSdLi4ulwAAsi X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231109_002612_109450_93122DA4 X-CRM114-Status: UNSURE ( 9.01 ) 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 Linux kernel RISC-V image format allows that UEFI Images can also be booted by non-UEFI firmware. However for that to work, the PE/Image combo requires that 'MZ' is a valid instruction. On RISC-V, [...] 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 Linux kernel RISC-V image format allows that UEFI Images can also be booted by non-UEFI firmware. However for that to work, the PE/Image combo requires that 'MZ' is a valid instruction. On RISC-V, 'MZ' is only a valid instruction if the hardware is C capable [1]. So add Emulate c.li Signed-off-by: Björn Töpel Signed-off-by: Xiang W --- lib/sbi/sbi_illegal_insn.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/sbi/sbi_illegal_insn.c b/lib/sbi/sbi_illegal_insn.c index 2be4757..4ab10f4 100644 --- a/lib/sbi/sbi_illegal_insn.c +++ b/lib/sbi/sbi_illegal_insn.c @@ -102,6 +102,22 @@ static int system_opcode_insn(ulong insn, struct sbi_trap_regs *regs) return 0; } +static int compressed_insn(ulong insn, struct sbi_trap_regs *regs) { + unsigned long imm, rd; + unsigned long *regs_p = (unsigned long *)regs; + + if ((insn & 0xe003) == 0x4001) { /* c.li */ + imm = (insn >> 2) & 0x1f; + imm |= ((insn >> 12) & 1) ? -32 : 0; + rd = (insn >> 7) & 0x1f; + if (rd) + regs_p[rd] = imm; + return 0; + } + + return truly_illegal_insn(insn, regs); +} + static const illegal_insn_func illegal_insn_table[32] = { truly_illegal_insn, /* 0 */ truly_illegal_insn, /* 1 */ @@ -160,7 +176,7 @@ int sbi_illegal_insn_handler(ulong insn, struct sbi_trap_regs *regs) return sbi_trap_redirect(regs, &uptrap); } if ((insn & 3) != 3) - return truly_illegal_insn(insn, regs); + return compressed_insn(insn, regs); } return illegal_insn_table[(insn & 0x7c) >> 2](insn, regs);