]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add native target for FreeBSD/riscv.
authorJohn Baldwin <jhb@FreeBSD.org>
Mon, 8 Oct 2018 21:47:34 +0000 (14:47 -0700)
committerJohn Baldwin <jhb@FreeBSD.org>
Mon, 8 Oct 2018 21:47:34 +0000 (14:47 -0700)
gdb/ChangeLog:

* Makefile.in (ALLDEPFILES): Add riscv-fbsd-nat.c.
* NEWS: Mention new FreeBSD/riscv native configuration.
* configure.host: Add riscv*-*-freebsd*.
* configure.nat: Likewise.
* riscv-fbsd-nat.c: New file.

gdb/doc/ChangeLog:

* gdb.texinfo (Contributors): Add SRI International and University
of Cambridge for FreeBSD/riscv.

gdb/ChangeLog
gdb/Makefile.in
gdb/NEWS
gdb/configure.host
gdb/configure.nat
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/riscv-fbsd-nat.c [new file with mode: 0644]

index b4d20bbca074d00c03b7cda56d60eee9921d1bb9..f074385c30986b756e661379f9928472d3d30379 100644 (file)
@@ -1,3 +1,11 @@
+2018-10-08  John Baldwin  <jhb@FreeBSD.org>
+
+       * Makefile.in (ALLDEPFILES): Add riscv-fbsd-nat.c.
+       * NEWS: Mention new FreeBSD/riscv native configuration.
+       * configure.host: Add riscv*-*-freebsd*.
+       * configure.nat: Likewise.
+       * riscv-fbsd-nat.c: New file.
+
 2018-10-08  John Baldwin  <jhb@FreeBSD.org>
 
        * Makefile.in (ALL_TARGET_OBS): Add riscv-fbsd-tdep.o.
index b1e94364376a0541438bb1f1680358ac77f40d95..0bb203f45f142179a828a169849daec8e9c7f8ac 100644 (file)
@@ -2308,6 +2308,7 @@ ALLDEPFILES = \
        procfs.c \
        ravenscar-thread.c \
        remote-sim.c \
+       riscv-fbsd-nat.c \
        riscv-fbsd-tdep.c \
        riscv-linux-nat.c \
        riscv-linux-tdep.c \
index 345e450fa7cf22e62f13a8af44f1ea9daf10a020..8a0dd52fa7f32140bca64e5958870e840b044a3b 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -93,6 +93,7 @@ thread apply [all | COUNT | -COUNT] [FLAG]... COMMAND
 * New native configurations
 
 GNU/Linux/RISC-V               riscv*-*-linux*
+FreeBSD/riscv                  riscv*-*-freebsd*
 
 * New targets
 
index 23a2f1639924a24167c451942af925ecc59c3fc2..c87f997abc18848a7c99abecf80264cb5eb06213 100644 (file)
@@ -149,6 +149,7 @@ powerpc64*-*-linux*)        gdb_host=ppc64-linux
                        ;;
 powerpc*-*-linux*)     gdb_host=linux ;;
 
+riscv*-*-freebsd*)     gdb_host=fbsd ;;
 riscv*-*-linux*)       gdb_host=linux ;;
 
 s390*-*-linux*)                gdb_host=linux ;;
index 10bf65fec3a7728af350ec588ed23caf3984fc05..200b716924365ff13ae1afb488cc99499b911520 100644 (file)
@@ -177,6 +177,10 @@ case ${gdb_host} in
                # systems running FreeBSD.
                NATDEPFILES="${NATDEPFILES} ppc-fbsd-nat.o bsd-kvm.o"
                ;;
+           riscv*)
+               # Host: FreeBSD/riscv
+               NATDEPFILES="${NATDEPFILES} riscv-fbsd-nat.o"
+               ;;
            sparc)
                # Host: FreeBSD/sparc64
                NATDEPFILES="${NATDEPFILES} sparc-nat.o sparc64-nat.o \
index acf68ceb34d746d5c423c8a8ac6c9958fb79f89f..a3aace7d6bc87904ad6966b2cb1d8b59c6de5376 100644 (file)
@@ -1,3 +1,8 @@
+2018-10-08  John Baldwin  <jhb@FreeBSD.org>
+
+       * gdb.texinfo (Contributors): Add SRI International and University
+       of Cambridge for FreeBSD/riscv.
+
 2018-10-06  Tom Tromey  <tom@tromey.com>
 
        PR python/19399:
index 5653bdcacab94ad83fd38acc15453f169736f8ba..efd6dffb1e5d18ebd2cb1bfb488740732d9f69a9 100644 (file)
@@ -546,6 +546,12 @@ was developed by SRI International and the University of Cambridge
 Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
 ("CTSRD"), as part of the DARPA CRASH research programme.
 
+Initial support for the FreeBSD/riscv target and native configuration
+was developed by SRI International and the University of Cambridge
+Computer Laboratory (Department of Computer Science and Technology)
+under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the DARPA
+SSITH research programme.
+
 The original port to the OpenRISC 1000 is believed to be due to
 Alessandro Forin and Per Bothner.  More recent ports have been the work
 of Jeremy Bennett, Franck Jullien, Stefan Wallentowitz and
diff --git a/gdb/riscv-fbsd-nat.c b/gdb/riscv-fbsd-nat.c
new file mode 100644 (file)
index 0000000..ad4ea1e
--- /dev/null
@@ -0,0 +1,135 @@
+/* Native-dependent code for FreeBSD/riscv.
+
+   Copyright (C) 2018 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "target.h"
+
+#include <sys/types.h>
+#include <sys/ptrace.h>
+#include <machine/reg.h>
+
+#include "fbsd-nat.h"
+#include "riscv-tdep.h"
+#include "riscv-fbsd-tdep.h"
+#include "inf-ptrace.h"
+
+struct riscv_fbsd_nat_target final : public fbsd_nat_target
+{
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+};
+
+static riscv_fbsd_nat_target the_riscv_fbsd_nat_target;
+
+/* Determine if PT_GETREGS fetches REGNUM.  */
+
+static bool
+getregs_supplies (struct gdbarch *gdbarch, int regnum)
+{
+  return (regnum >= RISCV_RA_REGNUM && regnum <= RISCV_PC_REGNUM);
+}
+
+/* Determine if PT_GETFPREGS fetches REGNUM.  */
+
+static bool
+getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
+{
+  return ((regnum >= RISCV_FIRST_FP_REGNUM && regnum <= RISCV_LAST_FP_REGNUM)
+         || regnum == RISCV_CSR_FCSR_REGNUM);
+}
+
+/* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
+   for all registers.  */
+
+void
+riscv_fbsd_nat_target::fetch_registers (struct regcache *regcache,
+                                       int regnum)
+{
+  pid_t pid = get_ptrace_pid (regcache->ptid ());
+
+  struct gdbarch *gdbarch = regcache->arch ();
+  if (regnum == -1 || regnum == RISCV_ZERO_REGNUM)
+    regcache->raw_supply_zeroed (RISCV_ZERO_REGNUM);
+  if (regnum == -1 || getregs_supplies (gdbarch, regnum))
+    {
+      struct reg regs;
+
+      if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+       perror_with_name (_("Couldn't get registers"));
+
+      regcache->supply_regset (&riscv_fbsd_gregset, regnum, &regs,
+                              sizeof (regs));
+    }
+
+  if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
+    {
+      struct fpreg fpregs;
+
+      if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+       perror_with_name (_("Couldn't get floating point status"));
+
+      regcache->supply_regset (&riscv_fbsd_fpregset, regnum, &fpregs,
+                              sizeof (fpregs));
+    }
+}
+
+/* Store register REGNUM back into the inferior.  If REGNUM is -1, do
+   this for all registers.  */
+
+void
+riscv_fbsd_nat_target::store_registers (struct regcache *regcache,
+                                       int regnum)
+{
+  pid_t pid = get_ptrace_pid (regcache->ptid ());
+
+  struct gdbarch *gdbarch = regcache->arch ();
+  if (regnum == -1 || getregs_supplies (gdbarch, regnum))
+    {
+      struct reg regs;
+
+      if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+       perror_with_name (_("Couldn't get registers"));
+
+      regcache->collect_regset (&riscv_fbsd_gregset, regnum, &regs,
+                              sizeof (regs));
+
+      if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+       perror_with_name (_("Couldn't write registers"));
+    }
+
+  if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
+    {
+      struct fpreg fpregs;
+
+      if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+       perror_with_name (_("Couldn't get floating point status"));
+
+      regcache->collect_regset (&riscv_fbsd_fpregset, regnum, &fpregs,
+                               sizeof (fpregs));
+
+      if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
+       perror_with_name (_("Couldn't write floating point status"));
+    }
+}
+
+void
+_initialize_riscv_fbsd_nat (void)
+{
+  add_inf_child_target (&the_riscv_fbsd_nat_target);
+}