From patchwork Wed Jan 10 23:46:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10156357 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 D04666032D for ; Wed, 10 Jan 2018 23:53:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C238B285CE for ; Wed, 10 Jan 2018 23:53:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B69DE2862B; Wed, 10 Jan 2018 23:53:23 +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 5428C285CE for ; Wed, 10 Jan 2018 23:53:23 +0000 (UTC) Received: from localhost ([::1]:50377 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZQBO-0001bF-FM for patchwork-qemu-devel@patchwork.kernel.org; Wed, 10 Jan 2018 18:53:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44781) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZQ7D-0006Fv-C3 for qemu-devel@nongnu.org; Wed, 10 Jan 2018 18:49:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZQ7B-0000RR-MH for qemu-devel@nongnu.org; Wed, 10 Jan 2018 18:49:03 -0500 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:43836) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eZQ7B-0000Px-5M for qemu-devel@nongnu.org; Wed, 10 Jan 2018 18:49:01 -0500 Received: by mail-pg0-x243.google.com with SMTP id f14so1092150pga.10 for ; Wed, 10 Jan 2018 15:49:01 -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=G2B/fJpOIfTTZtlhN0nNHaY9luzIQArUvbjqozDDCF4=; b=DSTnFcJ3H1Zg2n4Mxi/To/5WGfOXLijnenSu0NgJwrN+qzJ+vZsWvldoQ1IV2ULhFu Ir/D6BP/5d0kpgNgF2t7zDAuH6snepxRyMbKvKGl5etGdpNPMucTFPfMFyMG7XhFQRdS aCNsKi/8CdMFEnoEbO5FDeD+SKs0Nt7S032E5ZJvBLK51Y6H0EBmDsvTquXUAKTRX9UT wRUD8Rq8VANtAqQ2dwAUrAYFKxskoHrdWYBXF1+XLDna05PRbAbnrDPy7k3v3pE6g382 KUAMfY4JCeUqngZnZBnsxl6dVqBbQx8HJ2UtObifThCZrucFpGuUMtxc0Xi0HEGqWxa8 JMAA== 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=G2B/fJpOIfTTZtlhN0nNHaY9luzIQArUvbjqozDDCF4=; b=YV2cNT3sVlaU8KzL6TI06ahK/IWPvO6n5wNsmzOdkBR7DL4yyupUoqrxNbvcxZQI3N Fj1aVMPOsSYAQDaX+57M7Ss9qSydp2QFlQ/W0bj2OkVzCEYmU3rulcSKhgyCuAOE2OnB 65FEjsB343tIqc+QlRxFFGYMqNIn6Bpem5zHAJDP4gqYHMpA16+bmtJugLeMK/78TJaQ P+m53W5AbJEMrnxiVYkkhf0ymImmC4Ui32RLF7wMhIE/fD2p70BLBuVCUWFVY8MVrE6E x1aLO60d5TxoMqEe2WpIvPSMWCpYCJcX9HqDtYu+wrh6gpdw9myl7sU73YjuGl3Hk6TO WNqg== X-Gm-Message-State: AKGB3mK30YfMl4dR2k3qepxKbVfMM2jYFTy2g5iBW5Ov5LorF5TyLYo6 yLcczRfjPbXN9PGNRCBiVvQhAQFxqFQ= X-Google-Smtp-Source: ACJfBouzn64t2TV2WfHZ9kTLpfkWc1rqD4Zf5H4ouaYPRCcr4KzUuHXA3efVx1qRDkgxLbPaFuVU6A== X-Received: by 10.159.255.75 with SMTP id u11mr10289931pls.394.1515628139849; Wed, 10 Jan 2018 15:48:59 -0800 (PST) Received: from monty.com ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id g74sm9931676pfd.166.2018.01.10.15.48.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Jan 2018 15:48:58 -0800 (PST) From: Michael Clark To: qemu-devel@nongnu.org Date: Wed, 10 Jan 2018 15:46:26 -0800 Message-Id: <1515628000-93285-8-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1515628000-93285-1-git-send-email-mjc@sifive.com> References: <1515628000-93285-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:c05::243 Subject: [Qemu-devel] [PATCH v2 07/21] 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 , RISC-V Patches , Michael Clark , Palmer Dabbelt , Sagar Karandikar 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. Signed-off-by: Michael Clark --- target/riscv/gdbstub.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 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..12d1d9f --- /dev/null +++ b/target/riscv/gdbstub.c @@ -0,0 +1,59 @@ +/* + * 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) +{ + /* TODO proper x0 handling */ + 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) +{ + /* TODO proper x0 handling */ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + + 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; +}