1294908Sbr/*-
2294908Sbr * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com>
3294908Sbr * All rights reserved.
4294908Sbr *
5294908Sbr * Portions of this software were developed by SRI International and the
6294908Sbr * University of Cambridge Computer Laboratory under DARPA/AFRL contract
7294908Sbr * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.
8294908Sbr *
9294908Sbr * Portions of this software were developed by the University of Cambridge
10294908Sbr * Computer Laboratory as part of the CTSRD Project, with support from the
11294908Sbr * UK Higher Education Innovation Fund (HEIF).
12294908Sbr *
13294908Sbr * Redistribution and use in source and binary forms, with or without
14294908Sbr * modification, are permitted provided that the following conditions
15294908Sbr * are met:
16294908Sbr * 1. Redistributions of source code must retain the above copyright
17294908Sbr *    notice, this list of conditions and the following disclaimer.
18294908Sbr * 2. Redistributions in binary form must reproduce the above copyright
19294908Sbr *    notice, this list of conditions and the following disclaimer in the
20294908Sbr *    documentation and/or other materials provided with the distribution.
21294908Sbr *
22294908Sbr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23294908Sbr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24294908Sbr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25294908Sbr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26294908Sbr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27294908Sbr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28294908Sbr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29294908Sbr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30294908Sbr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31294908Sbr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32294908Sbr * SUCH DAMAGE.
33294908Sbr */
34294908Sbr
35294908Sbr#include <sys/cdefs.h>
36294908Sbr__FBSDID("$FreeBSD$");
37294908Sbr
38294908Sbr#include <sys/types.h>
39294908Sbr#include <string.h>
40294908Sbr#include <thread_db.h>
41294908Sbr
42294908Sbr#include "libpthread_db.h"
43294908Sbr
44294908Sbrvoid
45294908Sbrpt_reg_to_ucontext(const struct reg *r, ucontext_t *uc)
46294908Sbr{
47294908Sbr	mcontext_t *mc;
48294908Sbr
49294908Sbr	mc = &uc->uc_mcontext;
50294908Sbr
51294908Sbr	memcpy(mc->mc_gpregs.gp_t, r->t, sizeof(mc->mc_gpregs.gp_t));
52294908Sbr	memcpy(mc->mc_gpregs.gp_s, r->s, sizeof(mc->mc_gpregs.gp_s));
53294908Sbr	memcpy(mc->mc_gpregs.gp_a, r->a, sizeof(mc->mc_gpregs.gp_a));
54294908Sbr	mc->mc_gpregs.gp_ra = r->ra;
55294908Sbr	mc->mc_gpregs.gp_sp = r->sp;
56294908Sbr	mc->mc_gpregs.gp_gp = r->gp;
57294908Sbr	mc->mc_gpregs.gp_tp = r->tp;
58294908Sbr	mc->mc_gpregs.gp_sepc = r->sepc;
59294908Sbr	mc->mc_gpregs.gp_sstatus = r->sstatus;
60294908Sbr}
61294908Sbr
62294908Sbrvoid
63294908Sbrpt_ucontext_to_reg(const ucontext_t *uc, struct reg *r)
64294908Sbr{
65294908Sbr	const mcontext_t *mc;
66294908Sbr
67294908Sbr	mc = &uc->uc_mcontext;
68294908Sbr
69294908Sbr	memcpy(r->t, mc->mc_gpregs.gp_t, sizeof(mc->mc_gpregs.gp_t));
70294908Sbr	memcpy(r->s, mc->mc_gpregs.gp_s, sizeof(mc->mc_gpregs.gp_s));
71294908Sbr	memcpy(r->a, mc->mc_gpregs.gp_a, sizeof(mc->mc_gpregs.gp_a));
72294908Sbr	r->ra = mc->mc_gpregs.gp_ra;
73294908Sbr	r->sp = mc->mc_gpregs.gp_sp;
74294908Sbr	r->gp = mc->mc_gpregs.gp_gp;
75294908Sbr	r->tp = mc->mc_gpregs.gp_tp;
76294908Sbr	r->sepc = mc->mc_gpregs.gp_sepc;
77294908Sbr	r->sstatus = mc->mc_gpregs.gp_sstatus;
78294908Sbr}
79294908Sbr
80294908Sbrvoid
81294908Sbrpt_fpreg_to_ucontext(const struct fpreg *r __unused, ucontext_t *uc __unused)
82294908Sbr{
83294908Sbr
84294908Sbr	/* RISCVTODO */
85294908Sbr}
86294908Sbr
87294908Sbrvoid
88294908Sbrpt_ucontext_to_fpreg(const ucontext_t *uc __unused, struct fpreg *r __unused)
89294908Sbr{
90294908Sbr
91294908Sbr	/* RISCVTODO */
92294908Sbr}
93294908Sbr
94294908Sbrvoid
95294908Sbrpt_md_init(void)
96294908Sbr{
97294908Sbr}
98294908Sbr
99294908Sbrint
100294908Sbrpt_reg_sstep(struct reg *reg __unused, int step __unused)
101294908Sbr{
102294908Sbr
103294908Sbr	return (0);
104294908Sbr}
105