2 * Ptrace support for Hexagon
4 * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 and
8 * only version 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include <linux/kernel.h>
22 #include <linux/sched.h>
23 #include <linux/sched/task_stack.h>
25 #include <linux/smp.h>
26 #include <linux/errno.h>
27 #include <linux/ptrace.h>
28 #include <linux/regset.h>
29 #include <linux/user.h>
30 #include <linux/elf.h>
34 #if arch_has_single_step()
35 /* Both called from ptrace_resume */
36 void user_enable_single_step(struct task_struct *child)
38 pt_set_singlestep(task_pt_regs(child));
39 set_tsk_thread_flag(child, TIF_SINGLESTEP);
42 void user_disable_single_step(struct task_struct *child)
44 pt_clr_singlestep(task_pt_regs(child));
45 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
49 static int genregs_get(struct task_struct *target,
50 const struct user_regset *regset,
51 unsigned int pos, unsigned int count,
52 void *kbuf, void __user *ubuf)
56 struct pt_regs *regs = task_pt_regs(target);
62 /* The general idea here is that the copyout must happen in
63 * exactly the same order in which the userspace expects these
64 * regs. Now, the sequence in userspace does not match the
65 * sequence in the kernel, so everything past the 32 gprs
66 * happens one at a time.
68 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
69 ®s->r00, 0, 32*sizeof(unsigned long));
71 #define ONEXT(KPT_REG, USR_REG) \
73 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, \
74 KPT_REG, offsetof(struct user_regs_struct, USR_REG), \
75 offsetof(struct user_regs_struct, USR_REG) + \
76 sizeof(unsigned long));
78 /* Must be exactly same sequence as struct user_regs_struct */
79 ONEXT(®s->sa0, sa0);
80 ONEXT(®s->lc0, lc0);
81 ONEXT(®s->sa1, sa1);
82 ONEXT(®s->lc1, lc1);
85 ONEXT(®s->usr, usr);
86 ONEXT(®s->preds, p3_0);
88 ONEXT(®s->ugp, ugp);
89 ONEXT(&pt_elr(regs), pc);
90 dummy = pt_cause(regs);
92 ONEXT(&pt_badva(regs), badva);
93 #if CONFIG_HEXAGON_ARCH_VERSION >=4
94 ONEXT(®s->cs0, cs0);
95 ONEXT(®s->cs1, cs1);
98 /* Pad the rest with zeros, if needed */
100 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
101 offsetof(struct user_regs_struct, pad1), -1);
105 static int genregs_set(struct task_struct *target,
106 const struct user_regset *regset,
107 unsigned int pos, unsigned int count,
108 const void *kbuf, const void __user *ubuf)
111 unsigned long bucket;
112 struct pt_regs *regs = task_pt_regs(target);
117 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
118 ®s->r00, 0, 32*sizeof(unsigned long));
120 #define INEXT(KPT_REG, USR_REG) \
122 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
123 KPT_REG, offsetof(struct user_regs_struct, USR_REG), \
124 offsetof(struct user_regs_struct, USR_REG) + \
125 sizeof(unsigned long));
127 /* Must be exactly same sequence as struct user_regs_struct */
128 INEXT(®s->sa0, sa0);
129 INEXT(®s->lc0, lc0);
130 INEXT(®s->sa1, sa1);
131 INEXT(®s->lc1, lc1);
132 INEXT(®s->m0, m0);
133 INEXT(®s->m1, m1);
134 INEXT(®s->usr, usr);
135 INEXT(®s->preds, p3_0);
136 INEXT(®s->gp, gp);
137 INEXT(®s->ugp, ugp);
138 INEXT(&pt_elr(regs), pc);
140 /* CAUSE and BADVA aren't writeable. */
141 INEXT(&bucket, cause);
142 INEXT(&bucket, badva);
144 #if CONFIG_HEXAGON_ARCH_VERSION >=4
145 INEXT(®s->cs0, cs0);
146 INEXT(®s->cs1, cs1);
149 /* Ignore the rest, if needed */
151 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
152 offsetof(struct user_regs_struct, pad1), -1);
158 * This is special; SP is actually restored by the VM via the
159 * special event record which is set by the special trap.
161 regs->hvmer.vmpsp = regs->r29;
165 enum hexagon_regset {
169 static const struct user_regset hexagon_regsets[] = {
171 .core_note_type = NT_PRSTATUS,
173 .size = sizeof(unsigned long),
174 .align = sizeof(unsigned long),
180 static const struct user_regset_view hexagon_user_view = {
182 .e_machine = ELF_ARCH,
183 .ei_osabi = ELF_OSABI,
184 .regsets = hexagon_regsets,
185 .e_flags = ELF_CORE_EFLAGS,
186 .n = ARRAY_SIZE(hexagon_regsets)
189 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
191 return &hexagon_user_view;
194 void ptrace_disable(struct task_struct *child)
196 /* Boilerplate - resolves to null inline if no HW single-step */
197 user_disable_single_step(child);
200 long arch_ptrace(struct task_struct *child, long request,
201 unsigned long addr, unsigned long data)
203 return ptrace_request(child, request, addr, data);