From nobody Sun Nov 24 12:26:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1723828324; cv=none; d=zohomail.com; s=zohoarc; b=IQAemcIXSAPw+4+5alsfWG3dj84QIfrx0rZfirb6zyiFEDeu/PHWzY7TYPg0eApHnQbdS1UQZZclbBHIJ6ze2mN5aVlfNmJ4phDxYKbfk7B11UNqx3Brh4tnaZkeA+HaqD2WxasVRlj+Ij2KxRSRFmzP4Zalgeq2+wFLvx36WYw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723828324; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gy74LlRTmtwc1XLq4kdnjaS7OlYM0YhDmnWN/nXgpX8=; b=jfXZgtJ8e0bq+UDyjpYIj2Ssh5SH20oTOG0wEnbFXSbKO9VA6aJP1jtjDtF/sKE2gbCQkUGnyIWV9Iwt6j+DcEDXxPbe1rFLqxjsnW6/BumFEl53sgi6pCJAWz9jeEAQMyZ1Xz06MXwI5prEo2eAhNIjLw/L2TwEILvos3VXVD0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1723828324597422.5289676862128; Fri, 16 Aug 2024 10:12:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sf0TQ-0007Co-5M; Fri, 16 Aug 2024 13:10:48 -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 1sf0TK-0006Vi-OX for qemu-devel@nongnu.org; Fri, 16 Aug 2024 13:10:42 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sf0TI-0007Q4-TD for qemu-devel@nongnu.org; Fri, 16 Aug 2024 13:10:42 -0400 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-7c6b03c414fso788958a12.2 for ; Fri, 16 Aug 2024 10:10:40 -0700 (PDT) Received: from localhost.localdomain (121-45-122-195.tpgi.com.au. [121.45.122.195]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3ac7ca33dsm5988407a91.6.2024.08.16.10.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 10:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723828239; x=1724433039; 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=cZyaZh3GzwBuYcVV1amPt7INb9cOazQUKPKM9hUMflpuLffjk58/OHJi5mhtpmGhdy i71Jagd+JWT+mzi0nPJd5ic3oKubxsB9hhBK+pzjb52gjOan8JyWYxcZ4qYYSy3CPDTT tF1B0GF855QZaMVbKnWdIQMoxkaQaED1otFqReOTbQtyL9Km6CBQrwxTv0m5h6CjWZjo J7zj3bFHK+QQYe9fzKBLgeVh/BDLzRlxuxPe6kipgRLeWoypH0QjHgq4grGxew2uxba/ R60VKVmMG62MscKcHrGzwUib46nVpHjije5xpRYdhEhHTKVAF7ef1W5nQAsUs8pAcgMs VW9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723828239; x=1724433039; 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=l1GkbW3igEZRuHX/7ZL+Q94UucI7qTzfT3Rx/FBWSqxsiiyUQGYYUTrzZDdSjpncz/ +vTtAelUBgWtyRpHQcnkr10/jYG3TFhECc7gPqtOo0yxVyfwgl+BE4U1nI6hIWc8F4QT NHy+rVUEsLAfcOFTLlBG/YOJepC7up9gvu4+oK9nV+jyHBCm1pKG4AHrLpsKLV1GGt4h X2OjsL3KhFjXFxOfYy5MWV8HWfR52OLpZ3Y5dMdSmVN4gzZaPo/v91FxePaAI4ys7SjD iiIBJiWe7VxXqBfmpapJgSfhAb49YYCxPzwSnt69+ZpMTFWAxcCw4qxI2oemx6xtrss2 z0bg== X-Gm-Message-State: AOJu0Yzm/QDQt/tV1Qpq2Hqt8an7J5+9qeHlDPmLOYEnjMwwCcZCrSFx 5yUQuwmoZQ9n2EiA/OtmgbLWTwNH/W0v+TfC6mhUiRlY+QMWOlC62ItwJGrhuJ0= X-Google-Smtp-Source: AGHT+IGjg1mly/XIYVqi6sIAY6I/oLkMW2QK0E/3bkXpdiqm7tt6BCkNotk/Yy7Q1nbZTposy8BDHA== X-Received: by 2002:a17:90a:5e0f:b0:2c8:e3e6:ec99 with SMTP id 98e67ed59e1d1-2d3e03f2820mr3542541a91.43.1723828239036; Fri, 16 Aug 2024 10:10:39 -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 v2 15/17] bsd-user: Implement 'get_mcontext' for RISC-V Date: Sat, 17 Aug 2024 03:09:47 +1000 Message-Id: <20240816170949.238511-16-itachis@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816170949.238511-1-itachis@FreeBSD.org> References: <20240816170949.238511-1-itachis@FreeBSD.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=itachis6234@gmail.com; helo=mail-pg1-x52b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1723828326225116600 Content-Type: text/plain; charset="utf-8" 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_ulo= ng 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] =3D tswap64(regs->gpr[5]); + mcp->mc_gpregs.gp_t[1] =3D tswap64(regs->gpr[6]); + mcp->mc_gpregs.gp_t[2] =3D tswap64(regs->gpr[7]); + mcp->mc_gpregs.gp_t[3] =3D tswap64(regs->gpr[28]); + mcp->mc_gpregs.gp_t[4] =3D tswap64(regs->gpr[29]); + mcp->mc_gpregs.gp_t[5] =3D tswap64(regs->gpr[30]); + mcp->mc_gpregs.gp_t[6] =3D tswap64(regs->gpr[31]); + + mcp->mc_gpregs.gp_s[0] =3D tswap64(regs->gpr[8]); + mcp->mc_gpregs.gp_s[1] =3D tswap64(regs->gpr[9]); + mcp->mc_gpregs.gp_s[2] =3D tswap64(regs->gpr[18]); + mcp->mc_gpregs.gp_s[3] =3D tswap64(regs->gpr[19]); + mcp->mc_gpregs.gp_s[4] =3D tswap64(regs->gpr[20]); + mcp->mc_gpregs.gp_s[5] =3D tswap64(regs->gpr[21]); + mcp->mc_gpregs.gp_s[6] =3D tswap64(regs->gpr[22]); + mcp->mc_gpregs.gp_s[7] =3D tswap64(regs->gpr[23]); + mcp->mc_gpregs.gp_s[8] =3D tswap64(regs->gpr[24]); + mcp->mc_gpregs.gp_s[9] =3D tswap64(regs->gpr[25]); + mcp->mc_gpregs.gp_s[10] =3D tswap64(regs->gpr[26]); + mcp->mc_gpregs.gp_s[11] =3D tswap64(regs->gpr[27]); + + mcp->mc_gpregs.gp_a[0] =3D tswap64(regs->gpr[10]); + mcp->mc_gpregs.gp_a[1] =3D tswap64(regs->gpr[11]); + mcp->mc_gpregs.gp_a[2] =3D tswap64(regs->gpr[12]); + mcp->mc_gpregs.gp_a[3] =3D tswap64(regs->gpr[13]); + mcp->mc_gpregs.gp_a[4] =3D tswap64(regs->gpr[14]); + mcp->mc_gpregs.gp_a[5] =3D tswap64(regs->gpr[15]); + mcp->mc_gpregs.gp_a[6] =3D tswap64(regs->gpr[16]); + mcp->mc_gpregs.gp_a[7] =3D tswap64(regs->gpr[17]); + + if (flags & TARGET_MC_GET_CLEAR_RET) { + mcp->mc_gpregs.gp_a[0] =3D 0; /* a0 */ + mcp->mc_gpregs.gp_a[1] =3D 0; /* a1 */ + mcp->mc_gpregs.gp_t[0] =3D 0; /* clear syscall error */ + } + + mcp->mc_gpregs.gp_ra =3D tswap64(regs->gpr[1]); + mcp->mc_gpregs.gp_sp =3D tswap64(regs->gpr[2]); + mcp->mc_gpregs.gp_gp =3D tswap64(regs->gpr[3]); + mcp->mc_gpregs.gp_tp =3D tswap64(regs->gpr[4]); + mcp->mc_gpregs.gp_sepc =3D tswap64(regs->pc); + + return 0; +} --=20 2.34.1