2 * Ptrace support for Hexagon
4 * Copyright (c) 2010-2011, Code Aurora Forum. 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 <generated/compile.h>
23 #include <linux/kernel.h>
24 #include <linux/sched.h>
26 #include <linux/smp.h>
27 #include <linux/errno.h>
28 #include <linux/ptrace.h>
29 #include <linux/regset.h>
30 #include <linux/user.h>
34 static int genregs_get(struct task_struct *target,
35 const struct user_regset *regset,
36 unsigned int pos, unsigned int count,
37 void *kbuf, void __user *ubuf)
41 struct pt_regs *regs = task_pt_regs(target);
47 /* The general idea here is that the copyout must happen in
48 * exactly the same order in which the userspace expects these
49 * regs. Now, the sequence in userspace does not match the
50 * sequence in the kernel, so everything past the 32 gprs
51 * happens one at a time.
53 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
54 ®s->r00, 0, 32*sizeof(unsigned long));
56 #define ONEXT(KPT_REG, USR_REG) \
58 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, \
59 KPT_REG, offsetof(struct user_regs_struct, USR_REG), \
60 offsetof(struct user_regs_struct, USR_REG) + \
61 sizeof(unsigned long));
63 /* Must be exactly same sequence as struct user_regs_struct */
64 ONEXT(®s->sa0, sa0);
65 ONEXT(®s->lc0, lc0);
66 ONEXT(®s->sa1, sa1);
67 ONEXT(®s->lc1, lc1);
70 ONEXT(®s->usr, usr);
71 ONEXT(®s->preds, p3_0);
73 ONEXT(®s->ugp, ugp);
74 ONEXT(&pt_elr(regs), pc);
75 dummy = pt_cause(regs);
77 ONEXT(&pt_badva(regs), badva);
79 /* Pad the rest with zeros, if needed */
81 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
82 offsetof(struct user_regs_struct, pad1), -1);
86 static int genregs_set(struct task_struct *target,
87 const struct user_regset *regset,
88 unsigned int pos, unsigned int count,
89 const void *kbuf, const void __user *ubuf)
93 struct pt_regs *regs = task_pt_regs(target);
98 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
99 ®s->r00, 0, 32*sizeof(unsigned long));
101 #define INEXT(KPT_REG, USR_REG) \
103 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
104 KPT_REG, offsetof(struct user_regs_struct, USR_REG), \
105 offsetof(struct user_regs_struct, USR_REG) + \
106 sizeof(unsigned long));
108 /* Must be exactly same sequence as struct user_regs_struct */
109 INEXT(®s->sa0, sa0);
110 INEXT(®s->lc0, lc0);
111 INEXT(®s->sa1, sa1);
112 INEXT(®s->lc1, lc1);
113 INEXT(®s->m0, m0);
114 INEXT(®s->m1, m1);
115 INEXT(®s->usr, usr);
116 INEXT(®s->preds, p3_0);
117 INEXT(®s->gp, gp);
118 INEXT(®s->ugp, ugp);
119 INEXT(&pt_elr(regs), pc);
121 /* CAUSE and BADVA aren't writeable. */
122 INEXT(&bucket, cause);
123 INEXT(&bucket, badva);
125 /* Ignore the rest, if needed */
127 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
128 offsetof(struct user_regs_struct, pad1), -1);
134 * This is special; SP is actually restored by the VM via the
135 * special event record which is set by the special trap.
137 regs->hvmer.vmpsp = regs->r29;
141 enum hexagon_regset {
145 static const struct user_regset hexagon_regsets[] = {
147 .core_note_type = NT_PRSTATUS,
149 .size = sizeof(unsigned long),
150 .align = sizeof(unsigned long),
156 static const struct user_regset_view hexagon_user_view = {
158 .e_machine = ELF_ARCH,
159 .ei_osabi = ELF_OSABI,
160 .regsets = hexagon_regsets,
161 .n = ARRAY_SIZE(hexagon_regsets)
164 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
166 return &hexagon_user_view;
169 void ptrace_disable(struct task_struct *child)
171 /* Boilerplate - resolves to null inline if no HW single-step */
172 user_disable_single_step(child);
175 long arch_ptrace(struct task_struct *child, long request,
176 unsigned long addr, unsigned long data)
178 return ptrace_request(child, request, addr, data);