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
++))
173 psr
&= ~(PSR_ICC
| PSR_SYSCALL
);
174 psr
|= (reg
& (PSR_ICC
| PSR_SYSCALL
));
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
];
325 const struct user_regset_view
*view
;
328 view
= task_user_regset_view(current
);
331 case PTRACE_GETREGS
: {
332 struct pt_regs __user
*pregs
= (struct pt_regs __user
*) addr
;
334 ret
= copy_regset_to_user(child
, view
, REGSET_GENERAL
,
339 copy_regset_to_user(child
, view
, REGSET_GENERAL
,
346 case PTRACE_SETREGS
: {
347 struct pt_regs __user
*pregs
= (struct pt_regs __user
*) addr
;
349 ret
= copy_regset_from_user(child
, view
, REGSET_GENERAL
,
354 copy_regset_from_user(child
, view
, REGSET_GENERAL
,
361 case PTRACE_GETFPREGS
: {
363 unsigned long regs
[32];
369 unsigned long *insnaddr
;
373 struct fps __user
*fps
= (struct fps __user
*) addr
;
375 ret
= copy_regset_to_user(child
, view
, REGSET_FP
,
380 ret
= copy_regset_to_user(child
, view
, REGSET_FP
,
386 if (__put_user(0, &fps
->fpqd
) ||
387 __put_user(0, &fps
->flags
) ||
388 __put_user(0, &fps
->extra
) ||
389 clear_user(fps
->fpq
, sizeof(fps
->fpq
)))
395 case PTRACE_SETFPREGS
: {
397 unsigned long regs
[32];
403 unsigned long *insnaddr
;
407 struct fps __user
*fps
= (struct fps __user
*) addr
;
409 ret
= copy_regset_from_user(child
, view
, REGSET_FP
,
414 ret
= copy_regset_from_user(child
, view
, REGSET_FP
,
421 case PTRACE_READTEXT
:
422 case PTRACE_READDATA
:
423 ret
= ptrace_readdata(child
, addr
,
424 (void __user
*) addr2
, data
);
432 case PTRACE_WRITETEXT
:
433 case PTRACE_WRITEDATA
:
434 ret
= ptrace_writedata(child
, (void __user
*) addr2
,
444 if (request
== PTRACE_SPARC_DETACH
)
445 request
= PTRACE_DETACH
;
446 ret
= ptrace_request(child
, request
, addr
, data
);
453 asmlinkage
void syscall_trace(void)
455 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
457 if (!(current
->ptrace
& PT_PTRACED
))
459 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
462 * this isn't the same as continuing with a signal, but it will do
463 * for normal use. strace only continues with a signal if the
464 * stopping signal is not SIGTRAP. -brl
466 if (current
->exit_code
) {
467 send_sig (current
->exit_code
, current
, 1);
468 current
->exit_code
= 0;