/* Target-dependent code for FreeBSD on RISC-V processors.
- Copyright (C) 2018 Free Software Foundation, Inc.
+ Copyright (C) 2018-2020 Free Software Foundation, Inc.
This file is part of GDB.
#include "target.h"
#include "trad-frame.h"
#include "tramp-frame.h"
+#include "gdbarch.h"
+#include "inferior.h"
/* Register maps. */
+ RISCV_SIGFRAME_UCONTEXT_OFFSET
+ RISCV_UCONTEXT_MCONTEXT_OFFSET);
gdb_byte buf[4];
- int i;
trad_frame_set_reg_regmap (this_cache, riscv_fbsd_gregmap, mcontext_addr,
RISCV_FBSD_NUM_GREGS * riscv_isa_xlen (gdbarch));
riscv_fbsd_sigframe_init
};
+/* Implement the "get_thread_local_address" gdbarch method. */
+
+static CORE_ADDR
+riscv_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
+ CORE_ADDR lm_addr, CORE_ADDR offset)
+{
+ struct regcache *regcache;
+
+ regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
+ ptid, gdbarch);
+
+ target_fetch_registers (regcache, RISCV_TP_REGNUM);
+
+ ULONGEST tp;
+ if (regcache->cooked_read (RISCV_TP_REGNUM, &tp) != REG_VALID)
+ error (_("Unable to fetch %%tp"));
+
+ /* %tp points to the end of the TCB which contains two pointers.
+ The first pointer in the TCB points to the DTV array. */
+ CORE_ADDR dtv_addr = tp - (gdbarch_ptr_bit (gdbarch) / 8) * 2;
+ return fbsd_get_thread_local_address (gdbarch, dtv_addr, lm_addr, offset);
+}
+
/* Implement the 'init_osabi' method of struct gdb_osabi_handler. */
static void
riscv_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
-
/* Generic FreeBSD support. */
fbsd_init_abi (info, gdbarch);
set_gdbarch_iterate_over_regset_sections
(gdbarch, riscv_fbsd_iterate_over_regset_sections);
+
+ set_gdbarch_fetch_tls_load_module_address (gdbarch,
+ svr4_fetch_objfile_link_map);
+ set_gdbarch_get_thread_local_address (gdbarch,
+ riscv_fbsd_get_thread_local_address);
}
void