]>
Commit | Line | Data |
---|---|---|
52679b2d AJ |
1 | /* |
2 | * Port on Texas Instruments TMS320C6x architecture | |
3 | * | |
4 | * Copyright (C) 2004, 2006, 2009, 2010, 2011 Texas Instruments Incorporated | |
5 | * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com) | |
6 | * | |
7 | * Updated for 2.6.34: Mark Salter <msalter@redhat.com> | |
8 | * | |
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. | |
12 | */ | |
13 | #include <linux/ptrace.h> | |
14 | #include <linux/tracehook.h> | |
15 | #include <linux/regset.h> | |
16 | #include <linux/elf.h> | |
68db0cf1 | 17 | #include <linux/sched/task_stack.h> |
52679b2d AJ |
18 | |
19 | #include <asm/cacheflush.h> | |
20 | ||
21 | #define PT_REG_SIZE (sizeof(struct pt_regs)) | |
22 | ||
23 | /* | |
24 | * Called by kernel/ptrace.c when detaching. | |
25 | */ | |
26 | void ptrace_disable(struct task_struct *child) | |
27 | { | |
28 | /* nothing to do */ | |
29 | } | |
30 | ||
31 | /* | |
32 | * Get a register number from live pt_regs for the specified task. | |
33 | */ | |
34 | static inline long get_reg(struct task_struct *task, int regno) | |
35 | { | |
36 | long *addr = (long *)task_pt_regs(task); | |
37 | ||
38 | if (regno == PT_TSR || regno == PT_CSR) | |
39 | return 0; | |
40 | ||
41 | return addr[regno]; | |
42 | } | |
43 | ||
44 | /* | |
45 | * Write contents of register REGNO in task TASK. | |
46 | */ | |
47 | static inline int put_reg(struct task_struct *task, | |
48 | int regno, | |
49 | unsigned long data) | |
50 | { | |
51 | unsigned long *addr = (unsigned long *)task_pt_regs(task); | |
52 | ||
53 | if (regno != PT_TSR && regno != PT_CSR) | |
54 | addr[regno] = data; | |
55 | ||
56 | return 0; | |
57 | } | |
58 | ||
59 | /* regset get/set implementations */ | |
60 | ||
61 | static int gpr_get(struct task_struct *target, | |
62 | const struct user_regset *regset, | |
63 | unsigned int pos, unsigned int count, | |
64 | void *kbuf, void __user *ubuf) | |
65 | { | |
66 | struct pt_regs *regs = task_pt_regs(target); | |
67 | ||
68 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, | |
69 | regs, | |
70 | 0, sizeof(*regs)); | |
71 | } | |
72 | ||
73 | static int gpr_set(struct task_struct *target, | |
74 | const struct user_regset *regset, | |
75 | unsigned int pos, unsigned int count, | |
76 | const void *kbuf, const void __user *ubuf) | |
77 | { | |
78 | int ret; | |
79 | struct pt_regs *regs = task_pt_regs(target); | |
80 | ||
81 | /* Don't copyin TSR or CSR */ | |
82 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | |
83 | ®s, | |
84 | 0, PT_TSR * sizeof(long)); | |
85 | if (ret) | |
86 | return ret; | |
87 | ||
88 | ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, | |
89 | PT_TSR * sizeof(long), | |
90 | (PT_TSR + 1) * sizeof(long)); | |
91 | if (ret) | |
92 | return ret; | |
93 | ||
94 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | |
95 | ®s, | |
96 | (PT_TSR + 1) * sizeof(long), | |
97 | PT_CSR * sizeof(long)); | |
98 | if (ret) | |
99 | return ret; | |
100 | ||
101 | ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, | |
102 | PT_CSR * sizeof(long), | |
103 | (PT_CSR + 1) * sizeof(long)); | |
104 | if (ret) | |
105 | return ret; | |
106 | ||
107 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | |
108 | ®s, | |
109 | (PT_CSR + 1) * sizeof(long), -1); | |
110 | return ret; | |
111 | } | |
112 | ||
113 | enum c6x_regset { | |
114 | REGSET_GPR, | |
115 | }; | |
116 | ||
117 | static const struct user_regset c6x_regsets[] = { | |
118 | [REGSET_GPR] = { | |
119 | .core_note_type = NT_PRSTATUS, | |
120 | .n = ELF_NGREG, | |
121 | .size = sizeof(u32), | |
122 | .align = sizeof(u32), | |
123 | .get = gpr_get, | |
124 | .set = gpr_set | |
125 | }, | |
126 | }; | |
127 | ||
128 | static const struct user_regset_view user_c6x_native_view = { | |
129 | .name = "tic6x", | |
130 | .e_machine = EM_TI_C6000, | |
131 | .regsets = c6x_regsets, | |
132 | .n = ARRAY_SIZE(c6x_regsets), | |
133 | }; | |
134 | ||
135 | const struct user_regset_view *task_user_regset_view(struct task_struct *task) | |
136 | { | |
137 | return &user_c6x_native_view; | |
138 | } | |
139 | ||
140 | /* | |
141 | * Perform ptrace request | |
142 | */ | |
143 | long arch_ptrace(struct task_struct *child, long request, | |
144 | unsigned long addr, unsigned long data) | |
145 | { | |
146 | int ret = 0; | |
147 | ||
148 | switch (request) { | |
149 | /* | |
150 | * write the word at location addr. | |
151 | */ | |
152 | case PTRACE_POKETEXT: | |
153 | ret = generic_ptrace_pokedata(child, addr, data); | |
154 | if (ret == 0 && request == PTRACE_POKETEXT) | |
155 | flush_icache_range(addr, addr + 4); | |
156 | break; | |
157 | default: | |
158 | ret = ptrace_request(child, request, addr, data); | |
159 | break; | |
160 | } | |
161 | ||
162 | return ret; | |
163 | } | |
164 | ||
165 | /* | |
166 | * handle tracing of system call entry | |
167 | * - return the revised system call number or ULONG_MAX to cause ENOSYS | |
168 | */ | |
169 | asmlinkage unsigned long syscall_trace_entry(struct pt_regs *regs) | |
170 | { | |
171 | if (tracehook_report_syscall_entry(regs)) | |
172 | /* tracing decided this syscall should not happen, so | |
173 | * We'll return a bogus call number to get an ENOSYS | |
174 | * error, but leave the original number in | |
175 | * regs->orig_a4 | |
176 | */ | |
177 | return ULONG_MAX; | |
178 | ||
179 | return regs->b0; | |
180 | } | |
181 | ||
182 | /* | |
183 | * handle tracing of system call exit | |
184 | */ | |
185 | asmlinkage void syscall_trace_exit(struct pt_regs *regs) | |
186 | { | |
187 | tracehook_report_syscall_exit(regs, 0); | |
188 | } |