From patchwork Wed Aug 28 09:52:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9E709C54E71 for ; Wed, 28 Aug 2024 09:54:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMU-00020i-QW; Wed, 28 Aug 2024 05:53:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMM-0001vd-R0 for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:04 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMJ-0001nk-97 for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:02 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-7148912a1ebso1995089b3a.0 for ; Wed, 28 Aug 2024 02:52:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838776; x=1725443576; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WFvdTr8ItVOjTzK94rYNt0BNQVSxcF+DNvHDFPsSwO0=; b=dVDDhgjUPOWayHSa03rvAVcPseBIQB7KYhoRsxIsL7y0XmDOvPlFKxOEfE8teGR8DF 8ifpwdBznLjFzSVszrRQ4fxC05kr0ZBDFSORieGcO24LUCjqn7qWz8iN4rpuo+qhi6hH dIh/6aa26uisotXGiXNF8N1ZqQB/1tPsLgMp2zkbBudVL3bOlKam7uvJ3YSNJ4phOSPz spqYms/eMtg6cZOdnk0fpx5g9n1FOuYYDzsG2o49zReZRhfU8HftxgK0NylkQPwm1mFc N2XnLKeV3sMJeUtPgvqLSWx/7tv0/tdF+MlsL9tbYepdSDU7TEuPSPdMlImpvGf+ML4e ZFSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838776; x=1725443576; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WFvdTr8ItVOjTzK94rYNt0BNQVSxcF+DNvHDFPsSwO0=; b=Ote3I9lclI6W7SUo/6pwpUbIfyO52Lb7YPWVeinHV/nO0jhkaqvSJov0FkurGne+tn VErFwDHFzsKcE+KbipWtMK407CPN5+ISLAWzcvSjhD3aLMXWycsZylRhUCTNHUdFRzCm lpjCsFYPX4YdlPzIsmR9KJHY+jsnycDmElrt8CoqAKHens+6oZ+MlpcmivwD5eXqZvQN g4gW83MKyLX20UI5gtjtZsXyOLlbZk8flaglr8gvsYOqQaEzP4zrosS/tTigWBL9ORfk ALAvyqTzXCsHXZcW9m+tDcs+AjdIAxHPUfkHDRX8nWEzbjrtHneJ+dGkJk1roaye0amk LHAA== X-Gm-Message-State: AOJu0YxQHImoSxg2jfZl66jhDFmFjZ2X474pjlJ1ADu8qEAlKfFqLBl1 /s+ILLQsrETOCz1V/72s6D2bkqySJJvNlVMWJ2UnUtXdOWTBQYFqzSV0MlJA X-Google-Smtp-Source: AGHT+IHaEhCfXVcHUIE0CKEsGvpB4sBt5EkRPs8D/AUi7ZOKtswjyGsu4CINsETScm3hYeldvFD6jg== X-Received: by 2002:a05:6a00:84f:b0:714:2a0f:29e8 with SMTP id d2e1a72fcca58-715d10be868mr1650514b3a.10.1724838775922; Wed, 28 Aug 2024 02:52:55 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.52.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:52:55 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Jessica Clarke , Richard Henderson Subject: [PATCH v4 01/17] bsd-user: Implement RISC-V CPU initialization and main loop Date: Wed, 28 Aug 2024 19:52:27 +1000 Message-Id: <20240828095243.90491-2-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=itachis6234@gmail.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Mark Corbin Added the initial implementation for RISC-V CPU initialization and main loop. This includes setting up the general-purpose registers and program counter based on the provided target architecture definitions. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Co-authored-by: Jessica Clarke Reviewed-by: Richard Henderson --- bsd-user/riscv/target_arch_cpu.h | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 bsd-user/riscv/target_arch_cpu.h diff --git a/bsd-user/riscv/target_arch_cpu.h b/bsd-user/riscv/target_arch_cpu.h new file mode 100644 index 0000000000..e17c910ae9 --- /dev/null +++ b/bsd-user/riscv/target_arch_cpu.h @@ -0,0 +1,39 @@ +/* + * RISC-V CPU init and loop + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef TARGET_ARCH_CPU_H +#define TARGET_ARCH_CPU_H + +#include "target_arch.h" + +#define TARGET_DEFAULT_CPU_MODEL "max" + +static inline void target_cpu_init(CPURISCVState *env, + struct target_pt_regs *regs) +{ + int i; + + for (i = 1; i < 32; i++) { + env->gpr[i] = regs->regs[i]; + } + + env->pc = regs->sepc; +} + +#endif /* TARGET_ARCH_CPU_H */ From patchwork Wed Aug 28 09:52:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 88AE0C54E75 for ; Wed, 28 Aug 2024 09:54:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMU-00020o-Qi; Wed, 28 Aug 2024 05:53:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMM-0001vc-Qh for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:03 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMK-0001nq-Np for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:02 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-7142448aaf9so316332b3a.1 for ; Wed, 28 Aug 2024 02:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838779; x=1725443579; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ea8ovjK2oeupU9Y/oJRULt03XSKHKyefcQa3mNq/zsw=; b=kMZ1rcs5PKdGVIpFyASkOPvxGcgLZYLXWqnVdpcMTxuu4RDT8bzurduTWTJjMRzOW+ CQo3bOMCRRTmFKClBwbgxgzzpMp5ySALry2uWoUAAcrmaPuaUy48KVE2sD45r8mrPCWz m5ckvUpSnRAwTWAzbhI1ol+q9B4OQTArJfDQV/Z1W4+ylNDWxmzDuIHe98AV8XztBnnI rCcdW9TO6wqrbZp92wly1DH7dhHGZWHjWUndwgccsto7IgGQn7WpaAyuH8tHWHYK2ZS4 dWo4Kv2sS7KzSsHEJnci1BG3FiXg1nXBVeMT5pRnpIuALQG4+WRPyb7D8rsrX9ymYQC5 HXmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838779; x=1725443579; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ea8ovjK2oeupU9Y/oJRULt03XSKHKyefcQa3mNq/zsw=; b=f/JwWj6pHTWUnbRYDN2N+H878WVIGnwjdwd9E0XYgVXytP4ZKgLcwq5FvKlh3gTz6v sfe+cN1h71DecQdTIrrSBPYi0BFHudv1hWhW16ROlPI4TOoBa9mT7vCA1fcWGwJKnJBV 5aUKzcVhKzhWW+nvMylEiyKz9rIvwMLBoRHHmBxwz+1P/1f/eBAwNLrFT72A5W1WlFA4 gBQlyoJTPi7eshuK7pkpLd9scIEtNoeHPD79W56zdsy3JrJWj6BJI+AbalSfe2PnyRzf oMcZQMnkuXY4f+BSidIvc0EmE6KsAc5ieyqLAI3DH0xDimQIZNl9WjWs7SWn3O4BoVIK OC4Q== X-Gm-Message-State: AOJu0Yy4NRZBUmzTynYgdwgAetl8s/ImvlBwTaOlr8F9Ip8X23vCHAdt c3VpY+kkDTWEhE3D2xy3j7Nx20zgumGH0ZT9bJ5xO0jrn5dD5oYyY0SICzuI X-Google-Smtp-Source: AGHT+IH0AQRPFgL9dAcobhunXaLuMIt7QmPPoAGPCON3Qz4yZ9ygm79S59HGYez5pgCy5xmjTJHflA== X-Received: by 2002:a05:6a00:9196:b0:714:2371:7a02 with SMTP id d2e1a72fcca58-715d10be662mr2331015b3a.5.1724838778885; Wed, 28 Aug 2024 02:52:58 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.52.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:52:58 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Jessica Clarke , Kyle Evans , Richard Henderson Subject: [PATCH v4 02/17] bsd-user: Add RISC-V CPU execution loop and syscall handling Date: Wed, 28 Aug 2024 19:52:28 +1000 Message-Id: <20240828095243.90491-3-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=itachis6234@gmail.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Mark Corbin Implemented the RISC-V CPU execution loop, including handling various exceptions and system calls. The loop continuously executes CPU instructions,processes exceptions, and handles system calls by invoking FreeBSD syscall handlers. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Co-authored-by: Jessica Clarke Co-authored-by: Kyle Evans Reviewed-by: Richard Henderson --- bsd-user/riscv/target_arch_cpu.h | 94 ++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/bsd-user/riscv/target_arch_cpu.h b/bsd-user/riscv/target_arch_cpu.h index e17c910ae9..ba589909e2 100644 --- a/bsd-user/riscv/target_arch_cpu.h +++ b/bsd-user/riscv/target_arch_cpu.h @@ -36,4 +36,98 @@ static inline void target_cpu_init(CPURISCVState *env, env->pc = regs->sepc; } +static inline void target_cpu_loop(CPURISCVState *env) +{ + CPUState *cs = env_cpu(env); + int trapnr; + abi_long ret; + unsigned int syscall_num; + int32_t signo, code; + + for (;;) { + cpu_exec_start(cs); + trapnr = cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + signo = 0; + + switch (trapnr) { + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + case RISCV_EXCP_U_ECALL: + syscall_num = env->gpr[xT0]; + env->pc += TARGET_INSN_SIZE; + /* Compare to cpu_fetch_syscall_args() in riscv/riscv/trap.c */ + if (TARGET_FREEBSD_NR___syscall == syscall_num || + TARGET_FREEBSD_NR_syscall == syscall_num) { + ret = do_freebsd_syscall(env, + env->gpr[xA0], + env->gpr[xA1], + env->gpr[xA2], + env->gpr[xA3], + env->gpr[xA4], + env->gpr[xA5], + env->gpr[xA6], + env->gpr[xA7], + 0); + } else { + ret = do_freebsd_syscall(env, + syscall_num, + env->gpr[xA0], + env->gpr[xA1], + env->gpr[xA2], + env->gpr[xA3], + env->gpr[xA4], + env->gpr[xA5], + env->gpr[xA6], + env->gpr[xA7] + ); + } + + /* + * Compare to cpu_set_syscall_retval() in + * riscv/riscv/vm_machdep.c + */ + if (ret >= 0) { + env->gpr[xA0] = ret; + env->gpr[xT0] = 0; + } else if (ret == -TARGET_ERESTART) { + env->pc -= TARGET_INSN_SIZE; + } else if (ret != -TARGET_EJUSTRETURN) { + env->gpr[xA0] = -ret; + env->gpr[xT0] = 1; + } + break; + case RISCV_EXCP_ILLEGAL_INST: + signo = TARGET_SIGILL; + code = TARGET_ILL_ILLOPC; + break; + case RISCV_EXCP_BREAKPOINT: + signo = TARGET_SIGTRAP; + code = TARGET_TRAP_BRKPT; + break; + case EXCP_DEBUG: + signo = TARGET_SIGTRAP; + code = TARGET_TRAP_BRKPT; + break; + default: + fprintf(stderr, "qemu: unhandled CPU exception " + "0x%x - aborting\n", trapnr); + cpu_dump_state(cs, stderr, 0); + abort(); + } + + if (signo) { + force_sig_fault(signo, code, env->pc); + } + + process_pending_signals(env); + } +} + #endif /* TARGET_ARCH_CPU_H */ From patchwork Wed Aug 28 09:52:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781028 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44691C5479A for ; Wed, 28 Aug 2024 09:57:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMZ-0002Gl-4a; Wed, 28 Aug 2024 05:53:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMQ-0001wv-Q7 for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:07 -0400 Received: from mail-oo1-xc34.google.com ([2607:f8b0:4864:20::c34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMN-0001o9-5u for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:05 -0400 Received: by mail-oo1-xc34.google.com with SMTP id 006d021491bc7-5dcd8403656so3324196eaf.1 for ; Wed, 28 Aug 2024 02:53:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838781; x=1725443581; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T71bAWZ5le2Naj8DZ0ljjvL8S+u/egKAPUIr3/tluJ8=; b=NZTs+2EUVNqwBJ1RC8t1MOPCEz3GYbOeqQQvc4UKtHWLksPZjHgh6m9A6Dz8btDyYX lhT3joER4YcN8tS3niwM3Lj433QpOjrkZBVpOCB67cXBvCncy5B6P4LzVhf6z5aBjwSI 9HDOYiQl7TGd+0c22BDknHZYjkzsWIrOEFtQ3reK4LNntirpjkejM7Fmoi3QKljsV989 wDAoT9A8p67VX5/GOKO0u85i2CCCI4rMAEESlIYMIfd6AOQxRIWHw44kCtnWqWhBwISM UZKR0xXX8EvUrbYf8cRTmiwKvI74hHP1Pr/+Gf22dgBsJ8Q7n6UKjQECn1XcZLeylSwN XvOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838781; x=1725443581; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T71bAWZ5le2Naj8DZ0ljjvL8S+u/egKAPUIr3/tluJ8=; b=C/lIhaJZAo5ww+jZ8P2/PML+ILKk63wCKfaau+6stJrAZTU34gD8T8bSBIuIZ+Nvx4 CH/UyxdAxRyhC4IOKXsT1r/2z6GUy5Bro/gFJlpi/kiUeG8wh5LDGBlpBtOGtaOQmDyx be6DvF967YbVzV7yJsarUbCwDVqtYlLVG1O++9kTC7tR5pfLnw8cNeOBdEJzDWK360Tt hs/L2Yvx976YOwMdj/RDfUHPUJmp9mcb9FXxp+RjBi3BoUdoK73jp92e3CcTx3XDS/aO j71Cr08ZHKMLbYhN+Q4cE0lY/zSEOZPP7AmlqNVCxTrvDePg3V4gsZIfB/3jLdTL/Jke rZTw== X-Gm-Message-State: AOJu0Yya+7g2jvJH9ha+NJpJc4zGB71GbMU+FHoUyky00mxHfmd2roaL wvMyrCSqu5IvvFiKdyOBO7oNpQsQOH529WFGdW0CqFAIHVosHf6aROvDwWef X-Google-Smtp-Source: AGHT+IH4OD8zAfPcwO53guP+mNee6d6qN8ggHvB5WTMqp92jh4ZTGGGSlERXbhhlQrsS0DBfHwEUzQ== X-Received: by 2002:a05:6358:109:b0:1ac:f2a5:e79e with SMTP id e5c5f4694b2df-1b5c215c92bmr1934193155d.16.1724838781428; Wed, 28 Aug 2024 02:53:01 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.52.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:53:01 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Richard Henderson Subject: [PATCH v4 03/17] bsd-user: Implement RISC-V CPU register cloning and reset functions Date: Wed, 28 Aug 2024 19:52:29 +1000 Message-Id: <20240828095243.90491-4-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c34; envelope-from=itachis6234@gmail.com; helo=mail-oo1-xc34.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Mark Corbin Added functions for cloning CPU registers and resetting the CPU state for RISC-V architecture. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson --- bsd-user/riscv/target_arch_cpu.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bsd-user/riscv/target_arch_cpu.h b/bsd-user/riscv/target_arch_cpu.h index ba589909e2..b1575aab20 100644 --- a/bsd-user/riscv/target_arch_cpu.h +++ b/bsd-user/riscv/target_arch_cpu.h @@ -130,4 +130,18 @@ static inline void target_cpu_loop(CPURISCVState *env) } } +static inline void target_cpu_clone_regs(CPURISCVState *env, target_ulong newsp) +{ + if (newsp) { + env->gpr[xSP] = newsp; + } + + env->gpr[xA0] = 0; + env->gpr[xT0] = 0; +} + +static inline void target_cpu_reset(CPUArchState *env) +{ +} + #endif /* TARGET_ARCH_CPU_H */ From patchwork Wed Aug 28 09:52:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EC761C54E65 for ; Wed, 28 Aug 2024 09:56:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMV-00023V-G9; Wed, 28 Aug 2024 05:53:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMS-0001xp-Dl for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:09 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMQ-0001oN-IU for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:08 -0400 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-656d8b346d2so3921405a12.2 for ; Wed, 28 Aug 2024 02:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838784; x=1725443584; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q8SeRNxqA0kdGYXuMPPKRU3j4MVX/4+712bEYl1oABA=; b=nipOaqizqXm11mnpxNboXbor4g8QTL2gb8cvF+QoxZvzpbylFWx12eDVx5+byx3OMx QWMYhl8/klIsYLwTqJDvdfmVvA0CayeB6ZWH4y+M6GXGeBw+vD0K0ZBVSlMwXjXR4Qxw hH4/YrEDvv0RIeoI5LM8j2KfqHcdrh8EnUr1w9WnuhluXlP7Qf0lIF/s9ozEDKkox3Y+ TfHpTuirXU/ziOuZ7X4Y9Ss7mLIIpn1CEuz74DjundQqwxYNytidhuJlxSBHxMgnfhDa 9po71w1GeK8SWmHkIqFiwFYO+MrMaI8pPlEuXHrTIj9pzvA73zN1+dd+LJA8T47EYIb7 2zXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838784; x=1725443584; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q8SeRNxqA0kdGYXuMPPKRU3j4MVX/4+712bEYl1oABA=; b=WjlIEREJnSPNQGzGnCC1xUe2ia3gpe1+ccxgXcfaun2+L43m1ZAHzfh7fDAzCqHOHD He39WpFMN2oMy3YC6b/BlzXQvVkwJEmlv9hzW5F2wpJj1S/lEn4uyPbu7eCASs0H7oEH O7bslyWR5Ps9XI8An6JvaiEru5FQM4br6n3AlfY7GipVTD/nzkeour5YSEtW7Vos4SE3 0gBp5GcSO545xbU8qQ50psKHpblNeCBPxe71vxr0K1xU2dLD1lZUHaQYbzzmqnHn/TeR X/viuM0yZtIsl/d3nYFkSV+JO3Ns42Do4M+UcjG1uh0bEpx0ru8Wc+dJ2IfGl+ZnqsCC FgKw== X-Gm-Message-State: AOJu0YxjZ63KlWSjCgSZlsB6pqB4rM2tFwAuaGiXLpNySq/G9CZjIZ7a JJ0eMV0aZgvDVKJSybuwPo+me+ghYe7YH+MQ6fPFS1RSooGOrHgvooHZup8z X-Google-Smtp-Source: AGHT+IHE7ZCAZdcCsTYcgpVVGoE19yB+ZVfV1AbPLA61aNJH4aSfN3AI0BltMdJB5IENWucm7JzCeQ== X-Received: by 2002:a05:6a21:1584:b0:1ca:cbf5:5b0 with SMTP id adf61e73a8af0-1cc8b459221mr15988881637.21.1724838783884; Wed, 28 Aug 2024 02:53:03 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:53:03 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Richard Henderson Subject: [PATCH v4 04/17] bsd-user: Implement RISC-V TLS register setup Date: Wed, 28 Aug 2024 19:52:30 +1000 Message-Id: <20240828095243.90491-5-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=itachis6234@gmail.com; helo=mail-pg1-x536.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Mark Corbin Included the prototype for the 'target_cpu_set_tls' function in the 'target_arch.h' header file. This function is responsible for setting the Thread Local Storage (TLS) register for RISC-V architecture. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson --- bsd-user/riscv/target_arch.h | 27 +++++++++++++++++++++++++++ bsd-user/riscv/target_arch_cpu.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 bsd-user/riscv/target_arch.h create mode 100644 bsd-user/riscv/target_arch_cpu.c diff --git a/bsd-user/riscv/target_arch.h b/bsd-user/riscv/target_arch.h new file mode 100644 index 0000000000..26ce07f343 --- /dev/null +++ b/bsd-user/riscv/target_arch.h @@ -0,0 +1,27 @@ +/* + * RISC-V specific prototypes + * + * Copyright (c) 2019 Mark Corbin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef TARGET_ARCH_H +#define TARGET_ARCH_H + +#include "qemu.h" + +void target_cpu_set_tls(CPURISCVState *env, target_ulong newtls); + +#endif /* TARGET_ARCH_H */ diff --git a/bsd-user/riscv/target_arch_cpu.c b/bsd-user/riscv/target_arch_cpu.c new file mode 100644 index 0000000000..44e25d2ddf --- /dev/null +++ b/bsd-user/riscv/target_arch_cpu.c @@ -0,0 +1,29 @@ +/* + * RISC-V CPU related code + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#include "qemu/osdep.h" + +#include "target_arch.h" + +#define TP_OFFSET 16 + +/* Compare with cpu_set_user_tls() in riscv/riscv/vm_machdep.c */ +void target_cpu_set_tls(CPURISCVState *env, target_ulong newtls) +{ + env->gpr[xTP] = newtls + TP_OFFSET; +} From patchwork Wed Aug 28 09:52:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781016 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6815FC54E71 for ; Wed, 28 Aug 2024 09:54:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMW-000260-4c; Wed, 28 Aug 2024 05:53:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMT-0001zc-VN for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:10 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMS-0001od-8r for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:09 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-7142e002aceso5313711b3a.2 for ; Wed, 28 Aug 2024 02:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838787; x=1725443587; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g4MfaAoEg0D4PG1s02DK0HI+nWn0NbjMokYUO+miRKs=; b=d+LpRhdoODUr6dH0yRiIbYS8+U9RKvwf2A2NaNgftxSE6CXDf3jym46GZyJedfjF08 vx+wksINRpT4NHU4cjMTJkjr7+u4fdTuDxJBW492tqb6BLcDwkZMXalDgRDmRU1XaAet uD4drloJ2Zsh3ooYCkaSp6yCGZuyAj/dTs0QyHJaVk97DuqZ9PHwhouc2vpek5tbPKXQ Ijg4vK0ZexkwViGAXVXDqF3yYnjNLM9SJKWhGhJ//lwqmdjw76WuOvs6VVaEcF+j7WlX jBX/xwwvs/sTj8X7EMyoDaZIBkhzUDYlzor+swMVp/nZG4EGPcta1vP08Esj4yRg2JPU MLrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838787; x=1725443587; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g4MfaAoEg0D4PG1s02DK0HI+nWn0NbjMokYUO+miRKs=; b=Ut2LxMqoSZzw6F6ERJtF0uOWkjc82MziHXVK++JzpS3puHzARwRcW9s+GOplN1ZQnT efLOIlEXuFTArs+30KyWwKgLH0lM/+mdca9VuQ7eN5n6Hp4YiF5KRfqEPedEY+NAHtkD mg7gWwG3MRX9DtiexIYdPNTTTBHuTOls35cUPtajiFRCzXgf7UZ2SSViPVt1fnUaDA/g z/SaEFxKgooe/tnnGEIpyF/KCdrqWnsAtqiD+q9W2CCpyRDwGARX2lc5Ndh2OfJa4Ris CuenbRVridD4PBmbqMHV4xef3ZIJf6hAvrNlYG50PS4vvslcIkwTkl13DVUFUND3r7H9 sGdg== X-Gm-Message-State: AOJu0YyBc2kSucGU2CRRu7+1jUUhtltqM/oDkSuz/IxwjCv2qySoFWCm jhIDNS1nB/buG28u5BYio9i98WYnLTa6baxNaFm/CfnDynsvp0rcex40e/hP X-Google-Smtp-Source: AGHT+IEskS5wugh01RHkDYqs6hkB0X0lB4wI8izTQKz/6rOfKnUIixQVtVDCmaXNk63iCJHipMLqsA== X-Received: by 2002:a05:6a00:194d:b0:706:6c38:31f3 with SMTP id d2e1a72fcca58-715d10c19fdmr1547352b3a.8.1724838786539; Wed, 28 Aug 2024 02:53:06 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.53.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:53:06 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Kyle Evans , Richard Henderson Subject: [PATCH v4 05/17] bsd-user: Add RISC-V ELF definitions and hardware capability detection Date: Wed, 28 Aug 2024 19:52:31 +1000 Message-Id: <20240828095243.90491-6-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=itachis6234@gmail.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Mark Corbin Introduced RISC-V specific ELF definitions and hardware capability detection. Additionally, a function to retrieve hardware capabilities ('get_elf_hwcap') is implemented, which returns the common bits set in each CPU's ISA strings. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Co-authored-by: Kyle Evans Reviewed-by: Richard Henderson --- bsd-user/riscv/target_arch_elf.h | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 bsd-user/riscv/target_arch_elf.h diff --git a/bsd-user/riscv/target_arch_elf.h b/bsd-user/riscv/target_arch_elf.h new file mode 100644 index 0000000000..4eb915e61e --- /dev/null +++ b/bsd-user/riscv/target_arch_elf.h @@ -0,0 +1,42 @@ +/* + * RISC-V ELF definitions + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef TARGET_ARCH_ELF_H +#define TARGET_ARCH_ELF_H + +#define elf_check_arch(x) ((x) == EM_RISCV) +#define ELF_START_MMAP 0x80000000 +#define ELF_ET_DYN_LOAD_ADDR 0x100000 +#define ELF_CLASS ELFCLASS64 + +#define ELF_DATA ELFDATA2LSB +#define ELF_ARCH EM_RISCV + +#define ELF_HWCAP get_elf_hwcap() +static uint32_t get_elf_hwcap(void) +{ + RISCVCPU *cpu = RISCV_CPU(thread_cpu); + + return cpu->env.misa_ext_mask; +} + +#define USE_ELF_CORE_DUMP +#define ELF_EXEC_PAGESIZE 4096 + +#endif /* TARGET_ARCH_ELF_H */ From patchwork Wed Aug 28 09:52:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DAA0FC5479A for ; Wed, 28 Aug 2024 09:57:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMZ-0002Hv-6i; Wed, 28 Aug 2024 05:53:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMW-00028Q-NG for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:12 -0400 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMU-0001oq-NQ for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:12 -0400 Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-5dc93fa5639so4846348eaf.1 for ; Wed, 28 Aug 2024 02:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838789; x=1725443589; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a+NCEiOZJzboz9w1INUibK6hoUbq+IVFPstbDaWXows=; b=HxqKT21iD3bknQ5yTO/MUvJ4Yv7obeAaz+wAUBsPz7bO8B4vZQnkEf+wB69st4PR9o bNbEgjOQG0vWQDFTC2U28dpYAV9aAzxObBelIoCup9xFNTZ/Rw2EHGBo0I7kOL6tw1CS UvRFaU0cscoEoKaZVkzJYyiI5R5l/9k+4h1MnB4lmlY/N+eN9q4FOhQD50t7r62pIn4s WsLqwkbwsIusOIrGS0P5xO+5L90ng/mEhYMP8xKHNDY3gcfY0LgSsHKiOVkEHcENH8b/ Q39j1gG/qI/VHtDITbLyim5nBoPzgegGY4RdfFSwvz3BccP7BGLJTFSuJqeM7NBNmSOk nkvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838789; x=1725443589; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a+NCEiOZJzboz9w1INUibK6hoUbq+IVFPstbDaWXows=; b=ee4O0s1q1Cpb7TVWOup5pd8qV1VL1W8+OOVgoJdng9MVv3nTuQ6U2J2FQs/NLlJdDy eTkaDnOKlEh92QOHEn3hgBhwwkHQ4LsVA5r7Z7Ni92o1Ut6db7Q7IeYWxUN8VxAm6J0x oxOKNfiPKd0UI5Y0E7cGKl+BaNmI+KJJHLgpe8l2hZGdTX0fW8bLklXB6kxjoCnhM8L/ coCR6MGmQvyRWtcfTn0r8lEgxbJxfdnShvu6gCjV2TZyP4nqMLCnzYEUWEvp7LHhPhJg dU/j/o+QRBl2YXqnzQRYrrJLQ9RQ/l29BQhIalhaqfn8wf3MH7sa3ei7wC+vx/RfGGiv zjhw== X-Gm-Message-State: AOJu0Yz6s/1z+8+LQWgk71+7qb8FRxzzlz9SfxKcaL6hU1xdkV/0qXm7 FJBp/WhJjj2SfUAjP0384UOsGzf77YdL0e+oVg84PaSnNFJNmfxury2a3m5h X-Google-Smtp-Source: AGHT+IFeVAmuBlc8Lm+LPWhRzOKqi02uvzhAItRjpNJ2Bqtt8oZbOHVyOTNv0sSaDQLV3Qdr1zFb2A== X-Received: by 2002:a05:6358:57a3:b0:1ac:f109:e248 with SMTP id e5c5f4694b2df-1b5c3a458a8mr1878612555d.2.1724838789022; Wed, 28 Aug 2024 02:53:09 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.53.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:53:08 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Richard Henderson Subject: [PATCH v4 06/17] bsd-user: Define RISC-V register structures and register copying Date: Wed, 28 Aug 2024 19:52:32 +1000 Message-Id: <20240828095243.90491-7-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c2d; envelope-from=itachis6234@gmail.com; helo=mail-oo1-xc2d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Mark Corbin Added definitions for RISC-V register structures, including general-purpose registers and floating-point registers, in 'target_arch_reg.h'. Implemented the 'target_copy_regs' function to copy register values from the CPU state to the target register structure, ensuring proper endianness handling using 'tswapreg'. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson --- bsd-user/riscv/target_arch_reg.h | 88 ++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 bsd-user/riscv/target_arch_reg.h diff --git a/bsd-user/riscv/target_arch_reg.h b/bsd-user/riscv/target_arch_reg.h new file mode 100644 index 0000000000..12b1c96b61 --- /dev/null +++ b/bsd-user/riscv/target_arch_reg.h @@ -0,0 +1,88 @@ +/* + * RISC-V register structures + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef TARGET_ARCH_REG_H +#define TARGET_ARCH_REG_H + +/* Compare with riscv/include/reg.h */ +typedef struct target_reg { + uint64_t ra; /* return address */ + uint64_t sp; /* stack pointer */ + uint64_t gp; /* global pointer */ + uint64_t tp; /* thread pointer */ + uint64_t t[7]; /* temporaries */ + uint64_t s[12]; /* saved registers */ + uint64_t a[8]; /* function arguments */ + uint64_t sepc; /* exception program counter */ + uint64_t sstatus; /* status register */ +} target_reg_t; + +typedef struct target_fpreg { + uint64_t fp_x[32][2]; /* Floating point registers */ + uint64_t fp_fcsr; /* Floating point control reg */ +} target_fpreg_t; + +#define tswapreg(ptr) tswapal(ptr) + +/* Compare with struct trapframe in riscv/include/frame.h */ +static inline void target_copy_regs(target_reg_t *regs, + const CPURISCVState *env) +{ + + regs->ra = tswapreg(env->gpr[1]); + regs->sp = tswapreg(env->gpr[2]); + regs->gp = tswapreg(env->gpr[3]); + regs->tp = tswapreg(env->gpr[4]); + + regs->t[0] = tswapreg(env->gpr[5]); + regs->t[1] = tswapreg(env->gpr[6]); + regs->t[2] = tswapreg(env->gpr[7]); + regs->t[3] = tswapreg(env->gpr[28]); + regs->t[4] = tswapreg(env->gpr[29]); + regs->t[5] = tswapreg(env->gpr[30]); + regs->t[6] = tswapreg(env->gpr[31]); + + regs->s[0] = tswapreg(env->gpr[8]); + regs->s[1] = tswapreg(env->gpr[9]); + regs->s[2] = tswapreg(env->gpr[18]); + regs->s[3] = tswapreg(env->gpr[19]); + regs->s[4] = tswapreg(env->gpr[20]); + regs->s[5] = tswapreg(env->gpr[21]); + regs->s[6] = tswapreg(env->gpr[22]); + regs->s[7] = tswapreg(env->gpr[23]); + regs->s[8] = tswapreg(env->gpr[24]); + regs->s[9] = tswapreg(env->gpr[25]); + regs->s[10] = tswapreg(env->gpr[26]); + regs->s[11] = tswapreg(env->gpr[27]); + + regs->a[0] = tswapreg(env->gpr[10]); + regs->a[1] = tswapreg(env->gpr[11]); + regs->a[2] = tswapreg(env->gpr[12]); + regs->a[3] = tswapreg(env->gpr[13]); + regs->a[4] = tswapreg(env->gpr[14]); + regs->a[5] = tswapreg(env->gpr[15]); + regs->a[6] = tswapreg(env->gpr[16]); + regs->a[7] = tswapreg(env->gpr[17]); + + regs->sepc = tswapreg(env->pc); +} + +#undef tswapreg + +#endif /* TARGET_ARCH_REG_H */ From patchwork Wed Aug 28 09:52:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CA9F6C5479A for ; Wed, 28 Aug 2024 09:56:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMa-0002OE-Dt; Wed, 28 Aug 2024 05:53:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMY-0002HJ-Rx for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:14 -0400 Received: from mail-oa1-x36.google.com ([2001:4860:4864:20::36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMX-0001p3-1E for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:14 -0400 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-2704d461058so4490188fac.0 for ; Wed, 28 Aug 2024 02:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838791; x=1725443591; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mQk2A/hTjmVjUN/uDmSNUdNIQXXqerO9SIB89nvt1XM=; b=K7FX7Gt2n7Yao//0xJXu/zTrGHvJswwg3G+JgBNpN1F8S3zh/Iwefyf4xAtYFA7dpe 4GAx1wWy0ltm4Lmq15VYpasbRA3pj3AaMVqPpfXxYypWYO46jT4zZPW/B+LGeoU7+kjD pzErsSgsxtw4HjSJF79t7BYL0E6/din7FAnWrOAfmICOgdgMnWXV2To9X1QoZ8Q7xqWn upKKxio2ZJoHiIRu2XvGLDJtmPmTD6wF5ZkNHB48GOEF9igcn1Lz7j+fPqOFxfdD8cGh CZwosXKLp7+ubKUhhQX67J14W73FJ+aDL0lbv0DPYI1y2PgIEiTVSp6rkE+exlVXV3aB Q41w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838791; x=1725443591; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mQk2A/hTjmVjUN/uDmSNUdNIQXXqerO9SIB89nvt1XM=; b=XpF02S9W4fwP9UmLynjf6OFBDICx9AcPPk0tXBsLo7hPgpOqkbW69F6966kvxpASav yrJjqEwnyHpYED+qz77LI3IFNmmUk3wF2PYwbdS0EeDMBgI0U7scVDsajE3A1p788GLN oq2xN4HdBisket7IS+h0UmS0/5osgtOXfpIeKDBESrEWix7zkHc07g/XD1m+gA/HV3v4 Nkjrky0CK+llKZzfdVdAyuYXqbSV9roiW7aVtaSOcBJx0tBEhPuv/eE7+UylO3UR5UaG OfiK7SdOfknUEhbSEtdZ2c3ml1POyysOHoop3WV4RfEUnR3wJZHKFNnHlJ07P7hKEIFl Xq4w== X-Gm-Message-State: AOJu0Yx19l4OxwcYLiGMzZ44nh0BHOyaP/Pnw2JS2+UZAiuDn40XV7L2 EGxPZexfySJbo6P0ph6bFO3XvjCgS9YgQyqL2sbCYXf/tCr+QwN71rgi9Ylf X-Google-Smtp-Source: AGHT+IEBYdz0kwr9sC/X0GP0Yi1PlyHTXTgcSqIleC5qpHghXH4OkPjles+onTsrHFn601Q/h5mmTQ== X-Received: by 2002:a05:6870:8286:b0:270:130f:cee0 with SMTP id 586e51a60fabf-273e661aeadmr17559877fac.39.1724838791525; Wed, 28 Aug 2024 02:53:11 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:53:11 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Richard Henderson Subject: [PATCH v4 07/17] bsd-user: Add RISC-V signal trampoline setup function Date: Wed, 28 Aug 2024 19:52:33 +1000 Message-Id: <20240828095243.90491-8-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::36; envelope-from=itachis6234@gmail.com; helo=mail-oa1-x36.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Mark Corbin Implemented the 'setup_sigtramp' function for setting up the signal trampoline code in the RISC-V architecture. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson --- bsd-user/riscv/target_arch_sigtramp.h | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 bsd-user/riscv/target_arch_sigtramp.h diff --git a/bsd-user/riscv/target_arch_sigtramp.h b/bsd-user/riscv/target_arch_sigtramp.h new file mode 100644 index 0000000000..fce673e65a --- /dev/null +++ b/bsd-user/riscv/target_arch_sigtramp.h @@ -0,0 +1,42 @@ +/* + * RISC-V sigcode + * + * Copyright (c) 2019 Mark Corbin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef TARGET_ARCH_SIGTRAMP_H +#define TARGET_ARCH_SIGTRAMP_H + +/* Compare with sigcode() in riscv/riscv/locore.S */ +static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc, + unsigned sys_sigreturn) +{ + int i; + uint32_t sys_exit = TARGET_FREEBSD_NR_exit; + + static const uint32_t sigtramp_code[] = { + /* 1 */ const_le32(0x00010513), /* mv a0, sp */ + /* 2 */ const_le32(0x00050513 + (sigf_uc << 20)), /* addi a0, a0, sigf_uc */ + /* 3 */ const_le32(0x00000293 + (sys_sigreturn << 20)), /* li t0, sys_sigreturn */ + /* 4 */ const_le32(0x00000073), /* ecall */ + /* 5 */ const_le32(0x00000293 + (sys_exit << 20)), /* li t0, sys_exit */ + /* 6 */ const_le32(0x00000073), /* ecall */ + /* 7 */ const_le32(0xFF1FF06F) /* b -16 */ + }; + + return memcpy_to_target(offset, sigtramp_code, TARGET_SZSIGCODE); +} +#endif /* TARGET_ARCH_SIGTRAMP_H */ From patchwork Wed Aug 28 09:52:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781014 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0455FC54E62 for ; Wed, 28 Aug 2024 09:54:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMc-0002YB-VF; Wed, 28 Aug 2024 05:53:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMb-0002TZ-Pc for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:17 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMZ-0001pR-VV for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:17 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-714263cb074so4582625b3a.1 for ; Wed, 28 Aug 2024 02:53:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838794; x=1725443594; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lfzjBG7+9yzLMDJFHDoCCaXekwfn4Gr8dayPzH/NfvM=; b=llhVpMTwyi5fIKhoIWso8dS0jOShUQiF1/J6k/Qc4zRWdlrrEfRiZI6oY8UZfnI6Kp qYkIUSIMwFoprj0OrJGkR0ORgVxMk4b0MWx8zrWsQKw8ioYPCp3ZAiESy1FTWnFhG5QW aRNl6WhPRlh7WktJWTqDL2jh8Z7uVV7ljWwN2B4j++lxRPJbsGSfSKdQ69yNaDu1hGWU ia5GBxxcdMmqjoTH1LvqM4AEEYORvWOREbg/5HEalRFz1BwnOdObSo2GCY94EwwgwxSF FQK97Zl0sfuih6SKx/ECrxMSW69pJz4Ut7gXUQMlEiOGJQ2C5hnnnj8Cqgsy76QkbtEy YAjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838794; x=1725443594; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lfzjBG7+9yzLMDJFHDoCCaXekwfn4Gr8dayPzH/NfvM=; b=l3BJp5FJxLQAz10EyoPrpkO0i85rt/K08GJvxG9qx5tFTepkSDgViLJ0MpoMvb1MDM LraCtSpVcg74IaFFL+K7bOcQPWRoQgUOKRPgOY6W3zC1ki8wm6/qu7+AFShiaKWLZXs1 8WogBaup1bxNG0e79YWqaaqUFIbSI+JwPlc3jV3aNPcv4ABXBLoS2yXehXQ3zuO7JyfA 6TJa3rtU003/vlhNZhMUcWY6NjgfO0KDSNKMIH+JD6DZRJiY6mNkB80SCx8OOo6LChaC 2ea0ts6XoENrzuHR80g29Td//WBH3SHtTXWTthsEv8sIQAXXMRpVqrlDShfvwkBGfKYz 3Ejw== X-Gm-Message-State: AOJu0YzXo9NSigzG6G4M3fi2MGefm+AZwIQKdspXwo5PZ4lzidNE6cLu 4ooqsIYiiywcrG82LZu+XrjexiwXFZR1asffH4IHux1fmsw/fiTnoUtoVf16 X-Google-Smtp-Source: AGHT+IFVjTkPABRcen2vD9SFbYT8xn3QHxTxCXUnNlNVkvIR0zaWzJ9pAJPb6lkYsyT1L4glcIi9jg== X-Received: by 2002:a05:6a00:841:b0:70d:7547:90f7 with SMTP id d2e1a72fcca58-71445d4eec6mr17327240b3a.12.1724838794031; Wed, 28 Aug 2024 02:53:14 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:53:13 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Richard Henderson Subject: [PATCH v4 08/17] bsd-user: Implement RISC-V sysarch system call emulation Date: Wed, 28 Aug 2024 19:52:34 +1000 Message-Id: <20240828095243.90491-9-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=itachis6234@gmail.com; helo=mail-pf1-x42b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Mark Corbin Added the 'do_freebsd_arch_sysarch' function to emulate the 'sysarch' system call for the RISC-V architecture. Currently, this function returns '-TARGET_EOPNOTSUPP' to indicate that the operation is not supported. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson --- bsd-user/riscv/target_arch_sysarch.h | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 bsd-user/riscv/target_arch_sysarch.h diff --git a/bsd-user/riscv/target_arch_sysarch.h b/bsd-user/riscv/target_arch_sysarch.h new file mode 100644 index 0000000000..9af42331b4 --- /dev/null +++ b/bsd-user/riscv/target_arch_sysarch.h @@ -0,0 +1,41 @@ +/* + * RISC-V sysarch() system call emulation + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef TARGET_ARCH_SYSARCH_H +#define TARGET_ARCH_SYSARCH_H + +#include "target_syscall.h" +#include "target_arch.h" + +static inline abi_long do_freebsd_arch_sysarch(CPURISCVState *env, int op, + abi_ulong parms) +{ + + return -TARGET_EOPNOTSUPP; +} + +static inline void do_freebsd_arch_print_sysarch( + const struct syscallname *name, abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6) +{ + + gemu_log("UNKNOWN OP: %d, " TARGET_ABI_FMT_lx ")", (int)arg1, arg2); +} + +#endif /* TARGET_ARCH_SYSARCH_H */ From patchwork Wed Aug 28 09:52:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E8D02C54E65 for ; Wed, 28 Aug 2024 09:54:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMh-0002qu-GX; Wed, 28 Aug 2024 05:53:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMg-0002ls-9l for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:22 -0400 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMe-0001pl-72 for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:22 -0400 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3db1e4219f8so1039622b6e.3 for ; Wed, 28 Aug 2024 02:53:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838799; x=1725443599; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aPq6C7QoOX3nfkGLM/R7pqXc/B3Uq/1K4kEgtZxBVyo=; b=e7osteoyyAX4ITPQ2oaW1GxPJiyjPRBDKz3qPpl3BjD9wBLuTrDNTdG3Slf42WhIPP HkT9cUqmflAZD2bhhxkRae4WRJjFlRlMWvLxuJob8KAfFD09mtU+S4ooSQ3vgq4z6zNK DhBgegADeYOmfhDJj/UP1NR9i7SNHLQ++p6wWV7yjleooBONE64EJBE+VTWr3rbGf3ue 0yJ99NBcaOKyFfgU6eLrettEMCEamSXXr+rNr70/GOwR51Y8LxT7I65b3nYFSRIIrBOd ps1DZQdUuU5BdBPBQGxAThu0g9hiUtJYI21BL7bEW5gUSeOPJWfEe8PmHUahZ13K68Bg mIcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838799; x=1725443599; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aPq6C7QoOX3nfkGLM/R7pqXc/B3Uq/1K4kEgtZxBVyo=; b=c+PhG7FHhu2jcaEKpF6oD3vv+N+8KYt0nNQPpsLbt5kUIGsrqlZK5s5AyO0emGs5Iw DGPgoay29u0x/jvffeXlDT2n7Q4mi/bRYSjI9xerDVsGsgCzlmIgaRQfqpCiwqtnWvb2 US1O7TV97PB2475+fuqwys6Iy2pnzaBNxrOEjjp4sPcMOdMFqwTBDy5IwVKuRaBEBgQS +TZbKWhOhtlej9nqbg4PY4ucqaPSj944q2rYqiS6/6e/+35GFCbdW5j4MO71ZCQK5wLn yL/ak+IUJ7eEw+AMDCSzXWZZTEy+xYouRcA63E7pAIvDoGycN8A+AiFb2rhbLuOdthIl 1X0A== X-Gm-Message-State: AOJu0YxqUkB6URzbblsrtnVCgkF5m9qys5b5ZJLO8il0ix1n6tF/VQUX +cIAYl4BLqm0OKxkGHSKGGDXHzor9oQIzDnx9tuC60wSdi/hkRtbInmvb9Bt X-Google-Smtp-Source: AGHT+IHH5SQPjDOWMAEw23Z2mhEvqhRxVbVyav43MXN79zxxTrU20Yqgu7eJ8BdHmkvBDVbmiBnuVw== X-Received: by 2002:a05:6871:3297:b0:261:e19:458d with SMTP id 586e51a60fabf-273e646d7b8mr17435410fac.4.1724838798470; Wed, 28 Aug 2024 02:53:18 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:53:18 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Jessica Clarke , Kyle Evans , Richard Henderson Subject: [PATCH v4 09/17] bsd-user: Add RISC-V thread setup and initialization support Date: Wed, 28 Aug 2024 19:52:35 +1000 Message-Id: <20240828095243.90491-10-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::234; envelope-from=itachis6234@gmail.com; helo=mail-oi1-x234.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Mark Corbin Implemented functions for setting up and initializing threads in the RISC-V architecture. The 'target_thread_set_upcall' function sets up the stack pointer, program counter, and function argument for new threads. The 'target_thread_init' function initializes thread registers based on the provided image information. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Co-authored-by: Jessica Clarke Co-authored-by: Kyle Evans Reviewed-by: Richard Henderson --- bsd-user/riscv/target_arch_thread.h | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 bsd-user/riscv/target_arch_thread.h diff --git a/bsd-user/riscv/target_arch_thread.h b/bsd-user/riscv/target_arch_thread.h new file mode 100644 index 0000000000..db0f9eb52c --- /dev/null +++ b/bsd-user/riscv/target_arch_thread.h @@ -0,0 +1,47 @@ +/* + * RISC-V thread support + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef TARGET_ARCH_THREAD_H +#define TARGET_ARCH_THREAD_H + +/* Compare with cpu_set_upcall() in riscv/riscv/vm_machdep.c */ +static inline void target_thread_set_upcall(CPURISCVState *regs, + abi_ulong entry, abi_ulong arg, abi_ulong stack_base, + abi_ulong stack_size) +{ + abi_ulong sp; + + sp = ROUND_DOWN(stack_base + stack_size,16); + + regs->gpr[xSP] = sp; + regs->pc = entry; + regs->gpr[xA0] = arg; +} + +/* Compare with exec_setregs() in riscv/riscv/machdep.c */ +static inline void target_thread_init(struct target_pt_regs *regs, + struct image_info *infop) +{ + regs->sepc = infop->entry; + regs->regs[xRA] = infop->entry; + regs->regs[xA0] = infop->start_stack; + regs->regs[xSP] = ROUND_DOWN(infop->start_stack,16); +} + +#endif /* TARGET_ARCH_THREAD_H */ From patchwork Wed Aug 28 09:52:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3F9D9C5479A for ; Wed, 28 Aug 2024 09:54:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMk-00031B-0L; Wed, 28 Aug 2024 05:53:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMi-0002vB-Hp for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:24 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMg-0001pq-OW for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:24 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-7141feed424so5323179b3a.2 for ; Wed, 28 Aug 2024 02:53:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838801; x=1725443601; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BISuETtEj/uI6CddQsRG+h5xaQo8IxKpbRWv0bTNq7U=; b=d5TRUFbK+IU+gqx8cVYTHPOY/XI3eIzSs72IOcV2qv9vz2ywiL9VwltHaDOeTgmfbJ Wb9ilrtJudhA4I0H3HgDSzInwbpNGj70AyadD0ybWOVDxQ+VzFSy5frxXUV8R+eBo7tY Vm3yNsKdOOwxxLaB3jIRSg+9/3RN3ByrJdtrEymcQ2by3KsPaJxyGWFihbqi0sqWD3YF t4MUMqmkZxC/P28rcZNKHLKLuWgpfOn7T0TzGic5NP0MPSo6dGJMlUpYT++16Gg6Cp1A YtSp+zlDLz8KiGllfDePZCbpD7/1NJwy/H7yjyetKTVb9MYFSo2F9aEiwzpozwRYIObb z3lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838801; x=1725443601; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BISuETtEj/uI6CddQsRG+h5xaQo8IxKpbRWv0bTNq7U=; b=ktysV9iGby3LMY6cIAH6dQhPbONmMuiCVAjLOkg0VNp3CvmHwOr+c1WDXvM9JWQgoe lfQ7HCTY+zh1lXRvWZYHUGbWDid3MEVNqGehtdjTO4+ewsMG0vIGx9QXKOAE8ioJ3zZZ tS+hq+OBkCjDtHf7Th4QA/rjoCxkkyhnq+dg5OxVHZAShrHG+1AF/qanUHXexjztfB9s 23JydTwlR4jkfEWyOA11rFYiBG1XS/+r31cmU6ouMRrBIhuQjXESH6LVzgYDyW0Tvi8C s9/h3v5lio0BCjrg0em77dzLxdt3uVhLTaqXLRNGE56up310CNQ9kXLYujQbZol47Hft phuA== X-Gm-Message-State: AOJu0YztQKnPMs8kL87s/TljY+fMGEx0/44Va+B6tvqmXpBi6kqVUHg5 m/1PAdqNCuNbXOzxyTXGlh4iHVqNk+7X2Qn0EZRX4uuAFWMir2cJJbxsn84U X-Google-Smtp-Source: AGHT+IG4Kclq6hG4tVOJZn+Cct1B5OYHSFdWtbKuKX1RGO9T1luIHpIZMa02UA770z6vG5L372nAgg== X-Received: by 2002:a05:6a00:3ccc:b0:714:1bd8:35f7 with SMTP id d2e1a72fcca58-71445d5a9a7mr15839261b3a.15.1724838801016; Wed, 28 Aug 2024 02:53:21 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.53.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:53:20 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Richard Henderson Subject: [PATCH v4 10/17] bsd-user: Define RISC-V VM parameters and helper functions Date: Wed, 28 Aug 2024 19:52:36 +1000 Message-Id: <20240828095243.90491-11-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=itachis6234@gmail.com; helo=mail-pf1-x42b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Mark Corbin Added definitions for RISC-V VM parameters, including maximum and default sizes for text, data, and stack, as well as address space limits. Implemented helper functions for retrieving and setting specific values in the CPU state, such as stack pointer and return values. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson --- bsd-user/riscv/target_arch_vmparam.h | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 bsd-user/riscv/target_arch_vmparam.h diff --git a/bsd-user/riscv/target_arch_vmparam.h b/bsd-user/riscv/target_arch_vmparam.h new file mode 100644 index 0000000000..0f2486def1 --- /dev/null +++ b/bsd-user/riscv/target_arch_vmparam.h @@ -0,0 +1,53 @@ +/* + * RISC-V VM parameters definitions + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef TARGET_ARCH_VMPARAM_H +#define TARGET_ARCH_VMPARAM_H + +#include "cpu.h" + +/* Compare with riscv/include/vmparam.h */ +#define TARGET_MAXTSIZ (1 * GiB) /* max text size */ +#define TARGET_DFLDSIZ (128 * MiB) /* initial data size limit */ +#define TARGET_MAXDSIZ (1 * GiB) /* max data size */ +#define TARGET_DFLSSIZ (128 * MiB) /* initial stack size limit */ +#define TARGET_MAXSSIZ (1 * GiB) /* max stack size */ +#define TARGET_SGROWSIZ (128 * KiB) /* amount to grow stack */ + +#define TARGET_VM_MINUSER_ADDRESS (0x0000000000000000UL) +#define TARGET_VM_MAXUSER_ADDRESS (0x0000004000000000UL) + +#define TARGET_USRSTACK (TARGET_VM_MAXUSER_ADDRESS - TARGET_PAGE_SIZE) + +static inline abi_ulong get_sp_from_cpustate(CPURISCVState *state) +{ + return state->gpr[xSP]; +} + +static inline void set_second_rval(CPURISCVState *state, abi_ulong retval2) +{ + state->gpr[xA1] = retval2; +} + +static inline abi_ulong get_second_rval(CPURISCVState *state) +{ + return state->gpr[xA1]; +} + +#endif /* TARGET_ARCH_VMPARAM_H */ From patchwork Wed Aug 28 09:52:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781020 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F4075C54E62 for ; Wed, 28 Aug 2024 09:54:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMm-00039M-46; Wed, 28 Aug 2024 05:53:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMk-000355-VY for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:27 -0400 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMj-0001q4-8T for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:26 -0400 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-5d5f9d68805so4552044eaf.3 for ; Wed, 28 Aug 2024 02:53:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838804; x=1725443604; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/upld7cTqaC/atkB+nu7yGsbOxCVGK3zsoQHBJP0niw=; b=Gz66pF9/+2vxWohpdiXkaP38CaKmbvX2kpWAuF9znhbesCp8/RL7b+AsbTfdoWIxGQ fHnTChb15sJTY7//h5R31v8UJNJr4TTCuw0ujUQFXWf5alaS9iSTRwsvaMBIYoCb8DW2 4hbyB1AZheoRqnnEeyP7VZWmy/wLEccIw4LigryOqKM6vkl5DgNJbaYJXdvgCRUwJzj7 QFRAsbSFs2iJsmv5Vyw0gHBB8NA5xv1zyBvOaT+7aV0l3tiDrvJBz/+8iv+HDTmaxaeR i08CE48KlRIulj/a4lG3o6BM3ddsSDRQNyk90RqrHO1XcHzGGGjw0mPNs6uoed10eYJv GXDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838804; x=1725443604; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/upld7cTqaC/atkB+nu7yGsbOxCVGK3zsoQHBJP0niw=; b=TyJKrDK2G/mWz+JOrPWruy9Zm36Cj8qwhLpnbzGjOXfm1PS3p6ojQEKe1e8/H0Wfdb P7UXl9JZzaxlGazqp8HykYxPT0Ya2/iuS6rtf/r+4OMwJnfLpD+CZfPCiHh6Ah+ZpYuy ntz83QFlNMbCYt1/4zPpT/t7QJvtvDssMnBfRljgvnC70OWoDDIORoxM86KVV8ppgDhH XN5p8qD7Q5lmGPgX/g1NSIzRVw5LN59DifXsewC9D8UfT7v+XssOrR41IpVDtDjIEEHw p9k/aXAWiyl8e2xzUhvG1vSzunZ42NPy6HiOPdns2f4txOM5k8NoSt/rdeTPJvwznFvV OkMA== X-Gm-Message-State: AOJu0Yzy3TZLg5hmkCUlAexU2Ljp2xh/5GE/NiteTWPoYSlCAjGtBKHR v5E/DUAFN68Z5kaYDQgxw0HhzdhF8lqV2PYSgIZrrs0rPLzWe9G4W2lee6bb X-Google-Smtp-Source: AGHT+IGQ/XJ80Lf93JxE0kRt3TnA67ZSEepVtk1q49ndXJ937X+G3WiwquUu3FmLUy3JkIIT/CcV4A== X-Received: by 2002:a05:6358:9494:b0:1b1:a8b7:2d03 with SMTP id e5c5f4694b2df-1b5facdab69mr185350755d.13.1724838803786; Wed, 28 Aug 2024 02:53:23 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.53.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:53:23 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Jessica Clarke , Richard Henderson Subject: [PATCH v4 11/17] bsd-user: Define RISC-V system call structures and constants Date: Wed, 28 Aug 2024 19:52:37 +1000 Message-Id: <20240828095243.90491-12-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c2b; envelope-from=itachis6234@gmail.com; helo=mail-oo1-xc2b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Mark Corbin Introduced definitions for the RISC-V system call interface, including the 'target_pt_regs' structure that outlines the register storage layout during a system call. Added constants for hardware machine identifiers. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Co-authored-by: Jessica Clarke Reviewed-by: Richard Henderson --- bsd-user/riscv/target_syscall.h | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 bsd-user/riscv/target_syscall.h diff --git a/bsd-user/riscv/target_syscall.h b/bsd-user/riscv/target_syscall.h new file mode 100644 index 0000000000..e7e5231309 --- /dev/null +++ b/bsd-user/riscv/target_syscall.h @@ -0,0 +1,38 @@ +/* + * RISC-V system call definitions + * + * Copyright (c) Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef BSD_USER_RISCV_TARGET_SYSCALL_H +#define BSD_USER_RISCV_TARGET_SYSCALL_H + +/* + * struct target_pt_regs defines the way the registers are stored on the stack + * during a system call. + */ + +struct target_pt_regs { + abi_ulong regs[32]; + abi_ulong sepc; +}; + +#define UNAME_MACHINE "riscv64" + +#define TARGET_HW_MACHINE "riscv" +#define TARGET_HW_MACHINE_ARCH UNAME_MACHINE + +#endif /* BSD_USER_RISCV_TARGET_SYSCALL_H */ From patchwork Wed Aug 28 09:52:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 59362C54E62 for ; Wed, 28 Aug 2024 09:53:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMo-0003JZ-Mw; Wed, 28 Aug 2024 05:53:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMn-0003Ef-ED for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:29 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMm-0001qG-0N for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:29 -0400 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-7bb75419123so4141104a12.3 for ; Wed, 28 Aug 2024 02:53:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838806; x=1725443606; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cjm2NL6Wgqty15f3ap7G8BavBfHkA8e5dbFy1QdhwG4=; b=hRiymZlaADkZjhZaEKFtixZjgrkJ8SSf/hhlWnfsyMRzVMvbY6rFjrRQb16B81t+tM I4X/EPVxA6DUsz2YTw2ZYFTMzVnFQJqwGiq+YzZXaqMZvQaPVvcLX1apmtlkxfswvswm tpdwXRWyYRb7ADj/ojKI79hYxKvZzr3jSmoEWcAx3Yb7Usp+HjyBGC7zHMTJuqX8DKWA pr6wn4pCPrwmooodI6nQph1XqihGIaoNkVtDL515KAWZxE6bnKXu7Ei1c9swYdIQ0QJA u6/x6CntVcMCqY7j4Vajx213EZNJSWE/FcYSNRjN9ikk/2wQoTXirrs7gAciRCXuiSJS Ua4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838806; x=1725443606; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cjm2NL6Wgqty15f3ap7G8BavBfHkA8e5dbFy1QdhwG4=; b=wckLp6jQo1OF0gfrwO1VZul1I8bmmukcYNHoFV1U8u09XLLhbMziGfmBjnpHAF17T9 i4V0ReqbtCWEbJoA6hiagHUUzyVwXWfdDKJM2qbi6wXm8q6/rNbIjgu4hwjaPbFF5GMt 9xLuMesrOSoG6SS8cSemlMssCjCKGLOjQGkUtket+EMKBo9GlLKbMEHb4XuLZLcDkotv T1nfqwtPKMkXohafClv7e+rdaqRJFqZICrMFrCruCDIS+yrcIQLldYRImJDICQ+5UNq9 8God9y9rQL+C6hsqioxbUqEU5JBrlEmJa+fFxtOor7FX4oFL6ubT9aIQoWhhVD3twQjJ s6Cg== X-Gm-Message-State: AOJu0Yxr3b4AJWnsxezAfISDVtjpfUeR1qDvoDTVH3YduOFhwL7k2J9h cq+kns6xyO3VA1LcYzvWT7A8DLXpNwi8zlnkEkEAgTW/xuCawTceww5MKdZ7 X-Google-Smtp-Source: AGHT+IFfPsDngfLDLrovXM/npkCM4SbchAO1MzqKzMXKjtda1CB5VJC6q2PLu2w7zNi6hV0BSdwtLQ== X-Received: by 2002:a05:6a21:e8a:b0:1c4:9ef6:499b with SMTP id adf61e73a8af0-1cc8b4bc8aemr15433478637.29.1724838806290; Wed, 28 Aug 2024 02:53:26 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.53.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:53:26 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Richard Henderson Subject: [PATCH v4 12/17] bsd-user: Add generic RISC-V64 target definitions Date: Wed, 28 Aug 2024 19:52:38 +1000 Message-Id: <20240828095243.90491-13-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=itachis6234@gmail.com; helo=mail-pg1-x529.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Warner Losh Added a generic definition for RISC-V64 target-specific details. Implemented the 'regpairs_aligned' function,which returns 'false' to indicate that register pairs are not aligned in the RISC-V64 ABI. Signed-off-by: Warner Losh Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson --- bsd-user/riscv/target.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 bsd-user/riscv/target.h diff --git a/bsd-user/riscv/target.h b/bsd-user/riscv/target.h new file mode 100644 index 0000000000..036ddd185e --- /dev/null +++ b/bsd-user/riscv/target.h @@ -0,0 +1,20 @@ +/* + * Riscv64 general target stuff that's common to all aarch details + * + * Copyright (c) 2022 M. Warner Losh + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef TARGET_H +#define TARGET_H + +/* + * riscv64 ABI does not 'lump' the registers for 64-bit args. + */ +static inline bool regpairs_aligned(void *cpu_env) +{ + return false; +} + +#endif /* TARGET_H */ From patchwork Wed Aug 28 09:52:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781018 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C371FC54E62 for ; Wed, 28 Aug 2024 09:54:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMs-0003Zq-QJ; Wed, 28 Aug 2024 05:53:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMr-0003UP-C4 for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:33 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMo-0001qQ-Jz for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:33 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-7142a93ea9cso4676513b3a.3 for ; Wed, 28 Aug 2024 02:53:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838809; x=1725443609; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=voYN43OZ7lwbwneNl7z2eHNOhROV9NjNWmAvKPq1wXw=; b=VlE6cYJFOQhmp7SoDVN9agSH5p1RAqep/XY42v06kPhoGA4UZthopBK3+7ve+Fm0Ml blWoDD0PZRsVX6CaGEQBkt5teNfFh01wAoy4XFi73lwI1/W+2JSBpJ7hvjUd8RvH1JE0 yp2KYIbsVlbvGD9aOVpP980Au9liN1LcfO3/ibnt9VADkutfTSTgaAOu3Ag7HNBKZM0h F2vxUSiq9ilaEFXkk6xHagMC7W9oZKEraiZFOGVbeS2cGEFBh5xdH2cRvHFJ90FBjsm/ oYPZ8P0rYeVN+GOjWQAHYOLLlT1DCvwoolWipN72sA7ZkbssuZ1E126uGvhW5yLJr9wG Ns5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838809; x=1725443609; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=voYN43OZ7lwbwneNl7z2eHNOhROV9NjNWmAvKPq1wXw=; b=Nhaoywfh6+HRER+XUji6m5SS4MtSmARbkepqJjmHQhwwrvlTa9wOStio4n4ENzX7xM qjKk2XnhU1o7C8pUNP/G92f9hixPya1XAscgwCN1GM/8MyCXdiHjcrsi3jv0ncUG43rf CFW9RuoSLn+W7CiLUBC6ZCGhkmpgSGz7Q37/42hZaGDrjHzHedm9WVaLEecG6Fp6IY7P dzpJgSBXUUzLTjzpGogyVCC5SfczHv9XEkYTKdQXIAm3U1diE/kBM21pIv4hGmoJl31A QfWd5PmRHLz/VAUhSD9C5LkvlwF6Q5E6V/FGxotDjySEADjvibivTRuCgYKg3bsJ5xKG 7G8g== X-Gm-Message-State: AOJu0Yy+ZzPIxZvs/D+m2cyzYQqeXCpHiz0Q7wm3bsTeqCnXV1IMn7Pk 2vh/HSPruiVZgUAbU4u4Yn6JHDEmzdpZ5X9PQlj3c7IM5J+kjKZb4oyJu1VE X-Google-Smtp-Source: AGHT+IF4aqeaZBaKfaGCEPmVNhVUX0bEs4Yb6HLzPOVUBGbAGWe1I4ZiPMSFic1OdwvvAo8s4RDEXw== X-Received: by 2002:a05:6a21:1507:b0:1c4:8da5:c665 with SMTP id adf61e73a8af0-1cc89d29c87mr16704229637.11.1724838808730; Wed, 28 Aug 2024 02:53:28 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.53.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:53:28 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Richard Henderson Subject: [PATCH v4 13/17] bsd-user: Define RISC-V signal handling structures and constants Date: Wed, 28 Aug 2024 19:52:39 +1000 Message-Id: <20240828095243.90491-14-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=itachis6234@gmail.com; helo=mail-pf1-x431.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Mark Corbin Added definitions for RISC-V signal handling, including structures and constants for managing signal frames and context Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Co-authored-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/riscv/target_arch_signal.h | 75 +++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 bsd-user/riscv/target_arch_signal.h diff --git a/bsd-user/riscv/target_arch_signal.h b/bsd-user/riscv/target_arch_signal.h new file mode 100644 index 0000000000..1a634b865b --- /dev/null +++ b/bsd-user/riscv/target_arch_signal.h @@ -0,0 +1,75 @@ +/* + * RISC-V signal definitions + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef TARGET_ARCH_SIGNAL_H +#define TARGET_ARCH_SIGNAL_H + +#include "cpu.h" + + +#define TARGET_INSN_SIZE 4 /* riscv instruction size */ + +/* Size of the signal trampoline code placed on the stack. */ +#define TARGET_SZSIGCODE ((abi_ulong)(7 * TARGET_INSN_SIZE)) + +/* Compare with riscv/include/_limits.h */ +#define TARGET_MINSIGSTKSZ (1024 * 4) +#define TARGET_SIGSTKSZ (TARGET_MINSIGSTKSZ + 32768) + +struct target_gpregs { + uint64_t gp_ra; + uint64_t gp_sp; + uint64_t gp_gp; + uint64_t gp_tp; + uint64_t gp_t[7]; + uint64_t gp_s[12]; + uint64_t gp_a[8]; + uint64_t gp_sepc; + uint64_t gp_sstatus; +}; + +struct target_fpregs { + uint64_t fp_x[32][2]; + uint64_t fp_fcsr; + uint32_t fp_flags; + uint32_t pad; +}; + +typedef struct target_mcontext { + struct target_gpregs mc_gpregs; + struct target_fpregs mc_fpregs; + uint32_t mc_flags; +#define TARGET_MC_FP_VALID 0x01 + uint32_t mc_pad; + uint64_t mc_spare[8]; +} target_mcontext_t; + +#define TARGET_MCONTEXT_SIZE 864 +#define TARGET_UCONTEXT_SIZE 936 + +#include "target_os_ucontext.h" + +struct target_sigframe { + target_ucontext_t sf_uc; /* = *sf_uncontext */ + target_siginfo_t sf_si; /* = *sf_siginfo (SA_SIGINFO case)*/ +}; + +#define TARGET_SIGSTACK_ALIGN 16 + +#endif /* TARGET_ARCH_SIGNAL_H */ From patchwork Wed Aug 28 09:52:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 08877C5479A for ; Wed, 28 Aug 2024 09:54:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMu-0003eq-03; Wed, 28 Aug 2024 05:53:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMs-0003Zd-Nc for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:34 -0400 Received: from mail-oa1-x2f.google.com ([2001:4860:4864:20::2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMq-0001qU-TY for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:34 -0400 Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-2704b6a6fe6so4568623fac.1 for ; Wed, 28 Aug 2024 02:53:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838811; x=1725443611; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7+bsO6A/4UIjh+UAI8JcbcWlILl99UyeWUeQ1BHs21E=; b=bJps8pEpdV0oHR75mMx3QvDdgs4XT4QbhqANuRR6QlTmhMZD7/QbalcngVKmZflo2c hPXHyMEbR7hvAeRZ0cghboKSyR13BHkBJF626qCx2FiBIio+TudAgqY1XqPMHM9rSZXG n52AI8oH3LzW8gKzgsnie2Mo19MGpOAp8i/0VazcpTc4SAzmBtfKMDA4rXLAr4xqdQF8 TLIXiNrBABDxekKC+NHJCncnpwUdFzWKEOZZNk+rj8vCMfNBNs1myvwHd6LNaLeuW5/U MOCagjJ84ScVUBzHxkoK5sT/xqIcwHNQ8NIBeeN/9sIC1SfyGInGnHfRcbGPSWbSFyeO zCIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838811; x=1725443611; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7+bsO6A/4UIjh+UAI8JcbcWlILl99UyeWUeQ1BHs21E=; b=dXzS0X3FKw34b4MYTDIa2eMoKnjp1lU/HJwxJyGA2wv5V9y0OoZvYZA92LpItTgL5c T1PpekLkyTxlLu/8NUi0jpwTBHiwx72aoIvRXxUgIDj0kGTJ3DBOa1y+Cd8wCRXtdoy6 pe8lEyXNQvr+Z63qzMGKFUCZmZJLBtJzjmcAFXcEb3A/mr1llZhHzYbn5RCRNJP4zT9q ++eW7VSJe3QouL6D0qYtp1hz2h6V5zj/uVmdfCcjfryOnih0SrXXOOlGKf6Yh64aBIbg yxTsg/jH3wuMvY0AfQIDhys+ozCXY3miKo+Eggsnou8buXpBICKRTpQzkXlCrDl0ee54 NHdQ== X-Gm-Message-State: AOJu0YwgREKLoahs05wz2elLM7lUqB8ZVsL8XRqA9OKToRPVXq9VJbd6 tMN5zC+R+sGObkSi+lNaaUVlnHMDnRDqowjm4UfG9m4CRvJpgev3a1zgjQ== X-Google-Smtp-Source: AGHT+IHqNlVZOqCxRnzo2RVFi3hVTav9vLjMGt3c7MZMTZbe6YXfscGuk8pabzxcHsgM7q5dCZTYAQ== X-Received: by 2002:a05:6870:858a:b0:261:908:5899 with SMTP id 586e51a60fabf-2777d14bc55mr1353411fac.10.1724838811211; Wed, 28 Aug 2024 02:53:31 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.53.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:53:30 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Richard Henderson Subject: [PATCH v4 14/17] bsd-user: Implement RISC-V signal trampoline setup functions Date: Wed, 28 Aug 2024 19:52:40 +1000 Message-Id: <20240828095243.90491-15-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::2f; envelope-from=itachis6234@gmail.com; helo=mail-oa1-x2f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Mark Corbin Added functions for setting up the RISC-V signal trampoline and signal frame: 'set_sigtramp_args()': Configures the RISC-V CPU state with arguments for the signal handler. It sets up the registers with the signal number,pointers to the signal info and user context, the signal handler address, and the signal frame pointer. 'setup_sigframe_arch()': Initializes the signal frame with the current machine context.This function copies the context from the CPU state to the signal frame, preparing it for the signal handler. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Signed-off-by: Warner Losh Co-authored-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/riscv/signal.c | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 bsd-user/riscv/signal.c diff --git a/bsd-user/riscv/signal.c b/bsd-user/riscv/signal.c new file mode 100644 index 0000000000..2597fec2fd --- /dev/null +++ b/bsd-user/riscv/signal.c @@ -0,0 +1,63 @@ +/* + * RISC-V signal definitions + * + * Copyright (c) 2019 Mark Corbin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#include "qemu/osdep.h" + +#include "qemu.h" + +/* + * Compare with sendsig() in riscv/riscv/exec_machdep.c + * Assumes that target stack frame memory is locked. + */ +abi_long +set_sigtramp_args(CPURISCVState *regs, int sig, struct target_sigframe *frame, + abi_ulong frame_addr, struct target_sigaction *ka) +{ + /* + * Arguments to signal handler: + * a0 (10) = signal number + * a1 (11) = siginfo pointer + * a2 (12) = ucontext pointer + * pc = signal pointer handler + * sp (2) = sigframe pointer + * ra (1) = sigtramp at base of user stack + */ + + regs->gpr[xA0] = sig; + regs->gpr[xA1] = frame_addr + + offsetof(struct target_sigframe, sf_si); + regs->gpr[xA2] = frame_addr + + offsetof(struct target_sigframe, sf_uc); + regs->pc = ka->_sa_handler; + regs->gpr[xSP] = frame_addr; + regs->gpr[xRA] = TARGET_PS_STRINGS - TARGET_SZSIGCODE; + return 0; +} + +/* + * Compare to riscv/riscv/exec_machdep.c sendsig() + * Assumes that the memory is locked if frame points to user memory. + */ +abi_long setup_sigframe_arch(CPURISCVState *env, abi_ulong frame_addr, + struct target_sigframe *frame, int flags) +{ + target_mcontext_t *mcp = &frame->sf_uc.uc_mcontext; + + get_mcontext(env, mcp, flags); + return 0; +} From patchwork Wed Aug 28 09:52:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E0619C5479A for ; Wed, 28 Aug 2024 09:56:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMx-0003s2-CI; Wed, 28 Aug 2024 05:53:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMv-0003jB-2J for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:37 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMt-0001qi-Fa for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:36 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-714262f1bb4so4804798b3a.3 for ; Wed, 28 Aug 2024 02:53:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838814; x=1725443614; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gy74LlRTmtwc1XLq4kdnjaS7OlYM0YhDmnWN/nXgpX8=; b=ghpbtg+egFMkAtoh6Slu7QR2fXV6vyQcvG7Xq6eYlDwisExVMKcn9w/o+24GByIvxn ZtEbLlU8YqRjSR82AXK72gmw6UB7NjFDrNGDXn4rQAdm3vZoJLqB2gVGxwnQ1uCEzhvi kNaFCIbzq+hrXXVTo8KErxWHlgdjLKYlhDhLiB3MGJlA2rONHK0W0psp8TyyKvi56omU 9jUaSR3rNR0tcuKQiFhozz8XC/TktaRh4nZUbGfA/0CnEUZDbqEqKduPW0/THy6QVPBH LrkGrhKOMPxqxV223K0cpKuHHE8obikkOlO1VnzfFyqwDTUN4I6l4nIQqpA3MWwQqAl0 K6Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838814; x=1725443614; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gy74LlRTmtwc1XLq4kdnjaS7OlYM0YhDmnWN/nXgpX8=; b=qoqm/9AWproTBDnehjKSHHcMqAL32zSZaYWSaONfDP0rPd3/jHpUxNyXfy+XTxZK7f jlYSD34wWAo58XlFufIthP0AgXloWEZZ44rIBMH2LReGZoZjpFOLTAxPNneQJyHFBHZW UY6Oj8HSTCo7DihLzLopiPiRHiPgPHEWefcTTJMSksaeeQXDHsJbraCUIrb2R4KiSPak HUrUc/G/lcvXlm56YT5zL0GvFpr8S+j9y6eBAC0qX7FD0Zg/Yv+naXJby1PoDbn1rw3e xV3YdOAGxdBGwnA6Kdy+iYGqftgYJexWsi//j57pOEk8x88EeQKUFn0BGrd8zUEN9YX8 cl7w== X-Gm-Message-State: AOJu0Ywnp01tHw3rc5qf5P9iyxGMGZYvlyUihZIVoZkQ4O313udyY8cu chVPqVvL55hSfUotTQw9QHIix9zElVJCWgR6tvrRcZTjh1eZFyHC0rDHTg== X-Google-Smtp-Source: AGHT+IFRCPZSwDfAN08AzcETmd8mcfCLQ3Fl93n0/EgbXbSaiKcpMZpSOCLs2ztQJFztONmSD233MA== X-Received: by 2002:a05:6a00:91db:b0:70d:311b:8569 with SMTP id d2e1a72fcca58-71445ed4f93mr14654698b3a.26.1724838813694; Wed, 28 Aug 2024 02:53:33 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.53.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:53:33 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Richard Henderson Subject: [PATCH v4 15/17] bsd-user: Implement 'get_mcontext' for RISC-V Date: Wed, 28 Aug 2024 19:52:41 +1000 Message-Id: <20240828095243.90491-16-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=itachis6234@gmail.com; helo=mail-pf1-x434.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Mark Corbin Added the 'get_mcontext' function to extract and populate the RISC-V machine context from the CPU state. This function is used to gather the current state of the general-purpose registers and store it in a 'target_mcontext_' structure. Signed-off-by: Mark Corbin Signed-off-by: Ajeet Singh Signed-off-by: Warner Losh Co-authored-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/riscv/signal.c | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/bsd-user/riscv/signal.c b/bsd-user/riscv/signal.c index 2597fec2fd..072ad821d2 100644 --- a/bsd-user/riscv/signal.c +++ b/bsd-user/riscv/signal.c @@ -61,3 +61,56 @@ abi_long setup_sigframe_arch(CPURISCVState *env, abi_ulong frame_addr, get_mcontext(env, mcp, flags); return 0; } + +/* + * Compare with get_mcontext() in riscv/riscv/machdep.c + * Assumes that the memory is locked if mcp points to user memory. + */ +abi_long get_mcontext(CPURISCVState *regs, target_mcontext_t *mcp, + int flags) +{ + + mcp->mc_gpregs.gp_t[0] = tswap64(regs->gpr[5]); + mcp->mc_gpregs.gp_t[1] = tswap64(regs->gpr[6]); + mcp->mc_gpregs.gp_t[2] = tswap64(regs->gpr[7]); + mcp->mc_gpregs.gp_t[3] = tswap64(regs->gpr[28]); + mcp->mc_gpregs.gp_t[4] = tswap64(regs->gpr[29]); + mcp->mc_gpregs.gp_t[5] = tswap64(regs->gpr[30]); + mcp->mc_gpregs.gp_t[6] = tswap64(regs->gpr[31]); + + mcp->mc_gpregs.gp_s[0] = tswap64(regs->gpr[8]); + mcp->mc_gpregs.gp_s[1] = tswap64(regs->gpr[9]); + mcp->mc_gpregs.gp_s[2] = tswap64(regs->gpr[18]); + mcp->mc_gpregs.gp_s[3] = tswap64(regs->gpr[19]); + mcp->mc_gpregs.gp_s[4] = tswap64(regs->gpr[20]); + mcp->mc_gpregs.gp_s[5] = tswap64(regs->gpr[21]); + mcp->mc_gpregs.gp_s[6] = tswap64(regs->gpr[22]); + mcp->mc_gpregs.gp_s[7] = tswap64(regs->gpr[23]); + mcp->mc_gpregs.gp_s[8] = tswap64(regs->gpr[24]); + mcp->mc_gpregs.gp_s[9] = tswap64(regs->gpr[25]); + mcp->mc_gpregs.gp_s[10] = tswap64(regs->gpr[26]); + mcp->mc_gpregs.gp_s[11] = tswap64(regs->gpr[27]); + + mcp->mc_gpregs.gp_a[0] = tswap64(regs->gpr[10]); + mcp->mc_gpregs.gp_a[1] = tswap64(regs->gpr[11]); + mcp->mc_gpregs.gp_a[2] = tswap64(regs->gpr[12]); + mcp->mc_gpregs.gp_a[3] = tswap64(regs->gpr[13]); + mcp->mc_gpregs.gp_a[4] = tswap64(regs->gpr[14]); + mcp->mc_gpregs.gp_a[5] = tswap64(regs->gpr[15]); + mcp->mc_gpregs.gp_a[6] = tswap64(regs->gpr[16]); + mcp->mc_gpregs.gp_a[7] = tswap64(regs->gpr[17]); + + if (flags & TARGET_MC_GET_CLEAR_RET) { + mcp->mc_gpregs.gp_a[0] = 0; /* a0 */ + mcp->mc_gpregs.gp_a[1] = 0; /* a1 */ + mcp->mc_gpregs.gp_t[0] = 0; /* clear syscall error */ + } + + mcp->mc_gpregs.gp_ra = tswap64(regs->gpr[1]); + mcp->mc_gpregs.gp_sp = tswap64(regs->gpr[2]); + mcp->mc_gpregs.gp_gp = tswap64(regs->gpr[3]); + mcp->mc_gpregs.gp_tp = tswap64(regs->gpr[4]); + mcp->mc_gpregs.gp_sepc = tswap64(regs->pc); + + return 0; +} From patchwork Wed Aug 28 09:52:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 67F26C5479A for ; Wed, 28 Aug 2024 09:55:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFMy-0003xN-N3; Wed, 28 Aug 2024 05:53:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMx-0003r4-3e for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:39 -0400 Received: from mail-oo1-xc2a.google.com ([2607:f8b0:4864:20::c2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMv-0001qr-JU for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:38 -0400 Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-5da686531d3so5092679eaf.3 for ; Wed, 28 Aug 2024 02:53:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838816; x=1725443616; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9FVE9uwE5SGNsSu9ob6L64WLDml4rbiZ/hyx7tyV/IQ=; b=IKBsic42fRyfnnfVFwpJCQiyT3Cgizw8TBWnEEKl0TJ+xB0UBGEgv9x3RU/r+Zsovq pNOSDv8fjGW6piCXMuZYYt7r0pczQjIW3Q5Z/esbrOSFdv48QxxLmytn6IIcxIGyZJPE gfuLeQkUiD1L9KZ2q5ZASNwVi6VwDMLiy3weDWvSHy3wM4FUhR+LqgQ2HABGjTxn/i6e AgDgnQ30Ob+Vod55CCOFIhqaw2Em8frQK47HFD96mCtwgLjHf1xwNGOnbAOccDSKo3Wj O/HqPBjstQ4NMMC2+wmlfvLn3O0q4oAQW3FdDBszKjbHs4kaZAhe1v9lBEOHDWVT8LQM ielw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838816; x=1725443616; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9FVE9uwE5SGNsSu9ob6L64WLDml4rbiZ/hyx7tyV/IQ=; b=GpCUNlW2lIbmaLmZk0QWKB12wa856rNOe+jVeB/Y+akU+sWrs774PMKYucmdK9lYhD IsonIYvcZjler6h842gJ209P+M9uve60KHfRh6ja6n2pWAGkNBdmw5DYqDKbfnOH+I74 nXeRB4w2oYe/vkqr5PWEYWmFxQ5MnAN5IGjh2yvtlubTpvEfDaQsD1MRuVmvjsMjGp4W TFkE8AY6WaSniTx1FzDBI4X3PvpGe0NdV//02GEzN6cMoLReZKzqVWXKnXu6qEBiEoGF Va0CnUIGXI4T+/23ssoVY6bGRI4JK75omKDRwBp9/6wtlJHqfrUkL5UqzmtlX2D3WJ8M Kp8w== X-Gm-Message-State: AOJu0YxzvtMhIycE4ur0qbBxepHdX2hxHxCOj0zlPCLSHs6DS13mIw3d o9fkkZAUJIV+U1sPB8vsV3W8pl/5O9CBTkJ4Z3d4omv/676yJd0j+HEmCg== X-Google-Smtp-Source: AGHT+IHR+mVWu+8f4uV9yDbglWqT0a7Hw5K/+g4Rp9SbCBYcuNeahjokD+i/+bfrKiTDqXgVcxAr9Q== X-Received: by 2002:a05:6358:d39b:b0:1b5:e9d4:66f4 with SMTP id e5c5f4694b2df-1b5e9d467eemr733723255d.9.1724838816173; Wed, 28 Aug 2024 02:53:36 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.53.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:53:35 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Richard Henderson Subject: [PATCH v4 16/17] bsd-user: Implement set_mcontext and get_ucontext_sigreturn for RISCV Date: Wed, 28 Aug 2024 19:52:42 +1000 Message-Id: <20240828095243.90491-17-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c2a; envelope-from=itachis6234@gmail.com; helo=mail-oo1-xc2a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Mark Corbin Added implementations for 'set_mcontext' and 'get_ucontext_sigreturn' functions for RISC-V architecture, Both functions ensure that the CPU state and user context are properly managed. Signed-off-by: Mark Corbin Signed-off-by: Warner Losh Signed-off-by: Ajeet Singh Co-authored-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/riscv/signal.c | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/bsd-user/riscv/signal.c b/bsd-user/riscv/signal.c index 072ad821d2..10c940cd49 100644 --- a/bsd-user/riscv/signal.c +++ b/bsd-user/riscv/signal.c @@ -114,3 +114,57 @@ abi_long get_mcontext(CPURISCVState *regs, target_mcontext_t *mcp, return 0; } + +/* Compare with set_mcontext() in riscv/riscv/exec_machdep.c */ +abi_long set_mcontext(CPURISCVState *regs, target_mcontext_t *mcp, + int srflag) +{ + + regs->gpr[5] = tswap64(mcp->mc_gpregs.gp_t[0]); + regs->gpr[6] = tswap64(mcp->mc_gpregs.gp_t[1]); + regs->gpr[7] = tswap64(mcp->mc_gpregs.gp_t[2]); + regs->gpr[28] = tswap64(mcp->mc_gpregs.gp_t[3]); + regs->gpr[29] = tswap64(mcp->mc_gpregs.gp_t[4]); + regs->gpr[30] = tswap64(mcp->mc_gpregs.gp_t[5]); + regs->gpr[31] = tswap64(mcp->mc_gpregs.gp_t[6]); + + regs->gpr[8] = tswap64(mcp->mc_gpregs.gp_s[0]); + regs->gpr[9] = tswap64(mcp->mc_gpregs.gp_s[1]); + regs->gpr[18] = tswap64(mcp->mc_gpregs.gp_s[2]); + regs->gpr[19] = tswap64(mcp->mc_gpregs.gp_s[3]); + regs->gpr[20] = tswap64(mcp->mc_gpregs.gp_s[4]); + regs->gpr[21] = tswap64(mcp->mc_gpregs.gp_s[5]); + regs->gpr[22] = tswap64(mcp->mc_gpregs.gp_s[6]); + regs->gpr[23] = tswap64(mcp->mc_gpregs.gp_s[7]); + regs->gpr[24] = tswap64(mcp->mc_gpregs.gp_s[8]); + regs->gpr[25] = tswap64(mcp->mc_gpregs.gp_s[9]); + regs->gpr[26] = tswap64(mcp->mc_gpregs.gp_s[10]); + regs->gpr[27] = tswap64(mcp->mc_gpregs.gp_s[11]); + + regs->gpr[10] = tswap64(mcp->mc_gpregs.gp_a[0]); + regs->gpr[11] = tswap64(mcp->mc_gpregs.gp_a[1]); + regs->gpr[12] = tswap64(mcp->mc_gpregs.gp_a[2]); + regs->gpr[13] = tswap64(mcp->mc_gpregs.gp_a[3]); + regs->gpr[14] = tswap64(mcp->mc_gpregs.gp_a[4]); + regs->gpr[15] = tswap64(mcp->mc_gpregs.gp_a[5]); + regs->gpr[16] = tswap64(mcp->mc_gpregs.gp_a[6]); + regs->gpr[17] = tswap64(mcp->mc_gpregs.gp_a[7]); + + + regs->gpr[1] = tswap64(mcp->mc_gpregs.gp_ra); + regs->gpr[2] = tswap64(mcp->mc_gpregs.gp_sp); + regs->gpr[3] = tswap64(mcp->mc_gpregs.gp_gp); + regs->gpr[4] = tswap64(mcp->mc_gpregs.gp_tp); + regs->pc = tswap64(mcp->mc_gpregs.gp_sepc); + + return 0; +} + +/* Compare with sys_sigreturn() in riscv/riscv/machdep.c */ +abi_long get_ucontext_sigreturn(CPURISCVState *regs, + abi_ulong target_sf, abi_ulong *target_uc) +{ + + *target_uc = target_sf; + return 0; +} From patchwork Wed Aug 28 09:52:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajeet Singh X-Patchwork-Id: 13781022 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA460C54E62 for ; Wed, 28 Aug 2024 09:54:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjFN1-00047j-B2; Wed, 28 Aug 2024 05:53:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjFMz-000416-LH for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:41 -0400 Received: from mail-oo1-xc2e.google.com ([2607:f8b0:4864:20::c2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjFMy-0001r7-4s for qemu-devel@nongnu.org; Wed, 28 Aug 2024 05:53:41 -0400 Received: by mail-oo1-xc2e.google.com with SMTP id 006d021491bc7-5daa93677e1so4726124eaf.3 for ; Wed, 28 Aug 2024 02:53:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724838819; x=1725443619; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yaqkhcr8XXVjz3AUT5s3kLltD+ErMtVDTb6FVMqoohs=; b=hi4EzJsZw/s03MO3qXHrRi/0YPt5wcRuPRpuYCZO1iS2sDmbKB+oAKkFlZgdVCml/g ls78gCFX89ltPNPHKf++Q/d3iAc4RuZ7sdqZfbblI54EaVP9PFFaQQ+c4ZfjdvjNd3kX 9Jtp9ayo09rV6+7F+de2Wj+x2INRrwgh8xtyA4zAt0MY6MdC1gT5ZAk2Ot+LPRfgL/J1 DTf5dEUnjsaeBx+LMvx4EqofmAVGwnC36EdG93uNtAViCTXWN1lNELaBVVRZdVqGoGMn OugfRquj3GHzW/kani9OYXf8FzsZ77EC2e04M6ucBaXE9rgik8ksy6IC8K5wefoA+NY5 nqZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724838819; x=1725443619; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yaqkhcr8XXVjz3AUT5s3kLltD+ErMtVDTb6FVMqoohs=; b=OXSp56yCHDo9vSBMK88I89lJVDfxuA4P3LHPXBBo0uDkKV3fR2dSW8Lji/TDOGUeuc 9hSy/2LVCPTyqikJvMYJ3qzgJtvk72RjKRQq2jNeAHAdt3bG1iDFYjI9yPIozzicGEAn 6QsSE6SnlkFgjf/350v0dvecCjCVcxZsCxInhR7qcDEgPoFGlaxT5xaXWMa+1bMpTOae kZDKxymw171H1fttl82/YAAVdMwxtyeb7d2vVVyUqJFnwy9AxMTpxbM28X/bTUOrNzCG 2/m5RRcd2KrP9ti0NnbsVznoS3oKNugef3HaIRZ2M3L/IjYblawaa8FjbD1g4DgzcAJb OBNw== X-Gm-Message-State: AOJu0Yz+CBX9HHFeIkHKbKvo1IlTTkBtORyvAtnjZR9McWdZ/edxg++j nZivPiMeeoTk/AfqHaYSf/goGEvAbSgvWmZIxV8sOMJ6GkbJePRau66wdQ== X-Google-Smtp-Source: AGHT+IE2kyDCluBzV5FEkWR+vOYxoovDU8ixp0X+bmEQJ0Y5BhDSyhG0ObxU7J6jDGMRG9ZLjPM2mw== X-Received: by 2002:a05:6358:3413:b0:1b3:9f0b:89c3 with SMTP id e5c5f4694b2df-1b5fac8cc4dmr166192455d.1.1724838818636; Wed, 28 Aug 2024 02:53:38 -0700 (PDT) Received: from localhost.localdomain ([220.253.126.131]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430f6e7sm9787508b3a.160.2024.08.28.02.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 02:53:38 -0700 (PDT) From: Ajeet Singh X-Google-Original-From: Ajeet Singh To: qemu-devel@nongnu.org Cc: Mark Corbin , Warner Losh , Ajeet Singh , Richard Henderson Subject: [PATCH v4 17/17] bsd-user: Add RISC-V 64-bit Target Configuration and Debug XML Files Date: Wed, 28 Aug 2024 19:52:43 +1000 Message-Id: <20240828095243.90491-18-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828095243.90491-1-itachis@FreeBSD.org> References: <20240828095243.90491-1-itachis@FreeBSD.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c2e; envelope-from=itachis6234@gmail.com; helo=mail-oo1-xc2e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Warner Losh Added configuration for RISC-V 64-bit target to the build system. Signed-off-by: Warner Losh Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson --- configs/targets/riscv64-bsd-user.mak | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 configs/targets/riscv64-bsd-user.mak diff --git a/configs/targets/riscv64-bsd-user.mak b/configs/targets/riscv64-bsd-user.mak new file mode 100644 index 0000000000..191c2c483f --- /dev/null +++ b/configs/targets/riscv64-bsd-user.mak @@ -0,0 +1,4 @@ +TARGET_ARCH=riscv64 +TARGET_BASE_ARCH=riscv +TARGET_ABI_DIR=riscv +TARGET_XML_FILES= gdb-xml/riscv-64bit-cpu.xml gdb-xml/riscv-32bit-fpu.xml gdb-xml/riscv-64bit-fpu.xml gdb-xml/riscv-64bit-virtual.xml