2 * linux/arch/h8300/kernel/ptrace.c
4 * Yoshinori Sato <ysato@users.sourceforge.jp>
7 * linux/arch/m68k/kernel/ptrace.c
9 * Copyright (C) 1994 by Hamish Macdonald
10 * Taken from linux/kernel/ptrace.c and modified for M680x0.
11 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
13 * This file is subject to the terms and conditions of the GNU General
14 * Public License. See the file COPYING in the main directory of
15 * this archive for more details.
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
21 #include <linux/smp.h>
22 #include <linux/smp_lock.h>
23 #include <linux/errno.h>
24 #include <linux/ptrace.h>
25 #include <linux/user.h>
26 #include <linux/signal.h>
28 #include <asm/uaccess.h>
30 #include <asm/pgtable.h>
31 #include <asm/system.h>
32 #include <asm/processor.h>
33 #include <asm/signal.h>
35 /* cpu depend functions */
36 extern long h8300_get_reg(struct task_struct
*task
, int regno
);
37 extern int h8300_put_reg(struct task_struct
*task
, int regno
, unsigned long data
);
38 extern void h8300_disable_trace(struct task_struct
*child
);
39 extern void h8300_enable_trace(struct task_struct
*child
);
42 * does not yet catch signals sent when the child dies.
43 * in exit.c or in signal.c.
47 static int read_long(struct task_struct
* tsk
, unsigned long addr
,
48 unsigned long * result
)
50 *result
= *(unsigned long *)addr
;
54 void ptrace_disable(struct task_struct
*child
)
56 h8300_disable_trace(child
);
59 long arch_ptrace(struct task_struct
*child
, long request
, long addr
, long data
)
64 case PTRACE_PEEKTEXT
: /* read word at location addr. */
65 case PTRACE_PEEKDATA
: {
68 ret
= read_long(child
, addr
, &tmp
);
71 ret
= put_user(tmp
, (unsigned long *) data
);
75 /* read the word at location addr in the USER area. */
76 case PTRACE_PEEKUSR
: {
77 unsigned long tmp
= 0;
79 if ((addr
& 3) || addr
< 0 || addr
>= sizeof(struct user
)) {
84 ret
= 0; /* Default return condition */
85 addr
= addr
>> 2; /* temporary hack. */
87 if (addr
< H8300_REGS_NO
)
88 tmp
= h8300_get_reg(child
, addr
);
92 tmp
= child
->mm
->start_code
;
95 tmp
= child
->mm
->start_data
;
98 tmp
= child
->mm
->end_code
;
101 tmp
= child
->mm
->end_data
;
108 ret
= put_user(tmp
,(unsigned long *) data
);
112 /* when I and D space are separate, this will have to be fixed. */
113 case PTRACE_POKETEXT
: /* write the word at location addr. */
114 case PTRACE_POKEDATA
:
116 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1) == sizeof(data
))
121 case PTRACE_POKEUSR
: /* write the word at location addr in the USER area */
122 if ((addr
& 3) || addr
< 0 || addr
>= sizeof(struct user
)) {
126 addr
= addr
>> 2; /* temporary hack. */
128 if (addr
== PT_ORIG_ER0
) {
132 if (addr
< H8300_REGS_NO
) {
133 ret
= h8300_put_reg(child
, addr
, data
);
138 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
139 case PTRACE_CONT
: { /* restart after signal. */
141 if (!valid_signal(data
))
143 if (request
== PTRACE_SYSCALL
)
144 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
146 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
147 child
->exit_code
= data
;
148 wake_up_process(child
);
149 /* make sure the single step bit is not set. */
150 h8300_disable_trace(child
);
155 * make the child exit. Best I can do is send it a sigkill.
156 * perhaps it should be put in the status that it wants to
162 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
164 child
->exit_code
= SIGKILL
;
165 h8300_disable_trace(child
);
166 wake_up_process(child
);
170 case PTRACE_SINGLESTEP
: { /* set the trap flag. */
172 if (!valid_signal(data
))
174 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
175 child
->exit_code
= data
;
176 h8300_enable_trace(child
);
177 wake_up_process(child
);
182 case PTRACE_DETACH
: /* detach a process that was attached. */
183 ret
= ptrace_detach(child
, data
);
186 case PTRACE_GETREGS
: { /* Get all gp regs from the child. */
189 for (i
= 0; i
< H8300_REGS_NO
; i
++) {
190 tmp
= h8300_get_reg(child
, i
);
191 if (put_user(tmp
, (unsigned long *) data
)) {
195 data
+= sizeof(long);
201 case PTRACE_SETREGS
: { /* Set all gp regs in the child. */
204 for (i
= 0; i
< H8300_REGS_NO
; i
++) {
205 if (get_user(tmp
, (unsigned long *) data
)) {
209 h8300_put_reg(child
, i
, tmp
);
210 data
+= sizeof(long);
223 asmlinkage
void syscall_trace(void)
225 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
227 if (!(current
->ptrace
& PT_PTRACED
))
229 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
232 * this isn't the same as continuing with a signal, but it will do
233 * for normal use. strace only continues with a signal if the
234 * stopping signal is not SIGTRAP. -brl
236 if (current
->exit_code
) {
237 send_sig(current
->exit_code
, current
, 1);
238 current
->exit_code
= 0;