aboutsummaryrefslogtreecommitdiff
path: root/lib/libthread_db/arch
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libthread_db/arch')
-rw-r--r--lib/libthread_db/arch/aarch64/libpthread_md.c92
-rw-r--r--lib/libthread_db/arch/amd64/libpthread_md.c124
-rw-r--r--lib/libthread_db/arch/arm/libpthread_md.c119
-rw-r--r--lib/libthread_db/arch/i386/libpthread_md.c117
-rw-r--r--lib/libthread_db/arch/powerpc/libpthread_md.c82
-rw-r--r--lib/libthread_db/arch/riscv/libpthread_md.c107
6 files changed, 641 insertions, 0 deletions
diff --git a/lib/libthread_db/arch/aarch64/libpthread_md.c b/lib/libthread_db/arch/aarch64/libpthread_md.c
new file mode 100644
index 000000000000..1ff08e2804fa
--- /dev/null
+++ b/lib/libthread_db/arch/aarch64/libpthread_md.c
@@ -0,0 +1,92 @@
+/*-
+ * Copyright (c) 2014-2015 The FreeBSD Foundation
+ *
+ * This software was developed by Andrew Turner under
+ * sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <string.h>
+#include <thread_db.h>
+
+#include "libpthread_db.h"
+
+void abort(void);
+
+void
+pt_reg_to_ucontext(const struct reg *r, ucontext_t *uc)
+{
+ mcontext_t *mc = &uc->uc_mcontext;
+
+ memcpy(mc->mc_gpregs.gp_x, r->x, sizeof(mc->mc_gpregs.gp_x));
+ mc->mc_gpregs.gp_sp = r->sp;
+ mc->mc_gpregs.gp_lr = r->lr;
+ mc->mc_gpregs.gp_elr = r->elr;
+ mc->mc_gpregs.gp_spsr = r->spsr;
+}
+
+void
+pt_ucontext_to_reg(const ucontext_t *uc, struct reg *r)
+{
+ const mcontext_t *mc = &uc->uc_mcontext;
+
+ memcpy(r->x, mc->mc_gpregs.gp_x, sizeof(mc->mc_gpregs.gp_x));
+ r->sp = mc->mc_gpregs.gp_sp;
+ r->lr = mc->mc_gpregs.gp_lr;
+ r->elr = mc->mc_gpregs.gp_elr;
+ r->spsr = mc->mc_gpregs.gp_spsr;
+}
+
+void
+pt_fpreg_to_ucontext(const struct fpreg *r, ucontext_t *uc)
+{
+ mcontext_t *mc = &uc->uc_mcontext;
+
+ memcpy(&mc->mc_fpregs, r, sizeof(*r));
+ mc->mc_flags |= _MC_FP_VALID;
+}
+
+void
+pt_ucontext_to_fpreg(const ucontext_t *uc, struct fpreg *r)
+{
+ const mcontext_t *mc = &uc->uc_mcontext;
+
+ if (mc->mc_flags & _MC_FP_VALID)
+ memcpy(r, &mc->mc_fpregs, sizeof(*r));
+ else
+ memset(r, 0, sizeof(*r));
+
+}
+
+void
+pt_md_init(void)
+{
+}
+
+int
+pt_reg_sstep(struct reg *reg __unused, int step __unused)
+{
+
+ return (0);
+}
diff --git a/lib/libthread_db/arch/amd64/libpthread_md.c b/lib/libthread_db/arch/amd64/libpthread_md.c
new file mode 100644
index 000000000000..572f9d248562
--- /dev/null
+++ b/lib/libthread_db/arch/amd64/libpthread_md.c
@@ -0,0 +1,124 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2004 David Xu <davidxu@freebsd.org>
+ * Copyright (c) 2004 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#include <sys/procfs.h>
+#include <string.h>
+#include <thread_db.h>
+#include <ucontext.h>
+
+#include "libpthread_db.h"
+
+void
+pt_reg_to_ucontext(const struct reg *r, ucontext_t *uc)
+{
+ mcontext_t *mc = &uc->uc_mcontext;
+
+ mc->mc_rdi = r->r_rdi;
+ mc->mc_rsi = r->r_rsi;
+ mc->mc_rdx = r->r_rdx;
+ mc->mc_rcx = r->r_rcx;
+ mc->mc_r8 = r->r_r8;
+ mc->mc_r9 = r->r_r9;
+ mc->mc_rax = r->r_rax;
+ mc->mc_rbx = r->r_rbx;
+ mc->mc_rbp = r->r_rbp;
+ mc->mc_r10 = r->r_r10;
+ mc->mc_r11 = r->r_r11;
+ mc->mc_r12 = r->r_r12;
+ mc->mc_r13 = r->r_r13;
+ mc->mc_r14 = r->r_r14;
+ mc->mc_r15 = r->r_r15;
+ mc->mc_rip = r->r_rip;
+ mc->mc_cs = r->r_cs;
+ mc->mc_rflags = r->r_rflags;
+ mc->mc_rsp = r->r_rsp;
+ mc->mc_ss = r->r_ss;
+}
+
+void
+pt_ucontext_to_reg(const ucontext_t *uc, struct reg *r)
+{
+ const mcontext_t *mc = &uc->uc_mcontext;
+
+ r->r_rdi = mc->mc_rdi;
+ r->r_rsi = mc->mc_rsi;
+ r->r_rdx = mc->mc_rdx;
+ r->r_rcx = mc->mc_rcx;
+ r->r_r8 = mc->mc_r8;
+ r->r_r9 = mc->mc_r9;
+ r->r_rax = mc->mc_rax;
+ r->r_rbx = mc->mc_rbx;
+ r->r_rbp = mc->mc_rbp;
+ r->r_r10 = mc->mc_r10;
+ r->r_r11 = mc->mc_r11;
+ r->r_r12 = mc->mc_r12;
+ r->r_r13 = mc->mc_r13;
+ r->r_r14 = mc->mc_r14;
+ r->r_r15 = mc->mc_r15;
+ r->r_rip = mc->mc_rip;
+ r->r_cs = mc->mc_cs;
+ r->r_rflags = mc->mc_rflags;
+ r->r_rsp = mc->mc_rsp;
+ r->r_ss = mc->mc_ss;
+}
+
+void
+pt_fpreg_to_ucontext(const struct fpreg* r, ucontext_t *uc)
+{
+
+ memcpy(&uc->uc_mcontext.mc_fpstate, r, sizeof(*r));
+}
+
+void
+pt_ucontext_to_fpreg(const ucontext_t *uc, struct fpreg *r)
+{
+
+ memcpy(r, &uc->uc_mcontext.mc_fpstate, sizeof(*r));
+}
+
+void
+pt_md_init(void)
+{
+
+ /* Nothing to do */
+}
+
+int
+pt_reg_sstep(struct reg *reg, int step)
+{
+ register_t old;
+
+ old = reg->r_rflags;
+ if (step)
+ reg->r_rflags |= 0x0100;
+ else
+ reg->r_rflags &= ~0x0100;
+ return (old != reg->r_rflags); /* changed ? */
+}
diff --git a/lib/libthread_db/arch/arm/libpthread_md.c b/lib/libthread_db/arch/arm/libpthread_md.c
new file mode 100644
index 000000000000..4a619ad8f39f
--- /dev/null
+++ b/lib/libthread_db/arch/arm/libpthread_md.c
@@ -0,0 +1,119 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2007 Olivier Houchard
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <string.h>
+#include <thread_db.h>
+
+#include "libpthread_db.h"
+
+void
+pt_reg_to_ucontext(const struct reg *r, ucontext_t *uc)
+{
+ mcontext_t *mc = &uc->uc_mcontext;
+ __greg_t *gr = mc->__gregs;
+
+ gr[_REG_R0] = r->r[0];
+ gr[_REG_R1] = r->r[1];
+ gr[_REG_R2] = r->r[2];
+ gr[_REG_R3] = r->r[3];
+ gr[_REG_R4] = r->r[4];
+ gr[_REG_R5] = r->r[5];
+ gr[_REG_R6] = r->r[6];
+ gr[_REG_R7] = r->r[7];
+ gr[_REG_R8] = r->r[8];
+ gr[_REG_R9] = r->r[9];
+ gr[_REG_R10] = r->r[10];
+ gr[_REG_R11] = r->r[11];
+ gr[_REG_R12] = r->r[12];
+ gr[_REG_SP] = r->r_sp;
+ gr[_REG_LR] = r->r_lr;
+ gr[_REG_PC] = r->r_pc;
+ gr[_REG_CPSR] = r->r_cpsr;
+}
+
+void
+pt_ucontext_to_reg(const ucontext_t *uc, struct reg *r)
+{
+ const mcontext_t *mc = &uc->uc_mcontext;
+
+ const __greg_t *gr = mc->__gregs;
+
+ r->r[0] = gr[_REG_R0];
+ r->r[1] = gr[_REG_R1];
+ r->r[2] = gr[_REG_R2];
+ r->r[3] = gr[_REG_R3];
+ r->r[4] = gr[_REG_R4];
+ r->r[5] = gr[_REG_R5];
+ r->r[6] = gr[_REG_R6];
+ r->r[7] = gr[_REG_R7];
+ r->r[8] = gr[_REG_R8];
+ r->r[9] = gr[_REG_R9];
+ r->r[10] = gr[_REG_R10];
+ r->r[11] = gr[_REG_R11];
+ r->r[12] = gr[_REG_R12];
+ r->r_sp = gr[_REG_SP];
+ r->r_lr = gr[_REG_LR];
+ r->r_pc = gr[_REG_PC];
+ r->r_cpsr = gr[_REG_CPSR];
+}
+
+void
+pt_fpreg_to_ucontext(const struct fpreg *r, ucontext_t *uc)
+{
+ mcontext_vfp_t *mc_vfp;
+
+ mc_vfp = uc->uc_mcontext.mc_vfp_ptr;
+
+ if (mc_vfp != NULL)
+ memcpy(mc_vfp, r, sizeof(*r));
+}
+
+void
+pt_ucontext_to_fpreg(const ucontext_t *uc, struct fpreg *r)
+{
+ mcontext_vfp_t *mc_vfp;
+
+ mc_vfp = uc->uc_mcontext.mc_vfp_ptr;
+
+ if (mc_vfp != NULL)
+ memcpy(r, &mc_vfp, sizeof(*r));
+}
+
+void
+pt_md_init(void)
+{
+}
+
+int
+pt_reg_sstep(struct reg *reg __unused, int step __unused)
+{
+
+ /* XXX */
+ return (0);
+}
diff --git a/lib/libthread_db/arch/i386/libpthread_md.c b/lib/libthread_db/arch/i386/libpthread_md.c
new file mode 100644
index 000000000000..317710567ed6
--- /dev/null
+++ b/lib/libthread_db/arch/i386/libpthread_md.c
@@ -0,0 +1,117 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2004 David Xu <davidxu@freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <machine/npx.h>
+#include <string.h>
+#include <thread_db.h>
+
+#include "libpthread_db.h"
+
+static int has_xmm_regs;
+
+void
+pt_reg_to_ucontext(const struct reg *r, ucontext_t *uc)
+{
+ memcpy(&uc->uc_mcontext.mc_fs, &r->r_fs, 18*4);
+ uc->uc_mcontext.mc_gs = r->r_gs;
+}
+
+void
+pt_ucontext_to_reg(const ucontext_t *uc, struct reg *r)
+{
+ memcpy(&r->r_fs, &uc->uc_mcontext.mc_fs, 18*4);
+ r->r_gs = uc->uc_mcontext.mc_gs;
+}
+
+void
+pt_fpreg_to_ucontext(const struct fpreg* r, ucontext_t *uc)
+{
+ if (!has_xmm_regs)
+ memcpy(&uc->uc_mcontext.mc_fpstate, r,
+ sizeof(struct save87));
+ else {
+ int i;
+ struct savexmm *sx = (struct savexmm *)&uc->uc_mcontext.mc_fpstate;
+ memcpy(&sx->sv_env, &r->fpr_env, sizeof(r->fpr_env));
+ for (i = 0; i < 8; ++i)
+ memcpy(&sx->sv_fp[i].fp_acc, &r->fpr_acc[i], 10);
+ }
+}
+
+void
+pt_ucontext_to_fpreg(const ucontext_t *uc, struct fpreg *r)
+{
+ if (!has_xmm_regs)
+ memcpy(r, &uc->uc_mcontext.mc_fpstate, sizeof(struct save87));
+ else {
+ int i;
+ const struct savexmm *sx = (const struct savexmm *)&uc->uc_mcontext.mc_fpstate;
+ memcpy(&r->fpr_env, &sx->sv_env, sizeof(r->fpr_env));
+ for (i = 0; i < 8; ++i)
+ memcpy(&r->fpr_acc[i], &sx->sv_fp[i].fp_acc, 10);
+ }
+}
+
+void
+pt_fxsave_to_ucontext(const char* r, ucontext_t *uc)
+{
+ if (has_xmm_regs)
+ memcpy(&uc->uc_mcontext.mc_fpstate, r, sizeof(struct savexmm));
+}
+
+void
+pt_ucontext_to_fxsave(const ucontext_t *uc, char *r)
+{
+ if (has_xmm_regs)
+ memcpy(r, &uc->uc_mcontext.mc_fpstate, sizeof(struct savexmm));
+}
+
+void
+pt_md_init(void)
+{
+ ucontext_t uc;
+
+ getcontext(&uc);
+ if (uc.uc_mcontext.mc_fpformat == _MC_FPFMT_XMM)
+ has_xmm_regs = 1;
+}
+
+int
+pt_reg_sstep(struct reg *reg, int step)
+{
+ unsigned int old;
+
+ old = reg->r_eflags;
+ if (step)
+ reg->r_eflags |= 0x0100;
+ else
+ reg->r_eflags &= ~0x0100;
+ return (old != reg->r_eflags); /* changed ? */
+}
+
diff --git a/lib/libthread_db/arch/powerpc/libpthread_md.c b/lib/libthread_db/arch/powerpc/libpthread_md.c
new file mode 100644
index 000000000000..2a83549c5c79
--- /dev/null
+++ b/lib/libthread_db/arch/powerpc/libpthread_md.c
@@ -0,0 +1,82 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <string.h>
+#include <thread_db.h>
+
+#include "libpthread_db.h"
+
+void
+pt_reg_to_ucontext(const struct reg *r, ucontext_t *uc)
+{
+ mcontext_t *mc = &uc->uc_mcontext;
+
+ memcpy(mc->mc_frame, r, MIN(sizeof(mc->mc_frame), sizeof(*r)));
+}
+
+void
+pt_ucontext_to_reg(const ucontext_t *uc, struct reg *r)
+{
+ const mcontext_t *mc = &uc->uc_mcontext;
+
+ memcpy(r, mc->mc_frame, MIN(sizeof(mc->mc_frame), sizeof(*r)));
+}
+
+void
+pt_fpreg_to_ucontext(const struct fpreg *r, ucontext_t *uc)
+{
+ mcontext_t *mc = &uc->uc_mcontext;
+
+ memcpy(mc->mc_fpreg, r, MIN(sizeof(mc->mc_fpreg), sizeof(*r)));
+ mc->mc_flags |= _MC_FP_VALID;
+}
+
+void
+pt_ucontext_to_fpreg(const ucontext_t *uc, struct fpreg *r)
+{
+ const mcontext_t *mc = &uc->uc_mcontext;
+
+ if (mc->mc_flags & _MC_FP_VALID)
+ memcpy(r, mc->mc_fpreg, MIN(sizeof(mc->mc_fpreg), sizeof(*r)));
+ else
+ memset(r, 0, sizeof(*r));
+}
+
+void
+pt_md_init(void)
+{
+}
+
+int
+pt_reg_sstep(struct reg *reg __unused, int step __unused)
+{
+
+ /* XXX */
+ return (0);
+}
diff --git a/lib/libthread_db/arch/riscv/libpthread_md.c b/lib/libthread_db/arch/riscv/libpthread_md.c
new file mode 100644
index 000000000000..93f950c2fdaf
--- /dev/null
+++ b/lib/libthread_db/arch/riscv/libpthread_md.c
@@ -0,0 +1,107 @@
+/*-
+ * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com>
+ * All rights reserved.
+ *
+ * Portions of this software were 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.
+ *
+ * Portions of this software were developed by the University of Cambridge
+ * Computer Laboratory as part of the CTSRD Project, with support from the
+ * UK Higher Education Innovation Fund (HEIF).
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <string.h>
+#include <thread_db.h>
+
+#include "libpthread_db.h"
+
+void
+pt_reg_to_ucontext(const struct reg *r, ucontext_t *uc)
+{
+ mcontext_t *mc;
+
+ mc = &uc->uc_mcontext;
+
+ memcpy(mc->mc_gpregs.gp_t, r->t, sizeof(mc->mc_gpregs.gp_t));
+ memcpy(mc->mc_gpregs.gp_s, r->s, sizeof(mc->mc_gpregs.gp_s));
+ memcpy(mc->mc_gpregs.gp_a, r->a, sizeof(mc->mc_gpregs.gp_a));
+ mc->mc_gpregs.gp_ra = r->ra;
+ mc->mc_gpregs.gp_sp = r->sp;
+ mc->mc_gpregs.gp_gp = r->gp;
+ mc->mc_gpregs.gp_tp = r->tp;
+ mc->mc_gpregs.gp_sepc = r->sepc;
+ mc->mc_gpregs.gp_sstatus = r->sstatus;
+}
+
+void
+pt_ucontext_to_reg(const ucontext_t *uc, struct reg *r)
+{
+ const mcontext_t *mc;
+
+ mc = &uc->uc_mcontext;
+
+ memcpy(r->t, mc->mc_gpregs.gp_t, sizeof(mc->mc_gpregs.gp_t));
+ memcpy(r->s, mc->mc_gpregs.gp_s, sizeof(mc->mc_gpregs.gp_s));
+ memcpy(r->a, mc->mc_gpregs.gp_a, sizeof(mc->mc_gpregs.gp_a));
+ r->ra = mc->mc_gpregs.gp_ra;
+ r->sp = mc->mc_gpregs.gp_sp;
+ r->gp = mc->mc_gpregs.gp_gp;
+ r->tp = mc->mc_gpregs.gp_tp;
+ r->sepc = mc->mc_gpregs.gp_sepc;
+ r->sstatus = mc->mc_gpregs.gp_sstatus;
+}
+
+void
+pt_fpreg_to_ucontext(const struct fpreg *r __unused, ucontext_t *uc __unused)
+{
+ mcontext_t *mc = &uc->uc_mcontext;
+
+ memcpy(&mc->mc_fpregs, r, sizeof(*r));
+ mc->mc_flags |= _MC_FP_VALID;
+}
+
+void
+pt_ucontext_to_fpreg(const ucontext_t *uc __unused, struct fpreg *r __unused)
+{
+ const mcontext_t *mc = &uc->uc_mcontext;
+
+ if (mc->mc_flags & _MC_FP_VALID)
+ memcpy(r, &mc->mc_fpregs, sizeof(*r));
+ else
+ memset(r, 0, sizeof(*r));
+}
+
+void
+pt_md_init(void)
+{
+}
+
+int
+pt_reg_sstep(struct reg *reg __unused, int step __unused)
+{
+
+ return (0);
+}