Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) |
Paul Mackerras | b123923 | 2005-10-20 09:11:29 +1000 | [diff] [blame] | 11 | * and Paul Mackerras (paulus@samba.org). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/errno.h> |
| 23 | #include <linux/ptrace.h> |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 24 | #include <linux/regset.h> |
Roland McGrath | 4f72c42 | 2008-07-27 16:51:03 +1000 | [diff] [blame] | 25 | #include <linux/tracehook.h> |
Roland McGrath | 3caf06c | 2007-12-20 03:57:39 -0800 | [diff] [blame] | 26 | #include <linux/elf.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/user.h> |
| 28 | #include <linux/security.h> |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 29 | #include <linux/signal.h> |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 30 | #include <linux/seccomp.h> |
| 31 | #include <linux/audit.h> |
Ian Munsie | 02424d8 | 2011-02-02 17:27:24 +0000 | [diff] [blame] | 32 | #include <trace/syscall.h> |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 33 | #include <linux/hw_breakpoint.h> |
| 34 | #include <linux/perf_event.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #include <asm/uaccess.h> |
| 37 | #include <asm/page.h> |
| 38 | #include <asm/pgtable.h> |
David Howells | ae3a197 | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 39 | #include <asm/switch_to.h> |
Paul Mackerras | 21a6290 | 2005-11-19 20:47:22 +1100 | [diff] [blame] | 40 | |
Ian Munsie | 02424d8 | 2011-02-02 17:27:24 +0000 | [diff] [blame] | 41 | #define CREATE_TRACE_POINTS |
| 42 | #include <trace/events/syscalls.h> |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | /* |
Mahesh Salgaonkar | 359e428 | 2010-04-07 18:10:20 +1000 | [diff] [blame] | 45 | * The parameter save area on the stack is used to store arguments being passed |
| 46 | * to callee function and is located at fixed offset from stack pointer. |
| 47 | */ |
| 48 | #ifdef CONFIG_PPC32 |
| 49 | #define PARAMETER_SAVE_AREA_OFFSET 24 /* bytes */ |
| 50 | #else /* CONFIG_PPC32 */ |
| 51 | #define PARAMETER_SAVE_AREA_OFFSET 48 /* bytes */ |
| 52 | #endif |
| 53 | |
| 54 | struct pt_regs_offset { |
| 55 | const char *name; |
| 56 | int offset; |
| 57 | }; |
| 58 | |
| 59 | #define STR(s) #s /* convert to string */ |
| 60 | #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)} |
| 61 | #define GPR_OFFSET_NAME(num) \ |
| 62 | {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])} |
| 63 | #define REG_OFFSET_END {.name = NULL, .offset = 0} |
| 64 | |
| 65 | static const struct pt_regs_offset regoffset_table[] = { |
| 66 | GPR_OFFSET_NAME(0), |
| 67 | GPR_OFFSET_NAME(1), |
| 68 | GPR_OFFSET_NAME(2), |
| 69 | GPR_OFFSET_NAME(3), |
| 70 | GPR_OFFSET_NAME(4), |
| 71 | GPR_OFFSET_NAME(5), |
| 72 | GPR_OFFSET_NAME(6), |
| 73 | GPR_OFFSET_NAME(7), |
| 74 | GPR_OFFSET_NAME(8), |
| 75 | GPR_OFFSET_NAME(9), |
| 76 | GPR_OFFSET_NAME(10), |
| 77 | GPR_OFFSET_NAME(11), |
| 78 | GPR_OFFSET_NAME(12), |
| 79 | GPR_OFFSET_NAME(13), |
| 80 | GPR_OFFSET_NAME(14), |
| 81 | GPR_OFFSET_NAME(15), |
| 82 | GPR_OFFSET_NAME(16), |
| 83 | GPR_OFFSET_NAME(17), |
| 84 | GPR_OFFSET_NAME(18), |
| 85 | GPR_OFFSET_NAME(19), |
| 86 | GPR_OFFSET_NAME(20), |
| 87 | GPR_OFFSET_NAME(21), |
| 88 | GPR_OFFSET_NAME(22), |
| 89 | GPR_OFFSET_NAME(23), |
| 90 | GPR_OFFSET_NAME(24), |
| 91 | GPR_OFFSET_NAME(25), |
| 92 | GPR_OFFSET_NAME(26), |
| 93 | GPR_OFFSET_NAME(27), |
| 94 | GPR_OFFSET_NAME(28), |
| 95 | GPR_OFFSET_NAME(29), |
| 96 | GPR_OFFSET_NAME(30), |
| 97 | GPR_OFFSET_NAME(31), |
| 98 | REG_OFFSET_NAME(nip), |
| 99 | REG_OFFSET_NAME(msr), |
| 100 | REG_OFFSET_NAME(ctr), |
| 101 | REG_OFFSET_NAME(link), |
| 102 | REG_OFFSET_NAME(xer), |
| 103 | REG_OFFSET_NAME(ccr), |
| 104 | #ifdef CONFIG_PPC64 |
| 105 | REG_OFFSET_NAME(softe), |
| 106 | #else |
| 107 | REG_OFFSET_NAME(mq), |
| 108 | #endif |
| 109 | REG_OFFSET_NAME(trap), |
| 110 | REG_OFFSET_NAME(dar), |
| 111 | REG_OFFSET_NAME(dsisr), |
| 112 | REG_OFFSET_END, |
| 113 | }; |
| 114 | |
| 115 | /** |
| 116 | * regs_query_register_offset() - query register offset from its name |
| 117 | * @name: the name of a register |
| 118 | * |
| 119 | * regs_query_register_offset() returns the offset of a register in struct |
| 120 | * pt_regs from its name. If the name is invalid, this returns -EINVAL; |
| 121 | */ |
| 122 | int regs_query_register_offset(const char *name) |
| 123 | { |
| 124 | const struct pt_regs_offset *roff; |
| 125 | for (roff = regoffset_table; roff->name != NULL; roff++) |
| 126 | if (!strcmp(roff->name, name)) |
| 127 | return roff->offset; |
| 128 | return -EINVAL; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * regs_query_register_name() - query register name from its offset |
| 133 | * @offset: the offset of a register in struct pt_regs. |
| 134 | * |
| 135 | * regs_query_register_name() returns the name of a register from its |
| 136 | * offset in struct pt_regs. If the @offset is invalid, this returns NULL; |
| 137 | */ |
| 138 | const char *regs_query_register_name(unsigned int offset) |
| 139 | { |
| 140 | const struct pt_regs_offset *roff; |
| 141 | for (roff = regoffset_table; roff->name != NULL; roff++) |
| 142 | if (roff->offset == offset) |
| 143 | return roff->name; |
| 144 | return NULL; |
| 145 | } |
| 146 | |
| 147 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | * does not yet catch signals sent when the child dies. |
| 149 | * in exit.c or in signal.c. |
| 150 | */ |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 153 | * Set of msr bits that gdb can change on behalf of a process. |
| 154 | */ |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 155 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 156 | #define MSR_DEBUGCHANGE 0 |
| 157 | #else |
| 158 | #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE) |
| 159 | #endif |
| 160 | |
| 161 | /* |
| 162 | * Max register writeable via put_reg |
| 163 | */ |
| 164 | #ifdef CONFIG_PPC32 |
| 165 | #define PT_MAX_PUT_REG PT_MQ |
| 166 | #else |
| 167 | #define PT_MAX_PUT_REG PT_CCR |
| 168 | #endif |
| 169 | |
Roland McGrath | 26f7713 | 2007-12-20 03:57:51 -0800 | [diff] [blame] | 170 | static unsigned long get_user_msr(struct task_struct *task) |
| 171 | { |
| 172 | return task->thread.regs->msr | task->thread.fpexc_mode; |
| 173 | } |
| 174 | |
| 175 | static int set_user_msr(struct task_struct *task, unsigned long msr) |
| 176 | { |
| 177 | task->thread.regs->msr &= ~MSR_DEBUGCHANGE; |
| 178 | task->thread.regs->msr |= msr & MSR_DEBUGCHANGE; |
| 179 | return 0; |
| 180 | } |
| 181 | |
Alexey Kardashevskiy | 1715a82 | 2013-01-10 20:29:09 +0000 | [diff] [blame] | 182 | #ifdef CONFIG_PPC64 |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame^] | 183 | static int get_user_dscr(struct task_struct *task, unsigned long *data) |
Alexey Kardashevskiy | 1715a82 | 2013-01-10 20:29:09 +0000 | [diff] [blame] | 184 | { |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame^] | 185 | *data = task->thread.dscr; |
| 186 | return 0; |
Alexey Kardashevskiy | 1715a82 | 2013-01-10 20:29:09 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static int set_user_dscr(struct task_struct *task, unsigned long dscr) |
| 190 | { |
| 191 | task->thread.dscr = dscr; |
| 192 | task->thread.dscr_inherit = 1; |
| 193 | return 0; |
| 194 | } |
| 195 | #else |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame^] | 196 | static int get_user_dscr(struct task_struct *task, unsigned long *data) |
Alexey Kardashevskiy | 1715a82 | 2013-01-10 20:29:09 +0000 | [diff] [blame] | 197 | { |
| 198 | return -EIO; |
| 199 | } |
| 200 | |
| 201 | static int set_user_dscr(struct task_struct *task, unsigned long dscr) |
| 202 | { |
| 203 | return -EIO; |
| 204 | } |
| 205 | #endif |
| 206 | |
Roland McGrath | 26f7713 | 2007-12-20 03:57:51 -0800 | [diff] [blame] | 207 | /* |
| 208 | * We prevent mucking around with the reserved area of trap |
| 209 | * which are used internally by the kernel. |
| 210 | */ |
| 211 | static int set_user_trap(struct task_struct *task, unsigned long trap) |
| 212 | { |
| 213 | task->thread.regs->trap = trap & 0xfff0; |
| 214 | return 0; |
| 215 | } |
| 216 | |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 217 | /* |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 218 | * Get contents of register REGNO in task TASK. |
| 219 | */ |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame^] | 220 | int ptrace_get_reg(struct task_struct *task, int regno, unsigned long *data) |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 221 | { |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame^] | 222 | if ((task->thread.regs == NULL) || !data) |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 223 | return -EIO; |
| 224 | |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame^] | 225 | if (regno == PT_MSR) { |
| 226 | *data = get_user_msr(task); |
| 227 | return 0; |
| 228 | } |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 229 | |
Alexey Kardashevskiy | 1715a82 | 2013-01-10 20:29:09 +0000 | [diff] [blame] | 230 | if (regno == PT_DSCR) |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame^] | 231 | return get_user_dscr(task, data); |
Alexey Kardashevskiy | 1715a82 | 2013-01-10 20:29:09 +0000 | [diff] [blame] | 232 | |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame^] | 233 | if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long))) { |
| 234 | *data = ((unsigned long *)task->thread.regs)[regno]; |
| 235 | return 0; |
| 236 | } |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 237 | |
| 238 | return -EIO; |
| 239 | } |
| 240 | |
| 241 | /* |
| 242 | * Write contents of register REGNO in task TASK. |
| 243 | */ |
| 244 | int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data) |
| 245 | { |
| 246 | if (task->thread.regs == NULL) |
| 247 | return -EIO; |
| 248 | |
Roland McGrath | 26f7713 | 2007-12-20 03:57:51 -0800 | [diff] [blame] | 249 | if (regno == PT_MSR) |
| 250 | return set_user_msr(task, data); |
| 251 | if (regno == PT_TRAP) |
| 252 | return set_user_trap(task, data); |
Alexey Kardashevskiy | 1715a82 | 2013-01-10 20:29:09 +0000 | [diff] [blame] | 253 | if (regno == PT_DSCR) |
| 254 | return set_user_dscr(task, data); |
Roland McGrath | 26f7713 | 2007-12-20 03:57:51 -0800 | [diff] [blame] | 255 | |
| 256 | if (regno <= PT_MAX_PUT_REG) { |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 257 | ((unsigned long *)task->thread.regs)[regno] = data; |
| 258 | return 0; |
| 259 | } |
| 260 | return -EIO; |
| 261 | } |
| 262 | |
Roland McGrath | 44dd3f5 | 2007-12-20 03:57:55 -0800 | [diff] [blame] | 263 | static int gpr_get(struct task_struct *target, const struct user_regset *regset, |
| 264 | unsigned int pos, unsigned int count, |
| 265 | void *kbuf, void __user *ubuf) |
| 266 | { |
Mike Wolf | a71f5d5 | 2011-03-21 11:14:53 +1100 | [diff] [blame] | 267 | int i, ret; |
Roland McGrath | 44dd3f5 | 2007-12-20 03:57:55 -0800 | [diff] [blame] | 268 | |
| 269 | if (target->thread.regs == NULL) |
| 270 | return -EIO; |
| 271 | |
Mike Wolf | a71f5d5 | 2011-03-21 11:14:53 +1100 | [diff] [blame] | 272 | if (!FULL_REGS(target->thread.regs)) { |
| 273 | /* We have a partial register set. Fill 14-31 with bogus values */ |
| 274 | for (i = 14; i < 32; i++) |
| 275 | target->thread.regs->gpr[i] = NV_REG_POISON; |
| 276 | } |
Roland McGrath | 44dd3f5 | 2007-12-20 03:57:55 -0800 | [diff] [blame] | 277 | |
| 278 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 279 | target->thread.regs, |
| 280 | 0, offsetof(struct pt_regs, msr)); |
| 281 | if (!ret) { |
| 282 | unsigned long msr = get_user_msr(target); |
| 283 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr, |
| 284 | offsetof(struct pt_regs, msr), |
| 285 | offsetof(struct pt_regs, msr) + |
| 286 | sizeof(msr)); |
| 287 | } |
| 288 | |
| 289 | BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != |
| 290 | offsetof(struct pt_regs, msr) + sizeof(long)); |
| 291 | |
| 292 | if (!ret) |
| 293 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 294 | &target->thread.regs->orig_gpr3, |
| 295 | offsetof(struct pt_regs, orig_gpr3), |
| 296 | sizeof(struct pt_regs)); |
| 297 | if (!ret) |
| 298 | ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, |
| 299 | sizeof(struct pt_regs), -1); |
| 300 | |
| 301 | return ret; |
| 302 | } |
| 303 | |
| 304 | static int gpr_set(struct task_struct *target, const struct user_regset *regset, |
| 305 | unsigned int pos, unsigned int count, |
| 306 | const void *kbuf, const void __user *ubuf) |
| 307 | { |
| 308 | unsigned long reg; |
| 309 | int ret; |
| 310 | |
| 311 | if (target->thread.regs == NULL) |
| 312 | return -EIO; |
| 313 | |
| 314 | CHECK_FULL_REGS(target->thread.regs); |
| 315 | |
| 316 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 317 | target->thread.regs, |
| 318 | 0, PT_MSR * sizeof(reg)); |
| 319 | |
| 320 | if (!ret && count > 0) { |
| 321 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, ®, |
| 322 | PT_MSR * sizeof(reg), |
| 323 | (PT_MSR + 1) * sizeof(reg)); |
| 324 | if (!ret) |
| 325 | ret = set_user_msr(target, reg); |
| 326 | } |
| 327 | |
| 328 | BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != |
| 329 | offsetof(struct pt_regs, msr) + sizeof(long)); |
| 330 | |
| 331 | if (!ret) |
| 332 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 333 | &target->thread.regs->orig_gpr3, |
| 334 | PT_ORIG_R3 * sizeof(reg), |
| 335 | (PT_MAX_PUT_REG + 1) * sizeof(reg)); |
| 336 | |
| 337 | if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret) |
| 338 | ret = user_regset_copyin_ignore( |
| 339 | &pos, &count, &kbuf, &ubuf, |
| 340 | (PT_MAX_PUT_REG + 1) * sizeof(reg), |
| 341 | PT_TRAP * sizeof(reg)); |
| 342 | |
| 343 | if (!ret && count > 0) { |
| 344 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, ®, |
| 345 | PT_TRAP * sizeof(reg), |
| 346 | (PT_TRAP + 1) * sizeof(reg)); |
| 347 | if (!ret) |
| 348 | ret = set_user_trap(target, reg); |
| 349 | } |
| 350 | |
| 351 | if (!ret) |
| 352 | ret = user_regset_copyin_ignore( |
| 353 | &pos, &count, &kbuf, &ubuf, |
| 354 | (PT_TRAP + 1) * sizeof(reg), -1); |
| 355 | |
| 356 | return ret; |
| 357 | } |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 358 | |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 359 | static int fpr_get(struct task_struct *target, const struct user_regset *regset, |
| 360 | unsigned int pos, unsigned int count, |
| 361 | void *kbuf, void __user *ubuf) |
| 362 | { |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 363 | #ifdef CONFIG_VSX |
| 364 | double buf[33]; |
| 365 | int i; |
| 366 | #endif |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 367 | flush_fp_to_thread(target); |
| 368 | |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 369 | #ifdef CONFIG_VSX |
| 370 | /* copy to local buffer then write that out */ |
| 371 | for (i = 0; i < 32 ; i++) |
| 372 | buf[i] = target->thread.TS_FPR(i); |
| 373 | memcpy(&buf[32], &target->thread.fpscr, sizeof(double)); |
| 374 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1); |
| 375 | |
| 376 | #else |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 377 | BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) != |
Michael Neuling | 9c75a31 | 2008-06-26 17:07:48 +1000 | [diff] [blame] | 378 | offsetof(struct thread_struct, TS_FPR(32))); |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 379 | |
| 380 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 381 | &target->thread.fpr, 0, -1); |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 382 | #endif |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | static int fpr_set(struct task_struct *target, const struct user_regset *regset, |
| 386 | unsigned int pos, unsigned int count, |
| 387 | const void *kbuf, const void __user *ubuf) |
| 388 | { |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 389 | #ifdef CONFIG_VSX |
| 390 | double buf[33]; |
| 391 | int i; |
| 392 | #endif |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 393 | flush_fp_to_thread(target); |
| 394 | |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 395 | #ifdef CONFIG_VSX |
| 396 | /* copy to local buffer then write that out */ |
| 397 | i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1); |
| 398 | if (i) |
| 399 | return i; |
| 400 | for (i = 0; i < 32 ; i++) |
| 401 | target->thread.TS_FPR(i) = buf[i]; |
| 402 | memcpy(&target->thread.fpscr, &buf[32], sizeof(double)); |
| 403 | return 0; |
| 404 | #else |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 405 | BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) != |
Michael Neuling | 9c75a31 | 2008-06-26 17:07:48 +1000 | [diff] [blame] | 406 | offsetof(struct thread_struct, TS_FPR(32))); |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 407 | |
| 408 | return user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 409 | &target->thread.fpr, 0, -1); |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 410 | #endif |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 411 | } |
| 412 | |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 413 | #ifdef CONFIG_ALTIVEC |
| 414 | /* |
| 415 | * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go. |
| 416 | * The transfer totals 34 quadword. Quadwords 0-31 contain the |
| 417 | * corresponding vector registers. Quadword 32 contains the vscr as the |
| 418 | * last word (offset 12) within that quadword. Quadword 33 contains the |
| 419 | * vrsave as the first word (offset 0) within the quadword. |
| 420 | * |
| 421 | * This definition of the VMX state is compatible with the current PPC32 |
| 422 | * ptrace interface. This allows signal handling and ptrace to use the |
| 423 | * same structures. This also simplifies the implementation of a bi-arch |
| 424 | * (combined (32- and 64-bit) gdb. |
| 425 | */ |
| 426 | |
Roland McGrath | 3caf06c | 2007-12-20 03:57:39 -0800 | [diff] [blame] | 427 | static int vr_active(struct task_struct *target, |
| 428 | const struct user_regset *regset) |
| 429 | { |
| 430 | flush_altivec_to_thread(target); |
| 431 | return target->thread.used_vr ? regset->n : 0; |
| 432 | } |
| 433 | |
| 434 | static int vr_get(struct task_struct *target, const struct user_regset *regset, |
| 435 | unsigned int pos, unsigned int count, |
| 436 | void *kbuf, void __user *ubuf) |
| 437 | { |
| 438 | int ret; |
| 439 | |
| 440 | flush_altivec_to_thread(target); |
| 441 | |
| 442 | BUILD_BUG_ON(offsetof(struct thread_struct, vscr) != |
| 443 | offsetof(struct thread_struct, vr[32])); |
| 444 | |
| 445 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 446 | &target->thread.vr, 0, |
| 447 | 33 * sizeof(vector128)); |
| 448 | if (!ret) { |
| 449 | /* |
| 450 | * Copy out only the low-order word of vrsave. |
| 451 | */ |
| 452 | union { |
| 453 | elf_vrreg_t reg; |
| 454 | u32 word; |
| 455 | } vrsave; |
| 456 | memset(&vrsave, 0, sizeof(vrsave)); |
| 457 | vrsave.word = target->thread.vrsave; |
| 458 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave, |
| 459 | 33 * sizeof(vector128), -1); |
| 460 | } |
| 461 | |
| 462 | return ret; |
| 463 | } |
| 464 | |
| 465 | static int vr_set(struct task_struct *target, const struct user_regset *regset, |
| 466 | unsigned int pos, unsigned int count, |
| 467 | const void *kbuf, const void __user *ubuf) |
| 468 | { |
| 469 | int ret; |
| 470 | |
| 471 | flush_altivec_to_thread(target); |
| 472 | |
| 473 | BUILD_BUG_ON(offsetof(struct thread_struct, vscr) != |
| 474 | offsetof(struct thread_struct, vr[32])); |
| 475 | |
| 476 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 477 | &target->thread.vr, 0, 33 * sizeof(vector128)); |
| 478 | if (!ret && count > 0) { |
| 479 | /* |
| 480 | * We use only the first word of vrsave. |
| 481 | */ |
| 482 | union { |
| 483 | elf_vrreg_t reg; |
| 484 | u32 word; |
| 485 | } vrsave; |
| 486 | memset(&vrsave, 0, sizeof(vrsave)); |
| 487 | vrsave.word = target->thread.vrsave; |
| 488 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave, |
| 489 | 33 * sizeof(vector128), -1); |
| 490 | if (!ret) |
| 491 | target->thread.vrsave = vrsave.word; |
| 492 | } |
| 493 | |
| 494 | return ret; |
| 495 | } |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 496 | #endif /* CONFIG_ALTIVEC */ |
| 497 | |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 498 | #ifdef CONFIG_VSX |
| 499 | /* |
| 500 | * Currently to set and and get all the vsx state, you need to call |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 501 | * the fp and VMX calls as well. This only get/sets the lower 32 |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 502 | * 128bit VSX registers. |
| 503 | */ |
| 504 | |
| 505 | static int vsr_active(struct task_struct *target, |
| 506 | const struct user_regset *regset) |
| 507 | { |
| 508 | flush_vsx_to_thread(target); |
| 509 | return target->thread.used_vsr ? regset->n : 0; |
| 510 | } |
| 511 | |
| 512 | static int vsr_get(struct task_struct *target, const struct user_regset *regset, |
| 513 | unsigned int pos, unsigned int count, |
| 514 | void *kbuf, void __user *ubuf) |
| 515 | { |
Michael Neuling | f3e909c | 2008-07-01 14:01:39 +1000 | [diff] [blame] | 516 | double buf[32]; |
| 517 | int ret, i; |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 518 | |
| 519 | flush_vsx_to_thread(target); |
| 520 | |
Michael Neuling | f3e909c | 2008-07-01 14:01:39 +1000 | [diff] [blame] | 521 | for (i = 0; i < 32 ; i++) |
Michael Neuling | 7d2a175 | 2008-07-29 01:13:14 +1000 | [diff] [blame] | 522 | buf[i] = target->thread.fpr[i][TS_VSRLOWOFFSET]; |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 523 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
Michael Neuling | f3e909c | 2008-07-01 14:01:39 +1000 | [diff] [blame] | 524 | buf, 0, 32 * sizeof(double)); |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 525 | |
| 526 | return ret; |
| 527 | } |
| 528 | |
| 529 | static int vsr_set(struct task_struct *target, const struct user_regset *regset, |
| 530 | unsigned int pos, unsigned int count, |
| 531 | const void *kbuf, const void __user *ubuf) |
| 532 | { |
Michael Neuling | f3e909c | 2008-07-01 14:01:39 +1000 | [diff] [blame] | 533 | double buf[32]; |
| 534 | int ret,i; |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 535 | |
| 536 | flush_vsx_to_thread(target); |
| 537 | |
| 538 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
Michael Neuling | f3e909c | 2008-07-01 14:01:39 +1000 | [diff] [blame] | 539 | buf, 0, 32 * sizeof(double)); |
| 540 | for (i = 0; i < 32 ; i++) |
Michael Neuling | 7d2a175 | 2008-07-29 01:13:14 +1000 | [diff] [blame] | 541 | target->thread.fpr[i][TS_VSRLOWOFFSET] = buf[i]; |
Michael Neuling | f3e909c | 2008-07-01 14:01:39 +1000 | [diff] [blame] | 542 | |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 543 | |
| 544 | return ret; |
| 545 | } |
| 546 | #endif /* CONFIG_VSX */ |
| 547 | |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 548 | #ifdef CONFIG_SPE |
| 549 | |
| 550 | /* |
| 551 | * For get_evrregs/set_evrregs functions 'data' has the following layout: |
| 552 | * |
| 553 | * struct { |
| 554 | * u32 evr[32]; |
| 555 | * u64 acc; |
| 556 | * u32 spefscr; |
| 557 | * } |
| 558 | */ |
| 559 | |
Roland McGrath | a4e4b17 | 2007-12-20 03:57:48 -0800 | [diff] [blame] | 560 | static int evr_active(struct task_struct *target, |
| 561 | const struct user_regset *regset) |
| 562 | { |
| 563 | flush_spe_to_thread(target); |
| 564 | return target->thread.used_spe ? regset->n : 0; |
| 565 | } |
| 566 | |
| 567 | static int evr_get(struct task_struct *target, const struct user_regset *regset, |
| 568 | unsigned int pos, unsigned int count, |
| 569 | void *kbuf, void __user *ubuf) |
| 570 | { |
| 571 | int ret; |
| 572 | |
| 573 | flush_spe_to_thread(target); |
| 574 | |
| 575 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 576 | &target->thread.evr, |
| 577 | 0, sizeof(target->thread.evr)); |
| 578 | |
| 579 | BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) != |
| 580 | offsetof(struct thread_struct, spefscr)); |
| 581 | |
| 582 | if (!ret) |
| 583 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 584 | &target->thread.acc, |
| 585 | sizeof(target->thread.evr), -1); |
| 586 | |
| 587 | return ret; |
| 588 | } |
| 589 | |
| 590 | static int evr_set(struct task_struct *target, const struct user_regset *regset, |
| 591 | unsigned int pos, unsigned int count, |
| 592 | const void *kbuf, const void __user *ubuf) |
| 593 | { |
| 594 | int ret; |
| 595 | |
| 596 | flush_spe_to_thread(target); |
| 597 | |
| 598 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 599 | &target->thread.evr, |
| 600 | 0, sizeof(target->thread.evr)); |
| 601 | |
| 602 | BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) != |
| 603 | offsetof(struct thread_struct, spefscr)); |
| 604 | |
| 605 | if (!ret) |
| 606 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 607 | &target->thread.acc, |
| 608 | sizeof(target->thread.evr), -1); |
| 609 | |
| 610 | return ret; |
| 611 | } |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 612 | #endif /* CONFIG_SPE */ |
| 613 | |
| 614 | |
Roland McGrath | 80fdf47 | 2007-12-20 03:58:00 -0800 | [diff] [blame] | 615 | /* |
| 616 | * These are our native regset flavors. |
| 617 | */ |
| 618 | enum powerpc_regset { |
| 619 | REGSET_GPR, |
| 620 | REGSET_FPR, |
| 621 | #ifdef CONFIG_ALTIVEC |
| 622 | REGSET_VMX, |
| 623 | #endif |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 624 | #ifdef CONFIG_VSX |
| 625 | REGSET_VSX, |
| 626 | #endif |
Roland McGrath | 80fdf47 | 2007-12-20 03:58:00 -0800 | [diff] [blame] | 627 | #ifdef CONFIG_SPE |
| 628 | REGSET_SPE, |
| 629 | #endif |
| 630 | }; |
| 631 | |
| 632 | static const struct user_regset native_regsets[] = { |
| 633 | [REGSET_GPR] = { |
| 634 | .core_note_type = NT_PRSTATUS, .n = ELF_NGREG, |
| 635 | .size = sizeof(long), .align = sizeof(long), |
| 636 | .get = gpr_get, .set = gpr_set |
| 637 | }, |
| 638 | [REGSET_FPR] = { |
| 639 | .core_note_type = NT_PRFPREG, .n = ELF_NFPREG, |
| 640 | .size = sizeof(double), .align = sizeof(double), |
| 641 | .get = fpr_get, .set = fpr_set |
| 642 | }, |
| 643 | #ifdef CONFIG_ALTIVEC |
| 644 | [REGSET_VMX] = { |
| 645 | .core_note_type = NT_PPC_VMX, .n = 34, |
| 646 | .size = sizeof(vector128), .align = sizeof(vector128), |
| 647 | .active = vr_active, .get = vr_get, .set = vr_set |
| 648 | }, |
| 649 | #endif |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 650 | #ifdef CONFIG_VSX |
| 651 | [REGSET_VSX] = { |
Michael Neuling | f3e909c | 2008-07-01 14:01:39 +1000 | [diff] [blame] | 652 | .core_note_type = NT_PPC_VSX, .n = 32, |
| 653 | .size = sizeof(double), .align = sizeof(double), |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 654 | .active = vsr_active, .get = vsr_get, .set = vsr_set |
| 655 | }, |
| 656 | #endif |
Roland McGrath | 80fdf47 | 2007-12-20 03:58:00 -0800 | [diff] [blame] | 657 | #ifdef CONFIG_SPE |
| 658 | [REGSET_SPE] = { |
| 659 | .n = 35, |
| 660 | .size = sizeof(u32), .align = sizeof(u32), |
| 661 | .active = evr_active, .get = evr_get, .set = evr_set |
| 662 | }, |
| 663 | #endif |
| 664 | }; |
| 665 | |
| 666 | static const struct user_regset_view user_ppc_native_view = { |
| 667 | .name = UTS_MACHINE, .e_machine = ELF_ARCH, .ei_osabi = ELF_OSABI, |
| 668 | .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets) |
| 669 | }; |
| 670 | |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 671 | #ifdef CONFIG_PPC64 |
| 672 | #include <linux/compat.h> |
| 673 | |
| 674 | static int gpr32_get(struct task_struct *target, |
| 675 | const struct user_regset *regset, |
| 676 | unsigned int pos, unsigned int count, |
| 677 | void *kbuf, void __user *ubuf) |
| 678 | { |
| 679 | const unsigned long *regs = &target->thread.regs->gpr[0]; |
| 680 | compat_ulong_t *k = kbuf; |
| 681 | compat_ulong_t __user *u = ubuf; |
| 682 | compat_ulong_t reg; |
Mike Wolf | a71f5d5 | 2011-03-21 11:14:53 +1100 | [diff] [blame] | 683 | int i; |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 684 | |
| 685 | if (target->thread.regs == NULL) |
| 686 | return -EIO; |
| 687 | |
Mike Wolf | a71f5d5 | 2011-03-21 11:14:53 +1100 | [diff] [blame] | 688 | if (!FULL_REGS(target->thread.regs)) { |
| 689 | /* We have a partial register set. Fill 14-31 with bogus values */ |
| 690 | for (i = 14; i < 32; i++) |
| 691 | target->thread.regs->gpr[i] = NV_REG_POISON; |
| 692 | } |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 693 | |
| 694 | pos /= sizeof(reg); |
| 695 | count /= sizeof(reg); |
| 696 | |
| 697 | if (kbuf) |
| 698 | for (; count > 0 && pos < PT_MSR; --count) |
| 699 | *k++ = regs[pos++]; |
| 700 | else |
| 701 | for (; count > 0 && pos < PT_MSR; --count) |
| 702 | if (__put_user((compat_ulong_t) regs[pos++], u++)) |
| 703 | return -EFAULT; |
| 704 | |
| 705 | if (count > 0 && pos == PT_MSR) { |
| 706 | reg = get_user_msr(target); |
| 707 | if (kbuf) |
| 708 | *k++ = reg; |
| 709 | else if (__put_user(reg, u++)) |
| 710 | return -EFAULT; |
| 711 | ++pos; |
| 712 | --count; |
| 713 | } |
| 714 | |
| 715 | if (kbuf) |
| 716 | for (; count > 0 && pos < PT_REGS_COUNT; --count) |
| 717 | *k++ = regs[pos++]; |
| 718 | else |
| 719 | for (; count > 0 && pos < PT_REGS_COUNT; --count) |
| 720 | if (__put_user((compat_ulong_t) regs[pos++], u++)) |
| 721 | return -EFAULT; |
| 722 | |
| 723 | kbuf = k; |
| 724 | ubuf = u; |
| 725 | pos *= sizeof(reg); |
| 726 | count *= sizeof(reg); |
| 727 | return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, |
| 728 | PT_REGS_COUNT * sizeof(reg), -1); |
| 729 | } |
| 730 | |
| 731 | static int gpr32_set(struct task_struct *target, |
| 732 | const struct user_regset *regset, |
| 733 | unsigned int pos, unsigned int count, |
| 734 | const void *kbuf, const void __user *ubuf) |
| 735 | { |
| 736 | unsigned long *regs = &target->thread.regs->gpr[0]; |
| 737 | const compat_ulong_t *k = kbuf; |
| 738 | const compat_ulong_t __user *u = ubuf; |
| 739 | compat_ulong_t reg; |
| 740 | |
| 741 | if (target->thread.regs == NULL) |
| 742 | return -EIO; |
| 743 | |
| 744 | CHECK_FULL_REGS(target->thread.regs); |
| 745 | |
| 746 | pos /= sizeof(reg); |
| 747 | count /= sizeof(reg); |
| 748 | |
| 749 | if (kbuf) |
| 750 | for (; count > 0 && pos < PT_MSR; --count) |
| 751 | regs[pos++] = *k++; |
| 752 | else |
| 753 | for (; count > 0 && pos < PT_MSR; --count) { |
| 754 | if (__get_user(reg, u++)) |
| 755 | return -EFAULT; |
| 756 | regs[pos++] = reg; |
| 757 | } |
| 758 | |
| 759 | |
| 760 | if (count > 0 && pos == PT_MSR) { |
| 761 | if (kbuf) |
| 762 | reg = *k++; |
| 763 | else if (__get_user(reg, u++)) |
| 764 | return -EFAULT; |
| 765 | set_user_msr(target, reg); |
| 766 | ++pos; |
| 767 | --count; |
| 768 | } |
| 769 | |
Roland McGrath | c2372eb | 2008-03-13 19:25:35 +1100 | [diff] [blame] | 770 | if (kbuf) { |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 771 | for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) |
| 772 | regs[pos++] = *k++; |
Roland McGrath | c2372eb | 2008-03-13 19:25:35 +1100 | [diff] [blame] | 773 | for (; count > 0 && pos < PT_TRAP; --count, ++pos) |
| 774 | ++k; |
| 775 | } else { |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 776 | for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) { |
| 777 | if (__get_user(reg, u++)) |
| 778 | return -EFAULT; |
| 779 | regs[pos++] = reg; |
| 780 | } |
Roland McGrath | c2372eb | 2008-03-13 19:25:35 +1100 | [diff] [blame] | 781 | for (; count > 0 && pos < PT_TRAP; --count, ++pos) |
| 782 | if (__get_user(reg, u++)) |
| 783 | return -EFAULT; |
| 784 | } |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 785 | |
| 786 | if (count > 0 && pos == PT_TRAP) { |
| 787 | if (kbuf) |
| 788 | reg = *k++; |
| 789 | else if (__get_user(reg, u++)) |
| 790 | return -EFAULT; |
| 791 | set_user_trap(target, reg); |
| 792 | ++pos; |
| 793 | --count; |
| 794 | } |
| 795 | |
| 796 | kbuf = k; |
| 797 | ubuf = u; |
| 798 | pos *= sizeof(reg); |
| 799 | count *= sizeof(reg); |
| 800 | return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, |
| 801 | (PT_TRAP + 1) * sizeof(reg), -1); |
| 802 | } |
| 803 | |
| 804 | /* |
| 805 | * These are the regset flavors matching the CONFIG_PPC32 native set. |
| 806 | */ |
| 807 | static const struct user_regset compat_regsets[] = { |
| 808 | [REGSET_GPR] = { |
| 809 | .core_note_type = NT_PRSTATUS, .n = ELF_NGREG, |
| 810 | .size = sizeof(compat_long_t), .align = sizeof(compat_long_t), |
| 811 | .get = gpr32_get, .set = gpr32_set |
| 812 | }, |
| 813 | [REGSET_FPR] = { |
| 814 | .core_note_type = NT_PRFPREG, .n = ELF_NFPREG, |
| 815 | .size = sizeof(double), .align = sizeof(double), |
| 816 | .get = fpr_get, .set = fpr_set |
| 817 | }, |
| 818 | #ifdef CONFIG_ALTIVEC |
| 819 | [REGSET_VMX] = { |
| 820 | .core_note_type = NT_PPC_VMX, .n = 34, |
| 821 | .size = sizeof(vector128), .align = sizeof(vector128), |
| 822 | .active = vr_active, .get = vr_get, .set = vr_set |
| 823 | }, |
| 824 | #endif |
| 825 | #ifdef CONFIG_SPE |
| 826 | [REGSET_SPE] = { |
Roland McGrath | 24f1a84 | 2008-01-02 17:05:48 -0800 | [diff] [blame] | 827 | .core_note_type = NT_PPC_SPE, .n = 35, |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 828 | .size = sizeof(u32), .align = sizeof(u32), |
| 829 | .active = evr_active, .get = evr_get, .set = evr_set |
| 830 | }, |
| 831 | #endif |
| 832 | }; |
| 833 | |
| 834 | static const struct user_regset_view user_ppc_compat_view = { |
| 835 | .name = "ppc", .e_machine = EM_PPC, .ei_osabi = ELF_OSABI, |
| 836 | .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets) |
| 837 | }; |
| 838 | #endif /* CONFIG_PPC64 */ |
| 839 | |
Roland McGrath | 80fdf47 | 2007-12-20 03:58:00 -0800 | [diff] [blame] | 840 | const struct user_regset_view *task_user_regset_view(struct task_struct *task) |
| 841 | { |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 842 | #ifdef CONFIG_PPC64 |
| 843 | if (test_tsk_thread_flag(task, TIF_32BIT)) |
| 844 | return &user_ppc_compat_view; |
| 845 | #endif |
Roland McGrath | 80fdf47 | 2007-12-20 03:58:00 -0800 | [diff] [blame] | 846 | return &user_ppc_native_view; |
| 847 | } |
| 848 | |
| 849 | |
Roland McGrath | 2a84b0d | 2008-01-30 13:30:51 +0100 | [diff] [blame] | 850 | void user_enable_single_step(struct task_struct *task) |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 851 | { |
| 852 | struct pt_regs *regs = task->thread.regs; |
| 853 | |
| 854 | if (regs != NULL) { |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 855 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Roland McGrath | ec097c8 | 2009-05-28 21:26:38 +0000 | [diff] [blame] | 856 | task->thread.dbcr0 &= ~DBCR0_BT; |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 857 | task->thread.dbcr0 |= DBCR0_IDM | DBCR0_IC; |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 858 | regs->msr |= MSR_DE; |
| 859 | #else |
Roland McGrath | ec097c8 | 2009-05-28 21:26:38 +0000 | [diff] [blame] | 860 | regs->msr &= ~MSR_BE; |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 861 | regs->msr |= MSR_SE; |
| 862 | #endif |
| 863 | } |
| 864 | set_tsk_thread_flag(task, TIF_SINGLESTEP); |
| 865 | } |
| 866 | |
Roland McGrath | ec097c8 | 2009-05-28 21:26:38 +0000 | [diff] [blame] | 867 | void user_enable_block_step(struct task_struct *task) |
| 868 | { |
| 869 | struct pt_regs *regs = task->thread.regs; |
| 870 | |
| 871 | if (regs != NULL) { |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 872 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Roland McGrath | ec097c8 | 2009-05-28 21:26:38 +0000 | [diff] [blame] | 873 | task->thread.dbcr0 &= ~DBCR0_IC; |
| 874 | task->thread.dbcr0 = DBCR0_IDM | DBCR0_BT; |
| 875 | regs->msr |= MSR_DE; |
| 876 | #else |
| 877 | regs->msr &= ~MSR_SE; |
| 878 | regs->msr |= MSR_BE; |
| 879 | #endif |
| 880 | } |
| 881 | set_tsk_thread_flag(task, TIF_SINGLESTEP); |
| 882 | } |
| 883 | |
Roland McGrath | 2a84b0d | 2008-01-30 13:30:51 +0100 | [diff] [blame] | 884 | void user_disable_single_step(struct task_struct *task) |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 885 | { |
| 886 | struct pt_regs *regs = task->thread.regs; |
| 887 | |
| 888 | if (regs != NULL) { |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 889 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 890 | /* |
| 891 | * The logic to disable single stepping should be as |
| 892 | * simple as turning off the Instruction Complete flag. |
| 893 | * And, after doing so, if all debug flags are off, turn |
| 894 | * off DBCR0(IDM) and MSR(DE) .... Torez |
| 895 | */ |
| 896 | task->thread.dbcr0 &= ~DBCR0_IC; |
| 897 | /* |
| 898 | * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set. |
| 899 | */ |
| 900 | if (!DBCR_ACTIVE_EVENTS(task->thread.dbcr0, |
| 901 | task->thread.dbcr1)) { |
| 902 | /* |
| 903 | * All debug events were off..... |
| 904 | */ |
| 905 | task->thread.dbcr0 &= ~DBCR0_IDM; |
Dave Kleikamp | 28477fb | 2009-07-08 13:46:18 +0000 | [diff] [blame] | 906 | regs->msr &= ~MSR_DE; |
| 907 | } |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 908 | #else |
Roland McGrath | ec097c8 | 2009-05-28 21:26:38 +0000 | [diff] [blame] | 909 | regs->msr &= ~(MSR_SE | MSR_BE); |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 910 | #endif |
| 911 | } |
| 912 | clear_tsk_thread_flag(task, TIF_SINGLESTEP); |
| 913 | } |
| 914 | |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 915 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
Peter Zijlstra | a8b0ca1 | 2011-06-27 14:41:57 +0200 | [diff] [blame] | 916 | void ptrace_triggered(struct perf_event *bp, |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 917 | struct perf_sample_data *data, struct pt_regs *regs) |
| 918 | { |
| 919 | struct perf_event_attr attr; |
| 920 | |
| 921 | /* |
| 922 | * Disable the breakpoint request here since ptrace has defined a |
| 923 | * one-shot behaviour for breakpoint exceptions in PPC64. |
| 924 | * The SIGTRAP signal is generated automatically for us in do_dabr(). |
| 925 | * We don't have to do anything about that here |
| 926 | */ |
| 927 | attr = bp->attr; |
| 928 | attr.disabled = true; |
| 929 | modify_user_hw_breakpoint(bp, &attr); |
| 930 | } |
| 931 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
| 932 | |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 933 | int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 934 | unsigned long data) |
| 935 | { |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 936 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 937 | int ret; |
| 938 | struct thread_struct *thread = &(task->thread); |
| 939 | struct perf_event *bp; |
| 940 | struct perf_event_attr attr; |
| 941 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 942 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS |
| 943 | struct arch_hw_breakpoint hw_brk; |
| 944 | #endif |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 945 | |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 946 | /* For ppc64 we support one DABR and no IABR's at the moment (ppc64). |
| 947 | * For embedded processors we support one DAC and no IAC's at the |
| 948 | * moment. |
| 949 | */ |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 950 | if (addr > 0) |
| 951 | return -EINVAL; |
| 952 | |
Kumar Gala | 2325f0a | 2008-07-26 05:27:33 +1000 | [diff] [blame] | 953 | /* The bottom 3 bits in dabr are flags */ |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 954 | if ((data & ~0x7UL) >= TASK_SIZE) |
| 955 | return -EIO; |
| 956 | |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 957 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 958 | /* For processors using DABR (i.e. 970), the bottom 3 bits are flags. |
| 959 | * It was assumed, on previous implementations, that 3 bits were |
| 960 | * passed together with the data address, fitting the design of the |
| 961 | * DABR register, as follows: |
| 962 | * |
| 963 | * bit 0: Read flag |
| 964 | * bit 1: Write flag |
| 965 | * bit 2: Breakpoint translation |
| 966 | * |
| 967 | * Thus, we use them here as so. |
| 968 | */ |
| 969 | |
| 970 | /* Ensure breakpoint translation bit is set */ |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 971 | if (data && !(data & HW_BRK_TYPE_TRANSLATE)) |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 972 | return -EIO; |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 973 | hw_brk.address = data & (~HW_BRK_TYPE_DABR); |
| 974 | hw_brk.type = (data & HW_BRK_TYPE_DABR) | HW_BRK_TYPE_PRIV_ALL; |
| 975 | hw_brk.len = 8; |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 976 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
Frederic Weisbecker | 925f83c | 2011-05-06 01:53:18 +0200 | [diff] [blame] | 977 | if (ptrace_get_breakpoints(task) < 0) |
| 978 | return -ESRCH; |
| 979 | |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 980 | bp = thread->ptrace_bps[0]; |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 981 | if ((!data) || !(hw_brk.type & HW_BRK_TYPE_RDWR)) { |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 982 | if (bp) { |
| 983 | unregister_hw_breakpoint(bp); |
| 984 | thread->ptrace_bps[0] = NULL; |
| 985 | } |
Frederic Weisbecker | 925f83c | 2011-05-06 01:53:18 +0200 | [diff] [blame] | 986 | ptrace_put_breakpoints(task); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 987 | return 0; |
| 988 | } |
| 989 | if (bp) { |
| 990 | attr = bp->attr; |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 991 | attr.bp_addr = hw_brk.address; |
| 992 | arch_bp_generic_fields(hw_brk.type, &attr.bp_type); |
Aravinda Prasad | a53fd61 | 2012-11-04 22:15:28 +0000 | [diff] [blame] | 993 | |
| 994 | /* Enable breakpoint */ |
| 995 | attr.disabled = false; |
| 996 | |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 997 | ret = modify_user_hw_breakpoint(bp, &attr); |
Frederic Weisbecker | 925f83c | 2011-05-06 01:53:18 +0200 | [diff] [blame] | 998 | if (ret) { |
| 999 | ptrace_put_breakpoints(task); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1000 | return ret; |
Frederic Weisbecker | 925f83c | 2011-05-06 01:53:18 +0200 | [diff] [blame] | 1001 | } |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1002 | thread->ptrace_bps[0] = bp; |
Frederic Weisbecker | 925f83c | 2011-05-06 01:53:18 +0200 | [diff] [blame] | 1003 | ptrace_put_breakpoints(task); |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1004 | thread->hw_brk = hw_brk; |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1005 | return 0; |
| 1006 | } |
| 1007 | |
| 1008 | /* Create a new breakpoint request if one doesn't exist already */ |
| 1009 | hw_breakpoint_init(&attr); |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1010 | attr.bp_addr = hw_brk.address; |
| 1011 | arch_bp_generic_fields(hw_brk.type, |
| 1012 | &attr.bp_type); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1013 | |
| 1014 | thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr, |
Avi Kivity | 4dc0da8 | 2011-06-29 18:42:35 +0300 | [diff] [blame] | 1015 | ptrace_triggered, NULL, task); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1016 | if (IS_ERR(bp)) { |
| 1017 | thread->ptrace_bps[0] = NULL; |
Frederic Weisbecker | 925f83c | 2011-05-06 01:53:18 +0200 | [diff] [blame] | 1018 | ptrace_put_breakpoints(task); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1019 | return PTR_ERR(bp); |
| 1020 | } |
| 1021 | |
Frederic Weisbecker | 925f83c | 2011-05-06 01:53:18 +0200 | [diff] [blame] | 1022 | ptrace_put_breakpoints(task); |
| 1023 | |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1024 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1025 | task->thread.hw_brk = hw_brk; |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 1026 | #else /* CONFIG_PPC_ADV_DEBUG_REGS */ |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1027 | /* As described above, it was assumed 3 bits were passed with the data |
| 1028 | * address, but we will assume only the mode bits will be passed |
| 1029 | * as to not cause alignment restrictions for DAC-based processors. |
| 1030 | */ |
| 1031 | |
| 1032 | /* DAC's hold the whole address without any mode flags */ |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1033 | task->thread.dac1 = data & ~0x3UL; |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1034 | |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1035 | if (task->thread.dac1 == 0) { |
| 1036 | dbcr_dac(task) &= ~(DBCR_DAC1R | DBCR_DAC1W); |
| 1037 | if (!DBCR_ACTIVE_EVENTS(task->thread.dbcr0, |
| 1038 | task->thread.dbcr1)) { |
| 1039 | task->thread.regs->msr &= ~MSR_DE; |
| 1040 | task->thread.dbcr0 &= ~DBCR0_IDM; |
| 1041 | } |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1042 | return 0; |
| 1043 | } |
| 1044 | |
| 1045 | /* Read or Write bits must be set */ |
| 1046 | |
| 1047 | if (!(data & 0x3UL)) |
| 1048 | return -EINVAL; |
| 1049 | |
| 1050 | /* Set the Internal Debugging flag (IDM bit 1) for the DBCR0 |
| 1051 | register */ |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1052 | task->thread.dbcr0 |= DBCR0_IDM; |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1053 | |
| 1054 | /* Check for write and read flags and set DBCR0 |
| 1055 | accordingly */ |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1056 | dbcr_dac(task) &= ~(DBCR_DAC1R|DBCR_DAC1W); |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1057 | if (data & 0x1UL) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1058 | dbcr_dac(task) |= DBCR_DAC1R; |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1059 | if (data & 0x2UL) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1060 | dbcr_dac(task) |= DBCR_DAC1W; |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1061 | task->thread.regs->msr |= MSR_DE; |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 1062 | #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 1063 | return 0; |
| 1064 | } |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 1065 | |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 1066 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | * Called by kernel/ptrace.c when detaching.. |
| 1068 | * |
| 1069 | * Make sure single step bits etc are not set. |
| 1070 | */ |
| 1071 | void ptrace_disable(struct task_struct *child) |
| 1072 | { |
| 1073 | /* make sure the single step bit is not set. */ |
Roland McGrath | 2a84b0d | 2008-01-30 13:30:51 +0100 | [diff] [blame] | 1074 | user_disable_single_step(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1077 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Michael Neuling | 84295df | 2012-10-28 15:13:16 +0000 | [diff] [blame] | 1078 | static long set_instruction_bp(struct task_struct *child, |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1079 | struct ppc_hw_breakpoint *bp_info) |
| 1080 | { |
| 1081 | int slot; |
| 1082 | int slot1_in_use = ((child->thread.dbcr0 & DBCR0_IAC1) != 0); |
| 1083 | int slot2_in_use = ((child->thread.dbcr0 & DBCR0_IAC2) != 0); |
| 1084 | int slot3_in_use = ((child->thread.dbcr0 & DBCR0_IAC3) != 0); |
| 1085 | int slot4_in_use = ((child->thread.dbcr0 & DBCR0_IAC4) != 0); |
| 1086 | |
| 1087 | if (dbcr_iac_range(child) & DBCR_IAC12MODE) |
| 1088 | slot2_in_use = 1; |
| 1089 | if (dbcr_iac_range(child) & DBCR_IAC34MODE) |
| 1090 | slot4_in_use = 1; |
| 1091 | |
| 1092 | if (bp_info->addr >= TASK_SIZE) |
| 1093 | return -EIO; |
| 1094 | |
| 1095 | if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) { |
| 1096 | |
| 1097 | /* Make sure range is valid. */ |
| 1098 | if (bp_info->addr2 >= TASK_SIZE) |
| 1099 | return -EIO; |
| 1100 | |
| 1101 | /* We need a pair of IAC regsisters */ |
| 1102 | if ((!slot1_in_use) && (!slot2_in_use)) { |
| 1103 | slot = 1; |
| 1104 | child->thread.iac1 = bp_info->addr; |
| 1105 | child->thread.iac2 = bp_info->addr2; |
| 1106 | child->thread.dbcr0 |= DBCR0_IAC1; |
| 1107 | if (bp_info->addr_mode == |
| 1108 | PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE) |
| 1109 | dbcr_iac_range(child) |= DBCR_IAC12X; |
| 1110 | else |
| 1111 | dbcr_iac_range(child) |= DBCR_IAC12I; |
| 1112 | #if CONFIG_PPC_ADV_DEBUG_IACS > 2 |
| 1113 | } else if ((!slot3_in_use) && (!slot4_in_use)) { |
| 1114 | slot = 3; |
| 1115 | child->thread.iac3 = bp_info->addr; |
| 1116 | child->thread.iac4 = bp_info->addr2; |
| 1117 | child->thread.dbcr0 |= DBCR0_IAC3; |
| 1118 | if (bp_info->addr_mode == |
| 1119 | PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE) |
| 1120 | dbcr_iac_range(child) |= DBCR_IAC34X; |
| 1121 | else |
| 1122 | dbcr_iac_range(child) |= DBCR_IAC34I; |
| 1123 | #endif |
| 1124 | } else |
| 1125 | return -ENOSPC; |
| 1126 | } else { |
| 1127 | /* We only need one. If possible leave a pair free in |
| 1128 | * case a range is needed later |
| 1129 | */ |
| 1130 | if (!slot1_in_use) { |
| 1131 | /* |
| 1132 | * Don't use iac1 if iac1-iac2 are free and either |
| 1133 | * iac3 or iac4 (but not both) are free |
| 1134 | */ |
| 1135 | if (slot2_in_use || (slot3_in_use == slot4_in_use)) { |
| 1136 | slot = 1; |
| 1137 | child->thread.iac1 = bp_info->addr; |
| 1138 | child->thread.dbcr0 |= DBCR0_IAC1; |
| 1139 | goto out; |
| 1140 | } |
| 1141 | } |
| 1142 | if (!slot2_in_use) { |
| 1143 | slot = 2; |
| 1144 | child->thread.iac2 = bp_info->addr; |
| 1145 | child->thread.dbcr0 |= DBCR0_IAC2; |
| 1146 | #if CONFIG_PPC_ADV_DEBUG_IACS > 2 |
| 1147 | } else if (!slot3_in_use) { |
| 1148 | slot = 3; |
| 1149 | child->thread.iac3 = bp_info->addr; |
| 1150 | child->thread.dbcr0 |= DBCR0_IAC3; |
| 1151 | } else if (!slot4_in_use) { |
| 1152 | slot = 4; |
| 1153 | child->thread.iac4 = bp_info->addr; |
| 1154 | child->thread.dbcr0 |= DBCR0_IAC4; |
| 1155 | #endif |
| 1156 | } else |
| 1157 | return -ENOSPC; |
| 1158 | } |
| 1159 | out: |
| 1160 | child->thread.dbcr0 |= DBCR0_IDM; |
| 1161 | child->thread.regs->msr |= MSR_DE; |
| 1162 | |
| 1163 | return slot; |
| 1164 | } |
| 1165 | |
| 1166 | static int del_instruction_bp(struct task_struct *child, int slot) |
| 1167 | { |
| 1168 | switch (slot) { |
| 1169 | case 1: |
Dave Kleikamp | 30124d1 | 2010-03-01 04:57:34 +0000 | [diff] [blame] | 1170 | if ((child->thread.dbcr0 & DBCR0_IAC1) == 0) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1171 | return -ENOENT; |
| 1172 | |
| 1173 | if (dbcr_iac_range(child) & DBCR_IAC12MODE) { |
| 1174 | /* address range - clear slots 1 & 2 */ |
| 1175 | child->thread.iac2 = 0; |
| 1176 | dbcr_iac_range(child) &= ~DBCR_IAC12MODE; |
| 1177 | } |
| 1178 | child->thread.iac1 = 0; |
| 1179 | child->thread.dbcr0 &= ~DBCR0_IAC1; |
| 1180 | break; |
| 1181 | case 2: |
Dave Kleikamp | 30124d1 | 2010-03-01 04:57:34 +0000 | [diff] [blame] | 1182 | if ((child->thread.dbcr0 & DBCR0_IAC2) == 0) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1183 | return -ENOENT; |
| 1184 | |
| 1185 | if (dbcr_iac_range(child) & DBCR_IAC12MODE) |
| 1186 | /* used in a range */ |
| 1187 | return -EINVAL; |
| 1188 | child->thread.iac2 = 0; |
| 1189 | child->thread.dbcr0 &= ~DBCR0_IAC2; |
| 1190 | break; |
| 1191 | #if CONFIG_PPC_ADV_DEBUG_IACS > 2 |
| 1192 | case 3: |
Dave Kleikamp | 30124d1 | 2010-03-01 04:57:34 +0000 | [diff] [blame] | 1193 | if ((child->thread.dbcr0 & DBCR0_IAC3) == 0) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1194 | return -ENOENT; |
| 1195 | |
| 1196 | if (dbcr_iac_range(child) & DBCR_IAC34MODE) { |
| 1197 | /* address range - clear slots 3 & 4 */ |
| 1198 | child->thread.iac4 = 0; |
| 1199 | dbcr_iac_range(child) &= ~DBCR_IAC34MODE; |
| 1200 | } |
| 1201 | child->thread.iac3 = 0; |
| 1202 | child->thread.dbcr0 &= ~DBCR0_IAC3; |
| 1203 | break; |
| 1204 | case 4: |
Dave Kleikamp | 30124d1 | 2010-03-01 04:57:34 +0000 | [diff] [blame] | 1205 | if ((child->thread.dbcr0 & DBCR0_IAC4) == 0) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1206 | return -ENOENT; |
| 1207 | |
| 1208 | if (dbcr_iac_range(child) & DBCR_IAC34MODE) |
| 1209 | /* Used in a range */ |
| 1210 | return -EINVAL; |
| 1211 | child->thread.iac4 = 0; |
| 1212 | child->thread.dbcr0 &= ~DBCR0_IAC4; |
| 1213 | break; |
| 1214 | #endif |
| 1215 | default: |
| 1216 | return -EINVAL; |
| 1217 | } |
| 1218 | return 0; |
| 1219 | } |
| 1220 | |
| 1221 | static int set_dac(struct task_struct *child, struct ppc_hw_breakpoint *bp_info) |
| 1222 | { |
| 1223 | int byte_enable = |
| 1224 | (bp_info->condition_mode >> PPC_BREAKPOINT_CONDITION_BE_SHIFT) |
| 1225 | & 0xf; |
| 1226 | int condition_mode = |
| 1227 | bp_info->condition_mode & PPC_BREAKPOINT_CONDITION_MODE; |
| 1228 | int slot; |
| 1229 | |
| 1230 | if (byte_enable && (condition_mode == 0)) |
| 1231 | return -EINVAL; |
| 1232 | |
| 1233 | if (bp_info->addr >= TASK_SIZE) |
| 1234 | return -EIO; |
| 1235 | |
| 1236 | if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) { |
| 1237 | slot = 1; |
| 1238 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) |
| 1239 | dbcr_dac(child) |= DBCR_DAC1R; |
| 1240 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) |
| 1241 | dbcr_dac(child) |= DBCR_DAC1W; |
| 1242 | child->thread.dac1 = (unsigned long)bp_info->addr; |
| 1243 | #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 |
| 1244 | if (byte_enable) { |
| 1245 | child->thread.dvc1 = |
| 1246 | (unsigned long)bp_info->condition_value; |
| 1247 | child->thread.dbcr2 |= |
| 1248 | ((byte_enable << DBCR2_DVC1BE_SHIFT) | |
| 1249 | (condition_mode << DBCR2_DVC1M_SHIFT)); |
| 1250 | } |
| 1251 | #endif |
| 1252 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE |
| 1253 | } else if (child->thread.dbcr2 & DBCR2_DAC12MODE) { |
| 1254 | /* Both dac1 and dac2 are part of a range */ |
| 1255 | return -ENOSPC; |
| 1256 | #endif |
| 1257 | } else if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) { |
| 1258 | slot = 2; |
| 1259 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) |
| 1260 | dbcr_dac(child) |= DBCR_DAC2R; |
| 1261 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) |
| 1262 | dbcr_dac(child) |= DBCR_DAC2W; |
| 1263 | child->thread.dac2 = (unsigned long)bp_info->addr; |
| 1264 | #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 |
| 1265 | if (byte_enable) { |
| 1266 | child->thread.dvc2 = |
| 1267 | (unsigned long)bp_info->condition_value; |
| 1268 | child->thread.dbcr2 |= |
| 1269 | ((byte_enable << DBCR2_DVC2BE_SHIFT) | |
| 1270 | (condition_mode << DBCR2_DVC2M_SHIFT)); |
| 1271 | } |
| 1272 | #endif |
| 1273 | } else |
| 1274 | return -ENOSPC; |
| 1275 | child->thread.dbcr0 |= DBCR0_IDM; |
| 1276 | child->thread.regs->msr |= MSR_DE; |
| 1277 | |
| 1278 | return slot + 4; |
| 1279 | } |
| 1280 | |
| 1281 | static int del_dac(struct task_struct *child, int slot) |
| 1282 | { |
| 1283 | if (slot == 1) { |
Dave Kleikamp | 30124d1 | 2010-03-01 04:57:34 +0000 | [diff] [blame] | 1284 | if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1285 | return -ENOENT; |
| 1286 | |
| 1287 | child->thread.dac1 = 0; |
| 1288 | dbcr_dac(child) &= ~(DBCR_DAC1R | DBCR_DAC1W); |
| 1289 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE |
| 1290 | if (child->thread.dbcr2 & DBCR2_DAC12MODE) { |
| 1291 | child->thread.dac2 = 0; |
| 1292 | child->thread.dbcr2 &= ~DBCR2_DAC12MODE; |
| 1293 | } |
| 1294 | child->thread.dbcr2 &= ~(DBCR2_DVC1M | DBCR2_DVC1BE); |
| 1295 | #endif |
| 1296 | #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 |
| 1297 | child->thread.dvc1 = 0; |
| 1298 | #endif |
| 1299 | } else if (slot == 2) { |
Dave Kleikamp | 30124d1 | 2010-03-01 04:57:34 +0000 | [diff] [blame] | 1300 | if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1301 | return -ENOENT; |
| 1302 | |
| 1303 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE |
| 1304 | if (child->thread.dbcr2 & DBCR2_DAC12MODE) |
| 1305 | /* Part of a range */ |
| 1306 | return -EINVAL; |
| 1307 | child->thread.dbcr2 &= ~(DBCR2_DVC2M | DBCR2_DVC2BE); |
| 1308 | #endif |
| 1309 | #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 |
| 1310 | child->thread.dvc2 = 0; |
| 1311 | #endif |
| 1312 | child->thread.dac2 = 0; |
| 1313 | dbcr_dac(child) &= ~(DBCR_DAC2R | DBCR_DAC2W); |
| 1314 | } else |
| 1315 | return -EINVAL; |
| 1316 | |
| 1317 | return 0; |
| 1318 | } |
| 1319 | #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ |
| 1320 | |
| 1321 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE |
| 1322 | static int set_dac_range(struct task_struct *child, |
| 1323 | struct ppc_hw_breakpoint *bp_info) |
| 1324 | { |
| 1325 | int mode = bp_info->addr_mode & PPC_BREAKPOINT_MODE_MASK; |
| 1326 | |
| 1327 | /* We don't allow range watchpoints to be used with DVC */ |
| 1328 | if (bp_info->condition_mode) |
| 1329 | return -EINVAL; |
| 1330 | |
| 1331 | /* |
| 1332 | * Best effort to verify the address range. The user/supervisor bits |
| 1333 | * prevent trapping in kernel space, but let's fail on an obvious bad |
| 1334 | * range. The simple test on the mask is not fool-proof, and any |
| 1335 | * exclusive range will spill over into kernel space. |
| 1336 | */ |
| 1337 | if (bp_info->addr >= TASK_SIZE) |
| 1338 | return -EIO; |
| 1339 | if (mode == PPC_BREAKPOINT_MODE_MASK) { |
| 1340 | /* |
| 1341 | * dac2 is a bitmask. Don't allow a mask that makes a |
| 1342 | * kernel space address from a valid dac1 value |
| 1343 | */ |
| 1344 | if (~((unsigned long)bp_info->addr2) >= TASK_SIZE) |
| 1345 | return -EIO; |
| 1346 | } else { |
| 1347 | /* |
| 1348 | * For range breakpoints, addr2 must also be a valid address |
| 1349 | */ |
| 1350 | if (bp_info->addr2 >= TASK_SIZE) |
| 1351 | return -EIO; |
| 1352 | } |
| 1353 | |
| 1354 | if (child->thread.dbcr0 & |
| 1355 | (DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W)) |
| 1356 | return -ENOSPC; |
| 1357 | |
| 1358 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) |
| 1359 | child->thread.dbcr0 |= (DBCR0_DAC1R | DBCR0_IDM); |
| 1360 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) |
| 1361 | child->thread.dbcr0 |= (DBCR0_DAC1W | DBCR0_IDM); |
| 1362 | child->thread.dac1 = bp_info->addr; |
| 1363 | child->thread.dac2 = bp_info->addr2; |
| 1364 | if (mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE) |
| 1365 | child->thread.dbcr2 |= DBCR2_DAC12M; |
| 1366 | else if (mode == PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE) |
| 1367 | child->thread.dbcr2 |= DBCR2_DAC12MX; |
| 1368 | else /* PPC_BREAKPOINT_MODE_MASK */ |
| 1369 | child->thread.dbcr2 |= DBCR2_DAC12MM; |
| 1370 | child->thread.regs->msr |= MSR_DE; |
| 1371 | |
| 1372 | return 5; |
| 1373 | } |
| 1374 | #endif /* CONFIG_PPC_ADV_DEBUG_DAC_RANGE */ |
| 1375 | |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1376 | static long ppc_set_hwdebug(struct task_struct *child, |
| 1377 | struct ppc_hw_breakpoint *bp_info) |
| 1378 | { |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1379 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 1380 | int len = 0; |
| 1381 | struct thread_struct *thread = &(child->thread); |
| 1382 | struct perf_event *bp; |
| 1383 | struct perf_event_attr attr; |
| 1384 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Andreas Schwab | 4dfbf29 | 2010-11-27 14:24:53 +0000 | [diff] [blame] | 1385 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1386 | struct arch_hw_breakpoint brk; |
Andreas Schwab | 4dfbf29 | 2010-11-27 14:24:53 +0000 | [diff] [blame] | 1387 | #endif |
| 1388 | |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1389 | if (bp_info->version != 1) |
| 1390 | return -ENOTSUPP; |
| 1391 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1392 | /* |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1393 | * Check for invalid flags and combinations |
| 1394 | */ |
| 1395 | if ((bp_info->trigger_type == 0) || |
| 1396 | (bp_info->trigger_type & ~(PPC_BREAKPOINT_TRIGGER_EXECUTE | |
| 1397 | PPC_BREAKPOINT_TRIGGER_RW)) || |
| 1398 | (bp_info->addr_mode & ~PPC_BREAKPOINT_MODE_MASK) || |
| 1399 | (bp_info->condition_mode & |
| 1400 | ~(PPC_BREAKPOINT_CONDITION_MODE | |
| 1401 | PPC_BREAKPOINT_CONDITION_BE_ALL))) |
| 1402 | return -EINVAL; |
| 1403 | #if CONFIG_PPC_ADV_DEBUG_DVCS == 0 |
| 1404 | if (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE) |
| 1405 | return -EINVAL; |
| 1406 | #endif |
| 1407 | |
| 1408 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_EXECUTE) { |
| 1409 | if ((bp_info->trigger_type != PPC_BREAKPOINT_TRIGGER_EXECUTE) || |
| 1410 | (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE)) |
| 1411 | return -EINVAL; |
Michael Neuling | 84295df | 2012-10-28 15:13:16 +0000 | [diff] [blame] | 1412 | return set_instruction_bp(child, bp_info); |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1413 | } |
| 1414 | if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT) |
| 1415 | return set_dac(child, bp_info); |
| 1416 | |
| 1417 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE |
| 1418 | return set_dac_range(child, bp_info); |
| 1419 | #else |
| 1420 | return -EINVAL; |
| 1421 | #endif |
| 1422 | #else /* !CONFIG_PPC_ADV_DEBUG_DVCS */ |
| 1423 | /* |
| 1424 | * We only support one data breakpoint |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1425 | */ |
Andreas Schwab | 4dfbf29 | 2010-11-27 14:24:53 +0000 | [diff] [blame] | 1426 | if ((bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_RW) == 0 || |
| 1427 | (bp_info->trigger_type & ~PPC_BREAKPOINT_TRIGGER_RW) != 0 || |
Andreas Schwab | 4dfbf29 | 2010-11-27 14:24:53 +0000 | [diff] [blame] | 1428 | bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE) |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1429 | return -EINVAL; |
| 1430 | |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1431 | if ((unsigned long)bp_info->addr >= TASK_SIZE) |
| 1432 | return -EIO; |
| 1433 | |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1434 | brk.address = bp_info->addr & ~7UL; |
| 1435 | brk.type = HW_BRK_TYPE_TRANSLATE; |
Michael Neuling | 2bb78ef | 2013-03-11 16:42:49 +0000 | [diff] [blame] | 1436 | brk.len = 8; |
Andreas Schwab | 4dfbf29 | 2010-11-27 14:24:53 +0000 | [diff] [blame] | 1437 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1438 | brk.type |= HW_BRK_TYPE_READ; |
Andreas Schwab | 4dfbf29 | 2010-11-27 14:24:53 +0000 | [diff] [blame] | 1439 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1440 | brk.type |= HW_BRK_TYPE_WRITE; |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1441 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 1442 | if (ptrace_get_breakpoints(child) < 0) |
| 1443 | return -ESRCH; |
| 1444 | |
| 1445 | /* |
| 1446 | * Check if the request is for 'range' breakpoints. We can |
| 1447 | * support it if range < 8 bytes. |
| 1448 | */ |
| 1449 | if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE) { |
| 1450 | len = bp_info->addr2 - bp_info->addr; |
| 1451 | } else if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) { |
| 1452 | ptrace_put_breakpoints(child); |
| 1453 | return -EINVAL; |
| 1454 | } |
| 1455 | bp = thread->ptrace_bps[0]; |
| 1456 | if (bp) { |
| 1457 | ptrace_put_breakpoints(child); |
| 1458 | return -ENOSPC; |
| 1459 | } |
| 1460 | |
| 1461 | /* Create a new breakpoint request if one doesn't exist already */ |
| 1462 | hw_breakpoint_init(&attr); |
| 1463 | attr.bp_addr = (unsigned long)bp_info->addr & ~HW_BREAKPOINT_ALIGN; |
| 1464 | attr.bp_len = len; |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1465 | arch_bp_generic_fields(brk.type, &attr.bp_type); |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1466 | |
| 1467 | thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr, |
| 1468 | ptrace_triggered, NULL, child); |
| 1469 | if (IS_ERR(bp)) { |
| 1470 | thread->ptrace_bps[0] = NULL; |
| 1471 | ptrace_put_breakpoints(child); |
| 1472 | return PTR_ERR(bp); |
| 1473 | } |
| 1474 | |
| 1475 | ptrace_put_breakpoints(child); |
| 1476 | return 1; |
| 1477 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
| 1478 | |
| 1479 | if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) |
| 1480 | return -EINVAL; |
| 1481 | |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1482 | if (child->thread.hw_brk.address) |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1483 | return -ENOSPC; |
Andreas Schwab | 4dfbf29 | 2010-11-27 14:24:53 +0000 | [diff] [blame] | 1484 | |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1485 | child->thread.hw_brk = brk; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1486 | |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1487 | return 1; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1488 | #endif /* !CONFIG_PPC_ADV_DEBUG_DVCS */ |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
Michael Neuling | ec1b33d | 2012-10-28 15:13:17 +0000 | [diff] [blame] | 1491 | static long ppc_del_hwdebug(struct task_struct *child, long data) |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1492 | { |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1493 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 1494 | int ret = 0; |
| 1495 | struct thread_struct *thread = &(child->thread); |
| 1496 | struct perf_event *bp; |
| 1497 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1498 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
| 1499 | int rc; |
| 1500 | |
| 1501 | if (data <= 4) |
| 1502 | rc = del_instruction_bp(child, (int)data); |
| 1503 | else |
| 1504 | rc = del_dac(child, (int)data - 4); |
| 1505 | |
| 1506 | if (!rc) { |
| 1507 | if (!DBCR_ACTIVE_EVENTS(child->thread.dbcr0, |
| 1508 | child->thread.dbcr1)) { |
| 1509 | child->thread.dbcr0 &= ~DBCR0_IDM; |
| 1510 | child->thread.regs->msr &= ~MSR_DE; |
| 1511 | } |
| 1512 | } |
| 1513 | return rc; |
| 1514 | #else |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1515 | if (data != 1) |
| 1516 | return -EINVAL; |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1517 | |
| 1518 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 1519 | if (ptrace_get_breakpoints(child) < 0) |
| 1520 | return -ESRCH; |
| 1521 | |
| 1522 | bp = thread->ptrace_bps[0]; |
| 1523 | if (bp) { |
| 1524 | unregister_hw_breakpoint(bp); |
| 1525 | thread->ptrace_bps[0] = NULL; |
| 1526 | } else |
| 1527 | ret = -ENOENT; |
| 1528 | ptrace_put_breakpoints(child); |
| 1529 | return ret; |
| 1530 | #else /* CONFIG_HAVE_HW_BREAKPOINT */ |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1531 | if (child->thread.hw_brk.address == 0) |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1532 | return -ENOENT; |
| 1533 | |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1534 | child->thread.hw_brk.address = 0; |
| 1535 | child->thread.hw_brk.type = 0; |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1536 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1537 | |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1538 | return 0; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1539 | #endif |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
Namhyung Kim | 9b05a69 | 2010-10-27 15:33:47 -0700 | [diff] [blame] | 1542 | long arch_ptrace(struct task_struct *child, long request, |
| 1543 | unsigned long addr, unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | int ret = -EPERM; |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1546 | void __user *datavp = (void __user *) data; |
| 1547 | unsigned long __user *datalp = datavp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | switch (request) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | /* read the word at location addr in the USER area. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | case PTRACE_PEEKUSR: { |
| 1552 | unsigned long index, tmp; |
| 1553 | |
| 1554 | ret = -EIO; |
| 1555 | /* convert to index and check */ |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1556 | #ifdef CONFIG_PPC32 |
Namhyung Kim | 9b05a69 | 2010-10-27 15:33:47 -0700 | [diff] [blame] | 1557 | index = addr >> 2; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1558 | if ((addr & 3) || (index > PT_FPSCR) |
| 1559 | || (child->thread.regs == NULL)) |
| 1560 | #else |
Namhyung Kim | 9b05a69 | 2010-10-27 15:33:47 -0700 | [diff] [blame] | 1561 | index = addr >> 3; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1562 | if ((addr & 7) || (index > PT_FPSCR)) |
| 1563 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | break; |
| 1565 | |
| 1566 | CHECK_FULL_REGS(child->thread.regs); |
| 1567 | if (index < PT_FPR0) { |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame^] | 1568 | ret = ptrace_get_reg(child, (int) index, &tmp); |
| 1569 | if (ret) |
| 1570 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | } else { |
Benjamin Herrenschmidt | e69b742 | 2011-09-26 19:37:57 +0000 | [diff] [blame] | 1572 | unsigned int fpidx = index - PT_FPR0; |
| 1573 | |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1574 | flush_fp_to_thread(child); |
Benjamin Herrenschmidt | e69b742 | 2011-09-26 19:37:57 +0000 | [diff] [blame] | 1575 | if (fpidx < (PT_FPSCR - PT_FPR0)) |
| 1576 | tmp = ((unsigned long *)child->thread.fpr) |
| 1577 | [fpidx * TS_FPRWIDTH]; |
| 1578 | else |
| 1579 | tmp = child->thread.fpscr.val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | } |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1581 | ret = put_user(tmp, datalp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | break; |
| 1583 | } |
| 1584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | /* write the word at location addr in the USER area */ |
| 1586 | case PTRACE_POKEUSR: { |
| 1587 | unsigned long index; |
| 1588 | |
| 1589 | ret = -EIO; |
| 1590 | /* convert to index and check */ |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1591 | #ifdef CONFIG_PPC32 |
Namhyung Kim | 9b05a69 | 2010-10-27 15:33:47 -0700 | [diff] [blame] | 1592 | index = addr >> 2; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1593 | if ((addr & 3) || (index > PT_FPSCR) |
| 1594 | || (child->thread.regs == NULL)) |
| 1595 | #else |
Namhyung Kim | 9b05a69 | 2010-10-27 15:33:47 -0700 | [diff] [blame] | 1596 | index = addr >> 3; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1597 | if ((addr & 7) || (index > PT_FPSCR)) |
| 1598 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | break; |
| 1600 | |
| 1601 | CHECK_FULL_REGS(child->thread.regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | if (index < PT_FPR0) { |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 1603 | ret = ptrace_put_reg(child, index, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | } else { |
Benjamin Herrenschmidt | e69b742 | 2011-09-26 19:37:57 +0000 | [diff] [blame] | 1605 | unsigned int fpidx = index - PT_FPR0; |
| 1606 | |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1607 | flush_fp_to_thread(child); |
Benjamin Herrenschmidt | e69b742 | 2011-09-26 19:37:57 +0000 | [diff] [blame] | 1608 | if (fpidx < (PT_FPSCR - PT_FPR0)) |
| 1609 | ((unsigned long *)child->thread.fpr) |
| 1610 | [fpidx * TS_FPRWIDTH] = data; |
| 1611 | else |
| 1612 | child->thread.fpscr.val = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | ret = 0; |
| 1614 | } |
| 1615 | break; |
| 1616 | } |
| 1617 | |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1618 | case PPC_PTRACE_GETHWDBGINFO: { |
| 1619 | struct ppc_debug_info dbginfo; |
| 1620 | |
| 1621 | dbginfo.version = 1; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1622 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
| 1623 | dbginfo.num_instruction_bps = CONFIG_PPC_ADV_DEBUG_IACS; |
| 1624 | dbginfo.num_data_bps = CONFIG_PPC_ADV_DEBUG_DACS; |
| 1625 | dbginfo.num_condition_regs = CONFIG_PPC_ADV_DEBUG_DVCS; |
| 1626 | dbginfo.data_bp_alignment = 4; |
| 1627 | dbginfo.sizeof_condition = 4; |
| 1628 | dbginfo.features = PPC_DEBUG_FEATURE_INSN_BP_RANGE | |
| 1629 | PPC_DEBUG_FEATURE_INSN_BP_MASK; |
| 1630 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE |
| 1631 | dbginfo.features |= |
| 1632 | PPC_DEBUG_FEATURE_DATA_BP_RANGE | |
| 1633 | PPC_DEBUG_FEATURE_DATA_BP_MASK; |
| 1634 | #endif |
| 1635 | #else /* !CONFIG_PPC_ADV_DEBUG_REGS */ |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1636 | dbginfo.num_instruction_bps = 0; |
| 1637 | dbginfo.num_data_bps = 1; |
| 1638 | dbginfo.num_condition_regs = 0; |
| 1639 | #ifdef CONFIG_PPC64 |
| 1640 | dbginfo.data_bp_alignment = 8; |
| 1641 | #else |
| 1642 | dbginfo.data_bp_alignment = 4; |
| 1643 | #endif |
| 1644 | dbginfo.sizeof_condition = 0; |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1645 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 1646 | dbginfo.features = PPC_DEBUG_FEATURE_DATA_BP_RANGE; |
| 1647 | #else |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1648 | dbginfo.features = 0; |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1649 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1650 | #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1651 | |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1652 | if (!access_ok(VERIFY_WRITE, datavp, |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1653 | sizeof(struct ppc_debug_info))) |
| 1654 | return -EFAULT; |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1655 | ret = __copy_to_user(datavp, &dbginfo, |
| 1656 | sizeof(struct ppc_debug_info)) ? |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1657 | -EFAULT : 0; |
| 1658 | break; |
| 1659 | } |
| 1660 | |
| 1661 | case PPC_PTRACE_SETHWDEBUG: { |
| 1662 | struct ppc_hw_breakpoint bp_info; |
| 1663 | |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1664 | if (!access_ok(VERIFY_READ, datavp, |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1665 | sizeof(struct ppc_hw_breakpoint))) |
| 1666 | return -EFAULT; |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1667 | ret = __copy_from_user(&bp_info, datavp, |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1668 | sizeof(struct ppc_hw_breakpoint)) ? |
| 1669 | -EFAULT : 0; |
| 1670 | if (!ret) |
| 1671 | ret = ppc_set_hwdebug(child, &bp_info); |
| 1672 | break; |
| 1673 | } |
| 1674 | |
| 1675 | case PPC_PTRACE_DELHWDEBUG: { |
Michael Neuling | ec1b33d | 2012-10-28 15:13:17 +0000 | [diff] [blame] | 1676 | ret = ppc_del_hwdebug(child, data); |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1677 | break; |
| 1678 | } |
| 1679 | |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1680 | case PTRACE_GET_DEBUGREG: { |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1681 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS |
| 1682 | unsigned long dabr_fake; |
| 1683 | #endif |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1684 | ret = -EINVAL; |
| 1685 | /* We only support one DABR and no IABRS at the moment */ |
| 1686 | if (addr > 0) |
| 1687 | break; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1688 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1689 | ret = put_user(child->thread.dac1, datalp); |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1690 | #else |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1691 | dabr_fake = ((child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) | |
| 1692 | (child->thread.hw_brk.type & HW_BRK_TYPE_DABR)); |
| 1693 | ret = put_user(dabr_fake, datalp); |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1694 | #endif |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1695 | break; |
| 1696 | } |
| 1697 | |
| 1698 | case PTRACE_SET_DEBUGREG: |
| 1699 | ret = ptrace_set_debugreg(child, addr, data); |
| 1700 | break; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1701 | |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 1702 | #ifdef CONFIG_PPC64 |
| 1703 | case PTRACE_GETREGS64: |
| 1704 | #endif |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1705 | case PTRACE_GETREGS: /* Get all pt_regs from the child. */ |
| 1706 | return copy_regset_to_user(child, &user_ppc_native_view, |
| 1707 | REGSET_GPR, |
| 1708 | 0, sizeof(struct pt_regs), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1709 | datavp); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1710 | |
Benjamin Herrenschmidt | 0b3d5c4 | 2007-06-04 15:15:39 +1000 | [diff] [blame] | 1711 | #ifdef CONFIG_PPC64 |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 1712 | case PTRACE_SETREGS64: |
| 1713 | #endif |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1714 | case PTRACE_SETREGS: /* Set all gp regs in the child. */ |
| 1715 | return copy_regset_from_user(child, &user_ppc_native_view, |
| 1716 | REGSET_GPR, |
| 1717 | 0, sizeof(struct pt_regs), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1718 | datavp); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1719 | |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1720 | case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */ |
| 1721 | return copy_regset_to_user(child, &user_ppc_native_view, |
| 1722 | REGSET_FPR, |
| 1723 | 0, sizeof(elf_fpregset_t), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1724 | datavp); |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 1725 | |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1726 | case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */ |
| 1727 | return copy_regset_from_user(child, &user_ppc_native_view, |
| 1728 | REGSET_FPR, |
| 1729 | 0, sizeof(elf_fpregset_t), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1730 | datavp); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | #ifdef CONFIG_ALTIVEC |
| 1733 | case PTRACE_GETVRREGS: |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1734 | return copy_regset_to_user(child, &user_ppc_native_view, |
| 1735 | REGSET_VMX, |
| 1736 | 0, (33 * sizeof(vector128) + |
| 1737 | sizeof(u32)), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1738 | datavp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | |
| 1740 | case PTRACE_SETVRREGS: |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1741 | return copy_regset_from_user(child, &user_ppc_native_view, |
| 1742 | REGSET_VMX, |
| 1743 | 0, (33 * sizeof(vector128) + |
| 1744 | sizeof(u32)), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1745 | datavp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | #endif |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 1747 | #ifdef CONFIG_VSX |
| 1748 | case PTRACE_GETVSRREGS: |
| 1749 | return copy_regset_to_user(child, &user_ppc_native_view, |
| 1750 | REGSET_VSX, |
Michael Neuling | 1ac42ef8 | 2008-07-29 01:13:14 +1000 | [diff] [blame] | 1751 | 0, 32 * sizeof(double), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1752 | datavp); |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 1753 | |
| 1754 | case PTRACE_SETVSRREGS: |
| 1755 | return copy_regset_from_user(child, &user_ppc_native_view, |
| 1756 | REGSET_VSX, |
Michael Neuling | 1ac42ef8 | 2008-07-29 01:13:14 +1000 | [diff] [blame] | 1757 | 0, 32 * sizeof(double), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1758 | datavp); |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 1759 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | #ifdef CONFIG_SPE |
| 1761 | case PTRACE_GETEVRREGS: |
| 1762 | /* Get the child spe register state. */ |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1763 | return copy_regset_to_user(child, &user_ppc_native_view, |
| 1764 | REGSET_SPE, 0, 35 * sizeof(u32), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1765 | datavp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | |
| 1767 | case PTRACE_SETEVRREGS: |
| 1768 | /* Set the child spe register state. */ |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1769 | return copy_regset_from_user(child, &user_ppc_native_view, |
| 1770 | REGSET_SPE, 0, 35 * sizeof(u32), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1771 | datavp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | #endif |
| 1773 | |
| 1774 | default: |
| 1775 | ret = ptrace_request(child, request, addr, data); |
| 1776 | break; |
| 1777 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | return ret; |
| 1779 | } |
| 1780 | |
Roland McGrath | 4f72c42 | 2008-07-27 16:51:03 +1000 | [diff] [blame] | 1781 | /* |
| 1782 | * We must return the syscall number to actually look up in the table. |
| 1783 | * This can be -1L to skip running any syscall at all. |
| 1784 | */ |
| 1785 | long do_syscall_trace_enter(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | { |
Roland McGrath | 4f72c42 | 2008-07-27 16:51:03 +1000 | [diff] [blame] | 1787 | long ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | |
Will Drewry | e4da89d | 2012-04-17 14:48:57 -0500 | [diff] [blame] | 1789 | secure_computing_strict(regs->gpr[0]); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1790 | |
Roland McGrath | 4f72c42 | 2008-07-27 16:51:03 +1000 | [diff] [blame] | 1791 | if (test_thread_flag(TIF_SYSCALL_TRACE) && |
| 1792 | tracehook_report_syscall_entry(regs)) |
| 1793 | /* |
| 1794 | * Tracing decided this syscall should not happen. |
| 1795 | * We'll return a bogus call number to get an ENOSYS |
| 1796 | * error, but leave the original number in regs->gpr[0]. |
| 1797 | */ |
| 1798 | ret = -1L; |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 1799 | |
Ian Munsie | 02424d8 | 2011-02-02 17:27:24 +0000 | [diff] [blame] | 1800 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
| 1801 | trace_sys_enter(regs, regs->gpr[0]); |
| 1802 | |
David Woodhouse | cfcd170 | 2007-01-14 09:38:18 +0800 | [diff] [blame] | 1803 | #ifdef CONFIG_PPC64 |
Eric Paris | b05d844 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 1804 | if (!is_32bit_task()) |
| 1805 | audit_syscall_entry(AUDIT_ARCH_PPC64, |
| 1806 | regs->gpr[0], |
| 1807 | regs->gpr[3], regs->gpr[4], |
| 1808 | regs->gpr[5], regs->gpr[6]); |
| 1809 | else |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1810 | #endif |
Eric Paris | b05d844 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 1811 | audit_syscall_entry(AUDIT_ARCH_PPC, |
| 1812 | regs->gpr[0], |
| 1813 | regs->gpr[3] & 0xffffffff, |
| 1814 | regs->gpr[4] & 0xffffffff, |
| 1815 | regs->gpr[5] & 0xffffffff, |
| 1816 | regs->gpr[6] & 0xffffffff); |
Roland McGrath | 4f72c42 | 2008-07-27 16:51:03 +1000 | [diff] [blame] | 1817 | |
| 1818 | return ret ?: regs->gpr[0]; |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | void do_syscall_trace_leave(struct pt_regs *regs) |
| 1822 | { |
Roland McGrath | 4f72c42 | 2008-07-27 16:51:03 +1000 | [diff] [blame] | 1823 | int step; |
| 1824 | |
Eric Paris | d7e7528 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 1825 | audit_syscall_exit(regs); |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 1826 | |
Ian Munsie | 02424d8 | 2011-02-02 17:27:24 +0000 | [diff] [blame] | 1827 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
| 1828 | trace_sys_exit(regs, regs->result); |
| 1829 | |
Roland McGrath | 4f72c42 | 2008-07-27 16:51:03 +1000 | [diff] [blame] | 1830 | step = test_thread_flag(TIF_SINGLESTEP); |
| 1831 | if (step || test_thread_flag(TIF_SYSCALL_TRACE)) |
| 1832 | tracehook_report_syscall_exit(regs, step); |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 1833 | } |