1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2006-2007, Juniper Networks, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of Juniper Networks nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY JUNIPER NETWORKS ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34 
35 #include <sys/types.h>
36 #define	_WANT_MIPS_REGNUM
37 #include <sys/procfs.h>
38 #include <ucontext.h>
39 #include <string.h>
40 #include <thread_db.h>
41 #include "libpthread_db.h"
42 
43 void
pt_reg_to_ucontext(const struct reg * r,ucontext_t * uc)44 pt_reg_to_ucontext(const struct reg *r, ucontext_t *uc)
45 {
46 
47 	memcpy(uc->uc_mcontext.mc_regs, &r->r_regs[ZERO],
48 	    sizeof(uc->uc_mcontext.mc_regs));
49 	uc->uc_mcontext.mc_pc = r->r_regs[PC];
50 	uc->uc_mcontext.mullo = r->r_regs[MULLO];
51 	uc->uc_mcontext.mulhi = r->r_regs[MULHI];
52 }
53 
54 void
pt_ucontext_to_reg(const ucontext_t * uc,struct reg * r)55 pt_ucontext_to_reg(const ucontext_t *uc, struct reg *r)
56 {
57 	memcpy(&r->r_regs[ZERO], uc->uc_mcontext.mc_regs,
58 	    sizeof(uc->uc_mcontext.mc_regs));
59 	r->r_regs[PC] = uc->uc_mcontext.mc_pc;
60 	r->r_regs[MULLO] = uc->uc_mcontext.mullo;
61 	r->r_regs[MULHI] = uc->uc_mcontext.mulhi;
62 }
63 
64 void
pt_fpreg_to_ucontext(const struct fpreg * r,ucontext_t * uc)65 pt_fpreg_to_ucontext(const struct fpreg* r, ucontext_t *uc)
66 {
67 
68 	memcpy(uc->uc_mcontext.mc_fpregs, r->r_regs,
69 	    sizeof(uc->uc_mcontext.mc_fpregs));
70 }
71 
72 void
pt_ucontext_to_fpreg(const ucontext_t * uc,struct fpreg * r)73 pt_ucontext_to_fpreg(const ucontext_t *uc, struct fpreg *r)
74 {
75 
76 	memcpy(r->r_regs, uc->uc_mcontext.mc_fpregs,
77 	    sizeof(uc->uc_mcontext.mc_fpregs));
78 }
79 
80 void
pt_md_init(void)81 pt_md_init(void)
82 {
83 	/* Nothing to do */
84 }
85 
86 int
pt_reg_sstep(struct reg * reg __unused,int step __unused)87 pt_reg_sstep(struct reg *reg __unused, int step __unused)
88 {
89 	/*
90 	 * XXX: mips doesnt store single step info in any registers
91 	 */
92 	return (0);
93 }
94