~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/hexagon/kernel/ptrace.c

Version: ~ [ linux-5.12-rc7 ] ~ [ linux-5.11.13 ] ~ [ linux-5.10.29 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.111 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.186 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.230 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.266 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.266 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp