ptrace: change signature of arch_ptrace()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / m68knommu / kernel / ptrace.c
blob7dbb08f5534edb40aa5f36181ae9b72219fc2361
1 /*
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>
15 #include <linux/mm.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>
21 #include <linux/tracehook.h>
23 #include <asm/uaccess.h>
24 #include <asm/page.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[] = {
49 PT_REG(d1), PT_REG(d2), PT_REG(d3), PT_REG(d4),
50 PT_REG(d5), SW_REG(d6), SW_REG(d7), PT_REG(a0),
51 PT_REG(a1), PT_REG(a2), SW_REG(a3), SW_REG(a4),
52 SW_REG(a5), SW_REG(a6), PT_REG(d0), -1,
53 PT_REG(orig_d0), PT_REG(sr), PT_REG(pc),
57 * Get contents of register REGNO in task TASK.
59 static inline long get_reg(struct task_struct *task, int regno)
61 unsigned long *addr;
63 if (regno == PT_USP)
64 addr = &task->thread.usp;
65 else if (regno < ARRAY_SIZE(regoff))
66 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
67 else
68 return 0;
69 return *addr;
73 * Write contents of register REGNO in task TASK.
75 static inline int put_reg(struct task_struct *task, int regno,
76 unsigned long data)
78 unsigned long *addr;
80 if (regno == PT_USP)
81 addr = &task->thread.usp;
82 else if (regno < ARRAY_SIZE(regoff))
83 addr = (unsigned long *) (task->thread.esp0 + regoff[regno]);
84 else
85 return -1;
86 *addr = data;
87 return 0;
90 void user_enable_single_step(struct task_struct *task)
92 unsigned long srflags;
93 srflags = get_reg(task, PT_SR) | (TRACE_BITS << 16);
94 put_reg(task, PT_SR, srflags);
97 void user_disable_single_step(struct task_struct *task)
99 unsigned long srflags;
100 srflags = get_reg(task, PT_SR) & ~(TRACE_BITS << 16);
101 put_reg(task, PT_SR, srflags);
105 * Called by kernel/ptrace.c when detaching..
107 * Make sure the single step bit is not set.
109 void ptrace_disable(struct task_struct *child)
111 /* make sure the single step bit is not set. */
112 user_disable_single_step(child);
115 long arch_ptrace(struct task_struct *child, long request,
116 unsigned long addr, unsigned long data)
118 int ret;
120 switch (request) {
121 /* read the word at location addr in the USER area. */
122 case PTRACE_PEEKUSR: {
123 unsigned long tmp;
125 ret = -EIO;
126 if ((addr & 3) || addr < 0 ||
127 addr > sizeof(struct user) - 3)
128 break;
130 tmp = 0; /* Default return condition */
131 addr = addr >> 2; /* temporary hack. */
132 ret = -EIO;
133 if (addr < 19) {
134 tmp = get_reg(child, addr);
135 if (addr == PT_SR)
136 tmp >>= 16;
137 } else if (addr >= 21 && addr < 49) {
138 tmp = child->thread.fp[addr - 21];
139 } else if (addr == 49) {
140 tmp = child->mm->start_code;
141 } else if (addr == 50) {
142 tmp = child->mm->start_data;
143 } else if (addr == 51) {
144 tmp = child->mm->end_code;
145 } else
146 break;
147 ret = put_user(tmp,(unsigned long *) data);
148 break;
151 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
152 ret = -EIO;
153 if ((addr & 3) || addr < 0 ||
154 addr > sizeof(struct user) - 3)
155 break;
157 addr = addr >> 2; /* temporary hack. */
159 if (addr == PT_SR) {
160 data &= SR_MASK;
161 data <<= 16;
162 data |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
164 if (addr < 19) {
165 if (put_reg(child, addr, data))
166 break;
167 ret = 0;
168 break;
170 if (addr >= 21 && addr < 48)
172 child->thread.fp[addr - 21] = data;
173 ret = 0;
175 break;
177 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
178 int i;
179 unsigned long tmp;
180 for (i = 0; i < 19; i++) {
181 tmp = get_reg(child, i);
182 if (i == PT_SR)
183 tmp >>= 16;
184 if (put_user(tmp, (unsigned long *) data)) {
185 ret = -EFAULT;
186 break;
188 data += sizeof(unsigned long);
190 ret = 0;
191 break;
194 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
195 int i;
196 unsigned long tmp;
197 for (i = 0; i < 19; i++) {
198 if (get_user(tmp, (unsigned long *) data)) {
199 ret = -EFAULT;
200 break;
202 if (i == PT_SR) {
203 tmp &= SR_MASK;
204 tmp <<= 16;
205 tmp |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
207 put_reg(child, i, tmp);
208 data += sizeof(unsigned long);
210 ret = 0;
211 break;
214 #ifdef PTRACE_GETFPREGS
215 case PTRACE_GETFPREGS: { /* Get the child FPU state. */
216 ret = 0;
217 if (copy_to_user((void *)data, &child->thread.fp,
218 sizeof(struct user_m68kfp_struct)))
219 ret = -EFAULT;
220 break;
222 #endif
224 #ifdef PTRACE_SETFPREGS
225 case PTRACE_SETFPREGS: { /* Set the child FPU state. */
226 ret = 0;
227 if (copy_from_user(&child->thread.fp, (void *)data,
228 sizeof(struct user_m68kfp_struct)))
229 ret = -EFAULT;
230 break;
232 #endif
234 case PTRACE_GET_THREAD_AREA:
235 ret = put_user(task_thread_info(child)->tp_value,
236 (unsigned long __user *)data);
237 break;
239 default:
240 ret = ptrace_request(child, request, addr, data);
241 break;
243 return ret;
246 asmlinkage int syscall_trace_enter(void)
248 int ret = 0;
250 if (test_thread_flag(TIF_SYSCALL_TRACE))
251 ret = tracehook_report_syscall_entry(task_pt_regs(current));
252 return ret;
255 asmlinkage void syscall_trace_leave(void)
257 if (test_thread_flag(TIF_SYSCALL_TRACE))
258 tracehook_report_syscall_exit(task_pt_regs(current), 0);