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/smp_lock.h>
18 #include <linux/errno.h>
19 #include <linux/ptrace.h>
20 #include <linux/user.h>
21 #include <linux/signal.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 0x8000
41 /* Find the stack offset for a register, relative to thread.esp0. */
42 #define PT_REG(reg) ((long)&((struct pt_regs *)0)->reg)
43 #define SW_REG(reg) ((long)&((struct switch_stack *)0)->reg \
44 - sizeof(struct switch_stack))
45 /* Mapping from PT_xxx to the stack offset at which the register is
46 saved. Notice that usp has no stack-slot and needs to be treated
47 specially (see get_reg/put_reg below). */
48 static int regoff[] = {
65 [16] = PT_REG(orig_d0),
71 * Get contents of register REGNO in task TASK.
73 static inline long get_reg(struct task_struct *task, int regno)
78 addr = &task->thread.usp;
79 else if (regno < sizeof(regoff)/sizeof(regoff[0]))
80 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
87 * Write contents of register REGNO in task TASK.
89 static inline int put_reg(struct task_struct *task, int regno,
95 addr = &task->thread.usp;
96 else if (regno < sizeof(regoff)/sizeof(regoff[0]))
97 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
105 * Make sure the single step bit is not set.
107 static inline void singlestep_disable(struct task_struct *child)
109 unsigned long tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16);
110 put_reg(child, PT_SR, tmp);
111 clear_tsk_thread_flag(child, TIF_DELAYED_TRACE);
115 * Called by kernel/ptrace.c when detaching..
117 void ptrace_disable(struct task_struct *child)
119 singlestep_disable(child);
120 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
123 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
129 /* when I and D space are separate, these will need to be fixed. */
130 case PTRACE_PEEKTEXT: /* read word at location addr. */
131 case PTRACE_PEEKDATA:
132 i = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
133 if (i != sizeof(tmp))
135 ret = put_user(tmp, (unsigned long *)data);
138 /* read the word at location addr in the USER area. */
142 addr >>= 2; /* temporary hack. */
144 if (addr >= 0 && addr < 19) {
145 tmp = get_reg(child, addr);
148 } else if (addr >= 21 && addr < 49) {
149 tmp = child->thread.fp[addr - 21];
150 /* Convert internal fpu reg representation
151 * into long double format
153 if (FPU_IS_EMU && (addr < 45) && !(addr % 3))
154 tmp = ((tmp & 0xffff0000) << 15) |
155 ((tmp & 0x0000ffff) << 16);
158 ret = put_user(tmp, (unsigned long *)data);
161 /* when I and D space are separate, this will have to be fixed. */
162 case PTRACE_POKETEXT: /* write the word at location addr. */
163 case PTRACE_POKEDATA:
164 if (access_process_vm(child, addr, &data, sizeof(data), 1) != sizeof(data))
168 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
171 addr >>= 2; /* temporary hack. */
176 data |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
177 } else if (addr >= 0 && addr < 19) {
178 if (put_reg(child, addr, data))
180 } else if (addr >= 21 && addr < 48) {
181 /* Convert long double format
182 * into internal fpu reg representation
184 if (FPU_IS_EMU && (addr < 45) && !(addr % 3)) {
185 data = (unsigned long)data << 15;
186 data = (data & 0xffff0000) |
187 ((data & 0x0000ffff) >> 1);
189 child->thread.fp[addr - 21] = data;
194 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
195 case PTRACE_CONT: /* restart after signal. */
196 if (!valid_signal(data))
199 if (request == PTRACE_SYSCALL)
200 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
202 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
203 child->exit_code = data;
204 singlestep_disable(child);
205 wake_up_process(child);
209 * make the child exit. Best I can do is send it a sigkill.
210 * perhaps it should be put in the status that it wants to
214 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
216 child->exit_code = SIGKILL;
217 singlestep_disable(child);
218 wake_up_process(child);
221 case PTRACE_SINGLESTEP: /* set the trap flag. */
222 if (!valid_signal(data))
225 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
226 tmp = get_reg(child, PT_SR) | (TRACE_BITS << 16);
227 put_reg(child, PT_SR, tmp);
228 set_tsk_thread_flag(child, TIF_DELAYED_TRACE);
230 child->exit_code = data;
231 /* give it a chance to run. */
232 wake_up_process(child);
235 case PTRACE_DETACH: /* detach a process that was attached. */
236 ret = ptrace_detach(child, data);
239 case PTRACE_GETREGS: /* Get all gp regs from the child. */
240 for (i = 0; i < 19; i++) {
241 tmp = get_reg(child, i);
244 ret = put_user(tmp, (unsigned long *)data);
247 data += sizeof(long);
251 case PTRACE_SETREGS: /* Set all gp regs in the child. */
252 for (i = 0; i < 19; i++) {
253 ret = get_user(tmp, (unsigned long *)data);
259 tmp |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
261 put_reg(child, i, tmp);
262 data += sizeof(long);
266 case PTRACE_GETFPREGS: /* Get the child FPU state. */
267 if (copy_to_user((void *)data, &child->thread.fp,
268 sizeof(struct user_m68kfp_struct)))
272 case PTRACE_SETFPREGS: /* Set the child FPU state. */
273 if (copy_from_user(&child->thread.fp, (void *)data,
274 sizeof(struct user_m68kfp_struct)))
279 ret = ptrace_request(child, request, addr, data);
288 asmlinkage void syscall_trace(void)
290 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
293 * this isn't the same as continuing with a signal, but it will do
294 * for normal use. strace only continues with a signal if the
295 * stopping signal is not SIGTRAP. -brl
297 if (current->exit_code) {
298 send_sig(current->exit_code, current, 1);
299 current->exit_code = 0;