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>
29 #include <linux/sched.h>
30 #include <linux/ptrace.h>
31 #include <linux/signal.h>
32 #include <linux/elf.h>
33 #include <linux/audit.h>
34 #include <linux/seccomp.h>
35 #include <linux/tracehook.h>
37 #include <linux/errno.h>
38 #include <asm/processor.h>
39 #include <linux/uaccess.h>
40 #include <asm/asm-offsets.h>
41 #include <asm/cacheflush.h>
44 /* Returns the address where the register at REG_OFFS in P is stashed away. */
45 static microblaze_reg_t *reg_save_addr(unsigned reg_offs,
46 struct task_struct *t)
53 * (1) A register normally saved before calling the scheduler, is
54 * available in the kernel entry pt_regs structure at the top
55 * of the kernel stack. The kernel trap/irq exit path takes
56 * care to save/restore almost all registers for ptrace'd
59 * (2) A call-clobbered register, where the process P entered the
60 * kernel via [syscall] trap, is not stored anywhere; that's
61 * OK, because such registers are not expected to be preserved
62 * when the trap returns anyway (so we don't actually bother to
63 * test for this case).
65 * (3) A few registers not used at all by the kernel, and so
66 * normally never saved except by context-switches, are in the
67 * context switch state.
70 /* Register saved during kernel entry (or not available). */
71 regs = task_pt_regs(t);
73 return (microblaze_reg_t *)((char *)regs + reg_offs);
76 long arch_ptrace(struct task_struct *child, long request,
77 unsigned long addr, unsigned long data)
80 unsigned long val = 0;
83 /* Read/write the word at location ADDR in the registers. */
86 pr_debug("PEEKUSR/POKEUSR : 0x%08lx\n", addr);
88 if (addr >= PT_SIZE && request == PTRACE_PEEKUSR) {
90 * Special requests that don't actually correspond
91 * to offsets in struct pt_regs.
93 if (addr == PT_TEXT_ADDR) {
94 val = child->mm->start_code;
95 } else if (addr == PT_DATA_ADDR) {
96 val = child->mm->start_data;
97 } else if (addr == PT_TEXT_LEN) {
98 val = child->mm->end_code
99 - child->mm->start_code;
103 } else if (addr < PT_SIZE && (addr & 0x3) == 0) {
104 microblaze_reg_t *reg_addr = reg_save_addr(addr, child);
105 if (request == PTRACE_PEEKUSR)
111 /* MS potential problem on WB system
112 * Be aware that reg_addr is virtual address
113 * virt_to_phys conversion is necessary.
114 * This could be sensible solution.
116 u32 paddr = virt_to_phys((u32)reg_addr);
117 invalidate_icache_range(paddr, paddr + 4);
119 flush_dcache_range(paddr, paddr + 4);
125 if (rval == 0 && request == PTRACE_PEEKUSR)
126 rval = put_user(val, (unsigned long *)data);
129 rval = ptrace_request(child, request, addr, data);
134 asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
138 secure_computing(regs->r12);
140 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
141 tracehook_report_syscall_entry(regs))
143 * Tracing decided this syscall should not happen.
144 * We'll return a bogus call number to get an ENOSYS
145 * error, but leave the original number in regs->regs[0].
149 if (unlikely(current->audit_context))
150 audit_syscall_entry(EM_XILINX_MICROBLAZE, regs->r12,
154 return ret ?: regs->r12;
157 asmlinkage void do_syscall_trace_leave(struct pt_regs *regs)
161 if (unlikely(current->audit_context))
162 audit_syscall_exit(AUDITSC_RESULT(regs->r3), regs->r3);
164 step = test_thread_flag(TIF_SINGLESTEP);
165 if (step || test_thread_flag(TIF_SYSCALL_TRACE))
166 tracehook_report_syscall_exit(regs, step);
170 static asmlinkage void syscall_trace(void)
172 if (!test_thread_flag(TIF_SYSCALL_TRACE))
174 if (!(current->ptrace & PT_PTRACED))
176 /* The 0x80 provides a way for the tracing parent to distinguish
177 between a syscall stop and SIGTRAP delivery */
178 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
181 * this isn't the same as continuing with a signal, but it will do
182 * for normal use. strace only continues with a signal if the
183 * stopping signal is not SIGTRAP. -brl
185 if (current->exit_code) {
186 send_sig(current->exit_code, current, 1);
187 current->exit_code = 0;
192 void ptrace_disable(struct task_struct *child)