From patchwork Fri Feb 23 00:11:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10236675 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C8F20602A0 for ; Fri, 23 Feb 2018 00:20:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C500F2909B for ; Fri, 23 Feb 2018 00:20:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8109290A5; Fri, 23 Feb 2018 00:20:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4DBCE2909B for ; Fri, 23 Feb 2018 00:20:16 +0000 (UTC) Received: from localhost ([::1]:41811 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ep15z-0005LG-Cl for patchwork-qemu-devel@patchwork.kernel.org; Thu, 22 Feb 2018 19:20:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ep10u-0000zA-8V for qemu-devel@nongnu.org; Thu, 22 Feb 2018 19:16:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ep0zu-0005RV-5k for qemu-devel@nongnu.org; Thu, 22 Feb 2018 19:15:00 -0500 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]:34039) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ep0zt-0005Pv-N0 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 19:13:57 -0500 Received: by mail-pl0-x244.google.com with SMTP id u13so3876112plq.1 for ; Thu, 22 Feb 2018 16:13:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OLNn4yrLzqmdUjV2CE7Q5X+crGdYKawkVpbbl3oFeRA=; b=H6OyzWw85Y0JA5TmDezgnUuV/0Ivl2XPmwbWQkPSzvUgClDx2YbviRFJluvMvcIy3l GhHeiawkKsXlUUhMNwOHo7LbDYEKrVhmAw0BoALltI3/bDVBzjo3IbIwhTDiRkJChNHz IXMTRHHGS6zjrJWeEHe54QyJvVz0TrSc4yuecUvTxfrOemmZuV8vyyYUbOYrVVXDE3ST DnjI9UlUtp36Fkh9RS5lthn8THRESzrdRjHZQJtW4mOgPtpOGbGaRFTrQsv5gEXR/PEH KblzTNQLow4s9RY57+PsmOSn0fqKnsMRadJMJzG/n3Id48oPeAP6oq/bido/YzvBsCci Jdxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OLNn4yrLzqmdUjV2CE7Q5X+crGdYKawkVpbbl3oFeRA=; b=ZHINIkh/K7eYaskUPcpoeD7TP6bnctrMExnmMfDaObcCea79EphDh6Ua3d4xO1p2Yw Ld45FeJ5BqqI8eXTXg8NrrE1yz7vfBwMjmj6btopWSPHWkaTJ9R2q4cgmsU5qdNICd1o 3Rfq3fx1gzBmNc8bY6iF7bujFZESc1LtbBgKo+HfFPb3DLDONZc6/xjg1PIbvidkjcb2 ohGWXa1/IK63Mm8eIx4X8zAuA4X4EzyOmCTRuTejBnp8BM6PanHBNZELhzioU7yDzkIp pOgbcx/yOWEjos2J/lV2nfm0R78BZLoe6Aw35CQ3i+LQpW2tbbfh672I2Rii+l7J9WLg ErQw== X-Gm-Message-State: APf1xPBPTaR4fkf7wsO+aQ9cDkuHQlLzvKF+gUCDoDTpW/H7mBGtagtt X5kaBwem514pK5s7ULnC1/b4rV70rmU= X-Google-Smtp-Source: AH8x225IjIsgw2qYhgNGq5gvw8smf57130ZUs6LpmXPJI8xX41CDfPtzBapguHBmYvSJYijlpzCGwA== X-Received: by 2002:a17:902:9a01:: with SMTP id v1-v6mr7961654plp.76.1519344836716; Thu, 22 Feb 2018 16:13:56 -0800 (PST) Received: from localhost.localdomain (125-237-39-90.jetstream.xtra.co.nz. [125.237.39.90]) by smtp.gmail.com with ESMTPSA id u9sm1769551pgb.11.2018.02.22.16.13.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Feb 2018 16:13:56 -0800 (PST) From: Michael Clark To: qemu-devel@nongnu.org Date: Fri, 23 Feb 2018 13:11:53 +1300 Message-Id: <1519344729-73482-8-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1519344729-73482-1-git-send-email-mjc@sifive.com> References: <1519344729-73482-1-git-send-email-mjc@sifive.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::244 Subject: [Qemu-devel] [PATCH v6 07/23] RISC-V GDB Stub X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bastian Koppelmann , Michael Clark , Palmer Dabbelt , Sagar Karandikar , RISC-V Patches Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP GDB Register read and write routines. Reviewed-by: Richard Henderson Signed-off-by: Michael Clark --- target/riscv/gdbstub.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 target/riscv/gdbstub.c diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c new file mode 100644 index 0000000..aa5ec44 --- /dev/null +++ b/target/riscv/gdbstub.c @@ -0,0 +1,64 @@ +/* + * RISC-V GDB Server Stub + * + * Author: Sagar Karandikar, sagark@eecs.berkeley.edu + * + * + * 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 . + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "exec/gdbstub.h" +#include "cpu.h" + +int riscv_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + + if (n < 32) { + return gdb_get_regl(mem_buf, env->gpr[n]); + } else if (n == 32) { + return gdb_get_regl(mem_buf, env->pc); + } else if (n < 65) { + return gdb_get_reg64(mem_buf, env->fpr[n - 33]); + } else if (n < 4096 + 65) { + return gdb_get_regl(mem_buf, csr_read_helper(env, n - 65)); + } + return 0; +} + +int riscv_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + + if (n == 0) { + /* discard writes to x0 */ + return sizeof(target_ulong); + } else if (n < 32) { + env->gpr[n] = ldtul_p(mem_buf); + return sizeof(target_ulong); + } else if (n == 32) { + env->pc = ldtul_p(mem_buf); + return sizeof(target_ulong); + } else if (n < 65) { + env->fpr[n - 33] = ldq_p(mem_buf); /* always 64-bit */ + return sizeof(uint64_t); + } else if (n < 4096 + 65) { + csr_write_helper(env, ldtul_p(mem_buf), n - 65); + } + return 0; +}