2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1992 Ross Biro
7 * Copyright (C) Linus Torvalds
8 * Copyright (C) 1994, 95, 96, 97, 98, 2000 Ralf Baechle
9 * Copyright (C) 1996 David S. Miller
10 * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
11 * Copyright (C) 1999 MIPS Technologies, Inc.
12 * Copyright (C) 2000 Ulf Carlsson
14 * At this time Linux/MIPS64 only supports syscall tracing, even for 32-bit
17 #include <linux/compiler.h>
18 #include <linux/context_tracking.h>
19 #include <linux/elf.h>
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
22 #include <linux/sched/task_stack.h>
24 #include <linux/errno.h>
25 #include <linux/ptrace.h>
26 #include <linux/regset.h>
27 #include <linux/smp.h>
28 #include <linux/security.h>
29 #include <linux/stddef.h>
30 #include <linux/tracehook.h>
31 #include <linux/audit.h>
32 #include <linux/seccomp.h>
33 #include <linux/ftrace.h>
35 #include <asm/byteorder.h>
37 #include <asm/cpu-info.h>
40 #include <asm/mipsregs.h>
41 #include <asm/mipsmtregs.h>
42 #include <asm/pgtable.h>
44 #include <asm/processor.h>
45 #include <asm/syscall.h>
46 #include <linux/uaccess.h>
47 #include <asm/bootinfo.h>
50 #define CREATE_TRACE_POINTS
51 #include <trace/events/syscalls.h>
53 static void init_fp_ctx(struct task_struct *target)
55 /* If FP has been used then the target already has context */
56 if (tsk_used_math(target))
59 /* Begin with data registers set to all 1s... */
60 memset(&target->thread.fpu.fpr, ~0, sizeof(target->thread.fpu.fpr));
62 /* FCSR has been preset by `mips_set_personality_nan'. */
65 * Record that the target has "used" math, such that the context
66 * just initialised, and any modifications made by the caller,
69 set_stopped_child_used_math(target);
73 * Called by kernel/ptrace.c when detaching..
75 * Make sure single step bits etc are not set.
77 void ptrace_disable(struct task_struct *child)
79 /* Don't load the watchpoint registers for the ex-child. */
80 clear_tsk_thread_flag(child, TIF_LOAD_WATCH);
84 * Poke at FCSR according to its mask. Set the Cause bits even
85 * if a corresponding Enable bit is set. This will be noticed at
86 * the time the thread is switched to and SIGFPE thrown accordingly.
88 static void ptrace_setfcr31(struct task_struct *child, u32 value)
93 fcr31 = child->thread.fpu.fcr31;
94 mask = boot_cpu_data.fpu_msk31;
95 child->thread.fpu.fcr31 = (value & ~mask) | (fcr31 & mask);
99 * Read a general register set. We always use the 64-bit format, even
100 * for 32-bit kernels and for 32-bit processes on a 64-bit kernel.
101 * Registers are sign extended to fill the available space.
103 int ptrace_getregs(struct task_struct *child, struct user_pt_regs __user *data)
105 struct pt_regs *regs;
108 if (!access_ok(VERIFY_WRITE, data, 38 * 8))
111 regs = task_pt_regs(child);
113 for (i = 0; i < 32; i++)
114 __put_user((long)regs->regs[i], (__s64 __user *)&data->regs[i]);
115 __put_user((long)regs->lo, (__s64 __user *)&data->lo);
116 __put_user((long)regs->hi, (__s64 __user *)&data->hi);
117 __put_user((long)regs->cp0_epc, (__s64 __user *)&data->cp0_epc);
118 __put_user((long)regs->cp0_badvaddr, (__s64 __user *)&data->cp0_badvaddr);
119 __put_user((long)regs->cp0_status, (__s64 __user *)&data->cp0_status);
120 __put_user((long)regs->cp0_cause, (__s64 __user *)&data->cp0_cause);
126 * Write a general register set. As for PTRACE_GETREGS, we always use
127 * the 64-bit format. On a 32-bit kernel only the lower order half
128 * (according to endianness) will be used.
130 int ptrace_setregs(struct task_struct *child, struct user_pt_regs __user *data)
132 struct pt_regs *regs;
135 if (!access_ok(VERIFY_READ, data, 38 * 8))
138 regs = task_pt_regs(child);
140 for (i = 0; i < 32; i++)
141 __get_user(regs->regs[i], (__s64 __user *)&data->regs[i]);
142 __get_user(regs->lo, (__s64 __user *)&data->lo);
143 __get_user(regs->hi, (__s64 __user *)&data->hi);
144 __get_user(regs->cp0_epc, (__s64 __user *)&data->cp0_epc);
146 /* badvaddr, status, and cause may not be written. */
148 /* System call number may have been changed */
149 mips_syscall_update_nr(child, regs);
154 int ptrace_getfpregs(struct task_struct *child, __u32 __user *data)
158 if (!access_ok(VERIFY_WRITE, data, 33 * 8))
161 if (tsk_used_math(child)) {
162 union fpureg *fregs = get_fpu_regs(child);
163 for (i = 0; i < 32; i++)
164 __put_user(get_fpr64(&fregs[i], 0),
165 i + (__u64 __user *)data);
167 for (i = 0; i < 32; i++)
168 __put_user((__u64) -1, i + (__u64 __user *) data);
171 __put_user(child->thread.fpu.fcr31, data + 64);
172 __put_user(boot_cpu_data.fpu_id, data + 65);
177 int ptrace_setfpregs(struct task_struct *child, __u32 __user *data)
184 if (!access_ok(VERIFY_READ, data, 33 * 8))
188 fregs = get_fpu_regs(child);
190 for (i = 0; i < 32; i++) {
191 __get_user(fpr_val, i + (__u64 __user *)data);
192 set_fpr64(&fregs[i], 0, fpr_val);
195 __get_user(value, data + 64);
196 ptrace_setfcr31(child, value);
198 /* FIR may not be written. */
203 int ptrace_get_watch_regs(struct task_struct *child,
204 struct pt_watch_regs __user *addr)
206 enum pt_watch_style style;
209 if (!cpu_has_watch || boot_cpu_data.watch_reg_use_cnt == 0)
211 if (!access_ok(VERIFY_WRITE, addr, sizeof(struct pt_watch_regs)))
215 style = pt_watch_style_mips32;
216 #define WATCH_STYLE mips32
218 style = pt_watch_style_mips64;
219 #define WATCH_STYLE mips64
222 __put_user(style, &addr->style);
223 __put_user(boot_cpu_data.watch_reg_use_cnt,
224 &addr->WATCH_STYLE.num_valid);
225 for (i = 0; i < boot_cpu_data.watch_reg_use_cnt; i++) {
226 __put_user(child->thread.watch.mips3264.watchlo[i],
227 &addr->WATCH_STYLE.watchlo[i]);
228 __put_user(child->thread.watch.mips3264.watchhi[i] &
229 (MIPS_WATCHHI_MASK | MIPS_WATCHHI_IRW),
230 &addr->WATCH_STYLE.watchhi[i]);
231 __put_user(boot_cpu_data.watch_reg_masks[i],
232 &addr->WATCH_STYLE.watch_masks[i]);
235 __put_user(0, &addr->WATCH_STYLE.watchlo[i]);
236 __put_user(0, &addr->WATCH_STYLE.watchhi[i]);
237 __put_user(0, &addr->WATCH_STYLE.watch_masks[i]);
243 int ptrace_set_watch_regs(struct task_struct *child,
244 struct pt_watch_regs __user *addr)
247 int watch_active = 0;
248 unsigned long lt[NUM_WATCH_REGS];
249 u16 ht[NUM_WATCH_REGS];
251 if (!cpu_has_watch || boot_cpu_data.watch_reg_use_cnt == 0)
253 if (!access_ok(VERIFY_READ, addr, sizeof(struct pt_watch_regs)))
255 /* Check the values. */
256 for (i = 0; i < boot_cpu_data.watch_reg_use_cnt; i++) {
257 __get_user(lt[i], &addr->WATCH_STYLE.watchlo[i]);
259 if (lt[i] & __UA_LIMIT)
262 if (test_tsk_thread_flag(child, TIF_32BIT_ADDR)) {
263 if (lt[i] & 0xffffffff80000000UL)
266 if (lt[i] & __UA_LIMIT)
270 __get_user(ht[i], &addr->WATCH_STYLE.watchhi[i]);
271 if (ht[i] & ~MIPS_WATCHHI_MASK)
275 for (i = 0; i < boot_cpu_data.watch_reg_use_cnt; i++) {
276 if (lt[i] & MIPS_WATCHLO_IRW)
278 child->thread.watch.mips3264.watchlo[i] = lt[i];
280 child->thread.watch.mips3264.watchhi[i] = ht[i];
284 set_tsk_thread_flag(child, TIF_LOAD_WATCH);
286 clear_tsk_thread_flag(child, TIF_LOAD_WATCH);
291 /* regset get/set implementations */
293 #if defined(CONFIG_32BIT) || defined(CONFIG_MIPS32_O32)
295 static int gpr32_get(struct task_struct *target,
296 const struct user_regset *regset,
297 unsigned int pos, unsigned int count,
298 void *kbuf, void __user *ubuf)
300 struct pt_regs *regs = task_pt_regs(target);
301 u32 uregs[ELF_NGREG] = {};
303 mips_dump_regs32(uregs, regs);
304 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0,
308 static int gpr32_set(struct task_struct *target,
309 const struct user_regset *regset,
310 unsigned int pos, unsigned int count,
311 const void *kbuf, const void __user *ubuf)
313 struct pt_regs *regs = task_pt_regs(target);
314 u32 uregs[ELF_NGREG];
315 unsigned start, num_regs, i;
318 start = pos / sizeof(u32);
319 num_regs = count / sizeof(u32);
321 if (start + num_regs > ELF_NGREG)
324 err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, uregs, 0,
329 for (i = start; i < num_regs; i++) {
331 * Cast all values to signed here so that if this is a 64-bit
332 * kernel, the supplied 32-bit values will be sign extended.
335 case MIPS32_EF_R1 ... MIPS32_EF_R25:
336 /* k0/k1 are ignored. */
337 case MIPS32_EF_R28 ... MIPS32_EF_R31:
338 regs->regs[i - MIPS32_EF_R0] = (s32)uregs[i];
341 regs->lo = (s32)uregs[i];
344 regs->hi = (s32)uregs[i];
346 case MIPS32_EF_CP0_EPC:
347 regs->cp0_epc = (s32)uregs[i];
352 /* System call number may have been changed */
353 mips_syscall_update_nr(target, regs);
358 #endif /* CONFIG_32BIT || CONFIG_MIPS32_O32 */
362 static int gpr64_get(struct task_struct *target,
363 const struct user_regset *regset,
364 unsigned int pos, unsigned int count,
365 void *kbuf, void __user *ubuf)
367 struct pt_regs *regs = task_pt_regs(target);
368 u64 uregs[ELF_NGREG] = {};
370 mips_dump_regs64(uregs, regs);
371 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0,
375 static int gpr64_set(struct task_struct *target,
376 const struct user_regset *regset,
377 unsigned int pos, unsigned int count,
378 const void *kbuf, const void __user *ubuf)
380 struct pt_regs *regs = task_pt_regs(target);
381 u64 uregs[ELF_NGREG];
382 unsigned start, num_regs, i;
385 start = pos / sizeof(u64);
386 num_regs = count / sizeof(u64);
388 if (start + num_regs > ELF_NGREG)
391 err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, uregs, 0,
396 for (i = start; i < num_regs; i++) {
398 case MIPS64_EF_R1 ... MIPS64_EF_R25:
399 /* k0/k1 are ignored. */
400 case MIPS64_EF_R28 ... MIPS64_EF_R31:
401 regs->regs[i - MIPS64_EF_R0] = uregs[i];
409 case MIPS64_EF_CP0_EPC:
410 regs->cp0_epc = uregs[i];
415 /* System call number may have been changed */
416 mips_syscall_update_nr(target, regs);
421 #endif /* CONFIG_64BIT */
424 * Copy the floating-point context to the supplied NT_PRFPREG buffer,
425 * !CONFIG_CPU_HAS_MSA variant. FP context's general register slots
426 * correspond 1:1 to buffer slots. Only general registers are copied.
428 static int fpr_get_fpa(struct task_struct *target,
429 unsigned int *pos, unsigned int *count,
430 void **kbuf, void __user **ubuf)
432 return user_regset_copyout(pos, count, kbuf, ubuf,
434 0, NUM_FPU_REGS * sizeof(elf_fpreg_t));
438 * Copy the floating-point context to the supplied NT_PRFPREG buffer,
439 * CONFIG_CPU_HAS_MSA variant. Only lower 64 bits of FP context's
440 * general register slots are copied to buffer slots. Only general
441 * registers are copied.
443 static int fpr_get_msa(struct task_struct *target,
444 unsigned int *pos, unsigned int *count,
445 void **kbuf, void __user **ubuf)
451 BUILD_BUG_ON(sizeof(fpr_val) != sizeof(elf_fpreg_t));
452 for (i = 0; i < NUM_FPU_REGS; i++) {
453 fpr_val = get_fpr64(&target->thread.fpu.fpr[i], 0);
454 err = user_regset_copyout(pos, count, kbuf, ubuf,
455 &fpr_val, i * sizeof(elf_fpreg_t),
456 (i + 1) * sizeof(elf_fpreg_t));
465 * Copy the floating-point context to the supplied NT_PRFPREG buffer.
466 * Choose the appropriate helper for general registers, and then copy
467 * the FCSR and FIR registers separately.
469 static int fpr_get(struct task_struct *target,
470 const struct user_regset *regset,
471 unsigned int pos, unsigned int count,
472 void *kbuf, void __user *ubuf)
474 const int fcr31_pos = NUM_FPU_REGS * sizeof(elf_fpreg_t);
475 const int fir_pos = fcr31_pos + sizeof(u32);
478 if (sizeof(target->thread.fpu.fpr[0]) == sizeof(elf_fpreg_t))
479 err = fpr_get_fpa(target, &pos, &count, &kbuf, &ubuf);
481 err = fpr_get_msa(target, &pos, &count, &kbuf, &ubuf);
485 err = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
486 &target->thread.fpu.fcr31,
487 fcr31_pos, fcr31_pos + sizeof(u32));
491 err = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
492 &boot_cpu_data.fpu_id,
493 fir_pos, fir_pos + sizeof(u32));
499 * Copy the supplied NT_PRFPREG buffer to the floating-point context,
500 * !CONFIG_CPU_HAS_MSA variant. Buffer slots correspond 1:1 to FP
501 * context's general register slots. Only general registers are copied.
503 static int fpr_set_fpa(struct task_struct *target,
504 unsigned int *pos, unsigned int *count,
505 const void **kbuf, const void __user **ubuf)
507 return user_regset_copyin(pos, count, kbuf, ubuf,
509 0, NUM_FPU_REGS * sizeof(elf_fpreg_t));
513 * Copy the supplied NT_PRFPREG buffer to the floating-point context,
514 * CONFIG_CPU_HAS_MSA variant. Buffer slots are copied to lower 64
515 * bits only of FP context's general register slots. Only general
516 * registers are copied.
518 static int fpr_set_msa(struct task_struct *target,
519 unsigned int *pos, unsigned int *count,
520 const void **kbuf, const void __user **ubuf)
526 BUILD_BUG_ON(sizeof(fpr_val) != sizeof(elf_fpreg_t));
527 for (i = 0; i < NUM_FPU_REGS && *count > 0; i++) {
528 err = user_regset_copyin(pos, count, kbuf, ubuf,
529 &fpr_val, i * sizeof(elf_fpreg_t),
530 (i + 1) * sizeof(elf_fpreg_t));
533 set_fpr64(&target->thread.fpu.fpr[i], 0, fpr_val);
540 * Copy the supplied NT_PRFPREG buffer to the floating-point context.
541 * Choose the appropriate helper for general registers, and then copy
542 * the FCSR register separately. Ignore the incoming FIR register
543 * contents though, as the register is read-only.
545 * We optimize for the case where `count % sizeof(elf_fpreg_t) == 0',
546 * which is supposed to have been guaranteed by the kernel before
547 * calling us, e.g. in `ptrace_regset'. We enforce that requirement,
548 * so that we can safely avoid preinitializing temporaries for
549 * partial register writes.
551 static int fpr_set(struct task_struct *target,
552 const struct user_regset *regset,
553 unsigned int pos, unsigned int count,
554 const void *kbuf, const void __user *ubuf)
556 const int fcr31_pos = NUM_FPU_REGS * sizeof(elf_fpreg_t);
557 const int fir_pos = fcr31_pos + sizeof(u32);
561 BUG_ON(count % sizeof(elf_fpreg_t));
563 if (pos + count > sizeof(elf_fpregset_t))
568 if (sizeof(target->thread.fpu.fpr[0]) == sizeof(elf_fpreg_t))
569 err = fpr_set_fpa(target, &pos, &count, &kbuf, &ubuf);
571 err = fpr_set_msa(target, &pos, &count, &kbuf, &ubuf);
576 err = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
578 fcr31_pos, fcr31_pos + sizeof(u32));
582 ptrace_setfcr31(target, fcr31);
586 err = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
588 fir_pos + sizeof(u32));
593 #if defined(CONFIG_32BIT) || defined(CONFIG_MIPS32_O32)
596 * Copy the DSP context to the supplied 32-bit NT_MIPS_DSP buffer.
598 static int dsp32_get(struct task_struct *target,
599 const struct user_regset *regset,
600 unsigned int pos, unsigned int count,
601 void *kbuf, void __user *ubuf)
603 unsigned int start, num_regs, i;
604 u32 dspregs[NUM_DSP_REGS + 1];
606 BUG_ON(count % sizeof(u32));
611 start = pos / sizeof(u32);
612 num_regs = count / sizeof(u32);
614 if (start + num_regs > NUM_DSP_REGS + 1)
617 for (i = start; i < num_regs; i++)
619 case 0 ... NUM_DSP_REGS - 1:
620 dspregs[i] = target->thread.dsp.dspr[i];
623 dspregs[i] = target->thread.dsp.dspcontrol;
626 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, dspregs, 0,
631 * Copy the supplied 32-bit NT_MIPS_DSP buffer to the DSP context.
633 static int dsp32_set(struct task_struct *target,
634 const struct user_regset *regset,
635 unsigned int pos, unsigned int count,
636 const void *kbuf, const void __user *ubuf)
638 unsigned int start, num_regs, i;
639 u32 dspregs[NUM_DSP_REGS + 1];
642 BUG_ON(count % sizeof(u32));
647 start = pos / sizeof(u32);
648 num_regs = count / sizeof(u32);
650 if (start + num_regs > NUM_DSP_REGS + 1)
653 err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, dspregs, 0,
658 for (i = start; i < num_regs; i++)
660 case 0 ... NUM_DSP_REGS - 1:
661 target->thread.dsp.dspr[i] = (s32)dspregs[i];
664 target->thread.dsp.dspcontrol = (s32)dspregs[i];
671 #endif /* CONFIG_32BIT || CONFIG_MIPS32_O32 */
676 * Copy the DSP context to the supplied 64-bit NT_MIPS_DSP buffer.
678 static int dsp64_get(struct task_struct *target,
679 const struct user_regset *regset,
680 unsigned int pos, unsigned int count,
681 void *kbuf, void __user *ubuf)
683 unsigned int start, num_regs, i;
684 u64 dspregs[NUM_DSP_REGS + 1];
686 BUG_ON(count % sizeof(u64));
691 start = pos / sizeof(u64);
692 num_regs = count / sizeof(u64);
694 if (start + num_regs > NUM_DSP_REGS + 1)
697 for (i = start; i < num_regs; i++)
699 case 0 ... NUM_DSP_REGS - 1:
700 dspregs[i] = target->thread.dsp.dspr[i];
703 dspregs[i] = target->thread.dsp.dspcontrol;
706 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, dspregs, 0,
711 * Copy the supplied 64-bit NT_MIPS_DSP buffer to the DSP context.
713 static int dsp64_set(struct task_struct *target,
714 const struct user_regset *regset,
715 unsigned int pos, unsigned int count,
716 const void *kbuf, const void __user *ubuf)
718 unsigned int start, num_regs, i;
719 u64 dspregs[NUM_DSP_REGS + 1];
722 BUG_ON(count % sizeof(u64));
727 start = pos / sizeof(u64);
728 num_regs = count / sizeof(u64);
730 if (start + num_regs > NUM_DSP_REGS + 1)
733 err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, dspregs, 0,
738 for (i = start; i < num_regs; i++)
740 case 0 ... NUM_DSP_REGS - 1:
741 target->thread.dsp.dspr[i] = dspregs[i];
744 target->thread.dsp.dspcontrol = dspregs[i];
751 #endif /* CONFIG_64BIT */
754 * Determine whether the DSP context is present.
756 static int dsp_active(struct task_struct *target,
757 const struct user_regset *regset)
759 return cpu_has_dsp ? NUM_DSP_REGS + 1 : -ENODEV;
762 /* Copy the FP mode setting to the supplied NT_MIPS_FP_MODE buffer. */
763 static int fp_mode_get(struct task_struct *target,
764 const struct user_regset *regset,
765 unsigned int pos, unsigned int count,
766 void *kbuf, void __user *ubuf)
770 fp_mode = mips_get_process_fp_mode(target);
771 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, &fp_mode, 0,
776 * Copy the supplied NT_MIPS_FP_MODE buffer to the FP mode setting.
778 * We optimize for the case where `count % sizeof(int) == 0', which
779 * is supposed to have been guaranteed by the kernel before calling
780 * us, e.g. in `ptrace_regset'. We enforce that requirement, so
781 * that we can safely avoid preinitializing temporaries for partial
784 static int fp_mode_set(struct task_struct *target,
785 const struct user_regset *regset,
786 unsigned int pos, unsigned int count,
787 const void *kbuf, const void __user *ubuf)
792 BUG_ON(count % sizeof(int));
794 if (pos + count > sizeof(fp_mode))
797 err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &fp_mode, 0,
803 err = mips_set_process_fp_mode(target, fp_mode);
815 struct pt_regs_offset {
820 #define REG_OFFSET_NAME(reg, r) { \
822 .offset = offsetof(struct pt_regs, r) \
825 #define REG_OFFSET_END { \
830 static const struct pt_regs_offset regoffset_table[] = {
831 REG_OFFSET_NAME(r0, regs[0]),
832 REG_OFFSET_NAME(r1, regs[1]),
833 REG_OFFSET_NAME(r2, regs[2]),
834 REG_OFFSET_NAME(r3, regs[3]),
835 REG_OFFSET_NAME(r4, regs[4]),
836 REG_OFFSET_NAME(r5, regs[5]),
837 REG_OFFSET_NAME(r6, regs[6]),
838 REG_OFFSET_NAME(r7, regs[7]),
839 REG_OFFSET_NAME(r8, regs[8]),
840 REG_OFFSET_NAME(r9, regs[9]),
841 REG_OFFSET_NAME(r10, regs[10]),
842 REG_OFFSET_NAME(r11, regs[11]),
843 REG_OFFSET_NAME(r12, regs[12]),
844 REG_OFFSET_NAME(r13, regs[13]),
845 REG_OFFSET_NAME(r14, regs[14]),
846 REG_OFFSET_NAME(r15, regs[15]),
847 REG_OFFSET_NAME(r16, regs[16]),
848 REG_OFFSET_NAME(r17, regs[17]),
849 REG_OFFSET_NAME(r18, regs[18]),
850 REG_OFFSET_NAME(r19, regs[19]),
851 REG_OFFSET_NAME(r20, regs[20]),
852 REG_OFFSET_NAME(r21, regs[21]),
853 REG_OFFSET_NAME(r22, regs[22]),
854 REG_OFFSET_NAME(r23, regs[23]),
855 REG_OFFSET_NAME(r24, regs[24]),
856 REG_OFFSET_NAME(r25, regs[25]),
857 REG_OFFSET_NAME(r26, regs[26]),
858 REG_OFFSET_NAME(r27, regs[27]),
859 REG_OFFSET_NAME(r28, regs[28]),
860 REG_OFFSET_NAME(r29, regs[29]),
861 REG_OFFSET_NAME(r30, regs[30]),
862 REG_OFFSET_NAME(r31, regs[31]),
863 REG_OFFSET_NAME(c0_status, cp0_status),
864 REG_OFFSET_NAME(hi, hi),
865 REG_OFFSET_NAME(lo, lo),
866 #ifdef CONFIG_CPU_HAS_SMARTMIPS
867 REG_OFFSET_NAME(acx, acx),
869 REG_OFFSET_NAME(c0_badvaddr, cp0_badvaddr),
870 REG_OFFSET_NAME(c0_cause, cp0_cause),
871 REG_OFFSET_NAME(c0_epc, cp0_epc),
872 #ifdef CONFIG_CPU_CAVIUM_OCTEON
873 REG_OFFSET_NAME(mpl0, mpl[0]),
874 REG_OFFSET_NAME(mpl1, mpl[1]),
875 REG_OFFSET_NAME(mpl2, mpl[2]),
876 REG_OFFSET_NAME(mtp0, mtp[0]),
877 REG_OFFSET_NAME(mtp1, mtp[1]),
878 REG_OFFSET_NAME(mtp2, mtp[2]),
884 * regs_query_register_offset() - query register offset from its name
885 * @name: the name of a register
887 * regs_query_register_offset() returns the offset of a register in struct
888 * pt_regs from its name. If the name is invalid, this returns -EINVAL;
890 int regs_query_register_offset(const char *name)
892 const struct pt_regs_offset *roff;
893 for (roff = regoffset_table; roff->name != NULL; roff++)
894 if (!strcmp(roff->name, name))
899 #if defined(CONFIG_32BIT) || defined(CONFIG_MIPS32_O32)
901 static const struct user_regset mips_regsets[] = {
903 .core_note_type = NT_PRSTATUS,
905 .size = sizeof(unsigned int),
906 .align = sizeof(unsigned int),
911 .core_note_type = NT_PRFPREG,
913 .size = sizeof(elf_fpreg_t),
914 .align = sizeof(elf_fpreg_t),
919 .core_note_type = NT_MIPS_DSP,
920 .n = NUM_DSP_REGS + 1,
922 .align = sizeof(u32),
925 .active = dsp_active,
928 .core_note_type = NT_MIPS_FP_MODE,
931 .align = sizeof(int),
937 static const struct user_regset_view user_mips_view = {
939 .e_machine = ELF_ARCH,
940 .ei_osabi = ELF_OSABI,
941 .regsets = mips_regsets,
942 .n = ARRAY_SIZE(mips_regsets),
945 #endif /* CONFIG_32BIT || CONFIG_MIPS32_O32 */
949 static const struct user_regset mips64_regsets[] = {
951 .core_note_type = NT_PRSTATUS,
953 .size = sizeof(unsigned long),
954 .align = sizeof(unsigned long),
959 .core_note_type = NT_PRFPREG,
961 .size = sizeof(elf_fpreg_t),
962 .align = sizeof(elf_fpreg_t),
967 .core_note_type = NT_MIPS_DSP,
968 .n = NUM_DSP_REGS + 1,
970 .align = sizeof(u64),
973 .active = dsp_active,
976 .core_note_type = NT_MIPS_FP_MODE,
979 .align = sizeof(int),
985 static const struct user_regset_view user_mips64_view = {
987 .e_machine = ELF_ARCH,
988 .ei_osabi = ELF_OSABI,
989 .regsets = mips64_regsets,
990 .n = ARRAY_SIZE(mips64_regsets),
993 #ifdef CONFIG_MIPS32_N32
995 static const struct user_regset_view user_mipsn32_view = {
997 .e_flags = EF_MIPS_ABI2,
998 .e_machine = ELF_ARCH,
999 .ei_osabi = ELF_OSABI,
1000 .regsets = mips64_regsets,
1001 .n = ARRAY_SIZE(mips64_regsets),
1004 #endif /* CONFIG_MIPS32_N32 */
1006 #endif /* CONFIG_64BIT */
1008 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
1011 return &user_mips_view;
1013 #ifdef CONFIG_MIPS32_O32
1014 if (test_tsk_thread_flag(task, TIF_32BIT_REGS))
1015 return &user_mips_view;
1017 #ifdef CONFIG_MIPS32_N32
1018 if (test_tsk_thread_flag(task, TIF_32BIT_ADDR))
1019 return &user_mipsn32_view;
1021 return &user_mips64_view;
1025 long arch_ptrace(struct task_struct *child, long request,
1026 unsigned long addr, unsigned long data)
1029 void __user *addrp = (void __user *) addr;
1030 void __user *datavp = (void __user *) data;
1031 unsigned long __user *datalp = (void __user *) data;
1034 /* when I and D space are separate, these will need to be fixed. */
1035 case PTRACE_PEEKTEXT: /* read word at location addr. */
1036 case PTRACE_PEEKDATA:
1037 ret = generic_ptrace_peekdata(child, addr, data);
1040 /* Read the word at location addr in the USER area. */
1041 case PTRACE_PEEKUSR: {
1042 struct pt_regs *regs;
1043 union fpureg *fregs;
1044 unsigned long tmp = 0;
1046 regs = task_pt_regs(child);
1047 ret = 0; /* Default return value. */
1051 tmp = regs->regs[addr];
1053 case FPR_BASE ... FPR_BASE + 31:
1054 if (!tsk_used_math(child)) {
1055 /* FP not yet used */
1059 fregs = get_fpu_regs(child);
1062 if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) {
1064 * The odd registers are actually the high
1065 * order bits of the values stored in the even
1068 tmp = get_fpr32(&fregs[(addr & ~1) - FPR_BASE],
1073 tmp = get_fpr64(&fregs[addr - FPR_BASE], 0);
1076 tmp = regs->cp0_epc;
1079 tmp = regs->cp0_cause;
1082 tmp = regs->cp0_badvaddr;
1090 #ifdef CONFIG_CPU_HAS_SMARTMIPS
1096 tmp = child->thread.fpu.fcr31;
1099 /* implementation / version register */
1100 tmp = boot_cpu_data.fpu_id;
1102 case DSP_BASE ... DSP_BASE + 5: {
1110 dregs = __get_dsp_regs(child);
1111 tmp = dregs[addr - DSP_BASE];
1120 tmp = child->thread.dsp.dspcontrol;
1127 ret = put_user(tmp, datalp);
1131 /* when I and D space are separate, this will have to be fixed. */
1132 case PTRACE_POKETEXT: /* write the word at location addr. */
1133 case PTRACE_POKEDATA:
1134 ret = generic_ptrace_pokedata(child, addr, data);
1137 case PTRACE_POKEUSR: {
1138 struct pt_regs *regs;
1140 regs = task_pt_regs(child);
1144 regs->regs[addr] = data;
1145 /* System call number may have been changed */
1147 mips_syscall_update_nr(child, regs);
1148 else if (addr == 4 &&
1149 mips_syscall_is_indirect(child, regs))
1150 mips_syscall_update_nr(child, regs);
1152 case FPR_BASE ... FPR_BASE + 31: {
1153 union fpureg *fregs = get_fpu_regs(child);
1157 if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) {
1159 * The odd registers are actually the high
1160 * order bits of the values stored in the even
1163 set_fpr32(&fregs[(addr & ~1) - FPR_BASE],
1168 set_fpr64(&fregs[addr - FPR_BASE], 0, data);
1172 regs->cp0_epc = data;
1180 #ifdef CONFIG_CPU_HAS_SMARTMIPS
1187 ptrace_setfcr31(child, data);
1189 case DSP_BASE ... DSP_BASE + 5: {
1197 dregs = __get_dsp_regs(child);
1198 dregs[addr - DSP_BASE] = data;
1206 child->thread.dsp.dspcontrol = data;
1209 /* The rest are not allowed. */
1216 case PTRACE_GETREGS:
1217 ret = ptrace_getregs(child, datavp);
1220 case PTRACE_SETREGS:
1221 ret = ptrace_setregs(child, datavp);
1224 case PTRACE_GETFPREGS:
1225 ret = ptrace_getfpregs(child, datavp);
1228 case PTRACE_SETFPREGS:
1229 ret = ptrace_setfpregs(child, datavp);
1232 case PTRACE_GET_THREAD_AREA:
1233 ret = put_user(task_thread_info(child)->tp_value, datalp);
1236 case PTRACE_GET_WATCH_REGS:
1237 ret = ptrace_get_watch_regs(child, addrp);
1240 case PTRACE_SET_WATCH_REGS:
1241 ret = ptrace_set_watch_regs(child, addrp);
1245 ret = ptrace_request(child, request, addr, data);
1253 * Notification of system call entry/exit
1254 * - triggered by current->work.syscall_trace
1256 asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
1260 current_thread_info()->syscall = syscall;
1262 if (test_thread_flag(TIF_SYSCALL_TRACE)) {
1263 if (tracehook_report_syscall_entry(regs))
1265 syscall = current_thread_info()->syscall;
1268 #ifdef CONFIG_SECCOMP
1269 if (unlikely(test_thread_flag(TIF_SECCOMP))) {
1271 struct seccomp_data sd;
1272 unsigned long args[6];
1275 sd.arch = syscall_get_arch();
1276 syscall_get_arguments(current, regs, 0, 6, args);
1277 for (i = 0; i < 6; i++)
1278 sd.args[i] = args[i];
1279 sd.instruction_pointer = KSTK_EIP(current);
1281 ret = __secure_computing(&sd);
1284 syscall = current_thread_info()->syscall;
1288 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1289 trace_sys_enter(regs, regs->regs[2]);
1291 audit_syscall_entry(syscall, regs->regs[4], regs->regs[5],
1292 regs->regs[6], regs->regs[7]);
1295 * Negative syscall numbers are mistaken for rejected syscalls, but
1296 * won't have had the return value set appropriately, so we do so now.
1299 syscall_set_return_value(current, regs, -ENOSYS, 0);
1304 * Notification of system call entry/exit
1305 * - triggered by current->work.syscall_trace
1307 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
1310 * We may come here right after calling schedule_user()
1311 * or do_notify_resume(), in which case we can be in RCU
1316 audit_syscall_exit(regs);
1318 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1319 trace_sys_exit(regs, regs_return_value(regs));
1321 if (test_thread_flag(TIF_SYSCALL_TRACE))
1322 tracehook_report_syscall_exit(regs, 0);