1331722Seadler/*
2182372Sobrien * Copyright (c) 2006-2007, Juniper Networks, Inc.
3182372Sobrien * All rights reserved.
4182372Sobrien *
5182372Sobrien * Redistribution and use in source and binary forms, with or without
6182372Sobrien * modification, are permitted provided that the following conditions
7182372Sobrien * are met:
8182372Sobrien *
9182372Sobrien * 1. Redistributions of source code must retain the above copyright
10182372Sobrien *    notice, this list of conditions and the following disclaimer.
11182372Sobrien * 2. Redistributions in binary form must reproduce the above copyright
12182372Sobrien *    notice, this list of conditions and the following disclaimer in the
13182372Sobrien *    documentation and/or other materials provided with the distribution.
14182372Sobrien * 3. Neither the name of Juniper Networks nor the names of its contributors
15182372Sobrien *    may be used to endorse or promote products derived from this software
16182372Sobrien *    without specific prior written permission.
17182372Sobrien *
18182372Sobrien * THIS SOFTWARE IS PROVIDED BY JUNIPER NETWORKS ``AS IS'' AND ANY EXPRESS OR
19182372Sobrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20182372Sobrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21182372Sobrien * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22182372Sobrien * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23182372Sobrien * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24182372Sobrien * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25182372Sobrien * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26182372Sobrien * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27182372Sobrien * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28182372Sobrien */
29182372Sobrien
30182372Sobrien#include <sys/cdefs.h>
31182372Sobrien__FBSDID("$FreeBSD: stable/11/lib/libthread_db/arch/mips/libpthread_md.c 351792 2019-09-03 20:19:43Z kevans $");
32182372Sobrien
33182372Sobrien#include <sys/types.h>
34351792Skevans#define	_WANT_MIPS_REGNUM
35182372Sobrien#include <sys/procfs.h>
36182372Sobrien#include <ucontext.h>
37182372Sobrien#include <string.h>
38182372Sobrien#include <thread_db.h>
39182372Sobrien#include "libpthread_db.h"
40182372Sobrien
41182372Sobrienvoid
42182372Sobrienpt_reg_to_ucontext(const struct reg *r, ucontext_t *uc)
43182372Sobrien{
44182372Sobrien
45182372Sobrien	memcpy(uc->uc_mcontext.mc_regs, &r->r_regs[ZERO],
46182372Sobrien	    sizeof(uc->uc_mcontext.mc_regs));
47182372Sobrien	uc->uc_mcontext.mc_pc = r->r_regs[PC];
48182372Sobrien	uc->uc_mcontext.mullo = r->r_regs[MULLO];
49182372Sobrien	uc->uc_mcontext.mulhi = r->r_regs[MULHI];
50182372Sobrien}
51182372Sobrien
52182372Sobrienvoid
53182372Sobrienpt_ucontext_to_reg(const ucontext_t *uc, struct reg *r)
54182372Sobrien{
55182372Sobrien	memcpy(&r->r_regs[ZERO], uc->uc_mcontext.mc_regs,
56182372Sobrien	    sizeof(uc->uc_mcontext.mc_regs));
57182372Sobrien	r->r_regs[PC] = uc->uc_mcontext.mc_pc;
58182372Sobrien	r->r_regs[MULLO] = uc->uc_mcontext.mullo;
59182372Sobrien	r->r_regs[MULHI] = uc->uc_mcontext.mulhi;
60182372Sobrien}
61182372Sobrien
62182372Sobrienvoid
63182372Sobrienpt_fpreg_to_ucontext(const struct fpreg* r, ucontext_t *uc)
64182372Sobrien{
65182372Sobrien
66182372Sobrien	memcpy(uc->uc_mcontext.mc_fpregs, r->r_regs,
67182372Sobrien	    sizeof(uc->uc_mcontext.mc_fpregs));
68182372Sobrien}
69182372Sobrien
70182372Sobrienvoid
71182372Sobrienpt_ucontext_to_fpreg(const ucontext_t *uc, struct fpreg *r)
72182372Sobrien{
73182372Sobrien
74182372Sobrien	memcpy(r->r_regs, uc->uc_mcontext.mc_fpregs,
75182372Sobrien	    sizeof(uc->uc_mcontext.mc_fpregs));
76182372Sobrien}
77182372Sobrien
78182372Sobrienvoid
79182372Sobrienpt_md_init(void)
80182372Sobrien{
81182372Sobrien	/* Nothing to do */
82182372Sobrien}
83182372Sobrien
84182372Sobrienint
85182372Sobrienpt_reg_sstep(struct reg *reg __unused, int step __unused)
86182372Sobrien{
87182372Sobrien	/*
88182372Sobrien	 * XXX: mips doesnt store single step info in any registers
89182372Sobrien	 */
90182372Sobrien	return (0);
91182372Sobrien}
92