From patchwork Thu Oct 24 12:41:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 2001702 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=zZWiUJj8; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=RalBmRza; 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=kvm-riscv-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 4XZ5BR23RFz1xwy for ; Thu, 24 Oct 2024 23:41: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=YqN8MVDrokN2EPpEvBmTLAh+yiAk+k40aR4z2/ozNcg=; b=zZWiUJj8o+5pH+ BOMQymLHVsrTaHgmyQttsalkO8DsCaXPeRYVCzTjuSU1mStMS4wbCYdxxlsaIEQ7/8t8EqsUyfy5+ W9l9rscz6emOg3dCHRlST3puEK2WL4/plCfjgiL8jlFb3nrLk0a7xLBwKjaPysta3AKvkj90VwNVR uTw5wCzWoPSs3oBA09LTQ8rq82GmLX/GorcShu9uF9S2vLalqQoPgEgEA0QF6H+zO3a7sp6PwuFs7 vsz+nndfMO7yeIil/NvfGzTwoU3Q1JtbapfSHrDCmFpVHxVFo61THb8j89Sbd7W3iK3ltMjy3SEJB RzwAa6Y/5DsUV+aDPT4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t3x9S-00000000NeO-0HWe; Thu, 24 Oct 2024 12:41:18 +0000 Received: from out-174.mta0.migadu.com ([91.218.175.174]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t3x9P-00000000NdI-0xEQ for kvm-riscv@lists.infradead.org; Thu, 24 Oct 2024 12:41:16 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1729773672; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1ZH0HhhOm4eyVQFwXhRo2Jpmjl4zZD4HQBsv6A3Z8QE=; b=RalBmRzaadKIhBrisYclsaldrwNNnUcQD9OLFQjMBO1vSdYam9tV+O1ppVBCPurh47B5yB b7HksLvB+CkhQONRnGtVAope9E3GzQyvCepWFULsmI8qkvX3IZwJCtw391v41REdl6h8P5 ZaXIvMIfYO0BZYoQez/wviu47s2yfNs= From: Andrew Jones To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: atishp@rivosinc.com, jamestiotio@gmail.com Subject: [kvm-unit-tests PATCH 1/3] riscv: Implement setjmp/longjmp Date: Thu, 24 Oct 2024 14:41:03 +0200 Message-ID: <20241024124101.73405-6-andrew.jones@linux.dev> In-Reply-To: <20241024124101.73405-5-andrew.jones@linux.dev> References: <20241024124101.73405-5-andrew.jones@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241024_054115_427597_AC02795C X-CRM114-Status: GOOD ( 10.34 ) X-Spam-Score: -2.1 (--) 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: Being able to do setjmp and longjmp can be quite useful for tests. Implement the functions for riscv. Signed-off-by: Andrew Jones --- lib/riscv/setjmp.S | 50 ++++++++++++++++++++++++++++++++++++++++++++++ lib/setjmp.h | 4 ++++ riscv/Makefile | 1 + 3 files changed, 55 insertion [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [91.218.175.174 listed in sa-trusted.bondedsender.org] 0.0 RCVD_IN_VALIDITY_SAFE_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [91.218.175.174 listed in sa-accredit.habeas.com] 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [91.218.175.174 listed in bl.score.senderscore.com] X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Being able to do setjmp and longjmp can be quite useful for tests. Implement the functions for riscv. Signed-off-by: Andrew Jones --- lib/riscv/setjmp.S | 50 ++++++++++++++++++++++++++++++++++++++++++++++ lib/setjmp.h | 4 ++++ riscv/Makefile | 1 + 3 files changed, 55 insertions(+) create mode 100644 lib/riscv/setjmp.S diff --git a/lib/riscv/setjmp.S b/lib/riscv/setjmp.S new file mode 100644 index 000000000000..38b0f1cab576 --- /dev/null +++ b/lib/riscv/setjmp.S @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#define __ASSEMBLY__ +#include + +.section .text + +.balign 4 +.global setjmp +setjmp: + REG_S ra, (0 * SZREG)(a0) + REG_S s0, (1 * SZREG)(a0) + REG_S s1, (2 * SZREG)(a0) + REG_S s2, (3 * SZREG)(a0) + REG_S s3, (4 * SZREG)(a0) + REG_S s4, (5 * SZREG)(a0) + REG_S s5, (6 * SZREG)(a0) + REG_S s6, (7 * SZREG)(a0) + REG_S s7, (8 * SZREG)(a0) + REG_S s8, (9 * SZREG)(a0) + REG_S s9, (10 * SZREG)(a0) + REG_S s10, (11 * SZREG)(a0) + REG_S s11, (12 * SZREG)(a0) + REG_S sp, (13 * SZREG)(a0) + REG_S gp, (14 * SZREG)(a0) + REG_S tp, (15 * SZREG)(a0) + li a0, 0 + ret + +.balign 4 +.global longjmp +longjmp: + REG_L ra, (0 * SZREG)(a0) + REG_L s0, (1 * SZREG)(a0) + REG_L s1, (2 * SZREG)(a0) + REG_L s2, (3 * SZREG)(a0) + REG_L s3, (4 * SZREG)(a0) + REG_L s4, (5 * SZREG)(a0) + REG_L s5, (6 * SZREG)(a0) + REG_L s6, (7 * SZREG)(a0) + REG_L s7, (8 * SZREG)(a0) + REG_L s8, (9 * SZREG)(a0) + REG_L s9, (10 * SZREG)(a0) + REG_L s10, (11 * SZREG)(a0) + REG_L s11, (12 * SZREG)(a0) + REG_L sp, (13 * SZREG)(a0) + REG_L gp, (14 * SZREG)(a0) + REG_L tp, (15 * SZREG)(a0) + seqz a0, a1 + add a0, a0, a1 + ret diff --git a/lib/setjmp.h b/lib/setjmp.h index 6afdf665681a..f878ad81c645 100644 --- a/lib/setjmp.h +++ b/lib/setjmp.h @@ -8,7 +8,11 @@ #define _LIBCFLAT_SETJMP_H_ typedef struct jmp_buf_tag { +#if defined(__i386__) || defined(__x86_64__) long int regs[8]; +#elif defined(__riscv) + long int regs[16]; +#endif } jmp_buf[1]; extern int setjmp (struct jmp_buf_tag env[1]); diff --git a/riscv/Makefile b/riscv/Makefile index 734441f94dad..28b04156bfd5 100644 --- a/riscv/Makefile +++ b/riscv/Makefile @@ -36,6 +36,7 @@ cflatobjs += lib/riscv/isa.o cflatobjs += lib/riscv/mmu.o cflatobjs += lib/riscv/processor.o cflatobjs += lib/riscv/sbi.o +cflatobjs += lib/riscv/setjmp.o cflatobjs += lib/riscv/setup.o cflatobjs += lib/riscv/smp.o cflatobjs += lib/riscv/stack.o