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>
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
];
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
];
81 for (; count
> 0 && pos
< 32; count
--) {
82 if (get_user(reg
, ®_window
[pos
++]) ||
111 else if (put_user(reg
, u
++))
118 count
*= sizeof(reg
);
120 return user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
121 38 * sizeof(reg
), -1);
124 static int genregs32_set(struct task_struct
*target
,
125 const struct user_regset
*regset
,
126 unsigned int pos
, unsigned int count
,
127 const void *kbuf
, const void __user
*ubuf
)
129 struct pt_regs
*regs
= target
->thread
.kregs
;
130 unsigned long __user
*reg_window
;
131 const unsigned long *k
= kbuf
;
132 const unsigned long __user
*u
= ubuf
;
135 if (target
== current
)
136 flush_user_windows();
139 count
/= sizeof(reg
);
142 for (; count
> 0 && pos
< 16; count
--)
143 regs
->u_regs
[pos
++] = *k
++;
145 reg_window
= (unsigned long __user
*) regs
->u_regs
[UREG_I6
];
147 for (; count
> 0 && pos
< 32; count
--) {
148 if (put_user(*k
++, ®_window
[pos
++]))
152 for (; count
> 0 && pos
< 16; count
--) {
153 if (get_user(reg
, u
++))
155 regs
->u_regs
[pos
++] = reg
;
158 reg_window
= (unsigned long __user
*) regs
->u_regs
[UREG_I6
];
160 for (; count
> 0 && pos
< 32; count
--) {
161 if (get_user(reg
, u
++) ||
162 put_user(reg
, ®_window
[pos
++]))
171 else if (get_user(reg
, u
++))
177 psr
&= ~(PSR_ICC
| PSR_SYSCALL
);
178 psr
|= (reg
& (PSR_ICC
| PSR_SYSCALL
));
202 count
*= sizeof(reg
);
204 return user_regset_copyin_ignore(&pos
, &count
, &kbuf
, &ubuf
,
205 38 * sizeof(reg
), -1);
208 static int fpregs32_get(struct task_struct
*target
,
209 const struct user_regset
*regset
,
210 unsigned int pos
, unsigned int count
,
211 void *kbuf
, void __user
*ubuf
)
213 const unsigned long *fpregs
= target
->thread
.float_regs
;
217 if (target
== current
)
218 save_and_clear_fpu();
221 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
223 0, 32 * sizeof(u32
));
226 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
230 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
238 val
= (1 << 8) | (8 << 16);
239 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
246 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
247 35 * sizeof(u32
), -1);
252 static int fpregs32_set(struct task_struct
*target
,
253 const struct user_regset
*regset
,
254 unsigned int pos
, unsigned int count
,
255 const void *kbuf
, const void __user
*ubuf
)
257 unsigned long *fpregs
= target
->thread
.float_regs
;
261 if (target
== current
)
262 save_and_clear_fpu();
264 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
266 0, 32 * sizeof(u32
));
268 user_regset_copyin_ignore(&pos
, &count
, &kbuf
, &ubuf
,
271 if (!ret
&& count
> 0) {
272 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
279 ret
= user_regset_copyin_ignore(&pos
, &count
, &kbuf
, &ubuf
,
280 34 * sizeof(u32
), -1);
284 static const struct user_regset sparc32_regsets
[] = {
290 * PSR, PC, nPC, Y, WIM, TBR
293 .core_note_type
= NT_PRSTATUS
,
295 .size
= sizeof(u32
), .align
= sizeof(u32
),
296 .get
= genregs32_get
, .set
= genregs32_set
302 * FPU QUEUE COUNT (8-bit char)
303 * FPU QUEUE ENTRYSIZE (8-bit char)
304 * FPU ENABLED (8-bit char)
306 * FPU QUEUE (64 32-bit ints)
309 .core_note_type
= NT_PRFPREG
,
311 .size
= sizeof(u32
), .align
= sizeof(u32
),
312 .get
= fpregs32_get
, .set
= fpregs32_set
316 static const struct user_regset_view user_sparc32_view
= {
317 .name
= "sparc", .e_machine
= EM_SPARC
,
318 .regsets
= sparc32_regsets
, .n
= ARRAY_SIZE(sparc32_regsets
)
321 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
323 return &user_sparc32_view
;
327 unsigned long regs
[32];
333 unsigned long *insnaddr
;
338 long arch_ptrace(struct task_struct
*child
, long request
,
339 unsigned long addr
, unsigned long data
)
341 unsigned long addr2
= current
->thread
.kregs
->u_regs
[UREG_I4
];
343 const struct user_regset_view
*view
;
344 struct pt_regs __user
*pregs
;
345 struct fps __user
*fps
;
348 view
= task_user_regset_view(current
);
349 addr2p
= (void __user
*) addr2
;
350 pregs
= (struct pt_regs __user
*) addr
;
351 fps
= (struct fps __user
*) addr
;
354 case PTRACE_GETREGS
: {
355 ret
= copy_regset_to_user(child
, view
, REGSET_GENERAL
,
360 copy_regset_to_user(child
, view
, REGSET_GENERAL
,
367 case PTRACE_SETREGS
: {
368 ret
= copy_regset_from_user(child
, view
, REGSET_GENERAL
,
373 copy_regset_from_user(child
, view
, REGSET_GENERAL
,
380 case PTRACE_GETFPREGS
: {
381 ret
= copy_regset_to_user(child
, view
, REGSET_FP
,
386 ret
= copy_regset_to_user(child
, view
, REGSET_FP
,
392 if (__put_user(0, &fps
->fpqd
) ||
393 __put_user(0, &fps
->flags
) ||
394 __put_user(0, &fps
->extra
) ||
395 clear_user(fps
->fpq
, sizeof(fps
->fpq
)))
401 case PTRACE_SETFPREGS
: {
402 ret
= copy_regset_from_user(child
, view
, REGSET_FP
,
407 ret
= copy_regset_from_user(child
, view
, REGSET_FP
,
414 case PTRACE_READTEXT
:
415 case PTRACE_READDATA
:
416 ret
= ptrace_readdata(child
, addr
, addr2p
, data
);
424 case PTRACE_WRITETEXT
:
425 case PTRACE_WRITEDATA
:
426 ret
= ptrace_writedata(child
, addr2p
, addr
, data
);
435 if (request
== PTRACE_SPARC_DETACH
)
436 request
= PTRACE_DETACH
;
437 ret
= ptrace_request(child
, request
, addr
, data
);
444 asmlinkage
int syscall_trace(struct pt_regs
*regs
, int syscall_exit_p
)
448 if (test_thread_flag(TIF_SYSCALL_TRACE
)) {
450 tracehook_report_syscall_exit(regs
, 0);
452 ret
= tracehook_report_syscall_entry(regs
);