x86 module: merge the same functions in module_32.c and module_64.c
[linux-2.6/kvm.git] / arch / microblaze / kernel / ptrace.c
blobb86aa623e36d053f95c61de5533782c0d92a8bb2
1 /*
2 * `ptrace' system call
4 * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
5 * Copyright (C) 2007-2009 PetaLogix
6 * Copyright (C) 2004-2007 John Williams <john.williams@petalogix.com>
8 * derived from arch/v850/kernel/ptrace.c
10 * Copyright (C) 2002,03 NEC Electronics Corporation
11 * Copyright (C) 2002,03 Miles Bader <miles@gnu.org>
13 * Derived from arch/mips/kernel/ptrace.c:
15 * Copyright (C) 1992 Ross Biro
16 * Copyright (C) Linus Torvalds
17 * Copyright (C) 1994, 95, 96, 97, 98, 2000 Ralf Baechle
18 * Copyright (C) 1996 David S. Miller
19 * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
20 * Copyright (C) 1999 MIPS Technologies, Inc.
22 * This file is subject to the terms and conditions of the GNU General
23 * Public License. See the file COPYING in the main directory of this
24 * archive for more details.
27 #include <linux/kernel.h>
28 #include <linux/mm.h>
29 #include <linux/sched.h>
30 #include <linux/smp_lock.h>
31 #include <linux/ptrace.h>
32 #include <linux/signal.h>
34 #include <linux/errno.h>
35 #include <asm/processor.h>
36 #include <linux/uaccess.h>
37 #include <asm/asm-offsets.h>
39 /* Returns the address where the register at REG_OFFS in P is stashed away. */
40 static microblaze_reg_t *reg_save_addr(unsigned reg_offs,
41 struct task_struct *t)
43 struct pt_regs *regs;
46 * Three basic cases:
48 * (1) A register normally saved before calling the scheduler, is
49 * available in the kernel entry pt_regs structure at the top
50 * of the kernel stack. The kernel trap/irq exit path takes
51 * care to save/restore almost all registers for ptrace'd
52 * processes.
54 * (2) A call-clobbered register, where the process P entered the
55 * kernel via [syscall] trap, is not stored anywhere; that's
56 * OK, because such registers are not expected to be preserved
57 * when the trap returns anyway (so we don't actually bother to
58 * test for this case).
60 * (3) A few registers not used at all by the kernel, and so
61 * normally never saved except by context-switches, are in the
62 * context switch state.
65 /* Register saved during kernel entry (or not available). */
66 regs = task_pt_regs(t);
68 return (microblaze_reg_t *)((char *)regs + reg_offs);
71 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
73 int rval;
74 unsigned long val = 0;
75 unsigned long copied;
77 switch (request) {
78 case PTRACE_PEEKTEXT: /* read word at location addr. */
79 case PTRACE_PEEKDATA:
80 pr_debug("PEEKTEXT/PEEKDATA at %08lX\n", addr);
81 copied = access_process_vm(child, addr, &val, sizeof(val), 0);
82 rval = -EIO;
83 if (copied != sizeof(val))
84 break;
85 rval = put_user(val, (unsigned long *)data);
86 break;
88 case PTRACE_POKETEXT: /* write the word at location addr. */
89 case PTRACE_POKEDATA:
90 pr_debug("POKETEXT/POKEDATA to %08lX\n", addr);
91 rval = 0;
92 if (access_process_vm(child, addr, &data, sizeof(data), 1)
93 == sizeof(data))
94 break;
95 rval = -EIO;
96 break;
98 /* Read/write the word at location ADDR in the registers. */
99 case PTRACE_PEEKUSR:
100 case PTRACE_POKEUSR:
101 pr_debug("PEEKUSR/POKEUSR : 0x%08lx\n", addr);
102 rval = 0;
103 if (addr >= PT_SIZE && request == PTRACE_PEEKUSR) {
105 * Special requests that don't actually correspond
106 * to offsets in struct pt_regs.
108 if (addr == PT_TEXT_ADDR) {
109 val = child->mm->start_code;
110 } else if (addr == PT_DATA_ADDR) {
111 val = child->mm->start_data;
112 } else if (addr == PT_TEXT_LEN) {
113 val = child->mm->end_code
114 - child->mm->start_code;
115 } else {
116 rval = -EIO;
118 } else if (addr >= 0 && addr < PT_SIZE && (addr & 0x3) == 0) {
119 microblaze_reg_t *reg_addr = reg_save_addr(addr, child);
120 if (request == PTRACE_PEEKUSR)
121 val = *reg_addr;
122 else
123 *reg_addr = data;
124 } else
125 rval = -EIO;
127 if (rval == 0 && request == PTRACE_PEEKUSR)
128 rval = put_user(val, (unsigned long *)data);
129 break;
130 /* Continue and stop at next (return from) syscall */
131 case PTRACE_SYSCALL:
132 pr_debug("PTRACE_SYSCALL\n");
133 case PTRACE_SINGLESTEP:
134 pr_debug("PTRACE_SINGLESTEP\n");
135 /* Restart after a signal. */
136 case PTRACE_CONT:
137 pr_debug("PTRACE_CONT\n");
138 rval = -EIO;
139 if (!valid_signal(data))
140 break;
142 if (request == PTRACE_SYSCALL)
143 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
144 else
145 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
147 child->exit_code = data;
148 pr_debug("wakeup_process\n");
149 wake_up_process(child);
150 rval = 0;
151 break;
154 * make the child exit. Best I can do is send it a sigkill.
155 * perhaps it should be put in the status that it wants to
156 * exit.
158 case PTRACE_KILL:
159 pr_debug("PTRACE_KILL\n");
160 rval = 0;
161 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
162 break;
163 child->exit_code = SIGKILL;
164 wake_up_process(child);
165 break;
167 case PTRACE_DETACH: /* detach a process that was attached. */
168 pr_debug("PTRACE_DETACH\n");
169 rval = ptrace_detach(child, data);
170 break;
171 default:
172 /* rval = ptrace_request(child, request, addr, data); noMMU */
173 rval = -EIO;
175 return rval;
178 void ptrace_disable(struct task_struct *child)
180 /* nothing to do */