All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for-7.1 0/5] Fix gdb bugs and update gdb-xml
@ 2022-08-04 13:02 Song Gao
  2022-08-04 13:02 ` [PATCH for-7.1 1/5] target/loongarch: Fix GDB get the wrong pc Song Gao
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Song Gao @ 2022-08-04 13:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: richard.henderson, peter.maydell, gaosong, f4bug, alex.bennee,
	yangxiaojuan

Hi,All

This series fiex LoongArch GDB get the wrong pc, because the xml missing
the register orig_a0, and update loongarch gdb-xml to match GDB[1]

[1]:https://github.com/bminor/binutils-gdb/blob/master/gdb/features/loongarch

Please review!

Thanks.
Song Gao

Song Gao (5):
  target/loongarch: Fix GDB get the wrong pc
  target/loongarch: add gdb_arch_name()
  target/loongarch: update loongarch-base64.xml
  target/loongarch: Update loongarch-fpu.xml
  target/loongarch: Update gdb_set_fpu() and gdb_get_fpu()

 configs/targets/loongarch64-softmmu.mak |  2 +-
 gdb-xml/loongarch-base64.xml            | 13 +++---
 gdb-xml/loongarch-fpu.xml               | 50 ++++++++++++++++++++++
 gdb-xml/loongarch-fpu64.xml             | 57 -------------------------
 target/loongarch/cpu.c                  |  8 +++-
 target/loongarch/gdbstub.c              | 32 +++++++++-----
 6 files changed, 87 insertions(+), 75 deletions(-)
 create mode 100644 gdb-xml/loongarch-fpu.xml
 delete mode 100644 gdb-xml/loongarch-fpu64.xml

-- 
2.31.1



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH for-7.1 1/5] target/loongarch: Fix GDB get the wrong pc
  2022-08-04 13:02 [PATCH for-7.1 0/5] Fix gdb bugs and update gdb-xml Song Gao
@ 2022-08-04 13:02 ` Song Gao
  2022-08-04 15:56   ` Richard Henderson
  2022-08-04 13:02 ` [PATCH for-7.1 2/5] target/loongarch: add gdb_arch_name() Song Gao
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Song Gao @ 2022-08-04 13:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: richard.henderson, peter.maydell, gaosong, f4bug, alex.bennee,
	yangxiaojuan

GDB LoongArch add a register orig_a0, see the base64.xml [1].
We should add the orig_a0 to match the upstream GDB.

[1]: https://github.com/bminor/binutils-gdb/blob/master/gdb/features/loongarch/base64.xml

Signed-off-by: Song Gao <gaosong@loongson.cn>
---
 gdb-xml/loongarch-base64.xml | 1 +
 target/loongarch/cpu.c       | 2 +-
 target/loongarch/gdbstub.c   | 7 +++++--
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/gdb-xml/loongarch-base64.xml b/gdb-xml/loongarch-base64.xml
index 4962bdbd28..a1dd4f2208 100644
--- a/gdb-xml/loongarch-base64.xml
+++ b/gdb-xml/loongarch-base64.xml
@@ -39,6 +39,7 @@
   <reg name="r29" bitsize="64" type="uint64" group="general"/>
   <reg name="r30" bitsize="64" type="uint64" group="general"/>
   <reg name="r31" bitsize="64" type="uint64" group="general"/>
+  <reg name="orig_a0" bitsize="64" type="uint64" group="general"/>
   <reg name="pc" bitsize="64" type="code_ptr" group="general"/>
   <reg name="badvaddr" bitsize="64" type="code_ptr" group="general"/>
 </feature>
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index 1c69a76f2b..d84ec38cf7 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -683,7 +683,7 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data)
     cc->gdb_read_register = loongarch_cpu_gdb_read_register;
     cc->gdb_write_register = loongarch_cpu_gdb_write_register;
     cc->disas_set_info = loongarch_cpu_disas_set_info;
-    cc->gdb_num_core_regs = 34;
+    cc->gdb_num_core_regs = 35;
     cc->gdb_core_xml_file = "loongarch-base64.xml";
     cc->gdb_stop_before_watchpoint = true;
 
diff --git a/target/loongarch/gdbstub.c b/target/loongarch/gdbstub.c
index 24e126fb2d..e643eca2d5 100644
--- a/target/loongarch/gdbstub.c
+++ b/target/loongarch/gdbstub.c
@@ -19,8 +19,11 @@ int loongarch_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
     if (0 <= n && n < 32) {
         return gdb_get_regl(mem_buf, env->gpr[n]);
     } else if (n == 32) {
-        return gdb_get_regl(mem_buf, env->pc);
+        /* orig_a0 */
+        return gdb_get_regl(mem_buf, env->gpr[4]);
     } else if (n == 33) {
+        return gdb_get_regl(mem_buf, env->pc);
+    } else if (n == 34) {
         return gdb_get_regl(mem_buf, env->CSR_BADV);
     }
     return 0;
@@ -36,7 +39,7 @@ int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     if (0 <= n && n < 32) {
         env->gpr[n] = tmp;
         length = sizeof(target_ulong);
-    } else if (n == 32) {
+    } else if (n == 33) {
         env->pc = tmp;
         length = sizeof(target_ulong);
     }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH for-7.1 2/5] target/loongarch: add gdb_arch_name()
  2022-08-04 13:02 [PATCH for-7.1 0/5] Fix gdb bugs and update gdb-xml Song Gao
  2022-08-04 13:02 ` [PATCH for-7.1 1/5] target/loongarch: Fix GDB get the wrong pc Song Gao
@ 2022-08-04 13:02 ` Song Gao
  2022-08-04 16:02   ` Richard Henderson
  2022-08-04 13:02 ` [PATCH for-7.1 3/5] target/loongarch: update loongarch-base64.xml Song Gao
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Song Gao @ 2022-08-04 13:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: richard.henderson, peter.maydell, gaosong, f4bug, alex.bennee,
	yangxiaojuan

LoongArch gdb_arch_name() is "Loongarch64", Dump from GDB.

GNU gdb (GDB) 13.0.50.20220519-git
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "loongarch64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) show architecture
The target architecture is set to "auto" (currently "Loongarch64").
(gdb)

Signed-off-by: Song Gao <gaosong@loongson.cn>
---
 target/loongarch/cpu.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index d84ec38cf7..94d5617639 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -661,6 +661,11 @@ static const struct SysemuCPUOps loongarch_sysemu_ops = {
 };
 #endif
 
+static gchar *loongarch_gdb_arch_name(CPUState *cs)
+{
+    return g_strdup("Loongarch64");
+}
+
 static void loongarch_cpu_class_init(ObjectClass *c, void *data)
 {
     LoongArchCPUClass *lacc = LOONGARCH_CPU_CLASS(c);
@@ -686,6 +691,7 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data)
     cc->gdb_num_core_regs = 35;
     cc->gdb_core_xml_file = "loongarch-base64.xml";
     cc->gdb_stop_before_watchpoint = true;
+    cc->gdb_arch_name = loongarch_gdb_arch_name;
 
 #ifdef CONFIG_TCG
     cc->tcg_ops = &loongarch_tcg_ops;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH for-7.1 3/5] target/loongarch: update loongarch-base64.xml
  2022-08-04 13:02 [PATCH for-7.1 0/5] Fix gdb bugs and update gdb-xml Song Gao
  2022-08-04 13:02 ` [PATCH for-7.1 1/5] target/loongarch: Fix GDB get the wrong pc Song Gao
  2022-08-04 13:02 ` [PATCH for-7.1 2/5] target/loongarch: add gdb_arch_name() Song Gao
@ 2022-08-04 13:02 ` Song Gao
  2022-08-04 16:03   ` Richard Henderson
  2022-08-04 13:02 ` [PATCH for-7.1 4/5] target/loongarch: Update loongarch-fpu.xml Song Gao
  2022-08-04 13:02 ` [PATCH for-7.1 5/5] target/loongarch: Update gdb_set_fpu() and gdb_get_fpu() Song Gao
  4 siblings, 1 reply; 11+ messages in thread
From: Song Gao @ 2022-08-04 13:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: richard.henderson, peter.maydell, gaosong, f4bug, alex.bennee,
	yangxiaojuan

Update loongarch-base64.xml to match the upstream GDB [1].

[1]:https://github.com/bminor/binutils-gdb/blob/master/gdb/features/loongarch/base64.xml

Signed-off-by: Song Gao <gaosong@loongson.cn>
---
 gdb-xml/loongarch-base64.xml | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/gdb-xml/loongarch-base64.xml b/gdb-xml/loongarch-base64.xml
index a1dd4f2208..2d8a1f6b73 100644
--- a/gdb-xml/loongarch-base64.xml
+++ b/gdb-xml/loongarch-base64.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<!-- Copyright (C) 2021 Free Software Foundation, Inc.
+<!-- Copyright (C) 2022 Free Software Foundation, Inc.
 
      Copying and distribution of this file, with or without modification,
      are permitted in any medium without royalty provided the copyright
@@ -8,9 +8,9 @@
 <!DOCTYPE feature SYSTEM "gdb-target.dtd">
 <feature name="org.gnu.gdb.loongarch.base">
   <reg name="r0" bitsize="64" type="uint64" group="general"/>
-  <reg name="r1" bitsize="64" type="uint64" group="general"/>
-  <reg name="r2" bitsize="64" type="uint64" group="general"/>
-  <reg name="r3" bitsize="64" type="uint64" group="general"/>
+  <reg name="r1" bitsize="64" type="code_ptr" group="general"/>
+  <reg name="r2" bitsize="64" type="data_ptr" group="general"/>
+  <reg name="r3" bitsize="64" type="data_ptr" group="general"/>
   <reg name="r4" bitsize="64" type="uint64" group="general"/>
   <reg name="r5" bitsize="64" type="uint64" group="general"/>
   <reg name="r6" bitsize="64" type="uint64" group="general"/>
@@ -29,7 +29,7 @@
   <reg name="r19" bitsize="64" type="uint64" group="general"/>
   <reg name="r20" bitsize="64" type="uint64" group="general"/>
   <reg name="r21" bitsize="64" type="uint64" group="general"/>
-  <reg name="r22" bitsize="64" type="uint64" group="general"/>
+  <reg name="r22" bitsize="64" type="data_ptr" group="general"/>
   <reg name="r23" bitsize="64" type="uint64" group="general"/>
   <reg name="r24" bitsize="64" type="uint64" group="general"/>
   <reg name="r25" bitsize="64" type="uint64" group="general"/>
@@ -41,5 +41,5 @@
   <reg name="r31" bitsize="64" type="uint64" group="general"/>
   <reg name="orig_a0" bitsize="64" type="uint64" group="general"/>
   <reg name="pc" bitsize="64" type="code_ptr" group="general"/>
-  <reg name="badvaddr" bitsize="64" type="code_ptr" group="general"/>
+  <reg name="badv" bitsize="64" type="code_ptr" group="general"/>
 </feature>
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH for-7.1 4/5] target/loongarch: Update loongarch-fpu.xml
  2022-08-04 13:02 [PATCH for-7.1 0/5] Fix gdb bugs and update gdb-xml Song Gao
                   ` (2 preceding siblings ...)
  2022-08-04 13:02 ` [PATCH for-7.1 3/5] target/loongarch: update loongarch-base64.xml Song Gao
@ 2022-08-04 13:02 ` Song Gao
  2022-08-04 16:06   ` Richard Henderson
  2022-08-04 13:02 ` [PATCH for-7.1 5/5] target/loongarch: Update gdb_set_fpu() and gdb_get_fpu() Song Gao
  4 siblings, 1 reply; 11+ messages in thread
From: Song Gao @ 2022-08-04 13:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: richard.henderson, peter.maydell, gaosong, f4bug, alex.bennee,
	yangxiaojuan

Rename loongarch-fpu64.xml to loongarch-fpu.xml and update loongarch-fpu.xml to match upstream GDB [1]

[1]:https://github.com/bminor/binutils-gdb/blob/master/gdb/features/loongarch/fpu.xml

Signed-off-by: Song Gao <gaosong@loongson.cn>
---
 configs/targets/loongarch64-softmmu.mak |  2 +-
 gdb-xml/loongarch-fpu.xml               | 50 ++++++++++++++++++++++
 gdb-xml/loongarch-fpu64.xml             | 57 -------------------------
 target/loongarch/gdbstub.c              |  2 +-
 4 files changed, 52 insertions(+), 59 deletions(-)
 create mode 100644 gdb-xml/loongarch-fpu.xml
 delete mode 100644 gdb-xml/loongarch-fpu64.xml

diff --git a/configs/targets/loongarch64-softmmu.mak b/configs/targets/loongarch64-softmmu.mak
index 483474ba93..9abc99056f 100644
--- a/configs/targets/loongarch64-softmmu.mak
+++ b/configs/targets/loongarch64-softmmu.mak
@@ -1,5 +1,5 @@
 TARGET_ARCH=loongarch64
 TARGET_BASE_ARCH=loongarch
 TARGET_SUPPORTS_MTTCG=y
-TARGET_XML_FILES= gdb-xml/loongarch-base64.xml gdb-xml/loongarch-fpu64.xml
+TARGET_XML_FILES= gdb-xml/loongarch-base64.xml gdb-xml/loongarch-fpu.xml
 TARGET_NEED_FDT=y
diff --git a/gdb-xml/loongarch-fpu.xml b/gdb-xml/loongarch-fpu.xml
new file mode 100644
index 0000000000..a61057ec44
--- /dev/null
+++ b/gdb-xml/loongarch-fpu.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2021 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.loongarch.fpu">
+
+  <union id="fputype">
+    <field name="f" type="ieee_single"/>
+    <field name="d" type="ieee_double"/>
+  </union>
+
+  <reg name="f0" bitsize="64" type="fputype" group="float"/>
+  <reg name="f1" bitsize="64" type="fputype" group="float"/>
+  <reg name="f2" bitsize="64" type="fputype" group="float"/>
+  <reg name="f3" bitsize="64" type="fputype" group="float"/>
+  <reg name="f4" bitsize="64" type="fputype" group="float"/>
+  <reg name="f5" bitsize="64" type="fputype" group="float"/>
+  <reg name="f6" bitsize="64" type="fputype" group="float"/>
+  <reg name="f7" bitsize="64" type="fputype" group="float"/>
+  <reg name="f8" bitsize="64" type="fputype" group="float"/>
+  <reg name="f9" bitsize="64" type="fputype" group="float"/>
+  <reg name="f10" bitsize="64" type="fputype" group="float"/>
+  <reg name="f11" bitsize="64" type="fputype" group="float"/>
+  <reg name="f12" bitsize="64" type="fputype" group="float"/>
+  <reg name="f13" bitsize="64" type="fputype" group="float"/>
+  <reg name="f14" bitsize="64" type="fputype" group="float"/>
+  <reg name="f15" bitsize="64" type="fputype" group="float"/>
+  <reg name="f16" bitsize="64" type="fputype" group="float"/>
+  <reg name="f17" bitsize="64" type="fputype" group="float"/>
+  <reg name="f18" bitsize="64" type="fputype" group="float"/>
+  <reg name="f19" bitsize="64" type="fputype" group="float"/>
+  <reg name="f20" bitsize="64" type="fputype" group="float"/>
+  <reg name="f21" bitsize="64" type="fputype" group="float"/>
+  <reg name="f22" bitsize="64" type="fputype" group="float"/>
+  <reg name="f23" bitsize="64" type="fputype" group="float"/>
+  <reg name="f24" bitsize="64" type="fputype" group="float"/>
+  <reg name="f25" bitsize="64" type="fputype" group="float"/>
+  <reg name="f26" bitsize="64" type="fputype" group="float"/>
+  <reg name="f27" bitsize="64" type="fputype" group="float"/>
+  <reg name="f28" bitsize="64" type="fputype" group="float"/>
+  <reg name="f29" bitsize="64" type="fputype" group="float"/>
+  <reg name="f30" bitsize="64" type="fputype" group="float"/>
+  <reg name="f31" bitsize="64" type="fputype" group="float"/>
+  <reg name="fcc" bitsize="64" type="fputype" group="float"/>
+  <reg name="fcsr" bitsize="32" type="uint32" group="float"/>
+</feature>
diff --git a/gdb-xml/loongarch-fpu64.xml b/gdb-xml/loongarch-fpu64.xml
deleted file mode 100644
index e52cf89fbc..0000000000
--- a/gdb-xml/loongarch-fpu64.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-<?xml version="1.0"?>
-<!-- Copyright (C) 2021 Free Software Foundation, Inc.
-
-     Copying and distribution of this file, with or without modification,
-     are permitted in any medium without royalty provided the copyright
-     notice and this notice are preserved.  -->
-
-<!DOCTYPE feature SYSTEM "gdb-target.dtd">
-<feature name="org.gnu.gdb.loongarch.fpu">
-
-  <union id="fpu64type">
-    <field name="f" type="ieee_single"/>
-    <field name="d" type="ieee_double"/>
-  </union>
-
-  <reg name="f0" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f1" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f2" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f3" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f4" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f5" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f6" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f7" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f8" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f9" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f10" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f11" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f12" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f13" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f14" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f15" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f16" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f17" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f18" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f19" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f20" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f21" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f22" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f23" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f24" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f25" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f26" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f27" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f28" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f29" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f30" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="f31" bitsize="64" type="fpu64type" group="float"/>
-  <reg name="fcc0" bitsize="8" type="uint8" group="float"/>
-  <reg name="fcc1" bitsize="8" type="uint8" group="float"/>
-  <reg name="fcc2" bitsize="8" type="uint8" group="float"/>
-  <reg name="fcc3" bitsize="8" type="uint8" group="float"/>
-  <reg name="fcc4" bitsize="8" type="uint8" group="float"/>
-  <reg name="fcc5" bitsize="8" type="uint8" group="float"/>
-  <reg name="fcc6" bitsize="8" type="uint8" group="float"/>
-  <reg name="fcc7" bitsize="8" type="uint8" group="float"/>
-  <reg name="fcsr" bitsize="32" type="uint32" group="float"/>
-</feature>
diff --git a/target/loongarch/gdbstub.c b/target/loongarch/gdbstub.c
index e643eca2d5..7d95b4b11c 100644
--- a/target/loongarch/gdbstub.c
+++ b/target/loongarch/gdbstub.c
@@ -80,5 +80,5 @@ static int loongarch_gdb_set_fpu(CPULoongArchState *env,
 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);
+                             41, "loongarch-fpu.xml", 0);
 }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH for-7.1 5/5] target/loongarch: Update gdb_set_fpu() and gdb_get_fpu()
  2022-08-04 13:02 [PATCH for-7.1 0/5] Fix gdb bugs and update gdb-xml Song Gao
                   ` (3 preceding siblings ...)
  2022-08-04 13:02 ` [PATCH for-7.1 4/5] target/loongarch: Update loongarch-fpu.xml Song Gao
@ 2022-08-04 13:02 ` Song Gao
  2022-08-04 16:08   ` Richard Henderson
  4 siblings, 1 reply; 11+ messages in thread
From: Song Gao @ 2022-08-04 13:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: richard.henderson, peter.maydell, gaosong, f4bug, alex.bennee,
	yangxiaojuan

GDB LoongArch fpu use fcc register,  update gdb_set_fpu() and gdb_get_fpu() to match it.

Signed-off-by: Song Gao <gaosong@loongson.cn>
---
 target/loongarch/gdbstub.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/target/loongarch/gdbstub.c b/target/loongarch/gdbstub.c
index 7d95b4b11c..265f0f43b6 100644
--- a/target/loongarch/gdbstub.c
+++ b/target/loongarch/gdbstub.c
@@ -51,9 +51,14 @@ static int loongarch_gdb_get_fpu(CPULoongArchState *env,
 {
     if (0 <= n && n < 32) {
         return gdb_get_reg64(mem_buf, env->fpr[n]);
-    } else if (32 <= n && n < 40) {
-        return gdb_get_reg8(mem_buf, env->cf[n - 32]);
-    } else if (n == 40) {
+    } else if (n == 32) {
+        /* fcc */
+        uint64_t val = 0;
+        for (int i = 0; i < 8; ++i) {
+            val |= (uint64_t)env->cf[i] << (i * 8);
+        }
+        return gdb_get_reg64(mem_buf, val);
+    } else if (n == 33) {
         return gdb_get_reg32(mem_buf, env->fcsr0);
     }
     return 0;
@@ -67,10 +72,14 @@ static int loongarch_gdb_set_fpu(CPULoongArchState *env,
     if (0 <= n && n < 32) {
         env->fpr[n] = ldq_p(mem_buf);
         length = 8;
-    } else if (32 <= n && n < 40) {
-        env->cf[n - 32] = ldub_p(mem_buf);
-        length = 1;
-    } else if (n == 40) {
+    } else if (n == 32) {
+        /* fcc */
+        uint64_t val = ldq_p(mem_buf);
+        for (int i = 0; i < 8; ++i) {
+            env->cf[i] = (val >> (i * 8)) & 1;
+        }
+        length = 8;
+    } else if (n == 33) {
         env->fcsr0 = ldl_p(mem_buf);
         length = 4;
     }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH for-7.1 1/5] target/loongarch: Fix GDB get the wrong pc
  2022-08-04 13:02 ` [PATCH for-7.1 1/5] target/loongarch: Fix GDB get the wrong pc Song Gao
@ 2022-08-04 15:56   ` Richard Henderson
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2022-08-04 15:56 UTC (permalink / raw)
  To: Song Gao, qemu-devel; +Cc: peter.maydell, f4bug, alex.bennee, yangxiaojuan

On 8/4/22 06:02, Song Gao wrote:
> +        /* orig_a0 */
> +        return gdb_get_regl(mem_buf, env->gpr[4]);

There is no rational value to provide for orig_a0,
because this is only related to the linux kernel.
I understand that you need to enumerate the register
so that pc gets number 35, but you might as well
simply provide zero for this value.


r~


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH for-7.1 2/5] target/loongarch: add gdb_arch_name()
  2022-08-04 13:02 ` [PATCH for-7.1 2/5] target/loongarch: add gdb_arch_name() Song Gao
@ 2022-08-04 16:02   ` Richard Henderson
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2022-08-04 16:02 UTC (permalink / raw)
  To: Song Gao, qemu-devel; +Cc: peter.maydell, f4bug, alex.bennee, yangxiaojuan

On 8/4/22 06:02, Song Gao wrote:
> LoongArch gdb_arch_name() is "Loongarch64", Dump from GDB.
> 
> GNU gdb (GDB) 13.0.50.20220519-git
> Copyright (C) 2022 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.
> Type "show copying" and "show warranty" for details.
> This GDB was configured as "loongarch64-unknown-linux-gnu".
> Type "show configuration" for configuration details.
> For bug reporting instructions, please see:
> <https://www.gnu.org/software/gdb/bugs/>.
> Find the GDB manual and other documentation resources online at:
>      <http://www.gnu.org/software/gdb/documentation/>.
> 
> For help, type "help".
> Type "apropos word" to search for commands related to "word".
> (gdb) show architecture
> The target architecture is set to "auto" (currently "Loongarch64").
> (gdb)
> 
> Signed-off-by: Song Gao <gaosong@loongson.cn>

Matches bfd/cpu-loongarch.c, bfd_loongarch_arch.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

> ---
>   target/loongarch/cpu.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
> index d84ec38cf7..94d5617639 100644
> --- a/target/loongarch/cpu.c
> +++ b/target/loongarch/cpu.c
> @@ -661,6 +661,11 @@ static const struct SysemuCPUOps loongarch_sysemu_ops = {
>   };
>   #endif
>   
> +static gchar *loongarch_gdb_arch_name(CPUState *cs)
> +{
> +    return g_strdup("Loongarch64");
> +}
> +
>   static void loongarch_cpu_class_init(ObjectClass *c, void *data)
>   {
>       LoongArchCPUClass *lacc = LOONGARCH_CPU_CLASS(c);
> @@ -686,6 +691,7 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data)
>       cc->gdb_num_core_regs = 35;
>       cc->gdb_core_xml_file = "loongarch-base64.xml";
>       cc->gdb_stop_before_watchpoint = true;
> +    cc->gdb_arch_name = loongarch_gdb_arch_name;
>   
>   #ifdef CONFIG_TCG
>       cc->tcg_ops = &loongarch_tcg_ops;



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH for-7.1 3/5] target/loongarch: update loongarch-base64.xml
  2022-08-04 13:02 ` [PATCH for-7.1 3/5] target/loongarch: update loongarch-base64.xml Song Gao
@ 2022-08-04 16:03   ` Richard Henderson
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2022-08-04 16:03 UTC (permalink / raw)
  To: Song Gao, qemu-devel; +Cc: peter.maydell, f4bug, alex.bennee, yangxiaojuan

On 8/4/22 06:02, Song Gao wrote:
> Update loongarch-base64.xml to match the upstream GDB [1].
> 
> [1]:https://github.com/bminor/binutils-gdb/blob/master/gdb/features/loongarch/base64.xml
> 
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> ---
>   gdb-xml/loongarch-base64.xml | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH for-7.1 4/5] target/loongarch: Update loongarch-fpu.xml
  2022-08-04 13:02 ` [PATCH for-7.1 4/5] target/loongarch: Update loongarch-fpu.xml Song Gao
@ 2022-08-04 16:06   ` Richard Henderson
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2022-08-04 16:06 UTC (permalink / raw)
  To: Song Gao, qemu-devel; +Cc: peter.maydell, f4bug, alex.bennee, yangxiaojuan

On 8/4/22 06:02, Song Gao wrote:
> Rename loongarch-fpu64.xml to loongarch-fpu.xml and update loongarch-fpu.xml to match upstream GDB [1]
> 
> [1]:https://github.com/bminor/binutils-gdb/blob/master/gdb/features/loongarch/fpu.xml
> 
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> ---
>   configs/targets/loongarch64-softmmu.mak |  2 +-
>   gdb-xml/loongarch-fpu.xml               | 50 ++++++++++++++++++++++
>   gdb-xml/loongarch-fpu64.xml             | 57 -------------------------
>   target/loongarch/gdbstub.c              |  2 +-
>   4 files changed, 52 insertions(+), 59 deletions(-)
>   create mode 100644 gdb-xml/loongarch-fpu.xml
>   delete mode 100644 gdb-xml/loongarch-fpu64.xml
> 
> diff --git a/configs/targets/loongarch64-softmmu.mak b/configs/targets/loongarch64-softmmu.mak
> index 483474ba93..9abc99056f 100644
> --- a/configs/targets/loongarch64-softmmu.mak
> +++ b/configs/targets/loongarch64-softmmu.mak
> @@ -1,5 +1,5 @@
>   TARGET_ARCH=loongarch64
>   TARGET_BASE_ARCH=loongarch
>   TARGET_SUPPORTS_MTTCG=y
> -TARGET_XML_FILES= gdb-xml/loongarch-base64.xml gdb-xml/loongarch-fpu64.xml
> +TARGET_XML_FILES= gdb-xml/loongarch-base64.xml gdb-xml/loongarch-fpu.xml
>   TARGET_NEED_FDT=y
> diff --git a/gdb-xml/loongarch-fpu.xml b/gdb-xml/loongarch-fpu.xml
> new file mode 100644
> index 0000000000..a61057ec44
> --- /dev/null
> +++ b/gdb-xml/loongarch-fpu.xml
> @@ -0,0 +1,50 @@
> +<?xml version="1.0"?>
> +<!-- Copyright (C) 2021 Free Software Foundation, Inc.
> +
> +     Copying and distribution of this file, with or without modification,
> +     are permitted in any medium without royalty provided the copyright
> +     notice and this notice are preserved.  -->
> +
> +<!DOCTYPE feature SYSTEM "gdb-target.dtd">
> +<feature name="org.gnu.gdb.loongarch.fpu">
> +
> +  <union id="fputype">
> +    <field name="f" type="ieee_single"/>
> +    <field name="d" type="ieee_double"/>
> +  </union>
> +
> +  <reg name="f0" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f1" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f2" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f3" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f4" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f5" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f6" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f7" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f8" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f9" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f10" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f11" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f12" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f13" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f14" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f15" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f16" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f17" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f18" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f19" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f20" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f21" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f22" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f23" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f24" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f25" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f26" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f27" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f28" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f29" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f30" bitsize="64" type="fputype" group="float"/>
> +  <reg name="f31" bitsize="64" type="fputype" group="float"/>
> +  <reg name="fcc" bitsize="64" type="fputype" group="float"/>

While this matches upstream gdb, the type of fcc should be uint64_t.
Interpreting these 8 bits (lsb of each byte) as a double is going to fail badly.


r~


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH for-7.1 5/5] target/loongarch: Update gdb_set_fpu() and gdb_get_fpu()
  2022-08-04 13:02 ` [PATCH for-7.1 5/5] target/loongarch: Update gdb_set_fpu() and gdb_get_fpu() Song Gao
@ 2022-08-04 16:08   ` Richard Henderson
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2022-08-04 16:08 UTC (permalink / raw)
  To: Song Gao, qemu-devel; +Cc: peter.maydell, f4bug, alex.bennee, yangxiaojuan

On 8/4/22 06:02, Song Gao wrote:
> GDB LoongArch fpu use fcc register,  update gdb_set_fpu() and gdb_get_fpu() to match it.
> 
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> ---
>   target/loongarch/gdbstub.c | 23 ++++++++++++++++-------
>   1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/target/loongarch/gdbstub.c b/target/loongarch/gdbstub.c
> index 7d95b4b11c..265f0f43b6 100644
> --- a/target/loongarch/gdbstub.c
> +++ b/target/loongarch/gdbstub.c
> @@ -51,9 +51,14 @@ static int loongarch_gdb_get_fpu(CPULoongArchState *env,
>   {
>       if (0 <= n && n < 32) {
>           return gdb_get_reg64(mem_buf, env->fpr[n]);
> -    } else if (32 <= n && n < 40) {
> -        return gdb_get_reg8(mem_buf, env->cf[n - 32]);
> -    } else if (n == 40) {
> +    } else if (n == 32) {
> +        /* fcc */
> +        uint64_t val = 0;
> +        for (int i = 0; i < 8; ++i) {
> +            val |= (uint64_t)env->cf[i] << (i * 8);
> +        }
> +        return gdb_get_reg64(mem_buf, val);

You've got this function over in linux-user/loongarch/signal.c.
You might as well move it into target/loongarch/ and share it.


> +    } else if (n == 33) {
>           return gdb_get_reg32(mem_buf, env->fcsr0);
>       }
>       return 0;
> @@ -67,10 +72,14 @@ static int loongarch_gdb_set_fpu(CPULoongArchState *env,
>       if (0 <= n && n < 32) {
>           env->fpr[n] = ldq_p(mem_buf);
>           length = 8;
> -    } else if (32 <= n && n < 40) {
> -        env->cf[n - 32] = ldub_p(mem_buf);
> -        length = 1;
> -    } else if (n == 40) {
> +    } else if (n == 32) {
> +        /* fcc */
> +        uint64_t val = ldq_p(mem_buf);
> +        for (int i = 0; i < 8; ++i) {
> +            env->cf[i] = (val >> (i * 8)) & 1;
> +        }
> +        length = 8;

Likewise.


r~

> +    } else if (n == 33) {
>           env->fcsr0 = ldl_p(mem_buf);
>           length = 4;
>       }



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-08-04 16:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-04 13:02 [PATCH for-7.1 0/5] Fix gdb bugs and update gdb-xml Song Gao
2022-08-04 13:02 ` [PATCH for-7.1 1/5] target/loongarch: Fix GDB get the wrong pc Song Gao
2022-08-04 15:56   ` Richard Henderson
2022-08-04 13:02 ` [PATCH for-7.1 2/5] target/loongarch: add gdb_arch_name() Song Gao
2022-08-04 16:02   ` Richard Henderson
2022-08-04 13:02 ` [PATCH for-7.1 3/5] target/loongarch: update loongarch-base64.xml Song Gao
2022-08-04 16:03   ` Richard Henderson
2022-08-04 13:02 ` [PATCH for-7.1 4/5] target/loongarch: Update loongarch-fpu.xml Song Gao
2022-08-04 16:06   ` Richard Henderson
2022-08-04 13:02 ` [PATCH for-7.1 5/5] target/loongarch: Update gdb_set_fpu() and gdb_get_fpu() Song Gao
2022-08-04 16:08   ` Richard Henderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.