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 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]);
88 * Write contents of register REGNO in task TASK.
90 static inline int put_reg(struct task_struct *task, int regno,
96 addr = &task->thread.usp;
97 else if (regno < ARRAY_SIZE(regoff))
98 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
106 * Make sure the single step bit is not set.
108 static inline void singlestep_disable(struct task_struct *child)
110 unsigned long tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16);
111 put_reg(child, PT_SR, tmp);
112 clear_tsk_thread_flag(child, TIF_DELAYED_TRACE);
116 * Called by kernel/ptrace.c when detaching..
118 void ptrace_disable(struct task_struct *child)
120 singlestep_disable(child);
123 void user_enable_single_step(struct task_struct *child)
125 unsigned long tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16);
126 put_reg(child, PT_SR, tmp | (T1_BIT << 16));
127 set_tsk_thread_flag(child, TIF_DELAYED_TRACE);
130 void user_enable_block_step(struct task_struct *child)
132 unsigned long tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16);
133 put_reg(child, PT_SR, tmp | (T0_BIT << 16));
136 void user_disable_single_step(struct task_struct *child)
138 singlestep_disable(child);
141 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
147 /* read the word at location addr in the USER area. */
151 addr >>= 2; /* temporary hack. */
153 if (addr >= 0 && addr < 19) {
154 tmp = get_reg(child, addr);
157 } else if (addr >= 21 && addr < 49) {
158 tmp = child->thread.fp[addr - 21];
159 /* Convert internal fpu reg representation
160 * into long double format
162 if (FPU_IS_EMU && (addr < 45) && !(addr % 3))
163 tmp = ((tmp & 0xffff0000) << 15) |
164 ((tmp & 0x0000ffff) << 16);
167 ret = put_user(tmp, (unsigned long *)data);
170 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
173 addr >>= 2; /* temporary hack. */
178 data |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
179 } else if (addr >= 0 && addr < 19) {
180 if (put_reg(child, addr, data))
182 } else if (addr >= 21 && addr < 48) {
183 /* Convert long double format
184 * into internal fpu reg representation
186 if (FPU_IS_EMU && (addr < 45) && !(addr % 3)) {
187 data = (unsigned long)data << 15;
188 data = (data & 0xffff0000) |
189 ((data & 0x0000ffff) >> 1);
191 child->thread.fp[addr - 21] = data;
196 case PTRACE_GETREGS: /* Get all gp regs from the child. */
197 for (i = 0; i < 19; i++) {
198 tmp = get_reg(child, i);
201 ret = put_user(tmp, (unsigned long *)data);
204 data += sizeof(long);
208 case PTRACE_SETREGS: /* Set all gp regs in the child. */
209 for (i = 0; i < 19; i++) {
210 ret = get_user(tmp, (unsigned long *)data);
216 tmp |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
218 put_reg(child, i, tmp);
219 data += sizeof(long);
223 case PTRACE_GETFPREGS: /* Get the child FPU state. */
224 if (copy_to_user((void *)data, &child->thread.fp,
225 sizeof(struct user_m68kfp_struct)))
229 case PTRACE_SETFPREGS: /* Set the child FPU state. */
230 if (copy_from_user(&child->thread.fp, (void *)data,
231 sizeof(struct user_m68kfp_struct)))
236 ret = ptrace_request(child, request, addr, data);
245 asmlinkage void syscall_trace(void)
247 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
250 * this isn't the same as continuing with a signal, but it will do
251 * for normal use. strace only continues with a signal if the
252 * stopping signal is not SIGTRAP. -brl
254 if (current->exit_code) {
255 send_sig(current->exit_code, current, 1);
256 current->exit_code = 0;