gdbserver: LoongArch: Add floating-point support
authorTiezhu Yang <yangtiezhu@loongson.cn>
Tue, 12 Jul 2022 02:35:35 +0000 (10:35 +0800)
committerTiezhu Yang <yangtiezhu@loongson.cn>
Tue, 12 Jul 2022 12:14:52 +0000 (20:14 +0800)
This commit adds floating-point support for LoongArch gdbserver.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
gdbserver/linux-loongarch-low.cc

index 91826b4236145be516d6ca932c59c5fa60473069..7180f315b11094baf911c0d7d152b0b5352c8804 100644 (file)
@@ -120,10 +120,42 @@ loongarch_store_gregset (struct regcache *regcache, const void *buf)
   supply_register (regcache, LOONGARCH_BADV_REGNUM, *regset + LOONGARCH_BADV_REGNUM);
 }
 
+/* Collect FPRs from REGCACHE into BUF.  */
+
+static void
+loongarch_fill_fpregset (struct regcache *regcache, void *buf)
+{
+  gdb_byte *regbuf = nullptr;
+  int fprsize = register_size (regcache->tdesc, LOONGARCH_FIRST_FP_REGNUM);
+
+  for (int i = 0; i < LOONGARCH_LINUX_NUM_FPREGSET; i++)
+    {
+      regbuf = (gdb_byte *)buf + fprsize * i;
+      collect_register (regcache, LOONGARCH_FIRST_FP_REGNUM + i, regbuf);
+    }
+}
+
+/* Supply FPRs from BUF into REGCACHE.  */
+
+static void
+loongarch_store_fpregset (struct regcache *regcache, const void *buf)
+{
+  const gdb_byte *regbuf = nullptr;
+  int fprsize = register_size (regcache->tdesc, LOONGARCH_FIRST_FP_REGNUM);
+
+  for (int i = 0; i < LOONGARCH_LINUX_NUM_FPREGSET; i++)
+    {
+      regbuf = (const gdb_byte *)buf + fprsize * i;
+      supply_register (regcache, LOONGARCH_FIRST_FP_REGNUM + i, regbuf);
+    }
+}
+
 /* LoongArch/Linux regsets.  */
 static struct regset_info loongarch_regsets[] = {
   { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_PRSTATUS, sizeof (elf_gregset_t),
     GENERAL_REGS, loongarch_fill_gregset, loongarch_store_gregset },
+  { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_FPREGSET, sizeof (elf_fpregset_t),
+    FP_REGS, loongarch_fill_fpregset, loongarch_store_fpregset },
   NULL_REGSET
 };