pandora: defconfig: update
[pandora-kernel.git] / arch / hexagon / kernel / ptrace.c
1 /*
2  * Ptrace support for Hexagon
3  *
4  * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
5  *
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.
9  *
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.
14  *
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
18  * 02110-1301, USA.
19  */
20
21 #include <generated/compile.h>
22
23 #include <linux/kernel.h>
24 #include <linux/sched.h>
25 #include <linux/mm.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>
31 #include <linux/elf.h>
32
33 #include <asm/system.h>
34 #include <asm/user.h>
35
36 static int genregs_get(struct task_struct *target,
37                    const struct user_regset *regset,
38                    unsigned int pos, unsigned int count,
39                    void *kbuf, void __user *ubuf)
40 {
41         int ret;
42         unsigned int dummy;
43         struct pt_regs *regs = task_pt_regs(target);
44
45
46         if (!regs)
47                 return -EIO;
48
49         /* The general idea here is that the copyout must happen in
50          * exactly the same order in which the userspace expects these
51          * regs. Now, the sequence in userspace does not match the
52          * sequence in the kernel, so everything past the 32 gprs
53          * happens one at a time.
54          */
55         ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
56                                   &regs->r00, 0, 32*sizeof(unsigned long));
57
58 #define ONEXT(KPT_REG, USR_REG) \
59         if (!ret) \
60                 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, \
61                         KPT_REG, offsetof(struct user_regs_struct, USR_REG), \
62                         offsetof(struct user_regs_struct, USR_REG) + \
63                                  sizeof(unsigned long));
64
65         /* Must be exactly same sequence as struct user_regs_struct */
66         ONEXT(&regs->sa0, sa0);
67         ONEXT(&regs->lc0, lc0);
68         ONEXT(&regs->sa1, sa1);
69         ONEXT(&regs->lc1, lc1);
70         ONEXT(&regs->m0, m0);
71         ONEXT(&regs->m1, m1);
72         ONEXT(&regs->usr, usr);
73         ONEXT(&regs->preds, p3_0);
74         ONEXT(&regs->gp, gp);
75         ONEXT(&regs->ugp, ugp);
76         ONEXT(&pt_elr(regs), pc);
77         dummy = pt_cause(regs);
78         ONEXT(&dummy, cause);
79         ONEXT(&pt_badva(regs), badva);
80
81         /* Pad the rest with zeros, if needed */
82         if (!ret)
83                 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
84                                         offsetof(struct user_regs_struct, pad1), -1);
85         return ret;
86 }
87
88 static int genregs_set(struct task_struct *target,
89                    const struct user_regset *regset,
90                    unsigned int pos, unsigned int count,
91                    const void *kbuf, const void __user *ubuf)
92 {
93         int ret;
94         unsigned long bucket;
95         struct pt_regs *regs = task_pt_regs(target);
96
97         if (!regs)
98                 return -EIO;
99
100         ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
101                                  &regs->r00, 0, 32*sizeof(unsigned long));
102
103 #define INEXT(KPT_REG, USR_REG) \
104         if (!ret) \
105                 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
106                         KPT_REG, offsetof(struct user_regs_struct, USR_REG), \
107                         offsetof(struct user_regs_struct, USR_REG) + \
108                                 sizeof(unsigned long));
109
110         /* Must be exactly same sequence as struct user_regs_struct */
111         INEXT(&regs->sa0, sa0);
112         INEXT(&regs->lc0, lc0);
113         INEXT(&regs->sa1, sa1);
114         INEXT(&regs->lc1, lc1);
115         INEXT(&regs->m0, m0);
116         INEXT(&regs->m1, m1);
117         INEXT(&regs->usr, usr);
118         INEXT(&regs->preds, p3_0);
119         INEXT(&regs->gp, gp);
120         INEXT(&regs->ugp, ugp);
121         INEXT(&pt_elr(regs), pc);
122
123         /* CAUSE and BADVA aren't writeable. */
124         INEXT(&bucket, cause);
125         INEXT(&bucket, badva);
126
127         /* Ignore the rest, if needed */
128         if (!ret)
129                 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
130                                         offsetof(struct user_regs_struct, pad1), -1);
131
132         if (ret)
133                 return ret;
134
135         /*
136          * This is special; SP is actually restored by the VM via the
137          * special event record which is set by the special trap.
138          */
139         regs->hvmer.vmpsp = regs->r29;
140         return 0;
141 }
142
143 enum hexagon_regset {
144         REGSET_GENERAL,
145 };
146
147 static const struct user_regset hexagon_regsets[] = {
148         [REGSET_GENERAL] = {
149                 .core_note_type = NT_PRSTATUS,
150                 .n = ELF_NGREG,
151                 .size = sizeof(unsigned long),
152                 .align = sizeof(unsigned long),
153                 .get = genregs_get,
154                 .set = genregs_set,
155         },
156 };
157
158 static const struct user_regset_view hexagon_user_view = {
159         .name = UTS_MACHINE,
160         .e_machine = ELF_ARCH,
161         .ei_osabi = ELF_OSABI,
162         .regsets = hexagon_regsets,
163         .n = ARRAY_SIZE(hexagon_regsets)
164 };
165
166 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
167 {
168         return &hexagon_user_view;
169 }
170
171 void ptrace_disable(struct task_struct *child)
172 {
173         /* Boilerplate - resolves to null inline if no HW single-step */
174         user_disable_single_step(child);
175 }
176
177 long arch_ptrace(struct task_struct *child, long request,
178                  unsigned long addr, unsigned long data)
179 {
180         return ptrace_request(child, request, addr, data);
181 }