]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * PowerPC version |
3 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) | |
4 | * | |
5 | * Derived from "arch/m68k/kernel/ptrace.c" | |
6 | * Copyright (C) 1994 by Hamish Macdonald | |
7 | * Taken from linux/kernel/ptrace.c and modified for M680x0. | |
8 | * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds | |
9 | * | |
10 | * Modified by Cort Dougan (cort@hq.fsmlabs.com) | |
b123923d | 11 | * and Paul Mackerras (paulus@samba.org). |
1da177e4 LT |
12 | * |
13 | * This file is subject to the terms and conditions of the GNU General | |
14 | * Public License. See the file README.legal in the main directory of | |
15 | * this archive for more details. | |
16 | */ | |
17 | ||
18 | #include <linux/kernel.h> | |
19 | #include <linux/sched.h> | |
20 | #include <linux/mm.h> | |
21 | #include <linux/smp.h> | |
1da177e4 LT |
22 | #include <linux/errno.h> |
23 | #include <linux/ptrace.h> | |
f65255e8 | 24 | #include <linux/regset.h> |
4f72c427 | 25 | #include <linux/tracehook.h> |
3caf06c6 | 26 | #include <linux/elf.h> |
1da177e4 LT |
27 | #include <linux/user.h> |
28 | #include <linux/security.h> | |
7ed20e1a | 29 | #include <linux/signal.h> |
ea9c102c DW |
30 | #include <linux/seccomp.h> |
31 | #include <linux/audit.h> | |
02424d89 | 32 | #include <trace/syscall.h> |
5aae8a53 P |
33 | #include <linux/hw_breakpoint.h> |
34 | #include <linux/perf_event.h> | |
22ecbe8d | 35 | #include <linux/context_tracking.h> |
1da177e4 LT |
36 | |
37 | #include <asm/uaccess.h> | |
38 | #include <asm/page.h> | |
39 | #include <asm/pgtable.h> | |
ae3a197e | 40 | #include <asm/switch_to.h> |
21a62902 | 41 | |
02424d89 IM |
42 | #define CREATE_TRACE_POINTS |
43 | #include <trace/events/syscalls.h> | |
44 | ||
359e4284 MS |
45 | /* |
46 | * The parameter save area on the stack is used to store arguments being passed | |
47 | * to callee function and is located at fixed offset from stack pointer. | |
48 | */ | |
49 | #ifdef CONFIG_PPC32 | |
50 | #define PARAMETER_SAVE_AREA_OFFSET 24 /* bytes */ | |
51 | #else /* CONFIG_PPC32 */ | |
52 | #define PARAMETER_SAVE_AREA_OFFSET 48 /* bytes */ | |
53 | #endif | |
54 | ||
55 | struct pt_regs_offset { | |
56 | const char *name; | |
57 | int offset; | |
58 | }; | |
59 | ||
60 | #define STR(s) #s /* convert to string */ | |
61 | #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)} | |
62 | #define GPR_OFFSET_NAME(num) \ | |
343c3327 | 63 | {.name = STR(r##num), .offset = offsetof(struct pt_regs, gpr[num])}, \ |
359e4284 MS |
64 | {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])} |
65 | #define REG_OFFSET_END {.name = NULL, .offset = 0} | |
66 | ||
67 | static const struct pt_regs_offset regoffset_table[] = { | |
68 | GPR_OFFSET_NAME(0), | |
69 | GPR_OFFSET_NAME(1), | |
70 | GPR_OFFSET_NAME(2), | |
71 | GPR_OFFSET_NAME(3), | |
72 | GPR_OFFSET_NAME(4), | |
73 | GPR_OFFSET_NAME(5), | |
74 | GPR_OFFSET_NAME(6), | |
75 | GPR_OFFSET_NAME(7), | |
76 | GPR_OFFSET_NAME(8), | |
77 | GPR_OFFSET_NAME(9), | |
78 | GPR_OFFSET_NAME(10), | |
79 | GPR_OFFSET_NAME(11), | |
80 | GPR_OFFSET_NAME(12), | |
81 | GPR_OFFSET_NAME(13), | |
82 | GPR_OFFSET_NAME(14), | |
83 | GPR_OFFSET_NAME(15), | |
84 | GPR_OFFSET_NAME(16), | |
85 | GPR_OFFSET_NAME(17), | |
86 | GPR_OFFSET_NAME(18), | |
87 | GPR_OFFSET_NAME(19), | |
88 | GPR_OFFSET_NAME(20), | |
89 | GPR_OFFSET_NAME(21), | |
90 | GPR_OFFSET_NAME(22), | |
91 | GPR_OFFSET_NAME(23), | |
92 | GPR_OFFSET_NAME(24), | |
93 | GPR_OFFSET_NAME(25), | |
94 | GPR_OFFSET_NAME(26), | |
95 | GPR_OFFSET_NAME(27), | |
96 | GPR_OFFSET_NAME(28), | |
97 | GPR_OFFSET_NAME(29), | |
98 | GPR_OFFSET_NAME(30), | |
99 | GPR_OFFSET_NAME(31), | |
100 | REG_OFFSET_NAME(nip), | |
101 | REG_OFFSET_NAME(msr), | |
102 | REG_OFFSET_NAME(ctr), | |
103 | REG_OFFSET_NAME(link), | |
104 | REG_OFFSET_NAME(xer), | |
105 | REG_OFFSET_NAME(ccr), | |
106 | #ifdef CONFIG_PPC64 | |
107 | REG_OFFSET_NAME(softe), | |
108 | #else | |
109 | REG_OFFSET_NAME(mq), | |
110 | #endif | |
111 | REG_OFFSET_NAME(trap), | |
112 | REG_OFFSET_NAME(dar), | |
113 | REG_OFFSET_NAME(dsisr), | |
114 | REG_OFFSET_END, | |
115 | }; | |
116 | ||
117 | /** | |
118 | * regs_query_register_offset() - query register offset from its name | |
119 | * @name: the name of a register | |
120 | * | |
121 | * regs_query_register_offset() returns the offset of a register in struct | |
122 | * pt_regs from its name. If the name is invalid, this returns -EINVAL; | |
123 | */ | |
124 | int regs_query_register_offset(const char *name) | |
125 | { | |
126 | const struct pt_regs_offset *roff; | |
127 | for (roff = regoffset_table; roff->name != NULL; roff++) | |
128 | if (!strcmp(roff->name, name)) | |
129 | return roff->offset; | |
130 | return -EINVAL; | |
131 | } | |
132 | ||
133 | /** | |
134 | * regs_query_register_name() - query register name from its offset | |
135 | * @offset: the offset of a register in struct pt_regs. | |
136 | * | |
137 | * regs_query_register_name() returns the name of a register from its | |
138 | * offset in struct pt_regs. If the @offset is invalid, this returns NULL; | |
139 | */ | |
140 | const char *regs_query_register_name(unsigned int offset) | |
141 | { | |
142 | const struct pt_regs_offset *roff; | |
143 | for (roff = regoffset_table; roff->name != NULL; roff++) | |
144 | if (roff->offset == offset) | |
145 | return roff->name; | |
146 | return NULL; | |
147 | } | |
148 | ||
abd06505 BH |
149 | /* |
150 | * does not yet catch signals sent when the child dies. | |
151 | * in exit.c or in signal.c. | |
152 | */ | |
153 | ||
154 | /* | |
155 | * Set of msr bits that gdb can change on behalf of a process. | |
156 | */ | |
172ae2e7 | 157 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
abd06505 | 158 | #define MSR_DEBUGCHANGE 0 |
1da177e4 | 159 | #else |
abd06505 | 160 | #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE) |
1da177e4 | 161 | #endif |
acd89828 | 162 | |
1da177e4 | 163 | /* |
abd06505 | 164 | * Max register writeable via put_reg |
1da177e4 | 165 | */ |
abd06505 BH |
166 | #ifdef CONFIG_PPC32 |
167 | #define PT_MAX_PUT_REG PT_MQ | |
168 | #else | |
169 | #define PT_MAX_PUT_REG PT_CCR | |
170 | #endif | |
1da177e4 | 171 | |
26f77130 RM |
172 | static unsigned long get_user_msr(struct task_struct *task) |
173 | { | |
174 | return task->thread.regs->msr | task->thread.fpexc_mode; | |
175 | } | |
176 | ||
177 | static int set_user_msr(struct task_struct *task, unsigned long msr) | |
178 | { | |
179 | task->thread.regs->msr &= ~MSR_DEBUGCHANGE; | |
180 | task->thread.regs->msr |= msr & MSR_DEBUGCHANGE; | |
181 | return 0; | |
182 | } | |
183 | ||
1715a826 | 184 | #ifdef CONFIG_PPC64 |
ee4a3916 | 185 | static int get_user_dscr(struct task_struct *task, unsigned long *data) |
1715a826 | 186 | { |
ee4a3916 AK |
187 | *data = task->thread.dscr; |
188 | return 0; | |
1715a826 AK |
189 | } |
190 | ||
191 | static int set_user_dscr(struct task_struct *task, unsigned long dscr) | |
192 | { | |
193 | task->thread.dscr = dscr; | |
194 | task->thread.dscr_inherit = 1; | |
195 | return 0; | |
196 | } | |
197 | #else | |
ee4a3916 | 198 | static int get_user_dscr(struct task_struct *task, unsigned long *data) |
1715a826 AK |
199 | { |
200 | return -EIO; | |
201 | } | |
202 | ||
203 | static int set_user_dscr(struct task_struct *task, unsigned long dscr) | |
204 | { | |
205 | return -EIO; | |
206 | } | |
207 | #endif | |
208 | ||
26f77130 RM |
209 | /* |
210 | * We prevent mucking around with the reserved area of trap | |
211 | * which are used internally by the kernel. | |
212 | */ | |
213 | static int set_user_trap(struct task_struct *task, unsigned long trap) | |
214 | { | |
215 | task->thread.regs->trap = trap & 0xfff0; | |
216 | return 0; | |
217 | } | |
218 | ||
865418d8 BH |
219 | /* |
220 | * Get contents of register REGNO in task TASK. | |
221 | */ | |
ee4a3916 | 222 | int ptrace_get_reg(struct task_struct *task, int regno, unsigned long *data) |
865418d8 | 223 | { |
ee4a3916 | 224 | if ((task->thread.regs == NULL) || !data) |
865418d8 BH |
225 | return -EIO; |
226 | ||
ee4a3916 AK |
227 | if (regno == PT_MSR) { |
228 | *data = get_user_msr(task); | |
229 | return 0; | |
230 | } | |
865418d8 | 231 | |
1715a826 | 232 | if (regno == PT_DSCR) |
ee4a3916 | 233 | return get_user_dscr(task, data); |
1715a826 | 234 | |
ee4a3916 AK |
235 | if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long))) { |
236 | *data = ((unsigned long *)task->thread.regs)[regno]; | |
237 | return 0; | |
238 | } | |
865418d8 BH |
239 | |
240 | return -EIO; | |
241 | } | |
242 | ||
243 | /* | |
244 | * Write contents of register REGNO in task TASK. | |
245 | */ | |
246 | int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data) | |
247 | { | |
248 | if (task->thread.regs == NULL) | |
249 | return -EIO; | |
250 | ||
26f77130 RM |
251 | if (regno == PT_MSR) |
252 | return set_user_msr(task, data); | |
253 | if (regno == PT_TRAP) | |
254 | return set_user_trap(task, data); | |
1715a826 AK |
255 | if (regno == PT_DSCR) |
256 | return set_user_dscr(task, data); | |
26f77130 RM |
257 | |
258 | if (regno <= PT_MAX_PUT_REG) { | |
865418d8 BH |
259 | ((unsigned long *)task->thread.regs)[regno] = data; |
260 | return 0; | |
261 | } | |
262 | return -EIO; | |
263 | } | |
264 | ||
44dd3f50 RM |
265 | static int gpr_get(struct task_struct *target, const struct user_regset *regset, |
266 | unsigned int pos, unsigned int count, | |
267 | void *kbuf, void __user *ubuf) | |
268 | { | |
a71f5d5d | 269 | int i, ret; |
44dd3f50 RM |
270 | |
271 | if (target->thread.regs == NULL) | |
272 | return -EIO; | |
273 | ||
a71f5d5d MW |
274 | if (!FULL_REGS(target->thread.regs)) { |
275 | /* We have a partial register set. Fill 14-31 with bogus values */ | |
276 | for (i = 14; i < 32; i++) | |
277 | target->thread.regs->gpr[i] = NV_REG_POISON; | |
278 | } | |
44dd3f50 RM |
279 | |
280 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, | |
281 | target->thread.regs, | |
282 | 0, offsetof(struct pt_regs, msr)); | |
283 | if (!ret) { | |
284 | unsigned long msr = get_user_msr(target); | |
285 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr, | |
286 | offsetof(struct pt_regs, msr), | |
287 | offsetof(struct pt_regs, msr) + | |
288 | sizeof(msr)); | |
289 | } | |
290 | ||
291 | BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != | |
292 | offsetof(struct pt_regs, msr) + sizeof(long)); | |
293 | ||
294 | if (!ret) | |
295 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, | |
296 | &target->thread.regs->orig_gpr3, | |
297 | offsetof(struct pt_regs, orig_gpr3), | |
298 | sizeof(struct pt_regs)); | |
299 | if (!ret) | |
300 | ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, | |
301 | sizeof(struct pt_regs), -1); | |
302 | ||
303 | return ret; | |
304 | } | |
305 | ||
306 | static int gpr_set(struct task_struct *target, const struct user_regset *regset, | |
307 | unsigned int pos, unsigned int count, | |
308 | const void *kbuf, const void __user *ubuf) | |
309 | { | |
310 | unsigned long reg; | |
311 | int ret; | |
312 | ||
313 | if (target->thread.regs == NULL) | |
314 | return -EIO; | |
315 | ||
316 | CHECK_FULL_REGS(target->thread.regs); | |
317 | ||
318 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | |
319 | target->thread.regs, | |
320 | 0, PT_MSR * sizeof(reg)); | |
321 | ||
322 | if (!ret && count > 0) { | |
323 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, ®, | |
324 | PT_MSR * sizeof(reg), | |
325 | (PT_MSR + 1) * sizeof(reg)); | |
326 | if (!ret) | |
327 | ret = set_user_msr(target, reg); | |
328 | } | |
329 | ||
330 | BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != | |
331 | offsetof(struct pt_regs, msr) + sizeof(long)); | |
332 | ||
333 | if (!ret) | |
334 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | |
335 | &target->thread.regs->orig_gpr3, | |
336 | PT_ORIG_R3 * sizeof(reg), | |
337 | (PT_MAX_PUT_REG + 1) * sizeof(reg)); | |
338 | ||
339 | if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret) | |
340 | ret = user_regset_copyin_ignore( | |
341 | &pos, &count, &kbuf, &ubuf, | |
342 | (PT_MAX_PUT_REG + 1) * sizeof(reg), | |
343 | PT_TRAP * sizeof(reg)); | |
344 | ||
345 | if (!ret && count > 0) { | |
346 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, ®, | |
347 | PT_TRAP * sizeof(reg), | |
348 | (PT_TRAP + 1) * sizeof(reg)); | |
349 | if (!ret) | |
350 | ret = set_user_trap(target, reg); | |
351 | } | |
352 | ||
353 | if (!ret) | |
354 | ret = user_regset_copyin_ignore( | |
355 | &pos, &count, &kbuf, &ubuf, | |
356 | (PT_TRAP + 1) * sizeof(reg), -1); | |
357 | ||
358 | return ret; | |
359 | } | |
865418d8 | 360 | |
1ec8549d AK |
361 | /* |
362 | * When the transaction is active, 'transact_fp' holds the current running | |
363 | * value of all FPR registers and 'fp_state' holds the last checkpointed | |
364 | * value of all FPR registers for the current transaction. When transaction | |
365 | * is not active 'fp_state' holds the current running state of all the FPR | |
366 | * registers. So this function which returns the current running values of | |
367 | * all the FPR registers, needs to know whether any transaction is active | |
368 | * or not. | |
369 | * | |
370 | * Userspace interface buffer layout: | |
371 | * | |
372 | * struct data { | |
373 | * u64 fpr[32]; | |
374 | * u64 fpscr; | |
375 | * }; | |
376 | * | |
377 | * There are two config options CONFIG_VSX and CONFIG_PPC_TRANSACTIONAL_MEM | |
378 | * which determines the final code in this function. All the combinations of | |
379 | * these two config options are possible except the one below as transactional | |
380 | * memory config pulls in CONFIG_VSX automatically. | |
381 | * | |
382 | * !defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM) | |
383 | */ | |
f65255e8 RM |
384 | static int fpr_get(struct task_struct *target, const struct user_regset *regset, |
385 | unsigned int pos, unsigned int count, | |
386 | void *kbuf, void __user *ubuf) | |
387 | { | |
c6e6771b | 388 | #ifdef CONFIG_VSX |
de79f7b9 | 389 | u64 buf[33]; |
c6e6771b MN |
390 | int i; |
391 | #endif | |
f65255e8 RM |
392 | flush_fp_to_thread(target); |
393 | ||
1ec8549d AK |
394 | #if defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM) |
395 | /* copy to local buffer then write that out */ | |
396 | if (MSR_TM_ACTIVE(target->thread.regs->msr)) { | |
397 | flush_altivec_to_thread(target); | |
398 | flush_tmregs_to_thread(target); | |
399 | for (i = 0; i < 32 ; i++) | |
400 | buf[i] = target->thread.TS_TRANS_FPR(i); | |
401 | buf[32] = target->thread.transact_fp.fpscr; | |
402 | } else { | |
403 | for (i = 0; i < 32 ; i++) | |
404 | buf[i] = target->thread.TS_FPR(i); | |
405 | buf[32] = target->thread.fp_state.fpscr; | |
406 | } | |
407 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1); | |
408 | #endif | |
409 | ||
410 | #if defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM) | |
c6e6771b MN |
411 | /* copy to local buffer then write that out */ |
412 | for (i = 0; i < 32 ; i++) | |
413 | buf[i] = target->thread.TS_FPR(i); | |
de79f7b9 | 414 | buf[32] = target->thread.fp_state.fpscr; |
c6e6771b | 415 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1); |
1ec8549d | 416 | #endif |
c6e6771b | 417 | |
1ec8549d | 418 | #if !defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM) |
de79f7b9 | 419 | BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) != |
1e407ee3 | 420 | offsetof(struct thread_fp_state, fpr[32])); |
f65255e8 RM |
421 | |
422 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, | |
de79f7b9 | 423 | &target->thread.fp_state, 0, -1); |
c6e6771b | 424 | #endif |
f65255e8 RM |
425 | } |
426 | ||
1ec8549d AK |
427 | /* |
428 | * When the transaction is active, 'transact_fp' holds the current running | |
429 | * value of all FPR registers and 'fp_state' holds the last checkpointed | |
430 | * value of all FPR registers for the current transaction. When transaction | |
431 | * is not active 'fp_state' holds the current running state of all the FPR | |
432 | * registers. So this function which setss the current running values of | |
433 | * all the FPR registers, needs to know whether any transaction is active | |
434 | * or not. | |
435 | * | |
436 | * Userspace interface buffer layout: | |
437 | * | |
438 | * struct data { | |
439 | * u64 fpr[32]; | |
440 | * u64 fpscr; | |
441 | * }; | |
442 | * | |
443 | * There are two config options CONFIG_VSX and CONFIG_PPC_TRANSACTIONAL_MEM | |
444 | * which determines the final code in this function. All the combinations of | |
445 | * these two config options are possible except the one below as transactional | |
446 | * memory config pulls in CONFIG_VSX automatically. | |
447 | * | |
448 | * !defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM) | |
449 | */ | |
f65255e8 RM |
450 | static int fpr_set(struct task_struct *target, const struct user_regset *regset, |
451 | unsigned int pos, unsigned int count, | |
452 | const void *kbuf, const void __user *ubuf) | |
453 | { | |
c6e6771b | 454 | #ifdef CONFIG_VSX |
de79f7b9 | 455 | u64 buf[33]; |
c6e6771b MN |
456 | int i; |
457 | #endif | |
f65255e8 RM |
458 | flush_fp_to_thread(target); |
459 | ||
1ec8549d AK |
460 | #if defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM) |
461 | /* copy to local buffer then write that out */ | |
462 | i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1); | |
463 | if (i) | |
464 | return i; | |
465 | ||
466 | if (MSR_TM_ACTIVE(target->thread.regs->msr)) { | |
467 | flush_altivec_to_thread(target); | |
468 | flush_tmregs_to_thread(target); | |
469 | for (i = 0; i < 32 ; i++) | |
470 | target->thread.TS_TRANS_FPR(i) = buf[i]; | |
471 | target->thread.transact_fp.fpscr = buf[32]; | |
472 | } else { | |
473 | for (i = 0; i < 32 ; i++) | |
474 | target->thread.TS_FPR(i) = buf[i]; | |
475 | target->thread.fp_state.fpscr = buf[32]; | |
476 | } | |
477 | return 0; | |
478 | #endif | |
479 | ||
480 | #if defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM) | |
c6e6771b MN |
481 | /* copy to local buffer then write that out */ |
482 | i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1); | |
483 | if (i) | |
484 | return i; | |
485 | for (i = 0; i < 32 ; i++) | |
486 | target->thread.TS_FPR(i) = buf[i]; | |
de79f7b9 | 487 | target->thread.fp_state.fpscr = buf[32]; |
c6e6771b | 488 | return 0; |
1ec8549d AK |
489 | #endif |
490 | ||
491 | #if !defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM) | |
de79f7b9 | 492 | BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) != |
1e407ee3 | 493 | offsetof(struct thread_fp_state, fpr[32])); |
f65255e8 RM |
494 | |
495 | return user_regset_copyin(&pos, &count, &kbuf, &ubuf, | |
de79f7b9 | 496 | &target->thread.fp_state, 0, -1); |
c6e6771b | 497 | #endif |
f65255e8 RM |
498 | } |
499 | ||
865418d8 BH |
500 | #ifdef CONFIG_ALTIVEC |
501 | /* | |
502 | * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go. | |
503 | * The transfer totals 34 quadword. Quadwords 0-31 contain the | |
504 | * corresponding vector registers. Quadword 32 contains the vscr as the | |
505 | * last word (offset 12) within that quadword. Quadword 33 contains the | |
506 | * vrsave as the first word (offset 0) within the quadword. | |
507 | * | |
508 | * This definition of the VMX state is compatible with the current PPC32 | |
509 | * ptrace interface. This allows signal handling and ptrace to use the | |
510 | * same structures. This also simplifies the implementation of a bi-arch | |
511 | * (combined (32- and 64-bit) gdb. | |
512 | */ | |
513 | ||
3caf06c6 RM |
514 | static int vr_active(struct task_struct *target, |
515 | const struct user_regset *regset) | |
516 | { | |
517 | flush_altivec_to_thread(target); | |
518 | return target->thread.used_vr ? regset->n : 0; | |
519 | } | |
520 | ||
d844e279 AK |
521 | /* |
522 | * When the transaction is active, 'transact_vr' holds the current running | |
523 | * value of all the VMX registers and 'vr_state' holds the last checkpointed | |
524 | * value of all the VMX registers for the current transaction to fall back | |
525 | * on in case it aborts. When transaction is not active 'vr_state' holds | |
526 | * the current running state of all the VMX registers. So this function which | |
527 | * gets the current running values of all the VMX registers, needs to know | |
528 | * whether any transaction is active or not. | |
529 | * | |
530 | * Userspace interface buffer layout: | |
531 | * | |
532 | * struct data { | |
533 | * vector128 vr[32]; | |
534 | * vector128 vscr; | |
535 | * vector128 vrsave; | |
536 | * }; | |
537 | */ | |
3caf06c6 RM |
538 | static int vr_get(struct task_struct *target, const struct user_regset *regset, |
539 | unsigned int pos, unsigned int count, | |
540 | void *kbuf, void __user *ubuf) | |
541 | { | |
d844e279 | 542 | struct thread_vr_state *addr; |
3caf06c6 RM |
543 | int ret; |
544 | ||
545 | flush_altivec_to_thread(target); | |
546 | ||
de79f7b9 PM |
547 | BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) != |
548 | offsetof(struct thread_vr_state, vr[32])); | |
3caf06c6 | 549 | |
d844e279 AK |
550 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
551 | if (MSR_TM_ACTIVE(target->thread.regs->msr)) { | |
552 | flush_fp_to_thread(target); | |
553 | flush_tmregs_to_thread(target); | |
554 | addr = &target->thread.transact_vr; | |
555 | } else { | |
556 | addr = &target->thread.vr_state; | |
557 | } | |
558 | #else | |
559 | addr = &target->thread.vr_state; | |
560 | #endif | |
3caf06c6 | 561 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
d844e279 | 562 | addr, 0, |
3caf06c6 RM |
563 | 33 * sizeof(vector128)); |
564 | if (!ret) { | |
565 | /* | |
566 | * Copy out only the low-order word of vrsave. | |
567 | */ | |
568 | union { | |
569 | elf_vrreg_t reg; | |
570 | u32 word; | |
571 | } vrsave; | |
572 | memset(&vrsave, 0, sizeof(vrsave)); | |
d844e279 AK |
573 | |
574 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
575 | if (MSR_TM_ACTIVE(target->thread.regs->msr)) | |
576 | vrsave.word = target->thread.transact_vrsave; | |
577 | else | |
578 | vrsave.word = target->thread.vrsave; | |
579 | #else | |
3caf06c6 | 580 | vrsave.word = target->thread.vrsave; |
d844e279 AK |
581 | #endif |
582 | ||
3caf06c6 RM |
583 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave, |
584 | 33 * sizeof(vector128), -1); | |
585 | } | |
586 | ||
587 | return ret; | |
588 | } | |
589 | ||
d844e279 AK |
590 | /* |
591 | * When the transaction is active, 'transact_vr' holds the current running | |
592 | * value of all the VMX registers and 'vr_state' holds the last checkpointed | |
593 | * value of all the VMX registers for the current transaction to fall back | |
594 | * on in case it aborts. When transaction is not active 'vr_state' holds | |
595 | * the current running state of all the VMX registers. So this function which | |
596 | * sets the current running values of all the VMX registers, needs to know | |
597 | * whether any transaction is active or not. | |
598 | * | |
599 | * Userspace interface buffer layout: | |
600 | * | |
601 | * struct data { | |
602 | * vector128 vr[32]; | |
603 | * vector128 vscr; | |
604 | * vector128 vrsave; | |
605 | * }; | |
606 | */ | |
3caf06c6 RM |
607 | static int vr_set(struct task_struct *target, const struct user_regset *regset, |
608 | unsigned int pos, unsigned int count, | |
609 | const void *kbuf, const void __user *ubuf) | |
610 | { | |
d844e279 | 611 | struct thread_vr_state *addr; |
3caf06c6 RM |
612 | int ret; |
613 | ||
614 | flush_altivec_to_thread(target); | |
615 | ||
de79f7b9 PM |
616 | BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) != |
617 | offsetof(struct thread_vr_state, vr[32])); | |
3caf06c6 | 618 | |
d844e279 AK |
619 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
620 | if (MSR_TM_ACTIVE(target->thread.regs->msr)) { | |
621 | flush_fp_to_thread(target); | |
622 | flush_tmregs_to_thread(target); | |
623 | addr = &target->thread.transact_vr; | |
624 | } else { | |
625 | addr = &target->thread.vr_state; | |
626 | } | |
627 | #else | |
628 | addr = &target->thread.vr_state; | |
629 | #endif | |
3caf06c6 | 630 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
d844e279 | 631 | addr, 0, |
de79f7b9 | 632 | 33 * sizeof(vector128)); |
3caf06c6 RM |
633 | if (!ret && count > 0) { |
634 | /* | |
635 | * We use only the first word of vrsave. | |
636 | */ | |
637 | union { | |
638 | elf_vrreg_t reg; | |
639 | u32 word; | |
640 | } vrsave; | |
641 | memset(&vrsave, 0, sizeof(vrsave)); | |
d844e279 AK |
642 | |
643 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
644 | if (MSR_TM_ACTIVE(target->thread.regs->msr)) | |
645 | vrsave.word = target->thread.transact_vrsave; | |
646 | else | |
647 | vrsave.word = target->thread.vrsave; | |
648 | #else | |
3caf06c6 | 649 | vrsave.word = target->thread.vrsave; |
d844e279 | 650 | #endif |
3caf06c6 RM |
651 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave, |
652 | 33 * sizeof(vector128), -1); | |
d844e279 AK |
653 | if (!ret) { |
654 | ||
655 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
656 | if (MSR_TM_ACTIVE(target->thread.regs->msr)) | |
657 | target->thread.transact_vrsave = vrsave.word; | |
658 | else | |
659 | target->thread.vrsave = vrsave.word; | |
660 | #else | |
3caf06c6 | 661 | target->thread.vrsave = vrsave.word; |
d844e279 AK |
662 | #endif |
663 | } | |
3caf06c6 RM |
664 | } |
665 | ||
666 | return ret; | |
667 | } | |
865418d8 BH |
668 | #endif /* CONFIG_ALTIVEC */ |
669 | ||
ce48b210 MN |
670 | #ifdef CONFIG_VSX |
671 | /* | |
672 | * Currently to set and and get all the vsx state, you need to call | |
25985edc | 673 | * the fp and VMX calls as well. This only get/sets the lower 32 |
ce48b210 MN |
674 | * 128bit VSX registers. |
675 | */ | |
676 | ||
677 | static int vsr_active(struct task_struct *target, | |
678 | const struct user_regset *regset) | |
679 | { | |
680 | flush_vsx_to_thread(target); | |
681 | return target->thread.used_vsr ? regset->n : 0; | |
682 | } | |
683 | ||
94b7d361 AK |
684 | /* |
685 | * When the transaction is active, 'transact_fp' holds the current running | |
686 | * value of all FPR registers and 'fp_state' holds the last checkpointed | |
687 | * value of all FPR registers for the current transaction. When transaction | |
688 | * is not active 'fp_state' holds the current running state of all the FPR | |
689 | * registers. So this function which returns the current running values of | |
690 | * all the FPR registers, needs to know whether any transaction is active | |
691 | * or not. | |
692 | * | |
693 | * Userspace interface buffer layout: | |
694 | * | |
695 | * struct data { | |
696 | * u64 vsx[32]; | |
697 | * }; | |
698 | */ | |
ce48b210 MN |
699 | static int vsr_get(struct task_struct *target, const struct user_regset *regset, |
700 | unsigned int pos, unsigned int count, | |
701 | void *kbuf, void __user *ubuf) | |
702 | { | |
de79f7b9 | 703 | u64 buf[32]; |
f3e909c2 | 704 | int ret, i; |
ce48b210 | 705 | |
94b7d361 AK |
706 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
707 | flush_fp_to_thread(target); | |
708 | flush_altivec_to_thread(target); | |
709 | flush_tmregs_to_thread(target); | |
710 | #endif | |
ce48b210 MN |
711 | flush_vsx_to_thread(target); |
712 | ||
94b7d361 AK |
713 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
714 | if (MSR_TM_ACTIVE(target->thread.regs->msr)) { | |
715 | for (i = 0; i < 32 ; i++) | |
716 | buf[i] = target->thread. | |
717 | transact_fp.fpr[i][TS_VSRLOWOFFSET]; | |
718 | } else { | |
719 | for (i = 0; i < 32 ; i++) | |
720 | buf[i] = target->thread. | |
721 | fp_state.fpr[i][TS_VSRLOWOFFSET]; | |
722 | } | |
723 | #else | |
f3e909c2 | 724 | for (i = 0; i < 32 ; i++) |
de79f7b9 | 725 | buf[i] = target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET]; |
94b7d361 | 726 | #endif |
ce48b210 | 727 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
f3e909c2 | 728 | buf, 0, 32 * sizeof(double)); |
ce48b210 MN |
729 | |
730 | return ret; | |
731 | } | |
732 | ||
94b7d361 AK |
733 | /* |
734 | * When the transaction is active, 'transact_fp' holds the current running | |
735 | * value of all FPR registers and 'fp_state' holds the last checkpointed | |
736 | * value of all FPR registers for the current transaction. When transaction | |
737 | * is not active 'fp_state' holds the current running state of all the FPR | |
738 | * registers. So this function which sets the current running values of all | |
739 | * the FPR registers, needs to know whether any transaction is active or not. | |
740 | * | |
741 | * Userspace interface buffer layout: | |
742 | * | |
743 | * struct data { | |
744 | * u64 vsx[32]; | |
745 | * }; | |
746 | */ | |
ce48b210 MN |
747 | static int vsr_set(struct task_struct *target, const struct user_regset *regset, |
748 | unsigned int pos, unsigned int count, | |
749 | const void *kbuf, const void __user *ubuf) | |
750 | { | |
de79f7b9 | 751 | u64 buf[32]; |
f3e909c2 | 752 | int ret,i; |
ce48b210 | 753 | |
94b7d361 AK |
754 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
755 | flush_fp_to_thread(target); | |
756 | flush_altivec_to_thread(target); | |
757 | flush_tmregs_to_thread(target); | |
758 | #endif | |
ce48b210 MN |
759 | flush_vsx_to_thread(target); |
760 | ||
761 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | |
f3e909c2 | 762 | buf, 0, 32 * sizeof(double)); |
94b7d361 AK |
763 | |
764 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
765 | if (MSR_TM_ACTIVE(target->thread.regs->msr)) { | |
766 | for (i = 0; i < 32 ; i++) | |
767 | target->thread.transact_fp. | |
768 | fpr[i][TS_VSRLOWOFFSET] = buf[i]; | |
769 | } else { | |
770 | for (i = 0; i < 32 ; i++) | |
771 | target->thread.fp_state. | |
772 | fpr[i][TS_VSRLOWOFFSET] = buf[i]; | |
773 | } | |
774 | #else | |
f3e909c2 | 775 | for (i = 0; i < 32 ; i++) |
de79f7b9 | 776 | target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i]; |
94b7d361 | 777 | #endif |
f3e909c2 | 778 | |
ce48b210 MN |
779 | |
780 | return ret; | |
781 | } | |
782 | #endif /* CONFIG_VSX */ | |
783 | ||
865418d8 BH |
784 | #ifdef CONFIG_SPE |
785 | ||
786 | /* | |
787 | * For get_evrregs/set_evrregs functions 'data' has the following layout: | |
788 | * | |
789 | * struct { | |
790 | * u32 evr[32]; | |
791 | * u64 acc; | |
792 | * u32 spefscr; | |
793 | * } | |
794 | */ | |
795 | ||
a4e4b175 RM |
796 | static int evr_active(struct task_struct *target, |
797 | const struct user_regset *regset) | |
865418d8 | 798 | { |
a4e4b175 RM |
799 | flush_spe_to_thread(target); |
800 | return target->thread.used_spe ? regset->n : 0; | |
801 | } | |
865418d8 | 802 | |
a4e4b175 RM |
803 | static int evr_get(struct task_struct *target, const struct user_regset *regset, |
804 | unsigned int pos, unsigned int count, | |
805 | void *kbuf, void __user *ubuf) | |
806 | { | |
807 | int ret; | |
865418d8 | 808 | |
a4e4b175 | 809 | flush_spe_to_thread(target); |
865418d8 | 810 | |
a4e4b175 RM |
811 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
812 | &target->thread.evr, | |
813 | 0, sizeof(target->thread.evr)); | |
865418d8 | 814 | |
a4e4b175 RM |
815 | BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) != |
816 | offsetof(struct thread_struct, spefscr)); | |
817 | ||
818 | if (!ret) | |
819 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, | |
820 | &target->thread.acc, | |
821 | sizeof(target->thread.evr), -1); | |
822 | ||
823 | return ret; | |
824 | } | |
825 | ||
826 | static int evr_set(struct task_struct *target, const struct user_regset *regset, | |
827 | unsigned int pos, unsigned int count, | |
828 | const void *kbuf, const void __user *ubuf) | |
829 | { | |
830 | int ret; | |
831 | ||
832 | flush_spe_to_thread(target); | |
833 | ||
834 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | |
835 | &target->thread.evr, | |
836 | 0, sizeof(target->thread.evr)); | |
865418d8 | 837 | |
a4e4b175 RM |
838 | BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) != |
839 | offsetof(struct thread_struct, spefscr)); | |
840 | ||
841 | if (!ret) | |
842 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | |
843 | &target->thread.acc, | |
844 | sizeof(target->thread.evr), -1); | |
845 | ||
846 | return ret; | |
865418d8 | 847 | } |
865418d8 BH |
848 | #endif /* CONFIG_SPE */ |
849 | ||
850 | ||
80fdf470 RM |
851 | /* |
852 | * These are our native regset flavors. | |
853 | */ | |
854 | enum powerpc_regset { | |
855 | REGSET_GPR, | |
856 | REGSET_FPR, | |
857 | #ifdef CONFIG_ALTIVEC | |
858 | REGSET_VMX, | |
859 | #endif | |
ce48b210 MN |
860 | #ifdef CONFIG_VSX |
861 | REGSET_VSX, | |
862 | #endif | |
80fdf470 RM |
863 | #ifdef CONFIG_SPE |
864 | REGSET_SPE, | |
865 | #endif | |
866 | }; | |
867 | ||
868 | static const struct user_regset native_regsets[] = { | |
869 | [REGSET_GPR] = { | |
870 | .core_note_type = NT_PRSTATUS, .n = ELF_NGREG, | |
871 | .size = sizeof(long), .align = sizeof(long), | |
872 | .get = gpr_get, .set = gpr_set | |
873 | }, | |
874 | [REGSET_FPR] = { | |
875 | .core_note_type = NT_PRFPREG, .n = ELF_NFPREG, | |
876 | .size = sizeof(double), .align = sizeof(double), | |
877 | .get = fpr_get, .set = fpr_set | |
878 | }, | |
879 | #ifdef CONFIG_ALTIVEC | |
880 | [REGSET_VMX] = { | |
881 | .core_note_type = NT_PPC_VMX, .n = 34, | |
882 | .size = sizeof(vector128), .align = sizeof(vector128), | |
883 | .active = vr_active, .get = vr_get, .set = vr_set | |
884 | }, | |
885 | #endif | |
ce48b210 MN |
886 | #ifdef CONFIG_VSX |
887 | [REGSET_VSX] = { | |
f3e909c2 MN |
888 | .core_note_type = NT_PPC_VSX, .n = 32, |
889 | .size = sizeof(double), .align = sizeof(double), | |
ce48b210 MN |
890 | .active = vsr_active, .get = vsr_get, .set = vsr_set |
891 | }, | |
892 | #endif | |
80fdf470 RM |
893 | #ifdef CONFIG_SPE |
894 | [REGSET_SPE] = { | |
a0b38b4e | 895 | .core_note_type = NT_PPC_SPE, .n = 35, |
80fdf470 RM |
896 | .size = sizeof(u32), .align = sizeof(u32), |
897 | .active = evr_active, .get = evr_get, .set = evr_set | |
898 | }, | |
899 | #endif | |
900 | }; | |
901 | ||
902 | static const struct user_regset_view user_ppc_native_view = { | |
903 | .name = UTS_MACHINE, .e_machine = ELF_ARCH, .ei_osabi = ELF_OSABI, | |
904 | .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets) | |
905 | }; | |
906 | ||
fa8f5cb0 RM |
907 | #ifdef CONFIG_PPC64 |
908 | #include <linux/compat.h> | |
909 | ||
910 | static int gpr32_get(struct task_struct *target, | |
911 | const struct user_regset *regset, | |
912 | unsigned int pos, unsigned int count, | |
913 | void *kbuf, void __user *ubuf) | |
914 | { | |
915 | const unsigned long *regs = &target->thread.regs->gpr[0]; | |
916 | compat_ulong_t *k = kbuf; | |
917 | compat_ulong_t __user *u = ubuf; | |
918 | compat_ulong_t reg; | |
a71f5d5d | 919 | int i; |
fa8f5cb0 RM |
920 | |
921 | if (target->thread.regs == NULL) | |
922 | return -EIO; | |
923 | ||
a71f5d5d MW |
924 | if (!FULL_REGS(target->thread.regs)) { |
925 | /* We have a partial register set. Fill 14-31 with bogus values */ | |
926 | for (i = 14; i < 32; i++) | |
927 | target->thread.regs->gpr[i] = NV_REG_POISON; | |
928 | } | |
fa8f5cb0 RM |
929 | |
930 | pos /= sizeof(reg); | |
931 | count /= sizeof(reg); | |
932 | ||
933 | if (kbuf) | |
934 | for (; count > 0 && pos < PT_MSR; --count) | |
935 | *k++ = regs[pos++]; | |
936 | else | |
937 | for (; count > 0 && pos < PT_MSR; --count) | |
938 | if (__put_user((compat_ulong_t) regs[pos++], u++)) | |
939 | return -EFAULT; | |
940 | ||
941 | if (count > 0 && pos == PT_MSR) { | |
942 | reg = get_user_msr(target); | |
943 | if (kbuf) | |
944 | *k++ = reg; | |
945 | else if (__put_user(reg, u++)) | |
946 | return -EFAULT; | |
947 | ++pos; | |
948 | --count; | |
949 | } | |
950 | ||
951 | if (kbuf) | |
952 | for (; count > 0 && pos < PT_REGS_COUNT; --count) | |
953 | *k++ = regs[pos++]; | |
954 | else | |
955 | for (; count > 0 && pos < PT_REGS_COUNT; --count) | |
956 | if (__put_user((compat_ulong_t) regs[pos++], u++)) | |
957 | return -EFAULT; | |
958 | ||
959 | kbuf = k; | |
960 | ubuf = u; | |
961 | pos *= sizeof(reg); | |
962 | count *= sizeof(reg); | |
963 | return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, | |
964 | PT_REGS_COUNT * sizeof(reg), -1); | |
965 | } | |
966 | ||
967 | static int gpr32_set(struct task_struct *target, | |
968 | const struct user_regset *regset, | |
969 | unsigned int pos, unsigned int count, | |
970 | const void *kbuf, const void __user *ubuf) | |
971 | { | |
972 | unsigned long *regs = &target->thread.regs->gpr[0]; | |
973 | const compat_ulong_t *k = kbuf; | |
974 | const compat_ulong_t __user *u = ubuf; | |
975 | compat_ulong_t reg; | |
976 | ||
977 | if (target->thread.regs == NULL) | |
978 | return -EIO; | |
979 | ||
980 | CHECK_FULL_REGS(target->thread.regs); | |
981 | ||
982 | pos /= sizeof(reg); | |
983 | count /= sizeof(reg); | |
984 | ||
985 | if (kbuf) | |
986 | for (; count > 0 && pos < PT_MSR; --count) | |
987 | regs[pos++] = *k++; | |
988 | else | |
989 | for (; count > 0 && pos < PT_MSR; --count) { | |
990 | if (__get_user(reg, u++)) | |
991 | return -EFAULT; | |
992 | regs[pos++] = reg; | |
993 | } | |
994 | ||
995 | ||
996 | if (count > 0 && pos == PT_MSR) { | |
997 | if (kbuf) | |
998 | reg = *k++; | |
999 | else if (__get_user(reg, u++)) | |
1000 | return -EFAULT; | |
1001 | set_user_msr(target, reg); | |
1002 | ++pos; | |
1003 | --count; | |
1004 | } | |
1005 | ||
c2372eb9 | 1006 | if (kbuf) { |
fa8f5cb0 RM |
1007 | for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) |
1008 | regs[pos++] = *k++; | |
c2372eb9 RM |
1009 | for (; count > 0 && pos < PT_TRAP; --count, ++pos) |
1010 | ++k; | |
1011 | } else { | |
fa8f5cb0 RM |
1012 | for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) { |
1013 | if (__get_user(reg, u++)) | |
1014 | return -EFAULT; | |
1015 | regs[pos++] = reg; | |
1016 | } | |
c2372eb9 RM |
1017 | for (; count > 0 && pos < PT_TRAP; --count, ++pos) |
1018 | if (__get_user(reg, u++)) | |
1019 | return -EFAULT; | |
1020 | } | |
fa8f5cb0 RM |
1021 | |
1022 | if (count > 0 && pos == PT_TRAP) { | |
1023 | if (kbuf) | |
1024 | reg = *k++; | |
1025 | else if (__get_user(reg, u++)) | |
1026 | return -EFAULT; | |
1027 | set_user_trap(target, reg); | |
1028 | ++pos; | |
1029 | --count; | |
1030 | } | |
1031 | ||
1032 | kbuf = k; | |
1033 | ubuf = u; | |
1034 | pos *= sizeof(reg); | |
1035 | count *= sizeof(reg); | |
1036 | return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, | |
1037 | (PT_TRAP + 1) * sizeof(reg), -1); | |
1038 | } | |
1039 | ||
1040 | /* | |
1041 | * These are the regset flavors matching the CONFIG_PPC32 native set. | |
1042 | */ | |
1043 | static const struct user_regset compat_regsets[] = { | |
1044 | [REGSET_GPR] = { | |
1045 | .core_note_type = NT_PRSTATUS, .n = ELF_NGREG, | |
1046 | .size = sizeof(compat_long_t), .align = sizeof(compat_long_t), | |
1047 | .get = gpr32_get, .set = gpr32_set | |
1048 | }, | |
1049 | [REGSET_FPR] = { | |
1050 | .core_note_type = NT_PRFPREG, .n = ELF_NFPREG, | |
1051 | .size = sizeof(double), .align = sizeof(double), | |
1052 | .get = fpr_get, .set = fpr_set | |
1053 | }, | |
1054 | #ifdef CONFIG_ALTIVEC | |
1055 | [REGSET_VMX] = { | |
1056 | .core_note_type = NT_PPC_VMX, .n = 34, | |
1057 | .size = sizeof(vector128), .align = sizeof(vector128), | |
1058 | .active = vr_active, .get = vr_get, .set = vr_set | |
1059 | }, | |
1060 | #endif | |
1061 | #ifdef CONFIG_SPE | |
1062 | [REGSET_SPE] = { | |
24f1a849 | 1063 | .core_note_type = NT_PPC_SPE, .n = 35, |
fa8f5cb0 RM |
1064 | .size = sizeof(u32), .align = sizeof(u32), |
1065 | .active = evr_active, .get = evr_get, .set = evr_set | |
1066 | }, | |
1067 | #endif | |
1068 | }; | |
1069 | ||
1070 | static const struct user_regset_view user_ppc_compat_view = { | |
1071 | .name = "ppc", .e_machine = EM_PPC, .ei_osabi = ELF_OSABI, | |
1072 | .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets) | |
1073 | }; | |
1074 | #endif /* CONFIG_PPC64 */ | |
1075 | ||
80fdf470 RM |
1076 | const struct user_regset_view *task_user_regset_view(struct task_struct *task) |
1077 | { | |
fa8f5cb0 RM |
1078 | #ifdef CONFIG_PPC64 |
1079 | if (test_tsk_thread_flag(task, TIF_32BIT)) | |
1080 | return &user_ppc_compat_view; | |
1081 | #endif | |
80fdf470 RM |
1082 | return &user_ppc_native_view; |
1083 | } | |
1084 | ||
1085 | ||
2a84b0d7 | 1086 | void user_enable_single_step(struct task_struct *task) |
865418d8 BH |
1087 | { |
1088 | struct pt_regs *regs = task->thread.regs; | |
1089 | ||
1090 | if (regs != NULL) { | |
172ae2e7 | 1091 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
51ae8d4a BB |
1092 | task->thread.debug.dbcr0 &= ~DBCR0_BT; |
1093 | task->thread.debug.dbcr0 |= DBCR0_IDM | DBCR0_IC; | |
865418d8 BH |
1094 | regs->msr |= MSR_DE; |
1095 | #else | |
ec097c84 | 1096 | regs->msr &= ~MSR_BE; |
865418d8 BH |
1097 | regs->msr |= MSR_SE; |
1098 | #endif | |
1099 | } | |
1100 | set_tsk_thread_flag(task, TIF_SINGLESTEP); | |
1101 | } | |
1102 | ||
ec097c84 RM |
1103 | void user_enable_block_step(struct task_struct *task) |
1104 | { | |
1105 | struct pt_regs *regs = task->thread.regs; | |
1106 | ||
1107 | if (regs != NULL) { | |
172ae2e7 | 1108 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
51ae8d4a BB |
1109 | task->thread.debug.dbcr0 &= ~DBCR0_IC; |
1110 | task->thread.debug.dbcr0 = DBCR0_IDM | DBCR0_BT; | |
ec097c84 RM |
1111 | regs->msr |= MSR_DE; |
1112 | #else | |
1113 | regs->msr &= ~MSR_SE; | |
1114 | regs->msr |= MSR_BE; | |
1115 | #endif | |
1116 | } | |
1117 | set_tsk_thread_flag(task, TIF_SINGLESTEP); | |
1118 | } | |
1119 | ||
2a84b0d7 | 1120 | void user_disable_single_step(struct task_struct *task) |
865418d8 BH |
1121 | { |
1122 | struct pt_regs *regs = task->thread.regs; | |
1123 | ||
1124 | if (regs != NULL) { | |
172ae2e7 | 1125 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
3bffb652 DK |
1126 | /* |
1127 | * The logic to disable single stepping should be as | |
1128 | * simple as turning off the Instruction Complete flag. | |
1129 | * And, after doing so, if all debug flags are off, turn | |
1130 | * off DBCR0(IDM) and MSR(DE) .... Torez | |
1131 | */ | |
682775b8 | 1132 | task->thread.debug.dbcr0 &= ~(DBCR0_IC|DBCR0_BT); |
3bffb652 DK |
1133 | /* |
1134 | * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set. | |
1135 | */ | |
51ae8d4a BB |
1136 | if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0, |
1137 | task->thread.debug.dbcr1)) { | |
3bffb652 DK |
1138 | /* |
1139 | * All debug events were off..... | |
1140 | */ | |
51ae8d4a | 1141 | task->thread.debug.dbcr0 &= ~DBCR0_IDM; |
28477fb1 DK |
1142 | regs->msr &= ~MSR_DE; |
1143 | } | |
865418d8 | 1144 | #else |
ec097c84 | 1145 | regs->msr &= ~(MSR_SE | MSR_BE); |
865418d8 BH |
1146 | #endif |
1147 | } | |
1148 | clear_tsk_thread_flag(task, TIF_SINGLESTEP); | |
1149 | } | |
1150 | ||
5aae8a53 | 1151 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
a8b0ca17 | 1152 | void ptrace_triggered(struct perf_event *bp, |
5aae8a53 P |
1153 | struct perf_sample_data *data, struct pt_regs *regs) |
1154 | { | |
1155 | struct perf_event_attr attr; | |
1156 | ||
1157 | /* | |
1158 | * Disable the breakpoint request here since ptrace has defined a | |
1159 | * one-shot behaviour for breakpoint exceptions in PPC64. | |
1160 | * The SIGTRAP signal is generated automatically for us in do_dabr(). | |
1161 | * We don't have to do anything about that here | |
1162 | */ | |
1163 | attr = bp->attr; | |
1164 | attr.disabled = true; | |
1165 | modify_user_hw_breakpoint(bp, &attr); | |
1166 | } | |
1167 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ | |
1168 | ||
e51df2c1 | 1169 | static int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, |
abd06505 BH |
1170 | unsigned long data) |
1171 | { | |
5aae8a53 P |
1172 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
1173 | int ret; | |
1174 | struct thread_struct *thread = &(task->thread); | |
1175 | struct perf_event *bp; | |
1176 | struct perf_event_attr attr; | |
1177 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ | |
9422de3e MN |
1178 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS |
1179 | struct arch_hw_breakpoint hw_brk; | |
1180 | #endif | |
5aae8a53 | 1181 | |
d6a61bfc LM |
1182 | /* For ppc64 we support one DABR and no IABR's at the moment (ppc64). |
1183 | * For embedded processors we support one DAC and no IAC's at the | |
1184 | * moment. | |
1185 | */ | |
abd06505 BH |
1186 | if (addr > 0) |
1187 | return -EINVAL; | |
1188 | ||
2325f0a0 | 1189 | /* The bottom 3 bits in dabr are flags */ |
abd06505 BH |
1190 | if ((data & ~0x7UL) >= TASK_SIZE) |
1191 | return -EIO; | |
1192 | ||
172ae2e7 | 1193 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS |
d6a61bfc LM |
1194 | /* For processors using DABR (i.e. 970), the bottom 3 bits are flags. |
1195 | * It was assumed, on previous implementations, that 3 bits were | |
1196 | * passed together with the data address, fitting the design of the | |
1197 | * DABR register, as follows: | |
1198 | * | |
1199 | * bit 0: Read flag | |
1200 | * bit 1: Write flag | |
1201 | * bit 2: Breakpoint translation | |
1202 | * | |
1203 | * Thus, we use them here as so. | |
1204 | */ | |
1205 | ||
1206 | /* Ensure breakpoint translation bit is set */ | |
9422de3e | 1207 | if (data && !(data & HW_BRK_TYPE_TRANSLATE)) |
abd06505 | 1208 | return -EIO; |
9422de3e MN |
1209 | hw_brk.address = data & (~HW_BRK_TYPE_DABR); |
1210 | hw_brk.type = (data & HW_BRK_TYPE_DABR) | HW_BRK_TYPE_PRIV_ALL; | |
1211 | hw_brk.len = 8; | |
5aae8a53 P |
1212 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
1213 | bp = thread->ptrace_bps[0]; | |
9422de3e | 1214 | if ((!data) || !(hw_brk.type & HW_BRK_TYPE_RDWR)) { |
5aae8a53 P |
1215 | if (bp) { |
1216 | unregister_hw_breakpoint(bp); | |
1217 | thread->ptrace_bps[0] = NULL; | |
1218 | } | |
1219 | return 0; | |
1220 | } | |
1221 | if (bp) { | |
1222 | attr = bp->attr; | |
9422de3e MN |
1223 | attr.bp_addr = hw_brk.address; |
1224 | arch_bp_generic_fields(hw_brk.type, &attr.bp_type); | |
a53fd61a AP |
1225 | |
1226 | /* Enable breakpoint */ | |
1227 | attr.disabled = false; | |
1228 | ||
5aae8a53 | 1229 | ret = modify_user_hw_breakpoint(bp, &attr); |
925f83c0 | 1230 | if (ret) { |
5aae8a53 | 1231 | return ret; |
925f83c0 | 1232 | } |
5aae8a53 | 1233 | thread->ptrace_bps[0] = bp; |
9422de3e | 1234 | thread->hw_brk = hw_brk; |
5aae8a53 P |
1235 | return 0; |
1236 | } | |
1237 | ||
1238 | /* Create a new breakpoint request if one doesn't exist already */ | |
1239 | hw_breakpoint_init(&attr); | |
9422de3e MN |
1240 | attr.bp_addr = hw_brk.address; |
1241 | arch_bp_generic_fields(hw_brk.type, | |
1242 | &attr.bp_type); | |
5aae8a53 P |
1243 | |
1244 | thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr, | |
4dc0da86 | 1245 | ptrace_triggered, NULL, task); |
5aae8a53 P |
1246 | if (IS_ERR(bp)) { |
1247 | thread->ptrace_bps[0] = NULL; | |
1248 | return PTR_ERR(bp); | |
1249 | } | |
1250 | ||
1251 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ | |
9422de3e | 1252 | task->thread.hw_brk = hw_brk; |
172ae2e7 | 1253 | #else /* CONFIG_PPC_ADV_DEBUG_REGS */ |
d6a61bfc LM |
1254 | /* As described above, it was assumed 3 bits were passed with the data |
1255 | * address, but we will assume only the mode bits will be passed | |
1256 | * as to not cause alignment restrictions for DAC-based processors. | |
1257 | */ | |
1258 | ||
1259 | /* DAC's hold the whole address without any mode flags */ | |
51ae8d4a | 1260 | task->thread.debug.dac1 = data & ~0x3UL; |
3bffb652 | 1261 | |
51ae8d4a | 1262 | if (task->thread.debug.dac1 == 0) { |
3bffb652 | 1263 | dbcr_dac(task) &= ~(DBCR_DAC1R | DBCR_DAC1W); |
51ae8d4a BB |
1264 | if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0, |
1265 | task->thread.debug.dbcr1)) { | |
3bffb652 | 1266 | task->thread.regs->msr &= ~MSR_DE; |
51ae8d4a | 1267 | task->thread.debug.dbcr0 &= ~DBCR0_IDM; |
3bffb652 | 1268 | } |
d6a61bfc LM |
1269 | return 0; |
1270 | } | |
1271 | ||
1272 | /* Read or Write bits must be set */ | |
1273 | ||
1274 | if (!(data & 0x3UL)) | |
1275 | return -EINVAL; | |
1276 | ||
1277 | /* Set the Internal Debugging flag (IDM bit 1) for the DBCR0 | |
1278 | register */ | |
51ae8d4a | 1279 | task->thread.debug.dbcr0 |= DBCR0_IDM; |
d6a61bfc LM |
1280 | |
1281 | /* Check for write and read flags and set DBCR0 | |
1282 | accordingly */ | |
3bffb652 | 1283 | dbcr_dac(task) &= ~(DBCR_DAC1R|DBCR_DAC1W); |
d6a61bfc | 1284 | if (data & 0x1UL) |
3bffb652 | 1285 | dbcr_dac(task) |= DBCR_DAC1R; |
d6a61bfc | 1286 | if (data & 0x2UL) |
3bffb652 | 1287 | dbcr_dac(task) |= DBCR_DAC1W; |
d6a61bfc | 1288 | task->thread.regs->msr |= MSR_DE; |
172ae2e7 | 1289 | #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ |
abd06505 BH |
1290 | return 0; |
1291 | } | |
abd06505 | 1292 | |
1da177e4 LT |
1293 | /* |
1294 | * Called by kernel/ptrace.c when detaching.. | |
1295 | * | |
1296 | * Make sure single step bits etc are not set. | |
1297 | */ | |
1298 | void ptrace_disable(struct task_struct *child) | |
1299 | { | |
1300 | /* make sure the single step bit is not set. */ | |
2a84b0d7 | 1301 | user_disable_single_step(child); |
1da177e4 LT |
1302 | } |
1303 | ||
3bffb652 | 1304 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
84295dfc | 1305 | static long set_instruction_bp(struct task_struct *child, |
3bffb652 DK |
1306 | struct ppc_hw_breakpoint *bp_info) |
1307 | { | |
1308 | int slot; | |
51ae8d4a BB |
1309 | int slot1_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC1) != 0); |
1310 | int slot2_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC2) != 0); | |
1311 | int slot3_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC3) != 0); | |
1312 | int slot4_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC4) != 0); | |
3bffb652 DK |
1313 | |
1314 | if (dbcr_iac_range(child) & DBCR_IAC12MODE) | |
1315 | slot2_in_use = 1; | |
1316 | if (dbcr_iac_range(child) & DBCR_IAC34MODE) | |
1317 | slot4_in_use = 1; | |
1318 | ||
1319 | if (bp_info->addr >= TASK_SIZE) | |
1320 | return -EIO; | |
1321 | ||
1322 | if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) { | |
1323 | ||
1324 | /* Make sure range is valid. */ | |
1325 | if (bp_info->addr2 >= TASK_SIZE) | |
1326 | return -EIO; | |
1327 | ||
1328 | /* We need a pair of IAC regsisters */ | |
1329 | if ((!slot1_in_use) && (!slot2_in_use)) { | |
1330 | slot = 1; | |
51ae8d4a BB |
1331 | child->thread.debug.iac1 = bp_info->addr; |
1332 | child->thread.debug.iac2 = bp_info->addr2; | |
1333 | child->thread.debug.dbcr0 |= DBCR0_IAC1; | |
3bffb652 DK |
1334 | if (bp_info->addr_mode == |
1335 | PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE) | |
1336 | dbcr_iac_range(child) |= DBCR_IAC12X; | |
1337 | else | |
1338 | dbcr_iac_range(child) |= DBCR_IAC12I; | |
1339 | #if CONFIG_PPC_ADV_DEBUG_IACS > 2 | |
1340 | } else if ((!slot3_in_use) && (!slot4_in_use)) { | |
1341 | slot = 3; | |
51ae8d4a BB |
1342 | child->thread.debug.iac3 = bp_info->addr; |
1343 | child->thread.debug.iac4 = bp_info->addr2; | |
1344 | child->thread.debug.dbcr0 |= DBCR0_IAC3; | |
3bffb652 DK |
1345 | if (bp_info->addr_mode == |
1346 | PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE) | |
1347 | dbcr_iac_range(child) |= DBCR_IAC34X; | |
1348 | else | |
1349 | dbcr_iac_range(child) |= DBCR_IAC34I; | |
1350 | #endif | |
1351 | } else | |
1352 | return -ENOSPC; | |
1353 | } else { | |
1354 | /* We only need one. If possible leave a pair free in | |
1355 | * case a range is needed later | |
1356 | */ | |
1357 | if (!slot1_in_use) { | |
1358 | /* | |
1359 | * Don't use iac1 if iac1-iac2 are free and either | |
1360 | * iac3 or iac4 (but not both) are free | |
1361 | */ | |
1362 | if (slot2_in_use || (slot3_in_use == slot4_in_use)) { | |
1363 | slot = 1; | |
51ae8d4a BB |
1364 | child->thread.debug.iac1 = bp_info->addr; |
1365 | child->thread.debug.dbcr0 |= DBCR0_IAC1; | |
3bffb652 DK |
1366 | goto out; |
1367 | } | |
1368 | } | |
1369 | if (!slot2_in_use) { | |
1370 | slot = 2; | |
51ae8d4a BB |
1371 | child->thread.debug.iac2 = bp_info->addr; |
1372 | child->thread.debug.dbcr0 |= DBCR0_IAC2; | |
3bffb652 DK |
1373 | #if CONFIG_PPC_ADV_DEBUG_IACS > 2 |
1374 | } else if (!slot3_in_use) { | |
1375 | slot = 3; | |
51ae8d4a BB |
1376 | child->thread.debug.iac3 = bp_info->addr; |
1377 | child->thread.debug.dbcr0 |= DBCR0_IAC3; | |
3bffb652 DK |
1378 | } else if (!slot4_in_use) { |
1379 | slot = 4; | |
51ae8d4a BB |
1380 | child->thread.debug.iac4 = bp_info->addr; |
1381 | child->thread.debug.dbcr0 |= DBCR0_IAC4; | |
3bffb652 DK |
1382 | #endif |
1383 | } else | |
1384 | return -ENOSPC; | |
1385 | } | |
1386 | out: | |
51ae8d4a | 1387 | child->thread.debug.dbcr0 |= DBCR0_IDM; |
3bffb652 DK |
1388 | child->thread.regs->msr |= MSR_DE; |
1389 | ||
1390 | return slot; | |
1391 | } | |
1392 | ||
1393 | static int del_instruction_bp(struct task_struct *child, int slot) | |
1394 | { | |
1395 | switch (slot) { | |
1396 | case 1: | |
51ae8d4a | 1397 | if ((child->thread.debug.dbcr0 & DBCR0_IAC1) == 0) |
3bffb652 DK |
1398 | return -ENOENT; |
1399 | ||
1400 | if (dbcr_iac_range(child) & DBCR_IAC12MODE) { | |
1401 | /* address range - clear slots 1 & 2 */ | |
51ae8d4a | 1402 | child->thread.debug.iac2 = 0; |
3bffb652 DK |
1403 | dbcr_iac_range(child) &= ~DBCR_IAC12MODE; |
1404 | } | |
51ae8d4a BB |
1405 | child->thread.debug.iac1 = 0; |
1406 | child->thread.debug.dbcr0 &= ~DBCR0_IAC1; | |
3bffb652 DK |
1407 | break; |
1408 | case 2: | |
51ae8d4a | 1409 | if ((child->thread.debug.dbcr0 & DBCR0_IAC2) == 0) |
3bffb652 DK |
1410 | return -ENOENT; |
1411 | ||
1412 | if (dbcr_iac_range(child) & DBCR_IAC12MODE) | |
1413 | /* used in a range */ | |
1414 | return -EINVAL; | |
51ae8d4a BB |
1415 | child->thread.debug.iac2 = 0; |
1416 | child->thread.debug.dbcr0 &= ~DBCR0_IAC2; | |
3bffb652 DK |
1417 | break; |
1418 | #if CONFIG_PPC_ADV_DEBUG_IACS > 2 | |
1419 | case 3: | |
51ae8d4a | 1420 | if ((child->thread.debug.dbcr0 & DBCR0_IAC3) == 0) |
3bffb652 DK |
1421 | return -ENOENT; |
1422 | ||
1423 | if (dbcr_iac_range(child) & DBCR_IAC34MODE) { | |
1424 | /* address range - clear slots 3 & 4 */ | |
51ae8d4a | 1425 | child->thread.debug.iac4 = 0; |
3bffb652 DK |
1426 | dbcr_iac_range(child) &= ~DBCR_IAC34MODE; |
1427 | } | |
51ae8d4a BB |
1428 | child->thread.debug.iac3 = 0; |
1429 | child->thread.debug.dbcr0 &= ~DBCR0_IAC3; | |
3bffb652 DK |
1430 | break; |
1431 | case 4: | |
51ae8d4a | 1432 | if ((child->thread.debug.dbcr0 & DBCR0_IAC4) == 0) |
3bffb652 DK |
1433 | return -ENOENT; |
1434 | ||
1435 | if (dbcr_iac_range(child) & DBCR_IAC34MODE) | |
1436 | /* Used in a range */ | |
1437 | return -EINVAL; | |
51ae8d4a BB |
1438 | child->thread.debug.iac4 = 0; |
1439 | child->thread.debug.dbcr0 &= ~DBCR0_IAC4; | |
3bffb652 DK |
1440 | break; |
1441 | #endif | |
1442 | default: | |
1443 | return -EINVAL; | |
1444 | } | |
1445 | return 0; | |
1446 | } | |
1447 | ||
1448 | static int set_dac(struct task_struct *child, struct ppc_hw_breakpoint *bp_info) | |
1449 | { | |
1450 | int byte_enable = | |
1451 | (bp_info->condition_mode >> PPC_BREAKPOINT_CONDITION_BE_SHIFT) | |
1452 | & 0xf; | |
1453 | int condition_mode = | |
1454 | bp_info->condition_mode & PPC_BREAKPOINT_CONDITION_MODE; | |
1455 | int slot; | |
1456 | ||
1457 | if (byte_enable && (condition_mode == 0)) | |
1458 | return -EINVAL; | |
1459 | ||
1460 | if (bp_info->addr >= TASK_SIZE) | |
1461 | return -EIO; | |
1462 | ||
1463 | if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) { | |
1464 | slot = 1; | |
1465 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) | |
1466 | dbcr_dac(child) |= DBCR_DAC1R; | |
1467 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) | |
1468 | dbcr_dac(child) |= DBCR_DAC1W; | |
51ae8d4a | 1469 | child->thread.debug.dac1 = (unsigned long)bp_info->addr; |
3bffb652 DK |
1470 | #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 |
1471 | if (byte_enable) { | |
51ae8d4a | 1472 | child->thread.debug.dvc1 = |
3bffb652 | 1473 | (unsigned long)bp_info->condition_value; |
51ae8d4a | 1474 | child->thread.debug.dbcr2 |= |
3bffb652 DK |
1475 | ((byte_enable << DBCR2_DVC1BE_SHIFT) | |
1476 | (condition_mode << DBCR2_DVC1M_SHIFT)); | |
1477 | } | |
1478 | #endif | |
1479 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE | |
51ae8d4a | 1480 | } else if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) { |
3bffb652 DK |
1481 | /* Both dac1 and dac2 are part of a range */ |
1482 | return -ENOSPC; | |
1483 | #endif | |
1484 | } else if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) { | |
1485 | slot = 2; | |
1486 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) | |
1487 | dbcr_dac(child) |= DBCR_DAC2R; | |
1488 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) | |
1489 | dbcr_dac(child) |= DBCR_DAC2W; | |
51ae8d4a | 1490 | child->thread.debug.dac2 = (unsigned long)bp_info->addr; |
3bffb652 DK |
1491 | #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 |
1492 | if (byte_enable) { | |
51ae8d4a | 1493 | child->thread.debug.dvc2 = |
3bffb652 | 1494 | (unsigned long)bp_info->condition_value; |
51ae8d4a | 1495 | child->thread.debug.dbcr2 |= |
3bffb652 DK |
1496 | ((byte_enable << DBCR2_DVC2BE_SHIFT) | |
1497 | (condition_mode << DBCR2_DVC2M_SHIFT)); | |
1498 | } | |
1499 | #endif | |
1500 | } else | |
1501 | return -ENOSPC; | |
51ae8d4a | 1502 | child->thread.debug.dbcr0 |= DBCR0_IDM; |
3bffb652 DK |
1503 | child->thread.regs->msr |= MSR_DE; |
1504 | ||
1505 | return slot + 4; | |
1506 | } | |
1507 | ||
1508 | static int del_dac(struct task_struct *child, int slot) | |
1509 | { | |
1510 | if (slot == 1) { | |
30124d11 | 1511 | if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) |
3bffb652 DK |
1512 | return -ENOENT; |
1513 | ||
51ae8d4a | 1514 | child->thread.debug.dac1 = 0; |
3bffb652 DK |
1515 | dbcr_dac(child) &= ~(DBCR_DAC1R | DBCR_DAC1W); |
1516 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE | |
51ae8d4a BB |
1517 | if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) { |
1518 | child->thread.debug.dac2 = 0; | |
1519 | child->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE; | |
3bffb652 | 1520 | } |
51ae8d4a | 1521 | child->thread.debug.dbcr2 &= ~(DBCR2_DVC1M | DBCR2_DVC1BE); |
3bffb652 DK |
1522 | #endif |
1523 | #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 | |
51ae8d4a | 1524 | child->thread.debug.dvc1 = 0; |
3bffb652 DK |
1525 | #endif |
1526 | } else if (slot == 2) { | |
30124d11 | 1527 | if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) |
3bffb652 DK |
1528 | return -ENOENT; |
1529 | ||
1530 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE | |
51ae8d4a | 1531 | if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) |
3bffb652 DK |
1532 | /* Part of a range */ |
1533 | return -EINVAL; | |
51ae8d4a | 1534 | child->thread.debug.dbcr2 &= ~(DBCR2_DVC2M | DBCR2_DVC2BE); |
3bffb652 DK |
1535 | #endif |
1536 | #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 | |
51ae8d4a | 1537 | child->thread.debug.dvc2 = 0; |
3bffb652 | 1538 | #endif |
51ae8d4a | 1539 | child->thread.debug.dac2 = 0; |
3bffb652 DK |
1540 | dbcr_dac(child) &= ~(DBCR_DAC2R | DBCR_DAC2W); |
1541 | } else | |
1542 | return -EINVAL; | |
1543 | ||
1544 | return 0; | |
1545 | } | |
1546 | #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ | |
1547 | ||
1548 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE | |
1549 | static int set_dac_range(struct task_struct *child, | |
1550 | struct ppc_hw_breakpoint *bp_info) | |
1551 | { | |
1552 | int mode = bp_info->addr_mode & PPC_BREAKPOINT_MODE_MASK; | |
1553 | ||
1554 | /* We don't allow range watchpoints to be used with DVC */ | |
1555 | if (bp_info->condition_mode) | |
1556 | return -EINVAL; | |
1557 | ||
1558 | /* | |
1559 | * Best effort to verify the address range. The user/supervisor bits | |
1560 | * prevent trapping in kernel space, but let's fail on an obvious bad | |
1561 | * range. The simple test on the mask is not fool-proof, and any | |
1562 | * exclusive range will spill over into kernel space. | |
1563 | */ | |
1564 | if (bp_info->addr >= TASK_SIZE) | |
1565 | return -EIO; | |
1566 | if (mode == PPC_BREAKPOINT_MODE_MASK) { | |
1567 | /* | |
1568 | * dac2 is a bitmask. Don't allow a mask that makes a | |
1569 | * kernel space address from a valid dac1 value | |
1570 | */ | |
1571 | if (~((unsigned long)bp_info->addr2) >= TASK_SIZE) | |
1572 | return -EIO; | |
1573 | } else { | |
1574 | /* | |
1575 | * For range breakpoints, addr2 must also be a valid address | |
1576 | */ | |
1577 | if (bp_info->addr2 >= TASK_SIZE) | |
1578 | return -EIO; | |
1579 | } | |
1580 | ||
51ae8d4a | 1581 | if (child->thread.debug.dbcr0 & |
3bffb652 DK |
1582 | (DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W)) |
1583 | return -ENOSPC; | |
1584 | ||
1585 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) | |
51ae8d4a | 1586 | child->thread.debug.dbcr0 |= (DBCR0_DAC1R | DBCR0_IDM); |
3bffb652 | 1587 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) |
51ae8d4a BB |
1588 | child->thread.debug.dbcr0 |= (DBCR0_DAC1W | DBCR0_IDM); |
1589 | child->thread.debug.dac1 = bp_info->addr; | |
1590 | child->thread.debug.dac2 = bp_info->addr2; | |
3bffb652 | 1591 | if (mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE) |
51ae8d4a | 1592 | child->thread.debug.dbcr2 |= DBCR2_DAC12M; |
3bffb652 | 1593 | else if (mode == PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE) |
51ae8d4a | 1594 | child->thread.debug.dbcr2 |= DBCR2_DAC12MX; |
3bffb652 | 1595 | else /* PPC_BREAKPOINT_MODE_MASK */ |
51ae8d4a | 1596 | child->thread.debug.dbcr2 |= DBCR2_DAC12MM; |
3bffb652 DK |
1597 | child->thread.regs->msr |= MSR_DE; |
1598 | ||
1599 | return 5; | |
1600 | } | |
1601 | #endif /* CONFIG_PPC_ADV_DEBUG_DAC_RANGE */ | |
1602 | ||
3162d92d DK |
1603 | static long ppc_set_hwdebug(struct task_struct *child, |
1604 | struct ppc_hw_breakpoint *bp_info) | |
1605 | { | |
6c7a2856 P |
1606 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
1607 | int len = 0; | |
1608 | struct thread_struct *thread = &(child->thread); | |
1609 | struct perf_event *bp; | |
1610 | struct perf_event_attr attr; | |
1611 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ | |
4dfbf290 | 1612 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS |
9422de3e | 1613 | struct arch_hw_breakpoint brk; |
4dfbf290 AS |
1614 | #endif |
1615 | ||
3bffb652 DK |
1616 | if (bp_info->version != 1) |
1617 | return -ENOTSUPP; | |
1618 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS | |
1619 | /* | |
1620 | * Check for invalid flags and combinations | |
1621 | */ | |
1622 | if ((bp_info->trigger_type == 0) || | |
1623 | (bp_info->trigger_type & ~(PPC_BREAKPOINT_TRIGGER_EXECUTE | | |
1624 | PPC_BREAKPOINT_TRIGGER_RW)) || | |
1625 | (bp_info->addr_mode & ~PPC_BREAKPOINT_MODE_MASK) || | |
1626 | (bp_info->condition_mode & | |
1627 | ~(PPC_BREAKPOINT_CONDITION_MODE | | |
1628 | PPC_BREAKPOINT_CONDITION_BE_ALL))) | |
1629 | return -EINVAL; | |
1630 | #if CONFIG_PPC_ADV_DEBUG_DVCS == 0 | |
1631 | if (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE) | |
1632 | return -EINVAL; | |
1633 | #endif | |
1634 | ||
1635 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_EXECUTE) { | |
1636 | if ((bp_info->trigger_type != PPC_BREAKPOINT_TRIGGER_EXECUTE) || | |
1637 | (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE)) | |
1638 | return -EINVAL; | |
84295dfc | 1639 | return set_instruction_bp(child, bp_info); |
3bffb652 DK |
1640 | } |
1641 | if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT) | |
1642 | return set_dac(child, bp_info); | |
1643 | ||
1644 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE | |
1645 | return set_dac_range(child, bp_info); | |
1646 | #else | |
1647 | return -EINVAL; | |
1648 | #endif | |
1649 | #else /* !CONFIG_PPC_ADV_DEBUG_DVCS */ | |
3162d92d | 1650 | /* |
3bffb652 | 1651 | * We only support one data breakpoint |
3162d92d | 1652 | */ |
4dfbf290 AS |
1653 | if ((bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_RW) == 0 || |
1654 | (bp_info->trigger_type & ~PPC_BREAKPOINT_TRIGGER_RW) != 0 || | |
4dfbf290 | 1655 | bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE) |
3162d92d DK |
1656 | return -EINVAL; |
1657 | ||
3162d92d DK |
1658 | if ((unsigned long)bp_info->addr >= TASK_SIZE) |
1659 | return -EIO; | |
1660 | ||
9422de3e MN |
1661 | brk.address = bp_info->addr & ~7UL; |
1662 | brk.type = HW_BRK_TYPE_TRANSLATE; | |
2bb78efa | 1663 | brk.len = 8; |
4dfbf290 | 1664 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) |
9422de3e | 1665 | brk.type |= HW_BRK_TYPE_READ; |
4dfbf290 | 1666 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) |
9422de3e | 1667 | brk.type |= HW_BRK_TYPE_WRITE; |
6c7a2856 | 1668 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
6c7a2856 P |
1669 | /* |
1670 | * Check if the request is for 'range' breakpoints. We can | |
1671 | * support it if range < 8 bytes. | |
1672 | */ | |
6961ed96 | 1673 | if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE) |
6c7a2856 | 1674 | len = bp_info->addr2 - bp_info->addr; |
6961ed96 | 1675 | else if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT) |
b0b0aa9c | 1676 | len = 1; |
6961ed96 | 1677 | else |
6c7a2856 | 1678 | return -EINVAL; |
6c7a2856 | 1679 | bp = thread->ptrace_bps[0]; |
6961ed96 | 1680 | if (bp) |
6c7a2856 | 1681 | return -ENOSPC; |
6c7a2856 P |
1682 | |
1683 | /* Create a new breakpoint request if one doesn't exist already */ | |
1684 | hw_breakpoint_init(&attr); | |
1685 | attr.bp_addr = (unsigned long)bp_info->addr & ~HW_BREAKPOINT_ALIGN; | |
1686 | attr.bp_len = len; | |
9422de3e | 1687 | arch_bp_generic_fields(brk.type, &attr.bp_type); |
6c7a2856 P |
1688 | |
1689 | thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr, | |
1690 | ptrace_triggered, NULL, child); | |
1691 | if (IS_ERR(bp)) { | |
1692 | thread->ptrace_bps[0] = NULL; | |
6c7a2856 P |
1693 | return PTR_ERR(bp); |
1694 | } | |
1695 | ||
6c7a2856 P |
1696 | return 1; |
1697 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ | |
1698 | ||
1699 | if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) | |
1700 | return -EINVAL; | |
1701 | ||
9422de3e | 1702 | if (child->thread.hw_brk.address) |
6c7a2856 | 1703 | return -ENOSPC; |
4dfbf290 | 1704 | |
9422de3e | 1705 | child->thread.hw_brk = brk; |
3bffb652 | 1706 | |
3162d92d | 1707 | return 1; |
3bffb652 | 1708 | #endif /* !CONFIG_PPC_ADV_DEBUG_DVCS */ |
3162d92d DK |
1709 | } |
1710 | ||
ec1b33dc | 1711 | static long ppc_del_hwdebug(struct task_struct *child, long data) |
3162d92d | 1712 | { |
6c7a2856 P |
1713 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
1714 | int ret = 0; | |
1715 | struct thread_struct *thread = &(child->thread); | |
1716 | struct perf_event *bp; | |
1717 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ | |
3bffb652 DK |
1718 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
1719 | int rc; | |
1720 | ||
1721 | if (data <= 4) | |
1722 | rc = del_instruction_bp(child, (int)data); | |
1723 | else | |
1724 | rc = del_dac(child, (int)data - 4); | |
1725 | ||
1726 | if (!rc) { | |
51ae8d4a BB |
1727 | if (!DBCR_ACTIVE_EVENTS(child->thread.debug.dbcr0, |
1728 | child->thread.debug.dbcr1)) { | |
1729 | child->thread.debug.dbcr0 &= ~DBCR0_IDM; | |
3bffb652 DK |
1730 | child->thread.regs->msr &= ~MSR_DE; |
1731 | } | |
1732 | } | |
1733 | return rc; | |
1734 | #else | |
3162d92d DK |
1735 | if (data != 1) |
1736 | return -EINVAL; | |
6c7a2856 P |
1737 | |
1738 | #ifdef CONFIG_HAVE_HW_BREAKPOINT | |
6c7a2856 P |
1739 | bp = thread->ptrace_bps[0]; |
1740 | if (bp) { | |
1741 | unregister_hw_breakpoint(bp); | |
1742 | thread->ptrace_bps[0] = NULL; | |
1743 | } else | |
1744 | ret = -ENOENT; | |
6c7a2856 P |
1745 | return ret; |
1746 | #else /* CONFIG_HAVE_HW_BREAKPOINT */ | |
9422de3e | 1747 | if (child->thread.hw_brk.address == 0) |
3162d92d DK |
1748 | return -ENOENT; |
1749 | ||
9422de3e MN |
1750 | child->thread.hw_brk.address = 0; |
1751 | child->thread.hw_brk.type = 0; | |
6c7a2856 | 1752 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
3bffb652 | 1753 | |
3162d92d | 1754 | return 0; |
3bffb652 | 1755 | #endif |
3162d92d DK |
1756 | } |
1757 | ||
9b05a69e NK |
1758 | long arch_ptrace(struct task_struct *child, long request, |
1759 | unsigned long addr, unsigned long data) | |
1da177e4 | 1760 | { |
1da177e4 | 1761 | int ret = -EPERM; |
f68d2048 NK |
1762 | void __user *datavp = (void __user *) data; |
1763 | unsigned long __user *datalp = datavp; | |
1da177e4 | 1764 | |
1da177e4 | 1765 | switch (request) { |
1da177e4 | 1766 | /* read the word at location addr in the USER area. */ |
1da177e4 LT |
1767 | case PTRACE_PEEKUSR: { |
1768 | unsigned long index, tmp; | |
1769 | ||
1770 | ret = -EIO; | |
1771 | /* convert to index and check */ | |
e8a30302 | 1772 | #ifdef CONFIG_PPC32 |
9b05a69e | 1773 | index = addr >> 2; |
e8a30302 SR |
1774 | if ((addr & 3) || (index > PT_FPSCR) |
1775 | || (child->thread.regs == NULL)) | |
1776 | #else | |
9b05a69e | 1777 | index = addr >> 3; |
e8a30302 SR |
1778 | if ((addr & 7) || (index > PT_FPSCR)) |
1779 | #endif | |
1da177e4 LT |
1780 | break; |
1781 | ||
1782 | CHECK_FULL_REGS(child->thread.regs); | |
1783 | if (index < PT_FPR0) { | |
ee4a3916 AK |
1784 | ret = ptrace_get_reg(child, (int) index, &tmp); |
1785 | if (ret) | |
1786 | break; | |
1da177e4 | 1787 | } else { |
e69b742a BH |
1788 | unsigned int fpidx = index - PT_FPR0; |
1789 | ||
e8a30302 | 1790 | flush_fp_to_thread(child); |
e69b742a | 1791 | if (fpidx < (PT_FPSCR - PT_FPR0)) |
36aa1b18 | 1792 | memcpy(&tmp, &child->thread.TS_FPR(fpidx), |
87fec051 | 1793 | sizeof(long)); |
e69b742a | 1794 | else |
de79f7b9 | 1795 | tmp = child->thread.fp_state.fpscr; |
1da177e4 | 1796 | } |
f68d2048 | 1797 | ret = put_user(tmp, datalp); |
1da177e4 LT |
1798 | break; |
1799 | } | |
1800 | ||
1da177e4 LT |
1801 | /* write the word at location addr in the USER area */ |
1802 | case PTRACE_POKEUSR: { | |
1803 | unsigned long index; | |
1804 | ||
1805 | ret = -EIO; | |
1806 | /* convert to index and check */ | |
e8a30302 | 1807 | #ifdef CONFIG_PPC32 |
9b05a69e | 1808 | index = addr >> 2; |
e8a30302 SR |
1809 | if ((addr & 3) || (index > PT_FPSCR) |
1810 | || (child->thread.regs == NULL)) | |
1811 | #else | |
9b05a69e | 1812 | index = addr >> 3; |
e8a30302 SR |
1813 | if ((addr & 7) || (index > PT_FPSCR)) |
1814 | #endif | |
1da177e4 LT |
1815 | break; |
1816 | ||
1817 | CHECK_FULL_REGS(child->thread.regs); | |
1da177e4 | 1818 | if (index < PT_FPR0) { |
865418d8 | 1819 | ret = ptrace_put_reg(child, index, data); |
1da177e4 | 1820 | } else { |
e69b742a BH |
1821 | unsigned int fpidx = index - PT_FPR0; |
1822 | ||
e8a30302 | 1823 | flush_fp_to_thread(child); |
e69b742a | 1824 | if (fpidx < (PT_FPSCR - PT_FPR0)) |
36aa1b18 | 1825 | memcpy(&child->thread.TS_FPR(fpidx), &data, |
87fec051 | 1826 | sizeof(long)); |
e69b742a | 1827 | else |
de79f7b9 | 1828 | child->thread.fp_state.fpscr = data; |
1da177e4 LT |
1829 | ret = 0; |
1830 | } | |
1831 | break; | |
1832 | } | |
1833 | ||
3162d92d DK |
1834 | case PPC_PTRACE_GETHWDBGINFO: { |
1835 | struct ppc_debug_info dbginfo; | |
1836 | ||
1837 | dbginfo.version = 1; | |
3bffb652 DK |
1838 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
1839 | dbginfo.num_instruction_bps = CONFIG_PPC_ADV_DEBUG_IACS; | |
1840 | dbginfo.num_data_bps = CONFIG_PPC_ADV_DEBUG_DACS; | |
1841 | dbginfo.num_condition_regs = CONFIG_PPC_ADV_DEBUG_DVCS; | |
1842 | dbginfo.data_bp_alignment = 4; | |
1843 | dbginfo.sizeof_condition = 4; | |
1844 | dbginfo.features = PPC_DEBUG_FEATURE_INSN_BP_RANGE | | |
1845 | PPC_DEBUG_FEATURE_INSN_BP_MASK; | |
1846 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE | |
1847 | dbginfo.features |= | |
1848 | PPC_DEBUG_FEATURE_DATA_BP_RANGE | | |
1849 | PPC_DEBUG_FEATURE_DATA_BP_MASK; | |
1850 | #endif | |
1851 | #else /* !CONFIG_PPC_ADV_DEBUG_REGS */ | |
3162d92d DK |
1852 | dbginfo.num_instruction_bps = 0; |
1853 | dbginfo.num_data_bps = 1; | |
1854 | dbginfo.num_condition_regs = 0; | |
1855 | #ifdef CONFIG_PPC64 | |
1856 | dbginfo.data_bp_alignment = 8; | |
1857 | #else | |
1858 | dbginfo.data_bp_alignment = 4; | |
1859 | #endif | |
1860 | dbginfo.sizeof_condition = 0; | |
6c7a2856 P |
1861 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
1862 | dbginfo.features = PPC_DEBUG_FEATURE_DATA_BP_RANGE; | |
517b7314 MN |
1863 | if (cpu_has_feature(CPU_FTR_DAWR)) |
1864 | dbginfo.features |= PPC_DEBUG_FEATURE_DATA_BP_DAWR; | |
6c7a2856 | 1865 | #else |
3162d92d | 1866 | dbginfo.features = 0; |
6c7a2856 | 1867 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
3bffb652 | 1868 | #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ |
3162d92d | 1869 | |
f68d2048 | 1870 | if (!access_ok(VERIFY_WRITE, datavp, |
3162d92d DK |
1871 | sizeof(struct ppc_debug_info))) |
1872 | return -EFAULT; | |
f68d2048 NK |
1873 | ret = __copy_to_user(datavp, &dbginfo, |
1874 | sizeof(struct ppc_debug_info)) ? | |
3162d92d DK |
1875 | -EFAULT : 0; |
1876 | break; | |
1877 | } | |
1878 | ||
1879 | case PPC_PTRACE_SETHWDEBUG: { | |
1880 | struct ppc_hw_breakpoint bp_info; | |
1881 | ||
f68d2048 | 1882 | if (!access_ok(VERIFY_READ, datavp, |
3162d92d DK |
1883 | sizeof(struct ppc_hw_breakpoint))) |
1884 | return -EFAULT; | |
f68d2048 | 1885 | ret = __copy_from_user(&bp_info, datavp, |
3162d92d DK |
1886 | sizeof(struct ppc_hw_breakpoint)) ? |
1887 | -EFAULT : 0; | |
1888 | if (!ret) | |
1889 | ret = ppc_set_hwdebug(child, &bp_info); | |
1890 | break; | |
1891 | } | |
1892 | ||
1893 | case PPC_PTRACE_DELHWDEBUG: { | |
ec1b33dc | 1894 | ret = ppc_del_hwdebug(child, data); |
3162d92d DK |
1895 | break; |
1896 | } | |
1897 | ||
e8a30302 | 1898 | case PTRACE_GET_DEBUGREG: { |
9422de3e MN |
1899 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS |
1900 | unsigned long dabr_fake; | |
1901 | #endif | |
e8a30302 SR |
1902 | ret = -EINVAL; |
1903 | /* We only support one DABR and no IABRS at the moment */ | |
1904 | if (addr > 0) | |
1905 | break; | |
3bffb652 | 1906 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
51ae8d4a | 1907 | ret = put_user(child->thread.debug.dac1, datalp); |
3bffb652 | 1908 | #else |
9422de3e MN |
1909 | dabr_fake = ((child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) | |
1910 | (child->thread.hw_brk.type & HW_BRK_TYPE_DABR)); | |
1911 | ret = put_user(dabr_fake, datalp); | |
3bffb652 | 1912 | #endif |
e8a30302 SR |
1913 | break; |
1914 | } | |
1915 | ||
1916 | case PTRACE_SET_DEBUGREG: | |
1917 | ret = ptrace_set_debugreg(child, addr, data); | |
1918 | break; | |
e8a30302 | 1919 | |
e17666ba BH |
1920 | #ifdef CONFIG_PPC64 |
1921 | case PTRACE_GETREGS64: | |
1922 | #endif | |
c391cd00 RM |
1923 | case PTRACE_GETREGS: /* Get all pt_regs from the child. */ |
1924 | return copy_regset_to_user(child, &user_ppc_native_view, | |
1925 | REGSET_GPR, | |
1926 | 0, sizeof(struct pt_regs), | |
f68d2048 | 1927 | datavp); |
e8a30302 | 1928 | |
e17666ba BH |
1929 | #ifdef CONFIG_PPC64 |
1930 | case PTRACE_SETREGS64: | |
1931 | #endif | |
c391cd00 RM |
1932 | case PTRACE_SETREGS: /* Set all gp regs in the child. */ |
1933 | return copy_regset_from_user(child, &user_ppc_native_view, | |
1934 | REGSET_GPR, | |
1935 | 0, sizeof(struct pt_regs), | |
f68d2048 | 1936 | datavp); |
c391cd00 RM |
1937 | |
1938 | case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */ | |
1939 | return copy_regset_to_user(child, &user_ppc_native_view, | |
1940 | REGSET_FPR, | |
1941 | 0, sizeof(elf_fpregset_t), | |
f68d2048 | 1942 | datavp); |
c391cd00 RM |
1943 | |
1944 | case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */ | |
1945 | return copy_regset_from_user(child, &user_ppc_native_view, | |
1946 | REGSET_FPR, | |
1947 | 0, sizeof(elf_fpregset_t), | |
f68d2048 | 1948 | datavp); |
e8a30302 | 1949 | |
1da177e4 LT |
1950 | #ifdef CONFIG_ALTIVEC |
1951 | case PTRACE_GETVRREGS: | |
c391cd00 RM |
1952 | return copy_regset_to_user(child, &user_ppc_native_view, |
1953 | REGSET_VMX, | |
1954 | 0, (33 * sizeof(vector128) + | |
1955 | sizeof(u32)), | |
f68d2048 | 1956 | datavp); |
1da177e4 LT |
1957 | |
1958 | case PTRACE_SETVRREGS: | |
c391cd00 RM |
1959 | return copy_regset_from_user(child, &user_ppc_native_view, |
1960 | REGSET_VMX, | |
1961 | 0, (33 * sizeof(vector128) + | |
1962 | sizeof(u32)), | |
f68d2048 | 1963 | datavp); |
1da177e4 | 1964 | #endif |
ce48b210 MN |
1965 | #ifdef CONFIG_VSX |
1966 | case PTRACE_GETVSRREGS: | |
1967 | return copy_regset_to_user(child, &user_ppc_native_view, | |
1968 | REGSET_VSX, | |
1ac42ef8 | 1969 | 0, 32 * sizeof(double), |
f68d2048 | 1970 | datavp); |
ce48b210 MN |
1971 | |
1972 | case PTRACE_SETVSRREGS: | |
1973 | return copy_regset_from_user(child, &user_ppc_native_view, | |
1974 | REGSET_VSX, | |
1ac42ef8 | 1975 | 0, 32 * sizeof(double), |
f68d2048 | 1976 | datavp); |
ce48b210 | 1977 | #endif |
1da177e4 LT |
1978 | #ifdef CONFIG_SPE |
1979 | case PTRACE_GETEVRREGS: | |
1980 | /* Get the child spe register state. */ | |
c391cd00 RM |
1981 | return copy_regset_to_user(child, &user_ppc_native_view, |
1982 | REGSET_SPE, 0, 35 * sizeof(u32), | |
f68d2048 | 1983 | datavp); |
1da177e4 LT |
1984 | |
1985 | case PTRACE_SETEVRREGS: | |
1986 | /* Set the child spe register state. */ | |
c391cd00 RM |
1987 | return copy_regset_from_user(child, &user_ppc_native_view, |
1988 | REGSET_SPE, 0, 35 * sizeof(u32), | |
f68d2048 | 1989 | datavp); |
1da177e4 LT |
1990 | #endif |
1991 | ||
1992 | default: | |
1993 | ret = ptrace_request(child, request, addr, data); | |
1994 | break; | |
1995 | } | |
1da177e4 LT |
1996 | return ret; |
1997 | } | |
1998 | ||
2449acc5 ME |
1999 | #ifdef CONFIG_SECCOMP |
2000 | static int do_seccomp(struct pt_regs *regs) | |
2001 | { | |
2002 | if (!test_thread_flag(TIF_SECCOMP)) | |
2003 | return 0; | |
2004 | ||
2005 | /* | |
2006 | * The ABI we present to seccomp tracers is that r3 contains | |
2007 | * the syscall return value and orig_gpr3 contains the first | |
2008 | * syscall parameter. This is different to the ptrace ABI where | |
2009 | * both r3 and orig_gpr3 contain the first syscall parameter. | |
2010 | */ | |
2011 | regs->gpr[3] = -ENOSYS; | |
2012 | ||
2013 | /* | |
2014 | * We use the __ version here because we have already checked | |
2015 | * TIF_SECCOMP. If this fails, there is nothing left to do, we | |
2016 | * have already loaded -ENOSYS into r3, or seccomp has put | |
2017 | * something else in r3 (via SECCOMP_RET_ERRNO/TRACE). | |
2018 | */ | |
2f275de5 | 2019 | if (__secure_computing(NULL)) |
2449acc5 ME |
2020 | return -1; |
2021 | ||
2022 | /* | |
2023 | * The syscall was allowed by seccomp, restore the register | |
1addc57e | 2024 | * state to what audit expects. |
2449acc5 ME |
2025 | * Note that we use orig_gpr3, which means a seccomp tracer can |
2026 | * modify the first syscall parameter (in orig_gpr3) and also | |
2027 | * allow the syscall to proceed. | |
2028 | */ | |
2029 | regs->gpr[3] = regs->orig_gpr3; | |
2030 | ||
2031 | return 0; | |
2032 | } | |
2033 | #else | |
2034 | static inline int do_seccomp(struct pt_regs *regs) { return 0; } | |
2035 | #endif /* CONFIG_SECCOMP */ | |
2036 | ||
d3837414 ME |
2037 | /** |
2038 | * do_syscall_trace_enter() - Do syscall tracing on kernel entry. | |
2039 | * @regs: the pt_regs of the task to trace (current) | |
2040 | * | |
2041 | * Performs various types of tracing on syscall entry. This includes seccomp, | |
2042 | * ptrace, syscall tracepoints and audit. | |
2043 | * | |
2044 | * The pt_regs are potentially visible to userspace via ptrace, so their | |
2045 | * contents is ABI. | |
2046 | * | |
2047 | * One or more of the tracers may modify the contents of pt_regs, in particular | |
2048 | * to modify arguments or even the syscall number itself. | |
2049 | * | |
2050 | * It's also possible that a tracer can choose to reject the system call. In | |
2051 | * that case this function will return an illegal syscall number, and will put | |
2052 | * an appropriate return value in regs->r3. | |
2053 | * | |
2054 | * Return: the (possibly changed) syscall number. | |
4f72c427 RM |
2055 | */ |
2056 | long do_syscall_trace_enter(struct pt_regs *regs) | |
1da177e4 | 2057 | { |
22ecbe8d LZ |
2058 | user_exit(); |
2059 | ||
1addc57e KC |
2060 | /* |
2061 | * The tracer may decide to abort the syscall, if so tracehook | |
2062 | * will return !0. Note that the tracer may also just change | |
2063 | * regs->gpr[0] to an invalid syscall number, that is handled | |
2064 | * below on the exit path. | |
2065 | */ | |
2066 | if (test_thread_flag(TIF_SYSCALL_TRACE) && | |
2067 | tracehook_report_syscall_entry(regs)) | |
2068 | goto skip; | |
2069 | ||
2070 | /* Run seccomp after ptrace; allow it to set gpr[3]. */ | |
2449acc5 ME |
2071 | if (do_seccomp(regs)) |
2072 | return -1; | |
e8a30302 | 2073 | |
1addc57e KC |
2074 | /* Avoid trace and audit when syscall is invalid. */ |
2075 | if (regs->gpr[0] >= NR_syscalls) | |
2076 | goto skip; | |
ea9c102c | 2077 | |
02424d89 IM |
2078 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
2079 | trace_sys_enter(regs, regs->gpr[0]); | |
2080 | ||
cfcd1705 | 2081 | #ifdef CONFIG_PPC64 |
b05d8447 | 2082 | if (!is_32bit_task()) |
91397401 | 2083 | audit_syscall_entry(regs->gpr[0], regs->gpr[3], regs->gpr[4], |
b05d8447 EP |
2084 | regs->gpr[5], regs->gpr[6]); |
2085 | else | |
e8a30302 | 2086 | #endif |
91397401 | 2087 | audit_syscall_entry(regs->gpr[0], |
b05d8447 EP |
2088 | regs->gpr[3] & 0xffffffff, |
2089 | regs->gpr[4] & 0xffffffff, | |
2090 | regs->gpr[5] & 0xffffffff, | |
2091 | regs->gpr[6] & 0xffffffff); | |
4f72c427 | 2092 | |
d3837414 ME |
2093 | /* Return the possibly modified but valid syscall number */ |
2094 | return regs->gpr[0]; | |
1addc57e KC |
2095 | |
2096 | skip: | |
2097 | /* | |
2098 | * If we are aborting explicitly, or if the syscall number is | |
2099 | * now invalid, set the return value to -ENOSYS. | |
2100 | */ | |
2101 | regs->gpr[3] = -ENOSYS; | |
2102 | return -1; | |
ea9c102c DW |
2103 | } |
2104 | ||
2105 | void do_syscall_trace_leave(struct pt_regs *regs) | |
2106 | { | |
4f72c427 RM |
2107 | int step; |
2108 | ||
d7e7528b | 2109 | audit_syscall_exit(regs); |
ea9c102c | 2110 | |
02424d89 IM |
2111 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
2112 | trace_sys_exit(regs, regs->result); | |
2113 | ||
4f72c427 RM |
2114 | step = test_thread_flag(TIF_SINGLESTEP); |
2115 | if (step || test_thread_flag(TIF_SYSCALL_TRACE)) | |
2116 | tracehook_report_syscall_exit(regs, step); | |
22ecbe8d LZ |
2117 | |
2118 | user_enter(); | |
ea9c102c | 2119 | } |