From patchwork Wed Jan 3 00:44:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10141513 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 856676035E for ; Wed, 3 Jan 2018 00:51:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7350928CF7 for ; Wed, 3 Jan 2018 00:51:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 65E3728D52; Wed, 3 Jan 2018 00:51:10 +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 DC3EE28CF7 for ; Wed, 3 Jan 2018 00:51:09 +0000 (UTC) Received: from localhost ([::1]:33093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWXGv-00015p-3z for patchwork-qemu-devel@patchwork.kernel.org; Tue, 02 Jan 2018 19:51:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58731) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWXCd-0005dq-UM for qemu-devel@nongnu.org; Tue, 02 Jan 2018 19:46:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWXCb-00082q-CW for qemu-devel@nongnu.org; Tue, 02 Jan 2018 19:46:44 -0500 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]:43665) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eWXCb-000827-6j for qemu-devel@nongnu.org; Tue, 02 Jan 2018 19:46:41 -0500 Received: by mail-pl0-x241.google.com with SMTP id z5so130622plo.10 for ; Tue, 02 Jan 2018 16:46:41 -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=UkPjKzKbORh9ZxguM3WEedTBSIlBtS1eQOBxzefwvZg2LrkU6JPjSrsKsm4YtihTYD gKnu6ztPvsRj1OHqfL5SCGtPSjd1kAUWrQeTiKKRmzvKCL0XTa/woAjPeLThsI152YsO vw6yXKTP5dEkMe1xaw8XKmNGyNNI5nmtEcB030qo3yTIsjwfnj/CaTqs5Fsz4xIelkTT wmRQBf0SC/xC/3us5VitNKByktRHhoaA0uIrzeeuUiU2yWrW7dk/ILL8n+lp5Hz7Jooo mS/uCL9TgYIXrli41q9GXStJcfupswpGtv7NI5Y/vqa7cyV/o50SJkGapLBK72lxJAi1 st8g== 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=BJwsuN1FmlLxS5/wfJd9dghEB3Ab1vl7X62pxv/fLi6GmhCkyTlgZUZZigTfoSrath P9gTE2mgstMmJOYkyzI4Kmmm/FxbPaqH/P88y5YLTAbtXeahnad2AdX8YoLJ2ZIrVT1N hLQ7Zygt68nALdvFgNuoLM1NmVS0p9BeNmO1+lgP9sNBZRXHPiH0HjR6amvRWrwdv9PV hlWGFF5Dg6Nw+yITkKPZfHmtFYCRdZ+62+a/x4elU5m9emGgTjnu2hb4WZkwGEZFCFOD njtaJyiN59NTMThCBNLx4gLY5ZU7y5rPWxfPgsiDvoiw+ZnkO8wVDOvM9HSeQg9KPCLA dPPQ== X-Gm-Message-State: AKGB3mKndC9KdulW9G0ZAvSyjqKQWNDnJ+epdsgJfF+khNJxajexVK/c H7mbYKLP5fQQ9nJ0sKtpV5cO+s0Xn+M= X-Google-Smtp-Source: ACJfBostmaRPpzH5I0KZBrHDBwTAO0KdelCp4IRLtxtB8O1Zx17lbbZ6GrDhSTTnFGyUBcOaQoZCHA== X-Received: by 10.84.128.70 with SMTP id 64mr128576pla.267.1514940400177; Tue, 02 Jan 2018 16:46:40 -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 75sm97691351pfo.103.2018.01.02.16.46.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Jan 2018 16:46:39 -0800 (PST) From: Michael Clark To: qemu-devel@nongnu.org Date: Wed, 3 Jan 2018 13:44:11 +1300 Message-Id: <1514940265-18093-8-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1514940265-18093-1-git-send-email-mjc@sifive.com> References: <1514940265-18093-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::241 Subject: [Qemu-devel] [PATCH v1 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 , Michael Clark , 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 Reviewed-by: Richard Henderson --- 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; +}