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>
21 #include <linux/tracehook.h>
23 #include <asm/uaccess.h>
25 #include <asm/pgtable.h>
26 #include <asm/system.h>
27 #include <asm/processor.h>
30 * does not yet catch signals sent when the child dies.
31 * in exit.c or in signal.c.
34 /* determines which bits in the SR the user has access to. */
35 /* 1 = access 0 = no access */
36 #define SR_MASK 0x001f
38 /* sets the trace bits. */
39 #define TRACE_BITS 0xC000
43 /* Find the stack offset for a register, relative to thread.esp0. */
44 #define PT_REG(reg) ((long)&((struct pt_regs *)0)->reg)
45 #define SW_REG(reg) ((long)&((struct switch_stack *)0)->reg \
46 - sizeof(struct switch_stack))
47 /* Mapping from PT_xxx to the stack offset at which the register is
48 saved. Notice that usp has no stack-slot and needs to be treated
49 specially (see get_reg/put_reg below). */
50 static const int regoff
[] = {
67 [16] = PT_REG(orig_d0
),
73 * Get contents of register REGNO in task TASK.
75 static inline long get_reg(struct task_struct
*task
, int regno
)
80 addr
= &task
->thread
.usp
;
81 else if (regno
< ARRAY_SIZE(regoff
))
82 addr
= (unsigned long *)(task
->thread
.esp0
+ regoff
[regno
]);
85 /* Need to take stkadj into account. */
86 if (regno
== PT_SR
|| regno
== PT_PC
) {
87 long stkadj
= *(long *)(task
->thread
.esp0
+ PT_REG(stkadj
));
88 addr
= (unsigned long *) ((unsigned long)addr
+ stkadj
);
89 /* The sr is actually a 16 bit register. */
91 return *(unsigned short *)addr
;
97 * Write contents of register REGNO in task TASK.
99 static inline int put_reg(struct task_struct
*task
, int regno
,
105 addr
= &task
->thread
.usp
;
106 else if (regno
< ARRAY_SIZE(regoff
))
107 addr
= (unsigned long *)(task
->thread
.esp0
+ regoff
[regno
]);
110 /* Need to take stkadj into account. */
111 if (regno
== PT_SR
|| regno
== PT_PC
) {
112 long stkadj
= *(long *)(task
->thread
.esp0
+ PT_REG(stkadj
));
113 addr
= (unsigned long *) ((unsigned long)addr
+ stkadj
);
114 /* The sr is actually a 16 bit register. */
115 if (regno
== PT_SR
) {
116 *(unsigned short *)addr
= data
;
125 * Make sure the single step bit is not set.
127 static inline void singlestep_disable(struct task_struct
*child
)
129 unsigned long tmp
= get_reg(child
, PT_SR
) & ~TRACE_BITS
;
130 put_reg(child
, PT_SR
, tmp
);
131 clear_tsk_thread_flag(child
, TIF_DELAYED_TRACE
);
135 * Called by kernel/ptrace.c when detaching..
137 void ptrace_disable(struct task_struct
*child
)
139 singlestep_disable(child
);
142 void user_enable_single_step(struct task_struct
*child
)
144 unsigned long tmp
= get_reg(child
, PT_SR
) & ~TRACE_BITS
;
145 put_reg(child
, PT_SR
, tmp
| T1_BIT
);
146 set_tsk_thread_flag(child
, TIF_DELAYED_TRACE
);
149 void user_enable_block_step(struct task_struct
*child
)
151 unsigned long tmp
= get_reg(child
, PT_SR
) & ~TRACE_BITS
;
152 put_reg(child
, PT_SR
, tmp
| T0_BIT
);
155 void user_disable_single_step(struct task_struct
*child
)
157 singlestep_disable(child
);
160 long arch_ptrace(struct task_struct
*child
, long request
,
161 unsigned long addr
, unsigned long data
)
165 int regno
= addr
>> 2; /* temporary hack. */
166 unsigned long __user
*datap
= (unsigned long __user
*) data
;
169 /* read the word at location addr in the USER area. */
174 if (regno
>= 0 && regno
< 19) {
175 tmp
= get_reg(child
, regno
);
176 } else if (regno
>= 21 && regno
< 49) {
177 tmp
= child
->thread
.fp
[regno
- 21];
178 /* Convert internal fpu reg representation
179 * into long double format
181 if (FPU_IS_EMU
&& (regno
< 45) && !(regno
% 3))
182 tmp
= ((tmp
& 0xffff0000) << 15) |
183 ((tmp
& 0x0000ffff) << 16);
186 ret
= put_user(tmp
, datap
);
190 /* write the word at location addr in the USER area */
194 if (regno
== PT_SR
) {
196 data
|= get_reg(child
, PT_SR
) & ~SR_MASK
;
198 if (regno
>= 0 && regno
< 19) {
199 if (put_reg(child
, regno
, data
))
201 } else if (regno
>= 21 && regno
< 48) {
202 /* Convert long double format
203 * into internal fpu reg representation
205 if (FPU_IS_EMU
&& (regno
< 45) && !(regno
% 3)) {
207 data
= (data
& 0xffff0000) |
208 ((data
& 0x0000ffff) >> 1);
210 child
->thread
.fp
[regno
- 21] = data
;
215 case PTRACE_GETREGS
: /* Get all gp regs from the child. */
216 for (i
= 0; i
< 19; i
++) {
217 tmp
= get_reg(child
, i
);
218 ret
= put_user(tmp
, datap
);
225 case PTRACE_SETREGS
: /* Set all gp regs in the child. */
226 for (i
= 0; i
< 19; i
++) {
227 ret
= get_user(tmp
, datap
);
232 tmp
|= get_reg(child
, PT_SR
) & ~SR_MASK
;
234 put_reg(child
, i
, tmp
);
239 case PTRACE_GETFPREGS
: /* Get the child FPU state. */
240 if (copy_to_user(datap
, &child
->thread
.fp
,
241 sizeof(struct user_m68kfp_struct
)))
245 case PTRACE_SETFPREGS
: /* Set the child FPU state. */
246 if (copy_from_user(&child
->thread
.fp
, datap
,
247 sizeof(struct user_m68kfp_struct
)))
251 case PTRACE_GET_THREAD_AREA
:
252 ret
= put_user(task_thread_info(child
)->tp_value
, datap
);
256 ret
= ptrace_request(child
, request
, addr
, data
);
265 asmlinkage
void syscall_trace(void)
267 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
270 * this isn't the same as continuing with a signal, but it will do
271 * for normal use. strace only continues with a signal if the
272 * stopping signal is not SIGTRAP. -brl
274 if (current
->exit_code
) {
275 send_sig(current
->exit_code
, current
, 1);
276 current
->exit_code
= 0;
280 #ifdef CONFIG_COLDFIRE
281 asmlinkage
int syscall_trace_enter(void)
285 if (test_thread_flag(TIF_SYSCALL_TRACE
))
286 ret
= tracehook_report_syscall_entry(task_pt_regs(current
));
290 asmlinkage
void syscall_trace_leave(void)
292 if (test_thread_flag(TIF_SYSCALL_TRACE
))
293 tracehook_report_syscall_exit(task_pt_regs(current
), 0);
295 #endif /* CONFIG_COLDFIRE */