1 /* ptrace.c: Sparc process tracing support.
3 * Copyright (C) 1996, 2008 David S. Miller (davem@davemloft.net)
5 * Based upon code written by Ross Biro, Linus Torvalds, Bob Manson,
8 * Added Linux support -miguel (weird, eh?, the original code was meant
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
15 #include <linux/errno.h>
16 #include <linux/ptrace.h>
17 #include <linux/user.h>
18 #include <linux/smp.h>
19 #include <linux/security.h>
20 #include <linux/signal.h>
21 #include <linux/regset.h>
22 #include <linux/elf.h>
23 #include <linux/tracehook.h>
25 #include <asm/pgtable.h>
26 #include <asm/uaccess.h>
27 #include <asm/cacheflush.h>
31 /* #define ALLOW_INIT_TRACING */
34 * Called by kernel/ptrace.c when detaching..
36 * Make sure single step bits etc are not set.
38 void ptrace_disable(struct task_struct *child)
48 static int regwindow32_get(struct task_struct *target,
49 const struct pt_regs *regs,
52 unsigned long reg_window = regs->u_regs[UREG_I6];
53 int size = 16 * sizeof(u32);
55 if (target == current) {
56 if (copy_from_user(uregs, (void __user *)reg_window, size))
59 if (access_process_vm(target, reg_window, uregs, size,
66 static int regwindow32_set(struct task_struct *target,
67 const struct pt_regs *regs,
70 unsigned long reg_window = regs->u_regs[UREG_I6];
71 int size = 16 * sizeof(u32);
73 if (target == current) {
74 if (copy_to_user((void __user *)reg_window, uregs, size))
77 if (access_process_vm(target, reg_window, uregs, size,
78 FOLL_FORCE | FOLL_WRITE) != size)
84 static int genregs32_get(struct task_struct *target,
85 const struct user_regset *regset,
86 unsigned int pos, unsigned int count,
87 void *kbuf, void __user *ubuf)
89 const struct pt_regs *regs = target->thread.kregs;
93 if (target == current)
96 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
102 if (pos < 32 * sizeof(u32)) {
103 if (regwindow32_get(target, regs, uregs))
105 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
107 16 * sizeof(u32), 32 * sizeof(u32));
112 uregs[0] = regs->psr;
114 uregs[2] = regs->npc;
116 uregs[4] = 0; /* WIM */
117 uregs[5] = 0; /* TBR */
118 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
120 32 * sizeof(u32), 38 * sizeof(u32));
123 static int genregs32_set(struct task_struct *target,
124 const struct user_regset *regset,
125 unsigned int pos, unsigned int count,
126 const void *kbuf, const void __user *ubuf)
128 struct pt_regs *regs = target->thread.kregs;
133 if (target == current)
134 flush_user_windows();
136 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
138 0, 16 * sizeof(u32));
142 if (pos < 32 * sizeof(u32)) {
143 if (regwindow32_get(target, regs, uregs))
145 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
147 16 * sizeof(u32), 32 * sizeof(u32));
150 if (regwindow32_set(target, regs, uregs))
155 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
157 32 * sizeof(u32), 33 * sizeof(u32));
160 regs->psr = (regs->psr & ~(PSR_ICC | PSR_SYSCALL)) |
161 (psr & (PSR_ICC | PSR_SYSCALL));
164 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
166 33 * sizeof(u32), 34 * sizeof(u32));
169 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
171 34 * sizeof(u32), 35 * sizeof(u32));
174 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
176 35 * sizeof(u32), 36 * sizeof(u32));
179 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
180 36 * sizeof(u32), 38 * sizeof(u32));
183 static int fpregs32_get(struct task_struct *target,
184 const struct user_regset *regset,
185 unsigned int pos, unsigned int count,
186 void *kbuf, void __user *ubuf)
188 const unsigned long *fpregs = target->thread.float_regs;
192 if (target == current)
193 save_and_clear_fpu();
196 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
198 0, 32 * sizeof(u32));
201 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
205 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
213 val = (1 << 8) | (8 << 16);
214 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
221 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
222 35 * sizeof(u32), -1);
227 static int fpregs32_set(struct task_struct *target,
228 const struct user_regset *regset,
229 unsigned int pos, unsigned int count,
230 const void *kbuf, const void __user *ubuf)
232 unsigned long *fpregs = target->thread.float_regs;
236 if (target == current)
237 save_and_clear_fpu();
239 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
241 0, 32 * sizeof(u32));
243 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
246 if (!ret && count > 0) {
247 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
254 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
255 34 * sizeof(u32), -1);
259 static const struct user_regset sparc32_regsets[] = {
265 * PSR, PC, nPC, Y, WIM, TBR
268 .core_note_type = NT_PRSTATUS,
270 .size = sizeof(u32), .align = sizeof(u32),
271 .get = genregs32_get, .set = genregs32_set
277 * FPU QUEUE COUNT (8-bit char)
278 * FPU QUEUE ENTRYSIZE (8-bit char)
279 * FPU ENABLED (8-bit char)
281 * FPU QUEUE (64 32-bit ints)
284 .core_note_type = NT_PRFPREG,
286 .size = sizeof(u32), .align = sizeof(u32),
287 .get = fpregs32_get, .set = fpregs32_set
291 static const struct user_regset_view user_sparc32_view = {
292 .name = "sparc", .e_machine = EM_SPARC,
293 .regsets = sparc32_regsets, .n = ARRAY_SIZE(sparc32_regsets)
296 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
298 return &user_sparc32_view;
302 unsigned long regs[32];
308 unsigned long *insnaddr;
313 long arch_ptrace(struct task_struct *child, long request,
314 unsigned long addr, unsigned long data)
316 unsigned long addr2 = current->thread.kregs->u_regs[UREG_I4];
318 const struct user_regset_view *view;
319 struct pt_regs __user *pregs;
320 struct fps __user *fps;
323 view = task_user_regset_view(current);
324 addr2p = (void __user *) addr2;
325 pregs = (struct pt_regs __user *) addr;
326 fps = (struct fps __user *) addr;
329 case PTRACE_GETREGS: {
330 ret = copy_regset_to_user(child, view, REGSET_GENERAL,
335 copy_regset_to_user(child, view, REGSET_GENERAL,
342 case PTRACE_SETREGS: {
343 ret = copy_regset_from_user(child, view, REGSET_GENERAL,
348 copy_regset_from_user(child, view, REGSET_GENERAL,
355 case PTRACE_GETFPREGS: {
356 ret = copy_regset_to_user(child, view, REGSET_FP,
361 ret = copy_regset_to_user(child, view, REGSET_FP,
367 if (__put_user(0, &fps->fpqd) ||
368 __put_user(0, &fps->flags) ||
369 __put_user(0, &fps->extra) ||
370 clear_user(fps->fpq, sizeof(fps->fpq)))
376 case PTRACE_SETFPREGS: {
377 ret = copy_regset_from_user(child, view, REGSET_FP,
382 ret = copy_regset_from_user(child, view, REGSET_FP,
389 case PTRACE_READTEXT:
390 case PTRACE_READDATA:
391 ret = ptrace_readdata(child, addr, addr2p, data);
399 case PTRACE_WRITETEXT:
400 case PTRACE_WRITEDATA:
401 ret = ptrace_writedata(child, addr2p, addr, data);
410 if (request == PTRACE_SPARC_DETACH)
411 request = PTRACE_DETACH;
412 ret = ptrace_request(child, request, addr, data);
419 asmlinkage int syscall_trace(struct pt_regs *regs, int syscall_exit_p)
423 if (test_thread_flag(TIF_SYSCALL_TRACE)) {
425 tracehook_report_syscall_exit(regs, 0);
427 ret = tracehook_report_syscall_entry(regs);