From patchwork Mon Feb 26 22:17:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10243841 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 5A1C8602A0 for ; Mon, 26 Feb 2018 22:23:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E21F2A43A for ; Mon, 26 Feb 2018 22:23:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32F192A43C; Mon, 26 Feb 2018 22:23:57 +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 A59852A43A for ; Mon, 26 Feb 2018 22:23:56 +0000 (UTC) Received: from localhost ([::1]:33502 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqRBb-0001KI-S2 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 26 Feb 2018 17:23:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49316) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqR7T-0006GK-Pq for qemu-devel@nongnu.org; Mon, 26 Feb 2018 17:19:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eqR7S-00053O-KV for qemu-devel@nongnu.org; Mon, 26 Feb 2018 17:19:39 -0500 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]:43214) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eqR7S-00051c-Ef for qemu-devel@nongnu.org; Mon, 26 Feb 2018 17:19:38 -0500 Received: by mail-pl0-x244.google.com with SMTP id f23so10125806plr.10 for ; Mon, 26 Feb 2018 14:19:38 -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=9aTHMIcRmAKoewbtCuSSQsDrN2XNf9Za/BN2jHiQ7Jw=; b=Viy17ei/0ZV4Ij8mEkeF2a8+6nQWeS3oefGfqS/2zu4teOdVIqiX7W45Ws1YJqO4ea yZ5trPeqaawbVojZjxk7UE68C25UhefJTduS8/hr8XHHXxeLzrujW6uzq4mjTvP6bZ60 4q+n4QxzYmcsuTjQKul2HlHWK3n3W674gg0b1naw6+BrG94+uk1bc/sao7G+ycQZyTbz O2KjTyFmqv5N6EsiZkWged/kVZhJFGbTMliZUhIjyFDI8J4iGu0g6erWMrk05+31tXc9 nJ+KjpdilMArGqGtWlPWOxq08PywuoAXtX7IW+mAEx+7SX0NElkpNvHyK9Wz8YIFjiIK Kz1g== 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=9aTHMIcRmAKoewbtCuSSQsDrN2XNf9Za/BN2jHiQ7Jw=; b=Lj6qb9tJzpgCM/d1hqJDy1mSKs7bDZKhKLF6UJUMy1CFQEOdC5++r7F1V7SyCMIzim 5EeHZjzboHYFv4Q25fCOS+ojP4Krf0s7MVlBxjBf/x+LzWyTJZzcrDOvJ84e/ttVFI5n 2ofSjZuN9sQa8PPkudmGjrDfuJmXpdBbNbf9Mxs3FZRJ0Xd+4T7h5H/EzvYBjjWtbj5V XKpStfaLTRkbOT8eQbc5sMSIV0PqiJ9eg8PC4FKM37FmLM7Yf2LM8CoeKOVaxBuyTzNI RKQQPeZl62eWE4NmaufJUnM/tMRCI+gXfHoZuBqv4EBPQm5v8Atd/kewIU9I14kqhT+a +amQ== X-Gm-Message-State: APf1xPDvV8/Mw8qDtv7YXjLjop2rdvJ5yfon8kaWuBJk/hImNtCi0JEi VNq5dy5EreSE50x27cx9MPIEdlU2vBA= X-Google-Smtp-Source: AH8x226EaanGgQTb0v6JATNB5bZY+VJ6ogr5aQ6wbMi3GY/6GkY8LKenuyZeS5pZGhVFFGFwLMa6WA== X-Received: by 2002:a17:902:64d7:: with SMTP id y23-v6mr11997320pli.258.1519683577421; Mon, 26 Feb 2018 14:19:37 -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 n14sm13592702pfj.154.2018.02.26.14.19.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 14:19:36 -0800 (PST) From: Michael Clark To: qemu-devel@nongnu.org Date: Tue, 27 Feb 2018 11:17:44 +1300 Message-Id: <1519683480-33201-8-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1519683480-33201-1-git-send-email-mjc@sifive.com> References: <1519683480-33201-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 v7 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 | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 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..4f919b6 --- /dev/null +++ b/target/riscv/gdbstub.c @@ -0,0 +1,62 @@ +/* + * RISC-V GDB Server Stub + * + * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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-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; +}