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>
25 #include <asm/pgtable.h>
26 #include <asm/system.h>
27 #include <asm/uaccess.h>
29 /* #define ALLOW_INIT_TRACING */
32 * Called by kernel/ptrace.c when detaching..
34 * Make sure single step bits etc are not set.
36 void ptrace_disable(struct task_struct *child)
46 static int genregs32_get(struct task_struct *target,
47 const struct user_regset *regset,
48 unsigned int pos, unsigned int count,
49 void *kbuf, void __user *ubuf)
51 const struct pt_regs *regs = target->thread.kregs;
52 unsigned long __user *reg_window;
53 unsigned long *k = kbuf;
54 unsigned long __user *u = ubuf;
57 if (target == current)
64 for (; count > 0 && pos < 16; count--)
65 *k++ = regs->u_regs[pos++];
67 reg_window = (unsigned long __user *) regs->u_regs[UREG_I6];
68 for (; count > 0 && pos < 32; count--) {
69 if (get_user(*k++, ®_window[pos++]))
73 for (; count > 0 && pos < 16; count--) {
74 if (put_user(regs->u_regs[pos++], u++))
78 reg_window = (unsigned long __user *) regs->u_regs[UREG_I6];
79 for (; count > 0 && pos < 32; count--) {
80 if (get_user(reg, ®_window[pos++]) ||
109 else if (put_user(reg, u++))
116 count *= sizeof(reg);
118 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
119 38 * sizeof(reg), -1);
122 static int genregs32_set(struct task_struct *target,
123 const struct user_regset *regset,
124 unsigned int pos, unsigned int count,
125 const void *kbuf, const void __user *ubuf)
127 struct pt_regs *regs = target->thread.kregs;
128 unsigned long __user *reg_window;
129 const unsigned long *k = kbuf;
130 const unsigned long __user *u = ubuf;
133 if (target == current)
134 flush_user_windows();
137 count /= sizeof(reg);
140 for (; count > 0 && pos < 16; count--)
141 regs->u_regs[pos++] = *k++;
143 reg_window = (unsigned long __user *) regs->u_regs[UREG_I6];
144 for (; count > 0 && pos < 32; count--) {
145 if (put_user(*k++, ®_window[pos++]))
149 for (; count > 0 && pos < 16; count--) {
150 if (get_user(reg, u++))
152 regs->u_regs[pos++] = reg;
155 reg_window = (unsigned long __user *) regs->u_regs[UREG_I6];
156 for (; count > 0 && pos < 32; count--) {
157 if (get_user(reg, u++) ||
158 put_user(reg, ®_window[pos++]))
167 else if (get_user(reg, u++))
174 psr |= (reg & PSR_ICC);
198 count *= sizeof(reg);
200 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
201 38 * sizeof(reg), -1);
204 static int fpregs32_get(struct task_struct *target,
205 const struct user_regset *regset,
206 unsigned int pos, unsigned int count,
207 void *kbuf, void __user *ubuf)
209 const unsigned long *fpregs = target->thread.float_regs;
213 if (target == current)
214 save_and_clear_fpu();
217 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
219 0, 32 * sizeof(u32));
222 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
226 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
234 val = (1 << 8) | (8 << 16);
235 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
242 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
243 35 * sizeof(u32), -1);
248 static int fpregs32_set(struct task_struct *target,
249 const struct user_regset *regset,
250 unsigned int pos, unsigned int count,
251 const void *kbuf, const void __user *ubuf)
253 unsigned long *fpregs = target->thread.float_regs;
257 if (target == current)
258 save_and_clear_fpu();
260 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
262 0, 32 * sizeof(u32));
264 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
267 if (!ret && count > 0) {
268 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
275 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
276 34 * sizeof(u32), -1);
280 static const struct user_regset sparc32_regsets[] = {
286 * PSR, PC, nPC, Y, WIM, TBR
289 .core_note_type = NT_PRSTATUS,
290 .n = 38 * sizeof(u32),
291 .size = sizeof(u32), .align = sizeof(u32),
292 .get = genregs32_get, .set = genregs32_set
298 * FPU QUEUE COUNT (8-bit char)
299 * FPU QUEUE ENTRYSIZE (8-bit char)
300 * FPU ENABLED (8-bit char)
302 * FPU QUEUE (64 32-bit ints)
305 .core_note_type = NT_PRFPREG,
306 .n = 99 * sizeof(u32),
307 .size = sizeof(u32), .align = sizeof(u32),
308 .get = fpregs32_get, .set = fpregs32_set
312 static const struct user_regset_view user_sparc32_view = {
313 .name = "sparc", .e_machine = EM_SPARC,
314 .regsets = sparc32_regsets, .n = ARRAY_SIZE(sparc32_regsets)
317 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
319 return &user_sparc32_view;
322 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
324 unsigned long addr2 = current->thread.kregs->u_regs[UREG_I4];
328 case PTRACE_GETREGS: {
329 struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
330 struct pt_regs *cregs = child->thread.kregs;
333 if (!access_ok(VERIFY_WRITE, pregs, sizeof(struct pt_regs)))
336 __put_user(cregs->psr, (&pregs->psr));
337 __put_user(cregs->pc, (&pregs->pc));
338 __put_user(cregs->npc, (&pregs->npc));
339 __put_user(cregs->y, (&pregs->y));
340 for (i = 1; i < 16; i++)
341 __put_user(cregs->u_regs[i], &pregs->u_regs[i - 1]);
346 case PTRACE_SETREGS: {
347 struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
348 struct pt_regs *cregs = child->thread.kregs;
349 unsigned long psr, pc, npc, y;
351 /* Must be careful, tracing process can only set certain
355 if (!access_ok(VERIFY_READ, pregs, sizeof(struct pt_regs)))
358 __get_user(psr, (&pregs->psr));
359 __get_user(pc, (&pregs->pc));
360 __get_user(npc, (&pregs->npc));
361 __get_user(y, (&pregs->y));
363 cregs->psr &= ~PSR_ICC;
365 if (!((pc | npc) & 3)) {
370 for (i = 1; i < 16; i++)
371 __get_user(cregs->u_regs[i], &pregs->u_regs[i-1]);
376 case PTRACE_GETFPREGS: {
378 unsigned long regs[32];
384 unsigned long *insnaddr;
388 struct fps __user *fps = (struct fps __user *) addr;
391 if (!access_ok(VERIFY_WRITE, fps, sizeof(struct fps)))
394 for (i = 0; i < 32; i++)
395 __put_user(child->thread.float_regs[i], &fps->regs[i]);
396 __put_user(child->thread.fsr, (&fps->fsr));
397 __put_user(child->thread.fpqdepth, (&fps->fpqd));
398 __put_user(0, (&fps->flags));
399 __put_user(0, (&fps->extra));
400 for (i = 0; i < 16; i++) {
401 __put_user(child->thread.fpqueue[i].insn_addr,
402 (&fps->fpq[i].insnaddr));
403 __put_user(child->thread.fpqueue[i].insn,
410 case PTRACE_SETFPREGS: {
412 unsigned long regs[32];
418 unsigned long *insnaddr;
422 struct fps __user *fps = (struct fps __user *) addr;
425 if (!access_ok(VERIFY_READ, fps, sizeof(struct fps)))
428 copy_from_user(&child->thread.float_regs[0], &fps->regs[0],
429 (32 * sizeof(unsigned long)));
430 __get_user(child->thread.fsr, (&fps->fsr));
431 __get_user(child->thread.fpqdepth, (&fps->fpqd));
432 for (i = 0; i < 16; i++) {
433 __get_user(child->thread.fpqueue[i].insn_addr,
434 (&fps->fpq[i].insnaddr));
435 __get_user(child->thread.fpqueue[i].insn,
442 case PTRACE_READTEXT:
443 case PTRACE_READDATA:
444 ret = ptrace_readdata(child, addr,
445 (void __user *) addr2, data);
453 case PTRACE_WRITETEXT:
454 case PTRACE_WRITEDATA:
455 ret = ptrace_writedata(child, (void __user *) addr2,
465 ret = ptrace_request(child, request, addr, data);
472 asmlinkage void syscall_trace(void)
474 if (!test_thread_flag(TIF_SYSCALL_TRACE))
476 if (!(current->ptrace & PT_PTRACED))
478 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
481 * this isn't the same as continuing with a signal, but it will do
482 * for normal use. strace only continues with a signal if the
483 * stopping signal is not SIGTRAP. -brl
485 if (current->exit_code) {
486 send_sig (current->exit_code, current, 1);
487 current->exit_code = 0;