2 * linux/arch/m68knommu/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/smp_lock.h>
18 #include <linux/errno.h>
19 #include <linux/ptrace.h>
20 #include <linux/user.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 0x00000000
37 /* Find the stack offset for a register, relative to thread.ksp. */
38 #define PT_REG(reg) ((long)&((struct pt_regs *)0)->reg)
39 #define SW_REG(reg) ((long)&((struct switch_stack *)0)->reg \
40 - sizeof(struct switch_stack))
41 /* Mapping from PT_xxx to the stack offset at which the register is
42 saved. Notice that usp has no stack-slot and needs to be treated
43 specially (see get_reg/put_reg below). */
44 static int regoff
[] = {
45 -1, PT_REG(r1
), PT_REG(r2
), PT_REG(r3
), PT_REG(r4
),
46 PT_REG(r5
), PT_REG(r6
), PT_REG(r7
), PT_REG(r8
),
47 PT_REG(r9
), PT_REG(r10
), PT_REG(r11
), PT_REG(r12
),
48 PT_REG(r13
), PT_REG(r14
), PT_REG(r15
), SW_REG(r16
),
49 SW_REG(r17
), SW_REG(r18
), SW_REG(r19
), SW_REG(r20
),
50 SW_REG(r21
), SW_REG(r22
), SW_REG(r23
), -1, -1,
51 PT_REG(gp
), PT_REG(sp
), -1, -1, PT_REG(ra
), -1,
52 PT_REG(estatus
), -1, -1, -1
56 * Get contents of register REGNO in task TASK.
58 static inline long get_reg(struct task_struct
*task
, int regno
)
64 else if (regno
== PTR_BA
)
66 else if (regno
== PTR_STATUS
)
68 else if (regno
== PTR_IENABLE
)
70 else if (regno
== PTR_IPENDING
)
72 else if (regno
< sizeof(regoff
)/sizeof(regoff
[0]))
73 addr
= (unsigned long *)(task
->thread
.kregs
+ regoff
[regno
]);
80 * Write contents of register REGNO in task TASK.
82 static inline int put_reg(struct task_struct
*task
, int regno
,
89 else if (regno
== PTR_BA
)
91 else if (regno
== PTR_STATUS
)
93 else if (regno
== PTR_IENABLE
)
95 else if (regno
== PTR_IPENDING
)
97 else if (regno
< sizeof(regoff
)/sizeof(regoff
[0]))
98 addr
= (unsigned long *) (task
->thread
.kregs
+ regoff
[regno
]);
106 * Called by kernel/ptrace.c when detaching..
108 * Nothing special to do here, no processor debug support.
110 void ptrace_disable(struct task_struct
*child
)
114 long arch_ptrace(struct task_struct
*child
, long request
, long addr
, long data
)
119 /* when I and D space are separate, these will need to be fixed. */
120 case PTRACE_PEEKTEXT
: /* read word at location addr. */
121 case PTRACE_PEEKDATA
: {
125 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
127 if (copied
!= sizeof(tmp
))
129 ret
= put_user(tmp
,(unsigned long *) data
);
133 /* read the word at location addr in the USER area. */
134 case PTRACE_PEEKUSR
: {
138 if ((addr
& 3) || addr
< 0 ||
139 addr
> sizeof(struct user
) - 3)
142 tmp
= 0; /* Default return condition */
143 addr
= addr
>> 2; /* temporary hack. */
146 tmp
= get_reg(child
, addr
);
147 #if 0 // No FPU stuff
148 } else if (addr
>= 21 && addr
< 49) {
149 tmp
= child
->thread
.fp
[addr
- 21];
150 #ifdef CONFIG_M68KFPU_EMU
151 /* Convert internal fpu reg representation
152 * into long double format
154 if (FPU_IS_EMU
&& (addr
< 45) && !(addr
% 3))
155 tmp
= ((tmp
& 0xffff0000) << 15) |
156 ((tmp
& 0x0000ffff) << 16);
159 } else if (addr
== 49) {
160 tmp
= child
->mm
->start_code
;
161 } else if (addr
== 50) {
162 tmp
= child
->mm
->start_data
;
163 } else if (addr
== 51) {
164 tmp
= child
->mm
->end_code
;
167 ret
= put_user(tmp
,(unsigned long *) data
);
171 /* when I and D space are separate, this will have to be fixed. */
172 case PTRACE_POKETEXT
: /* write the word at location addr. */
173 case PTRACE_POKEDATA
:
175 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1) == sizeof(data
))
180 case PTRACE_POKEUSR
: /* write the word at location addr in the USER area */
182 if ((addr
& 3) || addr
< 0 ||
183 addr
> sizeof(struct user
) - 3)
186 addr
= addr
>> 2; /* temporary hack. */
188 if (addr
== PTR_ESTATUS
) {
190 data
|= get_reg(child
, PTR_ESTATUS
) & ~(SR_MASK
);
193 if (put_reg(child
, addr
, data
))
198 #if 0 // No FPU stuff
199 if (addr
>= 21 && addr
< 48)
201 #ifdef CONFIG_M68KFPU_EMU
202 /* Convert long double format
203 * into internal fpu reg representation
205 if (FPU_IS_EMU
&& (addr
< 45) && !(addr
% 3)) {
206 data
= (unsigned long)data
<< 15;
207 data
= (data
& 0xffff0000) |
208 ((data
& 0x0000ffff) >> 1);
211 child
->thread
.fp
[addr
- 21] = data
;
217 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
218 case PTRACE_CONT
: { /* restart after signal. */
221 if ((unsigned long) data
> _NSIG
)
223 if (request
== PTRACE_SYSCALL
)
224 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
226 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
227 child
->exit_code
= data
;
228 wake_up_process(child
);
234 * make the child exit. Best I can do is send it a sigkill.
235 * perhaps it should be put in the status that it wants to
241 if (child
->state
== EXIT_ZOMBIE
) /* already dead */
243 child
->exit_code
= SIGKILL
;
244 wake_up_process(child
);
249 * Single stepping requires placing break instructions in
250 * the code to break back. If you are stepping through a
251 * conditional branch you need to decode the test and put
252 * the break in the correct location.
254 case PTRACE_SINGLESTEP
: { /* set the trap flag. */
257 if ((unsigned long) data
> _NSIG
)
259 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
261 child
->exit_code
= data
;
262 /* give it a chance to run. */
263 wake_up_process(child
);
268 case PTRACE_DETACH
: /* detach a process that was attached. */
269 ret
= ptrace_detach(child
, data
);
272 case PTRACE_GETREGS
: { /* Get all gp regs from the child. */
275 for (i
= 0; i
< 19; i
++) {
276 tmp
= get_reg(child
, i
);
277 if (put_user(tmp
, (unsigned long *) data
)) {
281 data
+= sizeof(long);
287 case PTRACE_SETREGS
: { /* Set all gp regs in the child. */
290 for (i
= 0; i
< 19; i
++) {
291 if (get_user(tmp
, (unsigned long *) data
)) {
295 if (i
== PTR_ESTATUS
) {
297 tmp
|= get_reg(child
, PTR_ESTATUS
) & ~(SR_MASK
);
299 put_reg(child
, i
, tmp
);
300 data
+= sizeof(long);
306 #ifdef PTRACE_GETFPREGS
307 case PTRACE_GETFPREGS
: { /* Get the child FPU state. */
309 if (copy_to_user((void *)data
, &child
->thread
.fp
,
310 sizeof(struct user_m68kfp_struct
)))
316 #ifdef PTRACE_SETFPREGS
317 case PTRACE_SETFPREGS
: { /* Set the child FPU state. */
319 if (copy_from_user(&child
->thread
.fp
, (void *)data
,
320 sizeof(struct user_m68kfp_struct
)))
333 asmlinkage
void syscall_trace(void)
335 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
337 if (!(current
->ptrace
& PT_PTRACED
))
339 current
->exit_code
= SIGTRAP
;
340 current
->state
= TASK_STOPPED
;
341 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
344 * this isn't the same as continuing with a signal, but it will do
345 * for normal use. strace only continues with a signal if the
346 * stopping signal is not SIGTRAP. -brl
348 if (current
->exit_code
) {
349 send_sig(current
->exit_code
, current
, 1);
350 current
->exit_code
= 0;