aboutsummaryrefslogtreecommitdiffstats
path: root/arch/m68k
diff options
context:
space:
mode:
authorGreg Ungerer <gerg@uclinux.org>2012-01-24 01:16:35 -0500
committerGreg Ungerer <gerg@uclinux.org>2012-03-04 18:43:04 -0500
commit43dec91f4dbf4adbd2ffc9a86e34fa76ab1f5a05 (patch)
treefcfbfa0ba5e74aab1a9431104ef0a722bab5b251 /arch/m68k
parent397ac99c6cef38cdf260440635c8873f51109c34 (diff)
m68k: merge the mmu and non-mmu versions of ptrace.c
Most of the code in the non-mmu ptrace_no.c file is the same as the mmu version ptrace_mm.c. So merge them back into a single file. Signed-off-by: Greg Ungerer <gerg@uclinux.org> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Diffstat (limited to 'arch/m68k')
-rw-r--r--arch/m68k/kernel/ptrace.c306
-rw-r--r--arch/m68k/kernel/ptrace_mm.c295
-rw-r--r--arch/m68k/kernel/ptrace_no.c255
3 files changed, 303 insertions, 553 deletions
diff --git a/arch/m68k/kernel/ptrace.c b/arch/m68k/kernel/ptrace.c
index 07a417550e94..149a05f8b9ee 100644
--- a/arch/m68k/kernel/ptrace.c
+++ b/arch/m68k/kernel/ptrace.c
@@ -1,5 +1,305 @@
1/*
2 * linux/arch/m68k/kernel/ptrace.c
3 *
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
7 *
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.
11 */
12
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>
22
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>
28
29/*
30 * does not yet catch signals sent when the child dies.
31 * in exit.c or in signal.c.
32 */
33
34/* determines which bits in the SR the user has access to. */
35/* 1 = access 0 = no access */
36#define SR_MASK 0x001f
37
38/* sets the trace bits. */
39#define TRACE_BITS 0xC000
40#define T1_BIT 0x8000
41#define T0_BIT 0x4000
42
43/* Find the stack offset for a register, relative to thread.esp0. */
44#define PT_REG(reg) ((long)&((struct pt_regs *)0)->reg)
45#define SW_REG(reg) ((long)&((struct switch_stack *)0)->reg \
46 - sizeof(struct switch_stack))
47/* Mapping from PT_xxx to the stack offset at which the register is
48 saved. Notice that usp has no stack-slot and needs to be treated
49 specially (see get_reg/put_reg below). */
50static const int regoff[] = {
51 [0] = PT_REG(d1),
52 [1] = PT_REG(d2),
53 [2] = PT_REG(d3),
54 [3] = PT_REG(d4),
55 [4] = PT_REG(d5),
56 [5] = SW_REG(d6),
57 [6] = SW_REG(d7),
58 [7] = PT_REG(a0),
59 [8] = PT_REG(a1),
60 [9] = PT_REG(a2),
61 [10] = SW_REG(a3),
62 [11] = SW_REG(a4),
63 [12] = SW_REG(a5),
64 [13] = SW_REG(a6),
65 [14] = PT_REG(d0),
66 [15] = -1,
67 [16] = PT_REG(orig_d0),
68 [17] = PT_REG(sr),
69 [18] = PT_REG(pc),
70};
71
72/*
73 * Get contents of register REGNO in task TASK.
74 */
75static inline long get_reg(struct task_struct *task, int regno)
76{
77 unsigned long *addr;
78
79 if (regno == PT_USP)
80 addr = &task->thread.usp;
81 else if (regno < ARRAY_SIZE(regoff))
82 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
83 else
84 return 0;
85 /* Need to take stkadj into account. */
86 if (regno == PT_SR || regno == PT_PC) {
87 long stkadj = *(long *)(task->thread.esp0 + PT_REG(stkadj));
88 addr = (unsigned long *) ((unsigned long)addr + stkadj);
89 /* The sr is actually a 16 bit register. */
90 if (regno == PT_SR)
91 return *(unsigned short *)addr;
92 }
93 return *addr;
94}
95
96/*
97 * Write contents of register REGNO in task TASK.
98 */
99static inline int put_reg(struct task_struct *task, int regno,
100 unsigned long data)
101{
102 unsigned long *addr;
103
104 if (regno == PT_USP)
105 addr = &task->thread.usp;
106 else if (regno < ARRAY_SIZE(regoff))
107 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
108 else
109 return -1;
110 /* Need to take stkadj into account. */
111 if (regno == PT_SR || regno == PT_PC) {
112 long stkadj = *(long *)(task->thread.esp0 + PT_REG(stkadj));
113 addr = (unsigned long *) ((unsigned long)addr + stkadj);
114 /* The sr is actually a 16 bit register. */
115 if (regno == PT_SR) {
116 *(unsigned short *)addr = data;
117 return 0;
118 }
119 }
120 *addr = data;
121 return 0;
122}
123
124/*
125 * Make sure the single step bit is not set.
126 */
127static inline void singlestep_disable(struct task_struct *child)
128{
129 unsigned long tmp = get_reg(child, PT_SR) & ~TRACE_BITS;
130 put_reg(child, PT_SR, tmp);
131 clear_tsk_thread_flag(child, TIF_DELAYED_TRACE);
132}
133
134/*
135 * Called by kernel/ptrace.c when detaching..
136 */
137void ptrace_disable(struct task_struct *child)
138{
139 singlestep_disable(child);
140}
141
142void user_enable_single_step(struct task_struct *child)
143{
144 unsigned long tmp = get_reg(child, PT_SR) & ~TRACE_BITS;
145 put_reg(child, PT_SR, tmp | T1_BIT);
146 set_tsk_thread_flag(child, TIF_DELAYED_TRACE);
147}
148
1#ifdef CONFIG_MMU 149#ifdef CONFIG_MMU
2#include "ptrace_mm.c" 150void user_enable_block_step(struct task_struct *child)
3#else 151{
4#include "ptrace_no.c" 152 unsigned long tmp = get_reg(child, PT_SR) & ~TRACE_BITS;
153 put_reg(child, PT_SR, tmp | T0_BIT);
154}
5#endif 155#endif
156
157void user_disable_single_step(struct task_struct *child)
158{
159 singlestep_disable(child);
160}
161
162long arch_ptrace(struct task_struct *child, long request,
163 unsigned long addr, unsigned long data)
164{
165 unsigned long tmp;
166 int i, ret = 0;
167 int regno = addr >> 2; /* temporary hack. */
168 unsigned long __user *datap = (unsigned long __user *) data;
169
170 switch (request) {
171 /* read the word at location addr in the USER area. */
172 case PTRACE_PEEKUSR:
173 if (addr & 3)
174 goto out_eio;
175
176 if (regno >= 0 && regno < 19) {
177 tmp = get_reg(child, regno);
178 } else if (regno >= 21 && regno < 49) {
179 tmp = child->thread.fp[regno - 21];
180 /* Convert internal fpu reg representation
181 * into long double format
182 */
183 if (FPU_IS_EMU && (regno < 45) && !(regno % 3))
184 tmp = ((tmp & 0xffff0000) << 15) |
185 ((tmp & 0x0000ffff) << 16);
186#ifndef CONFIG_MMU
187 } else if (regno == 49) {
188 tmp = child->mm->start_code;
189 } else if (regno == 50) {
190 tmp = child->mm->start_data;
191 } else if (regno == 51) {
192 tmp = child->mm->end_code;
193#endif
194 } else
195 goto out_eio;
196 ret = put_user(tmp, datap);
197 break;
198
199 case PTRACE_POKEUSR:
200 /* write the word at location addr in the USER area */
201 if (addr & 3)
202 goto out_eio;
203
204 if (regno == PT_SR) {
205 data &= SR_MASK;
206 data |= get_reg(child, PT_SR) & ~SR_MASK;
207 }
208 if (regno >= 0 && regno < 19) {
209 if (put_reg(child, regno, data))
210 goto out_eio;
211 } else if (regno >= 21 && regno < 48) {
212 /* Convert long double format
213 * into internal fpu reg representation
214 */
215 if (FPU_IS_EMU && (regno < 45) && !(regno % 3)) {
216 data <<= 15;
217 data = (data & 0xffff0000) |
218 ((data & 0x0000ffff) >> 1);
219 }
220 child->thread.fp[regno - 21] = data;
221 } else
222 goto out_eio;
223 break;
224
225 case PTRACE_GETREGS: /* Get all gp regs from the child. */
226 for (i = 0; i < 19; i++) {
227 tmp = get_reg(child, i);
228 ret = put_user(tmp, datap);
229 if (ret)
230 break;
231 datap++;
232 }
233 break;
234
235 case PTRACE_SETREGS: /* Set all gp regs in the child. */
236 for (i = 0; i < 19; i++) {
237 ret = get_user(tmp, datap);
238 if (ret)
239 break;
240 if (i == PT_SR) {
241 tmp &= SR_MASK;
242 tmp |= get_reg(child, PT_SR) & ~SR_MASK;
243 }
244 put_reg(child, i, tmp);
245 datap++;
246 }
247 break;
248
249 case PTRACE_GETFPREGS: /* Get the child FPU state. */
250 if (copy_to_user(datap, &child->thread.fp,
251 sizeof(struct user_m68kfp_struct)))
252 ret = -EFAULT;
253 break;
254
255 case PTRACE_SETFPREGS: /* Set the child FPU state. */
256 if (copy_from_user(&child->thread.fp, datap,
257 sizeof(struct user_m68kfp_struct)))
258 ret = -EFAULT;
259 break;
260
261 case PTRACE_GET_THREAD_AREA:
262 ret = put_user(task_thread_info(child)->tp_value, datap);
263 break;
264
265 default:
266 ret = ptrace_request(child, request, addr, data);
267 break;
268 }
269
270 return ret;
271out_eio:
272 return -EIO;
273}
274
275asmlinkage void syscall_trace(void)
276{
277 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
278 ? 0x80 : 0));
279 /*
280 * this isn't the same as continuing with a signal, but it will do
281 * for normal use. strace only continues with a signal if the
282 * stopping signal is not SIGTRAP. -brl
283 */
284 if (current->exit_code) {
285 send_sig(current->exit_code, current, 1);
286 current->exit_code = 0;
287 }
288}
289
290#ifdef CONFIG_COLDFIRE
291asmlinkage int syscall_trace_enter(void)
292{
293 int ret = 0;
294
295 if (test_thread_flag(TIF_SYSCALL_TRACE))
296 ret = tracehook_report_syscall_entry(task_pt_regs(current));
297 return ret;
298}
299
300asmlinkage void syscall_trace_leave(void)
301{
302 if (test_thread_flag(TIF_SYSCALL_TRACE))
303 tracehook_report_syscall_exit(task_pt_regs(current), 0);
304}
305#endif /* CONFIG_COLDFIRE */
diff --git a/arch/m68k/kernel/ptrace_mm.c b/arch/m68k/kernel/ptrace_mm.c
deleted file mode 100644
index 7bc999b73529..000000000000
--- a/arch/m68k/kernel/ptrace_mm.c
+++ /dev/null
@@ -1,295 +0,0 @@
1/*
2 * linux/arch/m68k/kernel/ptrace.c
3 *
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
7 *
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.
11 */
12
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>
22
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>
28
29/*
30 * does not yet catch signals sent when the child dies.
31 * in exit.c or in signal.c.
32 */
33
34/* determines which bits in the SR the user has access to. */
35/* 1 = access 0 = no access */
36#define SR_MASK 0x001f
37
38/* sets the trace bits. */
39#define TRACE_BITS 0xC000
40#define T1_BIT 0x8000
41#define T0_BIT 0x4000
42
43/* Find the stack offset for a register, relative to thread.esp0. */
44#define PT_REG(reg) ((long)&((struct pt_regs *)0)->reg)
45#define SW_REG(reg) ((long)&((struct switch_stack *)0)->reg \
46 - sizeof(struct switch_stack))
47/* Mapping from PT_xxx to the stack offset at which the register is
48 saved. Notice that usp has no stack-slot and needs to be treated
49 specially (see get_reg/put_reg below). */
50static const int regoff[] = {
51 [0] = PT_REG(d1),
52 [1] = PT_REG(d2),
53 [2] = PT_REG(d3),
54 [3] = PT_REG(d4),
55 [4] = PT_REG(d5),
56 [5] = SW_REG(d6),
57 [6] = SW_REG(d7),
58 [7] = PT_REG(a0),
59 [8] = PT_REG(a1),
60 [9] = PT_REG(a2),
61 [10] = SW_REG(a3),
62 [11] = SW_REG(a4),
63 [12] = SW_REG(a5),
64 [13] = SW_REG(a6),
65 [14] = PT_REG(d0),
66 [15] = -1,
67 [16] = PT_REG(orig_d0),
68 [17] = PT_REG(sr),
69 [18] = PT_REG(pc),
70};
71
72/*
73 * Get contents of register REGNO in task TASK.
74 */
75static inline long get_reg(struct task_struct *task, int regno)
76{
77 unsigned long *addr;
78
79 if (regno == PT_USP)
80 addr = &task->thread.usp;
81 else if (regno < ARRAY_SIZE(regoff))
82 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
83 else
84 return 0;
85 /* Need to take stkadj into account. */
86 if (regno == PT_SR || regno == PT_PC) {
87 long stkadj = *(long *)(task->thread.esp0 + PT_REG(stkadj));
88 addr = (unsigned long *) ((unsigned long)addr + stkadj);
89 /* The sr is actually a 16 bit register. */
90 if (regno == PT_SR)
91 return *(unsigned short *)addr;
92 }
93 return *addr;
94}
95
96/*
97 * Write contents of register REGNO in task TASK.
98 */
99static inline int put_reg(struct task_struct *task, int regno,
100 unsigned long data)
101{
102 unsigned long *addr;
103
104 if (regno == PT_USP)
105 addr = &task->thread.usp;
106 else if (regno < ARRAY_SIZE(regoff))
107 addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
108 else
109 return -1;
110 /* Need to take stkadj into account. */
111 if (regno == PT_SR || regno == PT_PC) {
112 long stkadj = *(long *)(task->thread.esp0 + PT_REG(stkadj));
113 addr = (unsigned long *) ((unsigned long)addr + stkadj);
114 /* The sr is actually a 16 bit register. */
115 if (regno == PT_SR) {
116 *(unsigned short *)addr = data;
117 return 0;
118 }
119 }
120 *addr = data;
121 return 0;
122}
123
124/*
125 * Make sure the single step bit is not set.
126 */
127static inline void singlestep_disable(struct task_struct *child)
128{
129 unsigned long tmp = get_reg(child, PT_SR) & ~TRACE_BITS;
130 put_reg(child, PT_SR, tmp);
131 clear_tsk_thread_flag(child, TIF_DELAYED_TRACE);
132}
133
134/*
135 * Called by kernel/ptrace.c when detaching..
136 */
137void ptrace_disable(struct task_struct *child)
138{
139 singlestep_disable(child);
140}
141
142void user_enable_single_step(struct task_struct *child)
143{
144 unsigned long tmp = get_reg(child, PT_SR) & ~TRACE_BITS;
145 put_reg(child, PT_SR, tmp | T1_BIT);
146 set_tsk_thread_flag(child, TIF_DELAYED_TRACE);
147}
148
149void user_enable_block_step(struct task_struct *child)
150{
151 unsigned long tmp = get_reg(child, PT_SR) & ~TRACE_BITS;
152 put_reg(child, PT_SR, tmp | T0_BIT);
153}
154
155void user_disable_single_step(struct task_struct *child)
156{
157 singlestep_disable(child);
158}
159
160long arch_ptrace(struct task_struct *child, long request,
161 unsigned long addr, unsigned long data)
162{
163 unsigned long tmp;
164 int i, ret = 0;
165 int regno = addr >> 2; /* temporary hack. */
166 unsigned long __user *datap = (unsigned long __user *) data;
167
168 switch (request) {
169 /* read the word at location addr in the USER area. */
170 case PTRACE_PEEKUSR:
171 if (addr & 3)
172 goto out_eio;
173
174 if (regno >= 0 && regno < 19) {
175 tmp = get_reg(child, regno);
176 } else if (regno >= 21 && regno < 49) {
177 tmp = child->thread.fp[regno - 21];
178 /* Convert internal fpu reg representation
179 * into long double format
180 */
181 if (FPU_IS_EMU && (regno < 45) && !(regno % 3))
182 tmp = ((tmp & 0xffff0000) << 15) |
183 ((tmp & 0x0000ffff) << 16);
184 } else
185 goto out_eio;
186 ret = put_user(tmp, datap);
187 break;
188
189 case PTRACE_POKEUSR:
190 /* write the word at location addr in the USER area */
191 if (addr & 3)
192 goto out_eio;
193
194 if (regno == PT_SR) {
195 data &= SR_MASK;
196 data |= get_reg(child, PT_SR) & ~SR_MASK;
197 }
198 if (regno >= 0 && regno < 19) {
199 if (put_reg(child, regno, data))
200 goto out_eio;
201 } else if (regno >= 21 && regno < 48) {
202 /* Convert long double format
203 * into internal fpu reg representation
204 */
205 if (FPU_IS_EMU && (regno < 45) && !(regno % 3)) {
206 data <<= 15;
207 data = (data & 0xffff0000) |
208 ((data & 0x0000ffff) >> 1);
209 }
210 child->thread.fp[regno - 21] = data;
211 } else
212 goto out_eio;
213 break;
214
215 case PTRACE_GETREGS: /* Get all gp regs from the child. */
216 for (i = 0; i < 19; i++) {
217 tmp = get_reg(child, i);
218 ret = put_user(tmp, datap);
219 if (ret)
220 break;
221 datap++;
222 }
223 break;
224
225 case PTRACE_SETREGS: /* Set all gp regs in the child. */
226 for (i = 0; i < 19; i++) {
227 ret = get_user(tmp, datap);
228 if (ret)
229 break;
230 if (i == PT_SR) {
231 tmp &= SR_MASK;
232 tmp |= get_reg(child, PT_SR) & ~SR_MASK;
233 }
234 put_reg(child, i, tmp);
235 datap++;
236 }
237 break;
238
239 case PTRACE_GETFPREGS: /* Get the child FPU state. */
240 if (copy_to_user(datap, &child->thread.fp,
241 sizeof(struct user_m68kfp_struct)))
242 ret = -EFAULT;
243 break;
244
245 case PTRACE_SETFPREGS: /* Set the child FPU state. */
246 if (copy_from_user(&child->thread.fp, datap,
247 sizeof(struct user_m68kfp_struct)))
248 ret = -EFAULT;
249 break;
250
251 case PTRACE_GET_THREAD_AREA:
252 ret = put_user(task_thread_info(child)->tp_value, datap);
253 break;
254
255 default:
256 ret = ptrace_request(child, request, addr, data);
257 break;
258 }
259
260 return ret;
261out_eio:
262 return -EIO;
263}
264
265asmlinkage void syscall_trace(void)
266{
267 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
268 ? 0x80 : 0));
269 /*
270 * this isn't the same as continuing with a signal, but it will do
271 * for normal use. strace only continues with a signal if the
272 * stopping signal is not SIGTRAP. -brl
273 */
274 if (current->exit_code) {
275 send_sig(current->exit_code, current, 1);
276 current->exit_code = 0;
277 }
278}
279
280#ifdef CONFIG_COLDFIRE
281asmlinkage int syscall_trace_enter(void)
282{
283 int ret = 0;
284
285 if (test_thread_flag(TIF_SYSCALL_TRACE))
286 ret = tracehook_report_syscall_entry(task_pt_regs(current));
287 return ret;
288}
289
290asmlinkage void syscall_trace_leave(void)
291{
292 if (test_thread_flag(TIF_SYSCALL_TRACE))
293 tracehook_report_syscall_exit(task_pt_regs(current), 0);
294}
295#endif /* CONFIG_COLDFIRE */
diff --git a/arch/m68k/kernel/ptrace_no.c b/arch/m68k/kernel/ptrace_no.c
deleted file mode 100644
index 6709fb707335..000000000000
--- a/arch/m68k/kernel/ptrace_no.c
+++ /dev/null
@@ -1,255 +0,0 @@
1/*
2 * linux/arch/m68knommu/kernel/ptrace.c
3 *
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
7 *
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.
11 */
12
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>
22
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>
28
29/*
30 * does not yet catch signals sent when the child dies.
31 * in exit.c or in signal.c.
32 */
33
34/* determines which bits in the SR the user has access to. */
35/* 1 = access 0 = no access */
36#define SR_MASK 0x001f
37
38/* sets the trace bits. */
39#define TRACE_BITS 0x8000
40
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). */
48static 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),
54};
55
56/*
57 * Get contents of register REGNO in task TASK.
58 */
59static inline long get_reg(struct task_struct *task, int regno)
60{
61 unsigned long *addr;
62
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;
70}
71
72/*
73 * Write contents of register REGNO in task TASK.
74 */
75static inline int put_reg(struct task_struct *task, int regno,
76 unsigned long data)
77{
78 unsigned long *addr;
79
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;
88}
89
90void user_enable_single_step(struct task_struct *task)
91{
92 unsigned long srflags;
93 srflags = get_reg(task, PT_SR) | (TRACE_BITS << 16);
94 put_reg(task, PT_SR, srflags);
95}
96
97void user_disable_single_step(struct task_struct *task)
98{
99 unsigned long srflags;
100 srflags = get_reg(task, PT_SR) & ~(TRACE_BITS << 16);
101 put_reg(task, PT_SR, srflags);
102}
103
104/*
105 * Called by kernel/ptrace.c when detaching..
106 *
107 * Make sure the single step bit is not set.
108 */
109void ptrace_disable(struct task_struct *child)
110{
111 /* make sure the single step bit is not set. */
112 user_disable_single_step(child);
113}
114
115long arch_ptrace(struct task_struct *child, long request,
116 unsigned long addr, unsigned long data)
117{
118 int ret;
119 int regno = addr >> 2;
120 unsigned long __user *datap = (unsigned long __user *) data;
121
122 switch (request) {
123 /* read the word at location addr in the USER area. */
124 case PTRACE_PEEKUSR: {
125 unsigned long tmp;
126
127 ret = -EIO;
128 if ((addr & 3) || addr > sizeof(struct user) - 3)
129 break;
130
131 tmp = 0; /* Default return condition */
132 ret = -EIO;
133 if (regno < 19) {
134 tmp = get_reg(child, regno);
135 if (regno == PT_SR)
136 tmp >>= 16;
137 } else if (regno >= 21 && regno < 49) {
138 tmp = child->thread.fp[regno - 21];
139 } else if (regno == 49) {
140 tmp = child->mm->start_code;
141 } else if (regno == 50) {
142 tmp = child->mm->start_data;
143 } else if (regno == 51) {
144 tmp = child->mm->end_code;
145 } else
146 break;
147 ret = put_user(tmp, datap);
148 break;
149 }
150
151 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
152 ret = -EIO;
153 if ((addr & 3) || addr > sizeof(struct user) - 3)
154 break;
155
156 if (regno == PT_SR) {
157 data &= SR_MASK;
158 data <<= 16;
159 data |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
160 }
161 if (regno < 19) {
162 if (put_reg(child, regno, data))
163 break;
164 ret = 0;
165 break;
166 }
167 if (regno >= 21 && regno < 48)
168 {
169 child->thread.fp[regno - 21] = data;
170 ret = 0;
171 }
172 break;
173
174 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
175 int i;
176 unsigned long tmp;
177 for (i = 0; i < 19; i++) {
178 tmp = get_reg(child, i);
179 if (i == PT_SR)
180 tmp >>= 16;
181 if (put_user(tmp, datap)) {
182 ret = -EFAULT;
183 break;
184 }
185 datap++;
186 }
187 ret = 0;
188 break;
189 }
190
191 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
192 int i;
193 unsigned long tmp;
194 for (i = 0; i < 19; i++) {
195 if (get_user(tmp, datap)) {
196 ret = -EFAULT;
197 break;
198 }
199 if (i == PT_SR) {
200 tmp &= SR_MASK;
201 tmp <<= 16;
202 tmp |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
203 }
204 put_reg(child, i, tmp);
205 datap++;
206 }
207 ret = 0;
208 break;
209 }
210
211#ifdef PTRACE_GETFPREGS
212 case PTRACE_GETFPREGS: { /* Get the child FPU state. */
213 ret = 0;
214 if (copy_to_user(datap, &child->thread.fp,
215 sizeof(struct user_m68kfp_struct)))
216 ret = -EFAULT;
217 break;
218 }
219#endif
220
221#ifdef PTRACE_SETFPREGS
222 case PTRACE_SETFPREGS: { /* Set the child FPU state. */
223 ret = 0;
224 if (copy_from_user(&child->thread.fp, datap,
225 sizeof(struct user_m68kfp_struct)))
226 ret = -EFAULT;
227 break;
228 }
229#endif
230
231 case PTRACE_GET_THREAD_AREA:
232 ret = put_user(task_thread_info(child)->tp_value, datap);
233 break;
234
235 default:
236 ret = ptrace_request(child, request, addr, data);
237 break;
238 }
239 return ret;
240}
241
242asmlinkage int syscall_trace_enter(void)
243{
244 int ret = 0;
245
246 if (test_thread_flag(TIF_SYSCALL_TRACE))
247 ret = tracehook_report_syscall_entry(task_pt_regs(current));
248 return ret;
249}
250
251asmlinkage void syscall_trace_leave(void)
252{
253 if (test_thread_flag(TIF_SYSCALL_TRACE))
254 tracehook_report_syscall_exit(task_pt_regs(current), 0);
255}