2 * linux/arch/m68k/kernel/ptrace.c
4 * Copyright (C) 1994 by Hamish Macdonald
5 * Taken from linux/kernel/ptrace.c and modified for M680x0.
6 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
8 * This file is subject to the terms and conditions of the GNU General
9 * Public License. See the file COPYING in the main directory of
10 * this archive for more details.
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
16 #include <linux/smp.h>
17 #include <linux/errno.h>
18 #include <linux/ptrace.h>
19 #include <linux/user.h>
20 #include <linux/signal.h>
22 #include <asm/uaccess.h>
24 #include <asm/pgtable.h>
25 #include <asm/system.h>
26 #include <asm/processor.h>
29 * does not yet catch signals sent when the child dies.
30 * in exit.c or in signal.c.
33 /* determines which bits in the SR the user has access to. */
34 /* 1 = access 0 = no access */
35 #define SR_MASK 0x001f
37 /* sets the trace bits. */
38 #define TRACE_BITS 0x8000
40 /* Find the stack offset for a register, relative to thread.esp0. */
41 #define PT_REG(reg) ((long)&((struct pt_regs *)0)->reg)
42 #define SW_REG(reg) ((long)&((struct switch_stack *)0)->reg \
43 - sizeof(struct switch_stack))
44 /* Mapping from PT_xxx to the stack offset at which the register is
45 saved. Notice that usp has no stack-slot and needs to be treated
46 specially (see get_reg/put_reg below). */
47 static int regoff
[] = {
64 [16] = PT_REG(orig_d0
),
70 * Get contents of register REGNO in task TASK.
72 static inline long get_reg(struct task_struct
*task
, int regno
)
77 addr
= &task
->thread
.usp
;
78 else if (regno
< ARRAY_SIZE(regoff
))
79 addr
= (unsigned long *)(task
->thread
.esp0
+ regoff
[regno
]);
86 * Write contents of register REGNO in task TASK.
88 static inline int put_reg(struct task_struct
*task
, int regno
,
94 addr
= &task
->thread
.usp
;
95 else if (regno
< ARRAY_SIZE(regoff
))
96 addr
= (unsigned long *)(task
->thread
.esp0
+ regoff
[regno
]);
104 * Make sure the single step bit is not set.
106 static inline void singlestep_disable(struct task_struct
*child
)
108 unsigned long tmp
= get_reg(child
, PT_SR
) & ~(TRACE_BITS
<< 16);
109 put_reg(child
, PT_SR
, tmp
);
110 clear_tsk_thread_flag(child
, TIF_DELAYED_TRACE
);
114 * Called by kernel/ptrace.c when detaching..
116 void ptrace_disable(struct task_struct
*child
)
118 singlestep_disable(child
);
119 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
122 long arch_ptrace(struct task_struct
*child
, long request
, long addr
, long data
)
128 /* when I and D space are separate, these will need to be fixed. */
129 case PTRACE_PEEKTEXT
: /* read word at location addr. */
130 case PTRACE_PEEKDATA
:
131 ret
= generic_ptrace_peekdata(child
, addr
, data
);
134 /* read the word at location addr in the USER area. */
138 addr
>>= 2; /* temporary hack. */
140 if (addr
>= 0 && addr
< 19) {
141 tmp
= get_reg(child
, addr
);
144 } else if (addr
>= 21 && addr
< 49) {
145 tmp
= child
->thread
.fp
[addr
- 21];
146 /* Convert internal fpu reg representation
147 * into long double format
149 if (FPU_IS_EMU
&& (addr
< 45) && !(addr
% 3))
150 tmp
= ((tmp
& 0xffff0000) << 15) |
151 ((tmp
& 0x0000ffff) << 16);
154 ret
= put_user(tmp
, (unsigned long *)data
);
157 /* when I and D space are separate, this will have to be fixed. */
158 case PTRACE_POKETEXT
: /* write the word at location addr. */
159 case PTRACE_POKEDATA
:
160 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1) != sizeof(data
))
164 case PTRACE_POKEUSR
: /* write the word at location addr in the USER area */
167 addr
>>= 2; /* temporary hack. */
172 data
|= get_reg(child
, PT_SR
) & ~(SR_MASK
<< 16);
173 } else if (addr
>= 0 && addr
< 19) {
174 if (put_reg(child
, addr
, data
))
176 } else if (addr
>= 21 && addr
< 48) {
177 /* Convert long double format
178 * into internal fpu reg representation
180 if (FPU_IS_EMU
&& (addr
< 45) && !(addr
% 3)) {
181 data
= (unsigned long)data
<< 15;
182 data
= (data
& 0xffff0000) |
183 ((data
& 0x0000ffff) >> 1);
185 child
->thread
.fp
[addr
- 21] = data
;
190 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
191 case PTRACE_CONT
: /* restart after signal. */
192 if (!valid_signal(data
))
195 if (request
== PTRACE_SYSCALL
)
196 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
198 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
199 child
->exit_code
= data
;
200 singlestep_disable(child
);
201 wake_up_process(child
);
205 * make the child exit. Best I can do is send it a sigkill.
206 * perhaps it should be put in the status that it wants to
210 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
212 child
->exit_code
= SIGKILL
;
213 singlestep_disable(child
);
214 wake_up_process(child
);
217 case PTRACE_SINGLESTEP
: /* set the trap flag. */
218 if (!valid_signal(data
))
221 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
222 tmp
= get_reg(child
, PT_SR
) | (TRACE_BITS
<< 16);
223 put_reg(child
, PT_SR
, tmp
);
224 set_tsk_thread_flag(child
, TIF_DELAYED_TRACE
);
226 child
->exit_code
= data
;
227 /* give it a chance to run. */
228 wake_up_process(child
);
231 case PTRACE_DETACH
: /* detach a process that was attached. */
232 ret
= ptrace_detach(child
, data
);
235 case PTRACE_GETREGS
: /* Get all gp regs from the child. */
236 for (i
= 0; i
< 19; i
++) {
237 tmp
= get_reg(child
, i
);
240 ret
= put_user(tmp
, (unsigned long *)data
);
243 data
+= sizeof(long);
247 case PTRACE_SETREGS
: /* Set all gp regs in the child. */
248 for (i
= 0; i
< 19; i
++) {
249 ret
= get_user(tmp
, (unsigned long *)data
);
255 tmp
|= get_reg(child
, PT_SR
) & ~(SR_MASK
<< 16);
257 put_reg(child
, i
, tmp
);
258 data
+= sizeof(long);
262 case PTRACE_GETFPREGS
: /* Get the child FPU state. */
263 if (copy_to_user((void *)data
, &child
->thread
.fp
,
264 sizeof(struct user_m68kfp_struct
)))
268 case PTRACE_SETFPREGS
: /* Set the child FPU state. */
269 if (copy_from_user(&child
->thread
.fp
, (void *)data
,
270 sizeof(struct user_m68kfp_struct
)))
275 ret
= ptrace_request(child
, request
, addr
, data
);
284 asmlinkage
void syscall_trace(void)
286 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
289 * this isn't the same as continuing with a signal, but it will do
290 * for normal use. strace only continues with a signal if the
291 * stopping signal is not SIGTRAP. -brl
293 if (current
->exit_code
) {
294 send_sig(current
->exit_code
, current
, 1);
295 current
->exit_code
= 0;