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/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 0x8000
40 /* Find the stack offset for a register, relative to thread.esp0. */
41 #define PT_REG(reg) ((long)&((struct pt_regs *)0)->reg)
42 #define SW_REG(reg) ((long)&((struct switch_stack *)0)->reg \
43 - sizeof(struct switch_stack))
44 /* Mapping from PT_xxx to the stack offset at which the register is
45 saved. Notice that usp has no stack-slot and needs to be treated
46 specially (see get_reg/put_reg below). */
47 static int regoff[] = {
48 PT_REG(d1), PT_REG(d2), PT_REG(d3), PT_REG(d4),
49 PT_REG(d5), SW_REG(d6), SW_REG(d7), PT_REG(a0),
50 PT_REG(a1), PT_REG(a2), SW_REG(a3), SW_REG(a4),
51 SW_REG(a5), SW_REG(a6), PT_REG(d0), -1,
52 PT_REG(orig_d0), PT_REG(sr), PT_REG(pc),
56 * Get contents of register REGNO in task TASK.
58 static inline long get_reg(struct task_struct *task, int regno)
63 addr = &task->thread.usp;
64 else if (regno < ARRAY_SIZE(regoff))
65 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
72 * Write contents of register REGNO in task TASK.
74 static inline int put_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]);
89 void user_enable_single_step(struct task_struct *task)
91 unsigned long srflags;
92 srflags = get_reg(task, PT_SR) | (TRACE_BITS << 16);
93 put_reg(task, PT_SR, srflags);
96 void user_disable_single_step(struct task_struct *task)
98 unsigned long srflags;
99 srflags = get_reg(task, PT_SR) & ~(TRACE_BITS << 16);
100 put_reg(task, PT_SR, srflags);
104 * Called by kernel/ptrace.c when detaching..
106 * Make sure the single step bit is not set.
108 void ptrace_disable(struct task_struct *child)
110 /* make sure the single step bit is not set. */
111 user_disable_single_step(child);
114 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
119 /* read the word at location addr in the USER area. */
120 case PTRACE_PEEKUSR: {
124 if ((addr & 3) || addr < 0 ||
125 addr > sizeof(struct user) - 3)
128 tmp = 0; /* Default return condition */
129 addr = addr >> 2; /* temporary hack. */
132 tmp = get_reg(child, addr);
135 } else if (addr >= 21 && addr < 49) {
136 tmp = child->thread.fp[addr - 21];
137 } else if (addr == 49) {
138 tmp = child->mm->start_code;
139 } else if (addr == 50) {
140 tmp = child->mm->start_data;
141 } else if (addr == 51) {
142 tmp = child->mm->end_code;
145 ret = put_user(tmp,(unsigned long *) data);
149 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
151 if ((addr & 3) || addr < 0 ||
152 addr > sizeof(struct user) - 3)
155 addr = addr >> 2; /* temporary hack. */
160 data |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
163 if (put_reg(child, addr, data))
168 if (addr >= 21 && addr < 48)
170 child->thread.fp[addr - 21] = data;
175 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
178 for (i = 0; i < 19; i++) {
179 tmp = get_reg(child, i);
182 if (put_user(tmp, (unsigned long *) data)) {
186 data += sizeof(long);
192 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
195 for (i = 0; i < 19; i++) {
196 if (get_user(tmp, (unsigned long *) data)) {
203 tmp |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
205 put_reg(child, i, tmp);
206 data += sizeof(long);
212 #ifdef PTRACE_GETFPREGS
213 case PTRACE_GETFPREGS: { /* Get the child FPU state. */
215 if (copy_to_user((void *)data, &child->thread.fp,
216 sizeof(struct user_m68kfp_struct)))
222 #ifdef PTRACE_SETFPREGS
223 case PTRACE_SETFPREGS: { /* Set the child FPU state. */
225 if (copy_from_user(&child->thread.fp, (void *)data,
226 sizeof(struct user_m68kfp_struct)))
232 case PTRACE_GET_THREAD_AREA:
233 ret = put_user(task_thread_info(child)->tp_value,
234 (unsigned long __user *)data);
238 ret = ptrace_request(child, request, addr, data);
244 asmlinkage void syscall_trace(void)
246 if (!test_thread_flag(TIF_SYSCALL_TRACE))
248 if (!(current->ptrace & PT_PTRACED))
250 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
253 * this isn't the same as continuing with a signal, but it will do
254 * for normal use. strace only continues with a signal if the
255 * stopping signal is not SIGTRAP. -brl
257 if (current->exit_code) {
258 send_sig(current->exit_code, current, 1);
259 current->exit_code = 0;