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/smp_lock.h>
20 #include <linux/security.h>
21 #include <linux/signal.h>
22 #include <linux/regset.h>
23 #include <linux/elf.h>
24 #include <linux/tracehook.h>
26 #include <asm/pgtable.h>
27 #include <asm/system.h>
28 #include <asm/uaccess.h>
30 /* #define ALLOW_INIT_TRACING */
33 * Called by kernel/ptrace.c when detaching..
35 * Make sure single step bits etc are not set.
37 void ptrace_disable(struct task_struct *child)
47 static int genregs32_get(struct task_struct *target,
48 const struct user_regset *regset,
49 unsigned int pos, unsigned int count,
50 void *kbuf, void __user *ubuf)
52 const struct pt_regs *regs = target->thread.kregs;
53 unsigned long __user *reg_window;
54 unsigned long *k = kbuf;
55 unsigned long __user *u = ubuf;
58 if (target == current)
65 for (; count > 0 && pos < 16; count--)
66 *k++ = regs->u_regs[pos++];
68 reg_window = (unsigned long __user *) regs->u_regs[UREG_I6];
69 for (; count > 0 && pos < 32; count--) {
70 if (get_user(*k++, ®_window[pos++]))
74 for (; count > 0 && pos < 16; count--) {
75 if (put_user(regs->u_regs[pos++], u++))
79 reg_window = (unsigned long __user *) regs->u_regs[UREG_I6];
80 for (; count > 0 && pos < 32; count--) {
81 if (get_user(reg, ®_window[pos++]) ||
110 else if (put_user(reg, u++))
117 count *= sizeof(reg);
119 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
120 38 * sizeof(reg), -1);
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;
129 unsigned long __user *reg_window;
130 const unsigned long *k = kbuf;
131 const unsigned long __user *u = ubuf;
134 if (target == current)
135 flush_user_windows();
138 count /= sizeof(reg);
141 for (; count > 0 && pos < 16; count--)
142 regs->u_regs[pos++] = *k++;
144 reg_window = (unsigned long __user *) regs->u_regs[UREG_I6];
145 for (; count > 0 && pos < 32; count--) {
146 if (put_user(*k++, ®_window[pos++]))
150 for (; count > 0 && pos < 16; count--) {
151 if (get_user(reg, u++))
153 regs->u_regs[pos++] = reg;
156 reg_window = (unsigned long __user *) regs->u_regs[UREG_I6];
157 for (; count > 0 && pos < 32; count--) {
158 if (get_user(reg, u++) ||
159 put_user(reg, ®_window[pos++]))
168 else if (get_user(reg, u++))
174 psr &= ~(PSR_ICC | PSR_SYSCALL);
175 psr |= (reg & (PSR_ICC | PSR_SYSCALL));
199 count *= sizeof(reg);
201 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
202 38 * sizeof(reg), -1);
205 static int fpregs32_get(struct task_struct *target,
206 const struct user_regset *regset,
207 unsigned int pos, unsigned int count,
208 void *kbuf, void __user *ubuf)
210 const unsigned long *fpregs = target->thread.float_regs;
214 if (target == current)
215 save_and_clear_fpu();
218 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
220 0, 32 * sizeof(u32));
223 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
227 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
235 val = (1 << 8) | (8 << 16);
236 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
243 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
244 35 * sizeof(u32), -1);
249 static int fpregs32_set(struct task_struct *target,
250 const struct user_regset *regset,
251 unsigned int pos, unsigned int count,
252 const void *kbuf, const void __user *ubuf)
254 unsigned long *fpregs = target->thread.float_regs;
258 if (target == current)
259 save_and_clear_fpu();
261 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
263 0, 32 * sizeof(u32));
265 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
268 if (!ret && count > 0) {
269 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
276 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
277 34 * sizeof(u32), -1);
281 static const struct user_regset sparc32_regsets[] = {
287 * PSR, PC, nPC, Y, WIM, TBR
290 .core_note_type = NT_PRSTATUS,
291 .n = 38 * sizeof(u32),
292 .size = sizeof(u32), .align = sizeof(u32),
293 .get = genregs32_get, .set = genregs32_set
299 * FPU QUEUE COUNT (8-bit char)
300 * FPU QUEUE ENTRYSIZE (8-bit char)
301 * FPU ENABLED (8-bit char)
303 * FPU QUEUE (64 32-bit ints)
306 .core_note_type = NT_PRFPREG,
307 .n = 99 * sizeof(u32),
308 .size = sizeof(u32), .align = sizeof(u32),
309 .get = fpregs32_get, .set = fpregs32_set
313 static const struct user_regset_view user_sparc32_view = {
314 .name = "sparc", .e_machine = EM_SPARC,
315 .regsets = sparc32_regsets, .n = ARRAY_SIZE(sparc32_regsets)
318 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
320 return &user_sparc32_view;
323 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
325 unsigned long addr2 = current->thread.kregs->u_regs[UREG_I4];
326 const struct user_regset_view *view;
329 view = task_user_regset_view(current);
332 case PTRACE_GETREGS: {
333 struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
335 ret = copy_regset_to_user(child, view, REGSET_GENERAL,
340 copy_regset_to_user(child, view, REGSET_GENERAL,
347 case PTRACE_SETREGS: {
348 struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
350 ret = copy_regset_from_user(child, view, REGSET_GENERAL,
355 copy_regset_from_user(child, view, REGSET_GENERAL,
362 case PTRACE_GETFPREGS: {
364 unsigned long regs[32];
370 unsigned long *insnaddr;
374 struct fps __user *fps = (struct fps __user *) addr;
376 ret = copy_regset_to_user(child, view, REGSET_FP,
381 ret = copy_regset_to_user(child, view, REGSET_FP,
387 if (__put_user(0, &fps->fpqd) ||
388 __put_user(0, &fps->flags) ||
389 __put_user(0, &fps->extra) ||
390 clear_user(fps->fpq, sizeof(fps->fpq)))
396 case PTRACE_SETFPREGS: {
398 unsigned long regs[32];
404 unsigned long *insnaddr;
408 struct fps __user *fps = (struct fps __user *) addr;
410 ret = copy_regset_from_user(child, view, REGSET_FP,
415 ret = copy_regset_from_user(child, view, REGSET_FP,
422 case PTRACE_READTEXT:
423 case PTRACE_READDATA:
424 ret = ptrace_readdata(child, addr,
425 (void __user *) addr2, data);
433 case PTRACE_WRITETEXT:
434 case PTRACE_WRITEDATA:
435 ret = ptrace_writedata(child, (void __user *) addr2,
445 if (request == PTRACE_SPARC_DETACH)
446 request = PTRACE_DETACH;
447 ret = ptrace_request(child, request, addr, data);
454 asmlinkage int syscall_trace(struct pt_regs *regs, int syscall_exit_p)
458 if (test_thread_flag(TIF_SYSCALL_TRACE)) {
460 tracehook_report_syscall_exit(regs, 0);
462 ret = tracehook_report_syscall_entry(regs);