m68knommu: remove local gettimeofday code
[wrt350n-kernel.git] / arch / h8300 / kernel / ptrace.c
blobd32bbf02fc480a75229efc3acc3ac4b808da3959
1 /*
2 * linux/arch/h8300/kernel/ptrace.c
4 * Yoshinori Sato <ysato@users.sourceforge.jp>
6 * Based on:
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>
20 #include <linux/mm.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>
28 #include <asm/page.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.
45 inline
46 static int read_long(struct task_struct * tsk, unsigned long addr,
47 unsigned long * result)
49 *result = *(unsigned long *)addr;
50 return 0;
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)
60 int ret;
62 switch (request) {
63 case PTRACE_PEEKTEXT: /* read word at location addr. */
64 case PTRACE_PEEKDATA: {
65 unsigned long tmp;
67 ret = read_long(child, addr, &tmp);
68 if (ret < 0)
69 break ;
70 ret = put_user(tmp, (unsigned long *) data);
71 break ;
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)) {
79 ret = -EIO;
80 break ;
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);
88 else {
89 switch(addr) {
90 case 49:
91 tmp = child->mm->start_code;
92 break ;
93 case 50:
94 tmp = child->mm->start_data;
95 break ;
96 case 51:
97 tmp = child->mm->end_code;
98 break ;
99 case 52:
100 tmp = child->mm->end_data;
101 break ;
102 default:
103 ret = -EIO;
106 if (!ret)
107 ret = put_user(tmp,(unsigned long *) data);
108 break ;
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);
115 break;
117 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
118 if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) {
119 ret = -EIO;
120 break ;
122 addr = addr >> 2; /* temporary hack. */
124 if (addr == PT_ORIG_ER0) {
125 ret = -EIO;
126 break ;
128 if (addr < H8300_REGS_NO) {
129 ret = h8300_put_reg(child, addr, data);
130 break ;
132 ret = -EIO;
133 break ;
134 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
135 case PTRACE_CONT: { /* restart after signal. */
136 ret = -EIO;
137 if (!valid_signal(data))
138 break ;
139 if (request == PTRACE_SYSCALL)
140 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
141 else
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);
147 ret = 0;
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
153 * exit.
155 case PTRACE_KILL: {
157 ret = 0;
158 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
159 break;
160 child->exit_code = SIGKILL;
161 h8300_disable_trace(child);
162 wake_up_process(child);
163 break;
166 case PTRACE_SINGLESTEP: { /* set the trap flag. */
167 ret = -EIO;
168 if (!valid_signal(data))
169 break;
170 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
171 child->exit_code = data;
172 h8300_enable_trace(child);
173 wake_up_process(child);
174 ret = 0;
175 break;
178 case PTRACE_DETACH: /* detach a process that was attached. */
179 ret = ptrace_detach(child, data);
180 break;
182 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
183 int i;
184 unsigned long tmp;
185 for (i = 0; i < H8300_REGS_NO; i++) {
186 tmp = h8300_get_reg(child, i);
187 if (put_user(tmp, (unsigned long *) data)) {
188 ret = -EFAULT;
189 break;
191 data += sizeof(long);
193 ret = 0;
194 break;
197 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
198 int i;
199 unsigned long tmp;
200 for (i = 0; i < H8300_REGS_NO; i++) {
201 if (get_user(tmp, (unsigned long *) data)) {
202 ret = -EFAULT;
203 break;
205 h8300_put_reg(child, i, tmp);
206 data += sizeof(long);
208 ret = 0;
209 break;
212 default:
213 ret = -EIO;
214 break;
216 return ret;
219 asmlinkage void do_syscall_trace(void)
221 if (!test_thread_flag(TIF_SYSCALL_TRACE))
222 return;
223 if (!(current->ptrace & PT_PTRACED))
224 return;
225 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
226 ? 0x80 : 0));
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;