From patchwork Mon Feb 5 06:22:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10199869 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 594E3601A1 for ; Mon, 5 Feb 2018 06:26:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A1BC26E4A for ; Mon, 5 Feb 2018 06:26:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E7DB27B13; Mon, 5 Feb 2018 06:26:07 +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 C348126E4A for ; Mon, 5 Feb 2018 06:26:06 +0000 (UTC) Received: from localhost ([::1]:59332 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eiaE9-0006er-V4 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Feb 2018 01:26:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58275) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eiaCX-00054T-LH for qemu-devel@nongnu.org; Mon, 05 Feb 2018 01:24:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eiaCW-0006LI-0r for qemu-devel@nongnu.org; Mon, 05 Feb 2018 01:24:25 -0500 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]:38207) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eiaCV-0006Kx-QQ for qemu-devel@nongnu.org; Mon, 05 Feb 2018 01:24:23 -0500 Received: by mail-pl0-x243.google.com with SMTP id 13so11148755plb.5 for ; Sun, 04 Feb 2018 22:24:23 -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=YWrlpuE0PCU7hFvK5aVKf9VAP3SerxGCe9gKBhtUMj8=; b=HSQML85RxSb1cghmpT5Gqf1HZZYwJiR7dgoeT6KSp0W3OhU94E/jpjUSLsowqjHyKx 3DNpazAdvYve8ZdJL+F3uku9gi5796yz3IEIdY93pkqL5xUZx7E9Fiers2sO5Wb/4otY Ax8ht6yYt8CjJtn+gibr17SJn3/QoVmr+YZDQzjFuSFcfIN8BRN103PVX9yKYVWIiy0Y S8aXx3ZPQQrCQxlbGIJa38dsryYn186J+VSV1f5dn0ahoGLwdMomUwZNQDv6qpTsV5pa w2iHxhwGDRPe1/AXkmtwC3z0wpjwUaNM2vTdEOJ6EA13VFRar66XvgWZ1MWOBlGtvfs3 rKYg== 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=YWrlpuE0PCU7hFvK5aVKf9VAP3SerxGCe9gKBhtUMj8=; b=h3Vx8DmmG+rTQ5gb2nYIPqY8HhhxTlwbYzB9hqgMpWziK2v1usZaCrhCY8yHpDh47G nL10HUyDmyFO3lVbNvDhWzSeNccT8hL//7ZLGl054hzDvXgttwxVudd0s4ErvFzWdTQl opN06Xg27MnlR+F66uSjxc5lmXbb3+Os3mAr1/jtWW3E+QlvrNWvZ34moEnqmCcl5B9r 6jUS1LaY1b/rz1vOsxaXS2Tz4Ld3gvjEi2bkQ0bsY03X0uNWKe/otYrMX+XBffg7T54J UbsrXF5ssb6WPwh2+FMiEDGxmBeGP1bux4qc/At3AZ5pMZ9BpH9rN6JrIEmfhxglTy12 2duQ== X-Gm-Message-State: AKwxytdeBu/m9oqSk1S5Goe1C7/x+ogBSur+vybEap5LqB5vFEGmRb/Q TE7KI6hRKO07zrsLBnqBtcY4RYH1LZQ= X-Google-Smtp-Source: AH8x224ylid+CQL+JZza8dL2DhDvlcXQRziaXzaIqKwqNOEpFBS/Xa79XTg/ott6aEStKnURRmkdTQ== X-Received: by 2002:a17:902:6b83:: with SMTP id p3-v6mr7282321plk.18.1517811862833; Sun, 04 Feb 2018 22:24:22 -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 e82sm9517915pfh.53.2018.02.04.22.24.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 04 Feb 2018 22:24:22 -0800 (PST) From: Michael Clark To: qemu-devel@nongnu.org Date: Mon, 5 Feb 2018 19:22:32 +1300 Message-Id: <1517811767-75958-7-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1517811767-75958-1-git-send-email-mjc@sifive.com> References: <1517811767-75958-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::243 Subject: [Qemu-devel] [PATCH v4 07/22] 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 | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 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..500bd5f --- /dev/null +++ b/target/riscv/gdbstub.c @@ -0,0 +1,60 @@ +/* + * 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]); + } + 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); + } + return 0; +}