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/errno.h>
23 #include <linux/ptrace.h>
24 #include <linux/user.h>
25 #include <linux/signal.h>
27 #include <asm/uaccess.h>
29 #include <asm/pgtable.h>
30 #include <asm/system.h>
31 #include <asm/processor.h>
32 #include <asm/signal.h>
34 /* cpu depend functions */
35 extern long h8300_get_reg(struct task_struct *task, int regno);
36 extern int h8300_put_reg(struct task_struct *task, int regno, unsigned long data);
37 extern void h8300_disable_trace(struct task_struct *child);
38 extern void h8300_enable_trace(struct task_struct *child);
41 * does not yet catch signals sent when the child dies.
42 * in exit.c or in signal.c.
46 static int read_long(struct task_struct * tsk, unsigned long addr,
47 unsigned long * result)
49 *result = *(unsigned long *)addr;
53 void ptrace_disable(struct task_struct *child)
55 h8300_disable_trace(child);
58 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
63 case PTRACE_PEEKTEXT: /* read word at location addr. */
64 case PTRACE_PEEKDATA: {
67 ret = read_long(child, addr, &tmp);
70 ret = put_user(tmp, (unsigned long *) data);
74 /* read the word at location addr in the USER area. */
75 case PTRACE_PEEKUSR: {
76 unsigned long tmp = 0;
78 if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) {
83 ret = 0; /* Default return condition */
84 addr = addr >> 2; /* temporary hack. */
86 if (addr < H8300_REGS_NO)
87 tmp = h8300_get_reg(child, addr);
91 tmp = child->mm->start_code;
94 tmp = child->mm->start_data;
97 tmp = child->mm->end_code;
100 tmp = child->mm->end_data;
107 ret = put_user(tmp,(unsigned long *) data);
111 /* when I and D space are separate, this will have to be fixed. */
112 case PTRACE_POKETEXT: /* write the word at location addr. */
113 case PTRACE_POKEDATA:
114 ret = generic_ptrace_pokedata(child, addr, data);
117 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
118 if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) {
122 addr = addr >> 2; /* temporary hack. */
124 if (addr == PT_ORIG_ER0) {
128 if (addr < H8300_REGS_NO) {
129 ret = h8300_put_reg(child, addr, data);
134 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
135 case PTRACE_CONT: { /* restart after signal. */
137 if (!valid_signal(data))
139 if (request == PTRACE_SYSCALL)
140 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
142 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
143 child->exit_code = data;
144 wake_up_process(child);
145 /* make sure the single step bit is not set. */
146 h8300_disable_trace(child);
151 * make the child exit. Best I can do is send it a sigkill.
152 * perhaps it should be put in the status that it wants to
158 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
160 child->exit_code = SIGKILL;
161 h8300_disable_trace(child);
162 wake_up_process(child);
166 case PTRACE_SINGLESTEP: { /* set the trap flag. */
168 if (!valid_signal(data))
170 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
171 child->exit_code = data;
172 h8300_enable_trace(child);
173 wake_up_process(child);
178 case PTRACE_DETACH: /* detach a process that was attached. */
179 ret = ptrace_detach(child, data);
182 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
185 for (i = 0; i < H8300_REGS_NO; i++) {
186 tmp = h8300_get_reg(child, i);
187 if (put_user(tmp, (unsigned long *) data)) {
191 data += sizeof(long);
197 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
200 for (i = 0; i < H8300_REGS_NO; i++) {
201 if (get_user(tmp, (unsigned long *) data)) {
205 h8300_put_reg(child, i, tmp);
206 data += sizeof(long);
219 asmlinkage void do_syscall_trace(void)
221 if (!test_thread_flag(TIF_SYSCALL_TRACE))
223 if (!(current->ptrace & PT_PTRACED))
225 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
228 * this isn't the same as continuing with a signal, but it will do
229 * for normal use. strace only continues with a signal if the
230 * stopping signal is not SIGTRAP. -brl
232 if (current->exit_code) {
233 send_sig(current->exit_code, current, 1);
234 current->exit_code = 0;