From patchwork Mon Jan 14 15:41:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabiano Rosas X-Patchwork-Id: 10762987 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4AD12139A for ; Mon, 14 Jan 2019 15:49:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CF5528C18 for ; Mon, 14 Jan 2019 15:49:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3141828C29; Mon, 14 Jan 2019 15:49:06 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A99A828C13 for ; Mon, 14 Jan 2019 15:49:05 +0000 (UTC) Received: from localhost ([127.0.0.1]:58327 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj4U4-0005kF-Qv for patchwork-qemu-devel@patchwork.kernel.org; Mon, 14 Jan 2019 10:49:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj4Ms-0007nM-LI for qemu-devel@nongnu.org; Mon, 14 Jan 2019 10:41:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gj4Mr-0001AM-Ie for qemu-devel@nongnu.org; Mon, 14 Jan 2019 10:41:38 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:52580) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gj4Mr-0000gQ-4g for qemu-devel@nongnu.org; Mon, 14 Jan 2019 10:41:37 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id x0EFRogw054330 for ; Mon, 14 Jan 2019 10:41:25 -0500 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0a-001b2d01.pphosted.com with ESMTP id 2q0u2myb63-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 14 Jan 2019 10:41:24 -0500 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 14 Jan 2019 15:41:22 -0000 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 14 Jan 2019 15:41:21 -0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x0EFfKos11075618 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 14 Jan 2019 15:41:20 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 42CD6112063; Mon, 14 Jan 2019 15:41:20 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3FF48112067; Mon, 14 Jan 2019 15:41:19 +0000 (GMT) Received: from farosas.linux.ibm.com.ibmmodules.com (unknown [9.85.135.65]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 14 Jan 2019 15:41:18 +0000 (GMT) From: Fabiano Rosas To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2019 13:41:10 -0200 X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190114154113.6188-1-farosas@linux.ibm.com> References: <20190114154113.6188-1-farosas@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19011415-2213-0000-0000-0000033D33FC X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010404; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000274; SDB=6.01146399; UDB=6.00597076; IPR=6.00926686; MB=3.00025122; MTD=3.00000008; XFM=3.00000015; UTC=2019-01-14 15:41:22 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19011415-2214-0000-0000-00005CF7FB1D Message-Id: <20190114154113.6188-2-farosas@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-01-14_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901140114 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v2 1/3] target/ppc: Add SPRs XML generation code for gdbstub 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: qemu-ppc@nongnu.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP A following patch will add support for handling the Special Purpose Registers (SPR) in GDB via gdbstub. For that purpose, GDB needs to be provided with an XML description of the registers (see gdb-xml directory). This patch adds the code that generates the XML dynamically based on the SPRs already defined in the machine. This eliminates the need for several XML files to match each possible ppc machine. A "group" is defined so that the GDB command `info registers spr` can be used. Signed-off-by: Fabiano Rosas --- target/ppc/cpu.h | 8 +++++++ target/ppc/gdbstub.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 486abaf99b..34f0d2d419 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -230,6 +230,7 @@ struct ppc_spr_t { void (*oea_write)(DisasContext *ctx, int spr_num, int gpr_num); void (*hea_read)(DisasContext *ctx, int gpr_num, int spr_num); void (*hea_write)(DisasContext *ctx, int spr_num, int gpr_num); + unsigned int gdb_id; #endif const char *name; target_ulong default_value; @@ -1053,6 +1054,9 @@ struct CPUPPCState { /* Special purpose registers */ target_ulong spr[1024]; ppc_spr_t spr_cb[1024]; +#if !defined(CONFIG_USER_ONLY) + const char *gdb_spr_xml; +#endif /* Vector status and control register */ uint32_t vscr; /* VSX registers (including FP and AVR) */ @@ -1267,6 +1271,10 @@ int ppc_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); int ppc_cpu_gdb_read_register_apple(CPUState *cpu, uint8_t *buf, int reg); int ppc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); int ppc_cpu_gdb_write_register_apple(CPUState *cpu, uint8_t *buf, int reg); +#ifndef CONFIG_USER_ONLY +int ppc_gdb_gen_spr_xml(CPUState *cpu); +const char *ppc_gdb_get_dynamic_xml(CPUState *cs, const char *xml_name); +#endif int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, void *opaque); int ppc32_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, diff --git a/target/ppc/gdbstub.c b/target/ppc/gdbstub.c index 19565b584d..ce4b728028 100644 --- a/target/ppc/gdbstub.c +++ b/target/ppc/gdbstub.c @@ -319,3 +319,57 @@ int ppc_cpu_gdb_write_register_apple(CPUState *cs, uint8_t *mem_buf, int n) } return r; } + +#ifndef CONFIG_USER_ONLY +int ppc_gdb_gen_spr_xml(CPUState *cs) +{ + PowerPCCPU *cpu = POWERPC_CPU(cs); + CPUPPCState *env = &cpu->env; + GString *s = g_string_new(NULL); + unsigned int num_regs = 0; + int i; + + g_string_printf(s, ""); + g_string_append_printf(s, ""); + g_string_append_printf(s, ""); + + for (i = 0; i < ARRAY_SIZE(env->spr_cb); i++) { + ppc_spr_t *spr = &env->spr_cb[i]; + + if (!spr->name) { + continue; + } + + g_string_append_printf(s, "name, -1)); + g_string_append_printf(s, " bitsize=\"%d\"", TARGET_LONG_BITS); + g_string_append_printf(s, " group=\"spr\"/>"); + + /* + * GDB identifies registers based on the order they are + * presented in the XML. These ids will not match QEMU's + * representation (which follows the PowerISA). + * + * Store the position of the current register description so + * we can make the correspondence later. + */ + spr->gdb_id = num_regs; + num_regs++; + } + + g_string_append_printf(s, ""); + env->gdb_spr_xml = g_string_free(s, false); + return num_regs; +} + +const char *ppc_gdb_get_dynamic_xml(CPUState *cs, const char *xml_name) +{ + PowerPCCPU *cpu = POWERPC_CPU(cs); + CPUPPCState *env = &cpu->env; + + if (strcmp(xml_name, "power-spr.xml") == 0) { + return env->gdb_spr_xml; + } + return NULL; +} +#endif