Merge branch 'cleanup' of git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux...
[linux-2.6-xlnx.git] / arch / c6x / kernel / ptrace.c
blob3c494e84444d1e2347d91bb67531e314166c3109
1 /*
2 * Port on Texas Instruments TMS320C6x architecture
4 * Copyright (C) 2004, 2006, 2009, 2010, 2011 Texas Instruments Incorporated
5 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
7 * Updated for 2.6.34: Mark Salter <msalter@redhat.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 #include <linux/ptrace.h>
14 #include <linux/tracehook.h>
15 #include <linux/regset.h>
16 #include <linux/elf.h>
18 #include <asm/cacheflush.h>
20 #define PT_REG_SIZE (sizeof(struct pt_regs))
23 * Called by kernel/ptrace.c when detaching.
25 void ptrace_disable(struct task_struct *child)
27 /* nothing to do */
31 * Get a register number from live pt_regs for the specified task.
33 static inline long get_reg(struct task_struct *task, int regno)
35 long *addr = (long *)task_pt_regs(task);
37 if (regno == PT_TSR || regno == PT_CSR)
38 return 0;
40 return addr[regno];
44 * Write contents of register REGNO in task TASK.
46 static inline int put_reg(struct task_struct *task,
47 int regno,
48 unsigned long data)
50 unsigned long *addr = (unsigned long *)task_pt_regs(task);
52 if (regno != PT_TSR && regno != PT_CSR)
53 addr[regno] = data;
55 return 0;
58 /* regset get/set implementations */
60 static int gpr_get(struct task_struct *target,
61 const struct user_regset *regset,
62 unsigned int pos, unsigned int count,
63 void *kbuf, void __user *ubuf)
65 struct pt_regs *regs = task_pt_regs(target);
67 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
68 regs,
69 0, sizeof(*regs));
72 static int gpr_set(struct task_struct *target,
73 const struct user_regset *regset,
74 unsigned int pos, unsigned int count,
75 const void *kbuf, const void __user *ubuf)
77 int ret;
78 struct pt_regs *regs = task_pt_regs(target);
80 /* Don't copyin TSR or CSR */
81 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
82 &regs,
83 0, PT_TSR * sizeof(long));
84 if (ret)
85 return ret;
87 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
88 PT_TSR * sizeof(long),
89 (PT_TSR + 1) * sizeof(long));
90 if (ret)
91 return ret;
93 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
94 &regs,
95 (PT_TSR + 1) * sizeof(long),
96 PT_CSR * sizeof(long));
97 if (ret)
98 return ret;
100 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
101 PT_CSR * sizeof(long),
102 (PT_CSR + 1) * sizeof(long));
103 if (ret)
104 return ret;
106 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
107 &regs,
108 (PT_CSR + 1) * sizeof(long), -1);
109 return ret;
112 enum c6x_regset {
113 REGSET_GPR,
116 static const struct user_regset c6x_regsets[] = {
117 [REGSET_GPR] = {
118 .core_note_type = NT_PRSTATUS,
119 .n = ELF_NGREG,
120 .size = sizeof(u32),
121 .align = sizeof(u32),
122 .get = gpr_get,
123 .set = gpr_set
127 static const struct user_regset_view user_c6x_native_view = {
128 .name = "tic6x",
129 .e_machine = EM_TI_C6000,
130 .regsets = c6x_regsets,
131 .n = ARRAY_SIZE(c6x_regsets),
134 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
136 return &user_c6x_native_view;
140 * Perform ptrace request
142 long arch_ptrace(struct task_struct *child, long request,
143 unsigned long addr, unsigned long data)
145 int ret = 0;
147 switch (request) {
149 * write the word at location addr.
151 case PTRACE_POKETEXT:
152 ret = generic_ptrace_pokedata(child, addr, data);
153 if (ret == 0 && request == PTRACE_POKETEXT)
154 flush_icache_range(addr, addr + 4);
155 break;
156 default:
157 ret = ptrace_request(child, request, addr, data);
158 break;
161 return ret;
165 * handle tracing of system call entry
166 * - return the revised system call number or ULONG_MAX to cause ENOSYS
168 asmlinkage unsigned long syscall_trace_entry(struct pt_regs *regs)
170 if (tracehook_report_syscall_entry(regs))
171 /* tracing decided this syscall should not happen, so
172 * We'll return a bogus call number to get an ENOSYS
173 * error, but leave the original number in
174 * regs->orig_a4
176 return ULONG_MAX;
178 return regs->b0;
182 * handle tracing of system call exit
184 asmlinkage void syscall_trace_exit(struct pt_regs *regs)
186 tracehook_report_syscall_exit(regs, 0);