From nobody Thu Sep 25 22:53:28 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654084363693483.1533127426669; Wed, 1 Jun 2022 04:52:43 -0700 (PDT) Received: from localhost ([::1]:55536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nwMu2-0008Qc-13 for importer@patchew.org; Wed, 01 Jun 2022 07:52:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nwLpM-0001B3-UZ for qemu-devel@nongnu.org; Wed, 01 Jun 2022 06:43:48 -0400 Received: from mail.loongson.cn ([114.242.206.163]:45396 helo=loongson.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nwLp6-0003An-D3 for qemu-devel@nongnu.org; Wed, 01 Jun 2022 06:43:48 -0400 Received: from localhost.localdomain (unknown [10.2.5.185]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Cxb+aGPpdibocLAA--.49716S43; Wed, 01 Jun 2022 18:25:47 +0800 (CST) From: Xiaojuan Yang To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, gaosong@loongson.cn, maobibo@loongson.cn, mst@redhat.com, imammedo@redhat.com, ani@anisinha.ca, mark.cave-ayland@ilande.co.uk Subject: [PATCH v6 41/43] target/loongarch: Add gdb support. Date: Wed, 1 Jun 2022 18:25:07 +0800 Message-Id: <20220601102509.985650-42-yangxiaojuan@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220601102509.985650-1-yangxiaojuan@loongson.cn> References: <20220601102509.985650-1-yangxiaojuan@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf9Cxb+aGPpdibocLAA--.49716S43 X-Coremail-Antispam: 1UD129KBjvJXoWfJry7ArWDZr43GF1fWF1DAwb_yoWkKw4kpF 93C34DJr42g392yrZrA3s09Fn8ArnrCF4SvF1fX340k3yjgFW8Xwn5t3sxZrWUGayrXryj gFZa9a1rJa15JFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_UUUUUUUUU== X-CM-SenderInfo: p1dqw5xldry3tdq6z05rqj20fqof0/ Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=114.242.206.163; envelope-from=yangxiaojuan@loongson.cn; helo=loongson.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1654084365298100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Xiaojuan Yang Signed-off-by: Song Gao Reviewed-by: Richard Henderson --- MAINTAINERS | 1 + configs/targets/loongarch64-softmmu.mak | 1 + gdb-xml/loongarch-base64.xml | 44 ++++++++++++++ gdb-xml/loongarch-fpu64.xml | 57 +++++++++++++++++ target/loongarch/cpu.c | 9 +++ target/loongarch/gdbstub.c | 81 +++++++++++++++++++++++++ target/loongarch/internals.h | 4 ++ target/loongarch/meson.build | 1 + 8 files changed, 198 insertions(+) create mode 100644 gdb-xml/loongarch-base64.xml create mode 100644 gdb-xml/loongarch-fpu64.xml create mode 100644 target/loongarch/gdbstub.c diff --git a/MAINTAINERS b/MAINTAINERS index 9f4ee7978d..492dbf64e0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1138,6 +1138,7 @@ F: include/hw/intc/loongarch_*.h F: hw/intc/loongarch_*.c F: include/hw/pci-host/ls7a.h F: hw/rtc/ls7a_rtc.c +F: gdb-xml/loongarch*.xml =20 M68K Machines ------------- diff --git a/configs/targets/loongarch64-softmmu.mak b/configs/targets/loon= garch64-softmmu.mak index 666154022f..7bc06c850c 100644 --- a/configs/targets/loongarch64-softmmu.mak +++ b/configs/targets/loongarch64-softmmu.mak @@ -1,3 +1,4 @@ TARGET_ARCH=3Dloongarch64 TARGET_BASE_ARCH=3Dloongarch TARGET_SUPPORTS_MTTCG=3Dy +TARGET_XML_FILES=3D gdb-xml/loongarch-base64.xml gdb-xml/loongarch-fpu64.x= ml diff --git a/gdb-xml/loongarch-base64.xml b/gdb-xml/loongarch-base64.xml new file mode 100644 index 0000000000..4962bdbd28 --- /dev/null +++ b/gdb-xml/loongarch-base64.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gdb-xml/loongarch-fpu64.xml b/gdb-xml/loongarch-fpu64.xml new file mode 100644 index 0000000000..e52cf89fbc --- /dev/null +++ b/gdb-xml/loongarch-fpu64.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index fcd3ba4f35..2749297f74 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -482,6 +482,8 @@ static void loongarch_cpu_realizefn(DeviceState *dev, E= rror **errp) return; } =20 + loongarch_cpu_register_gdb_regs_for_features(cs); + cpu_reset(cs); qemu_init_vcpu(cs); =20 @@ -635,6 +637,13 @@ static void loongarch_cpu_class_init(ObjectClass *c, v= oid *data) dc->vmsd =3D &vmstate_loongarch_cpu; cc->sysemu_ops =3D &loongarch_sysemu_ops; cc->disas_set_info =3D loongarch_cpu_disas_set_info; + cc->gdb_read_register =3D loongarch_cpu_gdb_read_register; + cc->gdb_write_register =3D loongarch_cpu_gdb_write_register; + cc->disas_set_info =3D loongarch_cpu_disas_set_info; + cc->gdb_num_core_regs =3D 34; + cc->gdb_core_xml_file =3D "loongarch-base64.xml"; + cc->gdb_stop_before_watchpoint =3D true; + #ifdef CONFIG_TCG cc->tcg_ops =3D &loongarch_tcg_ops; #endif diff --git a/target/loongarch/gdbstub.c b/target/loongarch/gdbstub.c new file mode 100644 index 0000000000..0c48834201 --- /dev/null +++ b/target/loongarch/gdbstub.c @@ -0,0 +1,81 @@ +/* + * LOONGARCH gdb server stub + * + * Copyright (c) 2021 Loongson Technology Corporation Limited + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "internals.h" +#include "exec/gdbstub.h" + +int loongarch_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int= n) +{ + LoongArchCPU *cpu =3D LOONGARCH_CPU(cs); + CPULoongArchState *env =3D &cpu->env; + + if (0 <=3D n && n < 32) { + return gdb_get_regl(mem_buf, env->gpr[n]); + } else if (n =3D=3D 32) { + return gdb_get_regl(mem_buf, env->pc); + } else if (n =3D=3D 33) { + return gdb_get_regl(mem_buf, env->badaddr); + } + return 0; +} + +int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +{ + LoongArchCPU *cpu =3D LOONGARCH_CPU(cs); + CPULoongArchState *env =3D &cpu->env; + target_ulong tmp =3D ldtul_p(mem_buf); + int length =3D 0; + + if (0 <=3D n && n < 32) { + env->gpr[n] =3D tmp; + length =3D sizeof(target_ulong); + } else if (n =3D=3D 32) { + env->pc =3D tmp; + length =3D sizeof(target_ulong); + } + return length; +} + +static int loongarch_gdb_get_fpu(CPULoongArchState *env, + GByteArray *mem_buf, int n) +{ + if (0 <=3D n && n < 32) { + return gdb_get_reg64(mem_buf, env->fpr[n]); + } else if (32 <=3D n && n < 40) { + return gdb_get_reg8(mem_buf, env->cf[n - 32]); + } else if (n =3D=3D 40) { + return gdb_get_reg32(mem_buf, env->fcsr0); + } + return 0; +} + +static int loongarch_gdb_set_fpu(CPULoongArchState *env, + uint8_t *mem_buf, int n) +{ + int length =3D 0; + + if (0 <=3D n && n < 32) { + env->fpr[n] =3D ldq_p(mem_buf); + length =3D 8; + } else if (32 <=3D n && n < 40) { + env->cf[n - 32] =3D ldub_p(mem_buf); + length =3D 1; + } else if (n =3D=3D 40) { + env->fcsr0 =3D ldl_p(mem_buf); + length =3D 4; + } + return length; +} + +void loongarch_cpu_register_gdb_regs_for_features(CPUState *cs) +{ + gdb_register_coprocessor(cs, loongarch_gdb_get_fpu, loongarch_gdb_set_= fpu, + 41, "loongarch-fpu64.xml", 0); +} diff --git a/target/loongarch/internals.h b/target/loongarch/internals.h index a410c41c37..9d50fbdd81 100644 --- a/target/loongarch/internals.h +++ b/target/loongarch/internals.h @@ -49,4 +49,8 @@ bool loongarch_cpu_tlb_fill(CPUState *cs, vaddr address, = int size, =20 hwaddr loongarch_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); =20 +int loongarch_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int= n); +int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n= ); +void loongarch_cpu_register_gdb_regs_for_features(CPUState *cs); + #endif diff --git a/target/loongarch/meson.build b/target/loongarch/meson.build index 74e5f3b2a7..6376f9e84b 100644 --- a/target/loongarch/meson.build +++ b/target/loongarch/meson.build @@ -11,6 +11,7 @@ loongarch_tcg_ss.add(files( 'fpu_helper.c', 'op_helper.c', 'translate.c', + 'gdbstub.c', )) loongarch_tcg_ss.add(zlib) =20 --=20 2.31.1