]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/arm/ptrace_machdep.c
unbound: Vendor import 1.16.2
[FreeBSD/FreeBSD.git] / sys / arm / arm / ptrace_machdep.c
1 /*-
2  * Copyright (c) 2017 John Baldwin <jhb@FreeBSD.org>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include <sys/types.h>
31 #include <sys/elf.h>
32 #include <sys/proc.h>
33 #include <sys/ptrace.h>
34 #include <sys/reg.h>
35 #ifdef VFP
36 #include <machine/vfp.h>
37 #endif
38
39 #ifdef VFP
40 static bool
41 get_arm_vfp(struct regset *rs, struct thread *td, void *buf, size_t *sizep)
42 {
43         if (buf != NULL) {
44                 KASSERT(*sizep == sizeof(mcontext_vfp_t),
45                     ("%s: invalid size", __func__));
46                 get_vfpcontext(td, buf);
47         }
48         *sizep = sizeof(mcontext_vfp_t);
49         return (true);
50 }
51
52 static bool
53 set_arm_vfp(struct regset *rs, struct thread *td, void *buf,
54     size_t size)
55 {
56         KASSERT(size == sizeof(mcontext_vfp_t), ("%s: invalid size", __func__));
57         set_vfpcontext(td, buf);
58         return (true);
59 }
60
61 static struct regset regset_arm_vfp = {
62         .note = NT_ARM_VFP,
63         .size = sizeof(mcontext_vfp_t),
64         .get = get_arm_vfp,
65         .set = set_arm_vfp,
66 };
67 ELF_REGSET(regset_arm_vfp);
68 #endif
69
70 static bool
71 get_arm_tls(struct regset *rs, struct thread *td, void *buf,
72     size_t *sizep)
73 {
74         if (buf != NULL) {
75                 KASSERT(*sizep == sizeof(td->td_pcb->pcb_regs.sf_tpidrurw),
76                     ("%s: invalid size", __func__));
77                 memcpy(buf, &td->td_pcb->pcb_regs.sf_tpidrurw,
78                     sizeof(td->td_pcb->pcb_regs.sf_tpidrurw));
79         }
80         *sizep = sizeof(td->td_pcb->pcb_regs.sf_tpidrurw);
81
82         return (true);
83 }
84
85 static struct regset regset_arm_tls = {
86         .note = NT_ARM_TLS,
87         .size = sizeof(uint32_t),
88         .get = get_arm_tls,
89 };
90 ELF_REGSET(regset_arm_tls);
91
92 int
93 cpu_ptrace(struct thread *td, int req, void *addr, int data)
94 {
95 #ifdef VFP
96         mcontext_vfp_t vfp;
97 #endif
98         int error;
99
100         switch (req) {
101 #ifdef VFP
102         case PT_GETVFPREGS:
103                 get_vfpcontext(td, &vfp);
104                 error = copyout(&vfp, addr, sizeof(vfp));
105                 break;
106         case PT_SETVFPREGS:
107                 error = copyin(addr, &vfp, sizeof(vfp));
108                 if (error == 0)
109                         set_vfpcontext(td, &vfp);
110                 break;
111 #endif
112         default:
113                 error = EINVAL;
114         }
115
116         return (error);
117 }