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 0xC000
42 /* Find the stack offset for a register, relative to thread.esp0. */
43 #define PT_REG(reg) ((long)&((struct pt_regs *)0)->reg)
44 #define SW_REG(reg) ((long)&((struct switch_stack *)0)->reg \
45 - sizeof(struct switch_stack))
46 /* Mapping from PT_xxx to the stack offset at which the register is
47 saved. Notice that usp has no stack-slot and needs to be treated
48 specially (see get_reg/put_reg below). */
49 static const int regoff
[] = {
66 [16] = PT_REG(orig_d0
),
72 * Get contents of register REGNO in task TASK.
74 static inline long get_reg(struct task_struct
*task
, int regno
)
79 addr
= &task
->thread
.usp
;
80 else if (regno
< ARRAY_SIZE(regoff
))
81 addr
= (unsigned long *)(task
->thread
.esp0
+ regoff
[regno
]);
84 /* Need to take stkadj into account. */
85 if (regno
== PT_SR
|| regno
== PT_PC
) {
86 long stkadj
= *(long *)(task
->thread
.esp0
+ PT_REG(stkadj
));
87 addr
= (unsigned long *) ((unsigned long)addr
+ stkadj
);
88 /* The sr is actually a 16 bit register. */
90 return *(unsigned short *)addr
;
96 * Write contents of register REGNO in task TASK.
98 static inline int put_reg(struct task_struct
*task
, int regno
,
104 addr
= &task
->thread
.usp
;
105 else if (regno
< ARRAY_SIZE(regoff
))
106 addr
= (unsigned long *)(task
->thread
.esp0
+ regoff
[regno
]);
109 /* Need to take stkadj into account. */
110 if (regno
== PT_SR
|| regno
== PT_PC
) {
111 long stkadj
= *(long *)(task
->thread
.esp0
+ PT_REG(stkadj
));
112 addr
= (unsigned long *) ((unsigned long)addr
+ stkadj
);
113 /* The sr is actually a 16 bit register. */
114 if (regno
== PT_SR
) {
115 *(unsigned short *)addr
= data
;
124 * Make sure the single step bit is not set.
126 static inline void singlestep_disable(struct task_struct
*child
)
128 unsigned long tmp
= get_reg(child
, PT_SR
) & ~TRACE_BITS
;
129 put_reg(child
, PT_SR
, tmp
);
130 clear_tsk_thread_flag(child
, TIF_DELAYED_TRACE
);
134 * Called by kernel/ptrace.c when detaching..
136 void ptrace_disable(struct task_struct
*child
)
138 singlestep_disable(child
);
141 void user_enable_single_step(struct task_struct
*child
)
143 unsigned long tmp
= get_reg(child
, PT_SR
) & ~TRACE_BITS
;
144 put_reg(child
, PT_SR
, tmp
| T1_BIT
);
145 set_tsk_thread_flag(child
, TIF_DELAYED_TRACE
);
148 void user_enable_block_step(struct task_struct
*child
)
150 unsigned long tmp
= get_reg(child
, PT_SR
) & ~TRACE_BITS
;
151 put_reg(child
, PT_SR
, tmp
| T0_BIT
);
154 void user_disable_single_step(struct task_struct
*child
)
156 singlestep_disable(child
);
159 long arch_ptrace(struct task_struct
*child
, long request
,
160 unsigned long addr
, unsigned long data
)
164 int regno
= addr
>> 2; /* temporary hack. */
165 unsigned long __user
*datap
= (unsigned long __user
*) data
;
168 /* read the word at location addr in the USER area. */
173 if (regno
>= 0 && regno
< 19) {
174 tmp
= get_reg(child
, regno
);
175 } else if (regno
>= 21 && regno
< 49) {
176 tmp
= child
->thread
.fp
[regno
- 21];
177 /* Convert internal fpu reg representation
178 * into long double format
180 if (FPU_IS_EMU
&& (regno
< 45) && !(regno
% 3))
181 tmp
= ((tmp
& 0xffff0000) << 15) |
182 ((tmp
& 0x0000ffff) << 16);
185 ret
= put_user(tmp
, datap
);
189 /* write the word at location addr in the USER area */
193 if (regno
== PT_SR
) {
195 data
|= get_reg(child
, PT_SR
) & ~SR_MASK
;
197 if (regno
>= 0 && regno
< 19) {
198 if (put_reg(child
, regno
, data
))
200 } else if (regno
>= 21 && regno
< 48) {
201 /* Convert long double format
202 * into internal fpu reg representation
204 if (FPU_IS_EMU
&& (regno
< 45) && !(regno
% 3)) {
206 data
= (data
& 0xffff0000) |
207 ((data
& 0x0000ffff) >> 1);
209 child
->thread
.fp
[regno
- 21] = data
;
214 case PTRACE_GETREGS
: /* Get all gp regs from the child. */
215 for (i
= 0; i
< 19; i
++) {
216 tmp
= get_reg(child
, i
);
217 ret
= put_user(tmp
, datap
);
224 case PTRACE_SETREGS
: /* Set all gp regs in the child. */
225 for (i
= 0; i
< 19; i
++) {
226 ret
= get_user(tmp
, datap
);
231 tmp
|= get_reg(child
, PT_SR
) & ~SR_MASK
;
233 put_reg(child
, i
, tmp
);
238 case PTRACE_GETFPREGS
: /* Get the child FPU state. */
239 if (copy_to_user(datap
, &child
->thread
.fp
,
240 sizeof(struct user_m68kfp_struct
)))
244 case PTRACE_SETFPREGS
: /* Set the child FPU state. */
245 if (copy_from_user(&child
->thread
.fp
, datap
,
246 sizeof(struct user_m68kfp_struct
)))
250 case PTRACE_GET_THREAD_AREA
:
251 ret
= put_user(task_thread_info(child
)->tp_value
, datap
);
255 ret
= ptrace_request(child
, request
, addr
, data
);
264 asmlinkage
void syscall_trace(void)
266 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
269 * this isn't the same as continuing with a signal, but it will do
270 * for normal use. strace only continues with a signal if the
271 * stopping signal is not SIGTRAP. -brl
273 if (current
->exit_code
) {
274 send_sig(current
->exit_code
, current
, 1);
275 current
->exit_code
= 0;