From 74792ff782431ec6113b9a8a8e85b95f46094c7f Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Mon, 8 Oct 2018 14:47:34 -0700 Subject: [PATCH] Add native target for FreeBSD/riscv. 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 | 8 +++ gdb/Makefile.in | 1 + gdb/NEWS | 1 + gdb/configure.host | 1 + gdb/configure.nat | 4 ++ gdb/doc/ChangeLog | 5 ++ gdb/doc/gdb.texinfo | 6 ++ gdb/riscv-fbsd-nat.c | 135 +++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 161 insertions(+) create mode 100644 gdb/riscv-fbsd-nat.c diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b4d20bbca07..f074385c309 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2018-10-08 John Baldwin + + * 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 * Makefile.in (ALL_TARGET_OBS): Add riscv-fbsd-tdep.o. diff --git a/gdb/Makefile.in b/gdb/Makefile.in index b1e94364376..0bb203f45f1 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -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 \ diff --git a/gdb/NEWS b/gdb/NEWS index 345e450fa7c..8a0dd52fa7f 100644 --- 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 diff --git a/gdb/configure.host b/gdb/configure.host index 23a2f163992..c87f997abc1 100644 --- a/gdb/configure.host +++ b/gdb/configure.host @@ -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 ;; diff --git a/gdb/configure.nat b/gdb/configure.nat index 10bf65fec3a..200b7169243 100644 --- a/gdb/configure.nat +++ b/gdb/configure.nat @@ -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 \ diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index acf68ceb34d..a3aace7d6bc 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,8 @@ +2018-10-08 John Baldwin + + * gdb.texinfo (Contributors): Add SRI International and University + of Cambridge for FreeBSD/riscv. + 2018-10-06 Tom Tromey PR python/19399: diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 5653bdcacab..efd6dffb1e5 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -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 index 00000000000..ad4ea1e0ad1 --- /dev/null +++ b/gdb/riscv-fbsd-nat.c @@ -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 . */ + +#include "defs.h" +#include "target.h" + +#include +#include +#include + +#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) ®s, 0) == -1) + perror_with_name (_("Couldn't get registers")); + + regcache->supply_regset (&riscv_fbsd_gregset, regnum, ®s, + 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) ®s, 0) == -1) + perror_with_name (_("Couldn't get registers")); + + regcache->collect_regset (&riscv_fbsd_gregset, regnum, ®s, + sizeof (regs)); + + if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 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); +} -- 2.30.2