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:
115 if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))
120 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
121 if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) {
125 addr = addr >> 2; /* temporary hack. */
127 if (addr == PT_ORIG_ER0) {
131 if (addr < H8300_REGS_NO) {
132 ret = h8300_put_reg(child, addr, data);
137 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
138 case PTRACE_CONT: { /* restart after signal. */
140 if (!valid_signal(data))
142 if (request == PTRACE_SYSCALL)
143 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
145 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
146 child->exit_code = data;
147 wake_up_process(child);
148 /* make sure the single step bit is not set. */
149 h8300_disable_trace(child);
154 * make the child exit. Best I can do is send it a sigkill.
155 * perhaps it should be put in the status that it wants to
161 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
163 child->exit_code = SIGKILL;
164 h8300_disable_trace(child);
165 wake_up_process(child);
169 case PTRACE_SINGLESTEP: { /* set the trap flag. */
171 if (!valid_signal(data))
173 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
174 child->exit_code = data;
175 h8300_enable_trace(child);
176 wake_up_process(child);
181 case PTRACE_DETACH: /* detach a process that was attached. */
182 ret = ptrace_detach(child, data);
185 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
188 for (i = 0; i < H8300_REGS_NO; i++) {
189 tmp = h8300_get_reg(child, i);
190 if (put_user(tmp, (unsigned long *) data)) {
194 data += sizeof(long);
200 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
203 for (i = 0; i < H8300_REGS_NO; i++) {
204 if (get_user(tmp, (unsigned long *) data)) {
208 h8300_put_reg(child, i, tmp);
209 data += sizeof(long);
222 asmlinkage void syscall_trace(void)
224 if (!test_thread_flag(TIF_SYSCALL_TRACE))
226 if (!(current->ptrace & PT_PTRACED))
228 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
231 * this isn't the same as continuing with a signal, but it will do
232 * for normal use. strace only continues with a signal if the
233 * stopping signal is not SIGTRAP. -brl
235 if (current->exit_code) {
236 send_sig(current->exit_code, current, 1);
237 current->exit_code = 0;