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;
768 struct pt_regs_offset {
773 #define REG_OFFSET_NAME(reg, r) { \
775 .offset = offsetof(struct pt_regs, r) \
778 #define REG_OFFSET_END { \
783 static const struct pt_regs_offset regoffset_table[] = {
784 REG_OFFSET_NAME(r0, regs[0]),
785 REG_OFFSET_NAME(r1, regs[1]),
786 REG_OFFSET_NAME(r2, regs[2]),
787 REG_OFFSET_NAME(r3, regs[3]),
788 REG_OFFSET_NAME(r4, regs[4]),
789 REG_OFFSET_NAME(r5, regs[5]),
790 REG_OFFSET_NAME(r6, regs[6]),
791 REG_OFFSET_NAME(r7, regs[7]),
792 REG_OFFSET_NAME(r8, regs[8]),
793 REG_OFFSET_NAME(r9, regs[9]),
794 REG_OFFSET_NAME(r10, regs[10]),
795 REG_OFFSET_NAME(r11, regs[11]),
796 REG_OFFSET_NAME(r12, regs[12]),
797 REG_OFFSET_NAME(r13, regs[13]),
798 REG_OFFSET_NAME(r14, regs[14]),
799 REG_OFFSET_NAME(r15, regs[15]),
800 REG_OFFSET_NAME(r16, regs[16]),
801 REG_OFFSET_NAME(r17, regs[17]),
802 REG_OFFSET_NAME(r18, regs[18]),
803 REG_OFFSET_NAME(r19, regs[19]),
804 REG_OFFSET_NAME(r20, regs[20]),
805 REG_OFFSET_NAME(r21, regs[21]),
806 REG_OFFSET_NAME(r22, regs[22]),
807 REG_OFFSET_NAME(r23, regs[23]),
808 REG_OFFSET_NAME(r24, regs[24]),
809 REG_OFFSET_NAME(r25, regs[25]),
810 REG_OFFSET_NAME(r26, regs[26]),
811 REG_OFFSET_NAME(r27, regs[27]),
812 REG_OFFSET_NAME(r28, regs[28]),
813 REG_OFFSET_NAME(r29, regs[29]),
814 REG_OFFSET_NAME(r30, regs[30]),
815 REG_OFFSET_NAME(r31, regs[31]),
816 REG_OFFSET_NAME(c0_status, cp0_status),
817 REG_OFFSET_NAME(hi, hi),
818 REG_OFFSET_NAME(lo, lo),
819 #ifdef CONFIG_CPU_HAS_SMARTMIPS
820 REG_OFFSET_NAME(acx, acx),
822 REG_OFFSET_NAME(c0_badvaddr, cp0_badvaddr),
823 REG_OFFSET_NAME(c0_cause, cp0_cause),
824 REG_OFFSET_NAME(c0_epc, cp0_epc),
825 #ifdef CONFIG_CPU_CAVIUM_OCTEON
826 REG_OFFSET_NAME(mpl0, mpl[0]),
827 REG_OFFSET_NAME(mpl1, mpl[1]),
828 REG_OFFSET_NAME(mpl2, mpl[2]),
829 REG_OFFSET_NAME(mtp0, mtp[0]),
830 REG_OFFSET_NAME(mtp1, mtp[1]),
831 REG_OFFSET_NAME(mtp2, mtp[2]),
837 * regs_query_register_offset() - query register offset from its name
838 * @name: the name of a register
840 * regs_query_register_offset() returns the offset of a register in struct
841 * pt_regs from its name. If the name is invalid, this returns -EINVAL;
843 int regs_query_register_offset(const char *name)
845 const struct pt_regs_offset *roff;
846 for (roff = regoffset_table; roff->name != NULL; roff++)
847 if (!strcmp(roff->name, name))
852 #if defined(CONFIG_32BIT) || defined(CONFIG_MIPS32_O32)
854 static const struct user_regset mips_regsets[] = {
856 .core_note_type = NT_PRSTATUS,
858 .size = sizeof(unsigned int),
859 .align = sizeof(unsigned int),
864 .core_note_type = NT_PRFPREG,
866 .size = sizeof(elf_fpreg_t),
867 .align = sizeof(elf_fpreg_t),
872 .core_note_type = NT_MIPS_DSP,
873 .n = NUM_DSP_REGS + 1,
875 .align = sizeof(u32),
878 .active = dsp_active,
882 static const struct user_regset_view user_mips_view = {
884 .e_machine = ELF_ARCH,
885 .ei_osabi = ELF_OSABI,
886 .regsets = mips_regsets,
887 .n = ARRAY_SIZE(mips_regsets),
890 #endif /* CONFIG_32BIT || CONFIG_MIPS32_O32 */
894 static const struct user_regset mips64_regsets[] = {
896 .core_note_type = NT_PRSTATUS,
898 .size = sizeof(unsigned long),
899 .align = sizeof(unsigned long),
904 .core_note_type = NT_PRFPREG,
906 .size = sizeof(elf_fpreg_t),
907 .align = sizeof(elf_fpreg_t),
912 .core_note_type = NT_MIPS_DSP,
913 .n = NUM_DSP_REGS + 1,
915 .align = sizeof(u64),
918 .active = dsp_active,
922 static const struct user_regset_view user_mips64_view = {
924 .e_machine = ELF_ARCH,
925 .ei_osabi = ELF_OSABI,
926 .regsets = mips64_regsets,
927 .n = ARRAY_SIZE(mips64_regsets),
930 #ifdef CONFIG_MIPS32_N32
932 static const struct user_regset_view user_mipsn32_view = {
934 .e_flags = EF_MIPS_ABI2,
935 .e_machine = ELF_ARCH,
936 .ei_osabi = ELF_OSABI,
937 .regsets = mips64_regsets,
938 .n = ARRAY_SIZE(mips64_regsets),
941 #endif /* CONFIG_MIPS32_N32 */
943 #endif /* CONFIG_64BIT */
945 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
948 return &user_mips_view;
950 #ifdef CONFIG_MIPS32_O32
951 if (test_tsk_thread_flag(task, TIF_32BIT_REGS))
952 return &user_mips_view;
954 #ifdef CONFIG_MIPS32_N32
955 if (test_tsk_thread_flag(task, TIF_32BIT_ADDR))
956 return &user_mipsn32_view;
958 return &user_mips64_view;
962 long arch_ptrace(struct task_struct *child, long request,
963 unsigned long addr, unsigned long data)
966 void __user *addrp = (void __user *) addr;
967 void __user *datavp = (void __user *) data;
968 unsigned long __user *datalp = (void __user *) data;
971 /* when I and D space are separate, these will need to be fixed. */
972 case PTRACE_PEEKTEXT: /* read word at location addr. */
973 case PTRACE_PEEKDATA:
974 ret = generic_ptrace_peekdata(child, addr, data);
977 /* Read the word at location addr in the USER area. */
978 case PTRACE_PEEKUSR: {
979 struct pt_regs *regs;
981 unsigned long tmp = 0;
983 regs = task_pt_regs(child);
984 ret = 0; /* Default return value. */
988 tmp = regs->regs[addr];
990 case FPR_BASE ... FPR_BASE + 31:
991 if (!tsk_used_math(child)) {
992 /* FP not yet used */
996 fregs = get_fpu_regs(child);
999 if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) {
1001 * The odd registers are actually the high
1002 * order bits of the values stored in the even
1005 tmp = get_fpr32(&fregs[(addr & ~1) - FPR_BASE],
1010 tmp = get_fpr64(&fregs[addr - FPR_BASE], 0);
1013 tmp = regs->cp0_epc;
1016 tmp = regs->cp0_cause;
1019 tmp = regs->cp0_badvaddr;
1027 #ifdef CONFIG_CPU_HAS_SMARTMIPS
1033 tmp = child->thread.fpu.fcr31;
1036 /* implementation / version register */
1037 tmp = boot_cpu_data.fpu_id;
1039 case DSP_BASE ... DSP_BASE + 5: {
1047 dregs = __get_dsp_regs(child);
1048 tmp = dregs[addr - DSP_BASE];
1057 tmp = child->thread.dsp.dspcontrol;
1064 ret = put_user(tmp, datalp);
1068 /* when I and D space are separate, this will have to be fixed. */
1069 case PTRACE_POKETEXT: /* write the word at location addr. */
1070 case PTRACE_POKEDATA:
1071 ret = generic_ptrace_pokedata(child, addr, data);
1074 case PTRACE_POKEUSR: {
1075 struct pt_regs *regs;
1077 regs = task_pt_regs(child);
1081 regs->regs[addr] = data;
1082 /* System call number may have been changed */
1084 mips_syscall_update_nr(child, regs);
1085 else if (addr == 4 &&
1086 mips_syscall_is_indirect(child, regs))
1087 mips_syscall_update_nr(child, regs);
1089 case FPR_BASE ... FPR_BASE + 31: {
1090 union fpureg *fregs = get_fpu_regs(child);
1094 if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) {
1096 * The odd registers are actually the high
1097 * order bits of the values stored in the even
1100 set_fpr32(&fregs[(addr & ~1) - FPR_BASE],
1105 set_fpr64(&fregs[addr - FPR_BASE], 0, data);
1109 regs->cp0_epc = data;
1117 #ifdef CONFIG_CPU_HAS_SMARTMIPS
1124 ptrace_setfcr31(child, data);
1126 case DSP_BASE ... DSP_BASE + 5: {
1134 dregs = __get_dsp_regs(child);
1135 dregs[addr - DSP_BASE] = data;
1143 child->thread.dsp.dspcontrol = data;
1146 /* The rest are not allowed. */
1153 case PTRACE_GETREGS:
1154 ret = ptrace_getregs(child, datavp);
1157 case PTRACE_SETREGS:
1158 ret = ptrace_setregs(child, datavp);
1161 case PTRACE_GETFPREGS:
1162 ret = ptrace_getfpregs(child, datavp);
1165 case PTRACE_SETFPREGS:
1166 ret = ptrace_setfpregs(child, datavp);
1169 case PTRACE_GET_THREAD_AREA:
1170 ret = put_user(task_thread_info(child)->tp_value, datalp);
1173 case PTRACE_GET_WATCH_REGS:
1174 ret = ptrace_get_watch_regs(child, addrp);
1177 case PTRACE_SET_WATCH_REGS:
1178 ret = ptrace_set_watch_regs(child, addrp);
1182 ret = ptrace_request(child, request, addr, data);
1190 * Notification of system call entry/exit
1191 * - triggered by current->work.syscall_trace
1193 asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
1197 current_thread_info()->syscall = syscall;
1199 if (test_thread_flag(TIF_SYSCALL_TRACE)) {
1200 if (tracehook_report_syscall_entry(regs))
1202 syscall = current_thread_info()->syscall;
1205 #ifdef CONFIG_SECCOMP
1206 if (unlikely(test_thread_flag(TIF_SECCOMP))) {
1208 struct seccomp_data sd;
1209 unsigned long args[6];
1212 sd.arch = syscall_get_arch();
1213 syscall_get_arguments(current, regs, 0, 6, args);
1214 for (i = 0; i < 6; i++)
1215 sd.args[i] = args[i];
1216 sd.instruction_pointer = KSTK_EIP(current);
1218 ret = __secure_computing(&sd);
1221 syscall = current_thread_info()->syscall;
1225 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1226 trace_sys_enter(regs, regs->regs[2]);
1228 audit_syscall_entry(syscall, regs->regs[4], regs->regs[5],
1229 regs->regs[6], regs->regs[7]);
1232 * Negative syscall numbers are mistaken for rejected syscalls, but
1233 * won't have had the return value set appropriately, so we do so now.
1236 syscall_set_return_value(current, regs, -ENOSYS, 0);
1241 * Notification of system call entry/exit
1242 * - triggered by current->work.syscall_trace
1244 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
1247 * We may come here right after calling schedule_user()
1248 * or do_notify_resume(), in which case we can be in RCU
1253 audit_syscall_exit(regs);
1255 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1256 trace_sys_exit(regs, regs_return_value(regs));
1258 if (test_thread_flag(TIF_SYSCALL_TRACE))
1259 tracehook_report_syscall_exit(regs, 0);