+/* 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 (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);
+}
+