2 * Copyright (c) 2014 Andrew Turner
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
35 #include <sys/imgact.h>
36 #include <sys/kernel.h>
37 #include <sys/limits.h>
39 #include <sys/mutex.h>
41 #include <sys/ptrace.h>
43 #include <sys/rwlock.h>
44 #include <sys/signalvar.h>
45 #include <sys/syscallsubr.h>
46 #include <sys/sysent.h>
47 #include <sys/sysproto.h>
48 #include <sys/ucontext.h>
50 #include <machine/armreg.h>
51 #include <machine/pcb.h>
53 /* Only used to get/set 32bits VFP regs */
55 cpu_ptrace(struct thread *td, int req, void *arg, int data)
57 #if defined(VFP) && defined(COMPAT_FREEBSD32)
61 if (!SV_CURPROC_FLAG(SV_ILP32))
65 get_fpcontext32(td, &vfp);
66 error = copyout(&vfp, arg, sizeof(vfp));
69 error = copyin(arg, &vfp, sizeof(vfp));
71 set_fpcontext32(td, &vfp);
83 #if defined(VFP) && defined(COMPAT_FREEBSD32)
85 get_arm_vfp(struct regset *rs, struct thread *td, void *buf, size_t *sizep)
88 KASSERT(*sizep == sizeof(mcontext32_vfp_t),
89 ("%s: invalid size", __func__));
90 get_fpcontext32(td, buf);
92 *sizep = sizeof(mcontext32_vfp_t);
97 set_arm_vfp(struct regset *rs, struct thread *td, void *buf,
100 KASSERT(size == sizeof(mcontext32_vfp_t), ("%s: invalid size",
102 set_fpcontext32(td, buf);
106 static struct regset regset_arm_vfp = {
108 .size = sizeof(mcontext32_vfp_t),
112 ELF32_REGSET(regset_arm_vfp);
116 get_arm64_tls(struct regset *rs, struct thread *td, void *buf,
120 KASSERT(*sizep == sizeof(td->td_pcb->pcb_tpidr_el0),
121 ("%s: invalid size", __func__));
122 memcpy(buf, &td->td_pcb->pcb_tpidr_el0,
123 sizeof(td->td_pcb->pcb_tpidr_el0));
125 *sizep = sizeof(td->td_pcb->pcb_tpidr_el0);
130 static struct regset regset_arm64_tls = {
132 .size = sizeof(uint64_t),
133 .get = get_arm64_tls,
135 ELF_REGSET(regset_arm64_tls);
137 #ifdef COMPAT_FREEBSD32
139 get_arm_tls(struct regset *rs, struct thread *td, void *buf,
145 KASSERT(*sizep == sizeof(uint32_t),
146 ("%s: invalid size", __func__));
147 tp = (uint32_t)td->td_pcb->pcb_tpidr_el0;
148 memcpy(buf, &tp, sizeof(tp));
150 *sizep = sizeof(uint32_t);
155 static struct regset regset_arm_tls = {
157 .size = sizeof(uint32_t),
160 ELF32_REGSET(regset_arm_tls);
164 ptrace_set_pc(struct thread *td, u_long addr)
167 td->td_frame->tf_elr = addr;
172 ptrace_single_step(struct thread *td)
174 PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
175 if ((td->td_frame->tf_spsr & PSR_SS) == 0) {
176 td->td_frame->tf_spsr |= PSR_SS;
177 td->td_pcb->pcb_flags |= PCB_SINGLE_STEP;
178 td->td_dbgflags |= TDB_STEP;
184 ptrace_clear_single_step(struct thread *td)
186 PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
187 td->td_frame->tf_spsr &= ~PSR_SS;
188 td->td_pcb->pcb_flags &= ~PCB_SINGLE_STEP;
189 td->td_dbgflags &= ~TDB_STEP;