ptrace-fpu.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. #include <linux/regset.h>
  3. #include <asm/switch_to.h>
  4. #include "ptrace-decl.h"
  5. int ptrace_get_fpr(struct task_struct *child, int index, unsigned long *data)
  6. {
  7. #ifdef CONFIG_PPC_FPU_REGS
  8. unsigned int fpidx = index - PT_FPR0;
  9. #endif
  10. if (index > PT_FPSCR)
  11. return -EIO;
  12. #ifdef CONFIG_PPC_FPU_REGS
  13. flush_fp_to_thread(child);
  14. if (fpidx < (PT_FPSCR - PT_FPR0)) {
  15. if (IS_ENABLED(CONFIG_PPC32))
  16. // On 32-bit the index we are passed refers to 32-bit words
  17. *data = ((u32 *)child->thread.fp_state.fpr)[fpidx];
  18. else
  19. memcpy(data, &child->thread.TS_FPR(fpidx), sizeof(long));
  20. } else
  21. *data = child->thread.fp_state.fpscr;
  22. #else
  23. *data = 0;
  24. #endif
  25. return 0;
  26. }
  27. int ptrace_put_fpr(struct task_struct *child, int index, unsigned long data)
  28. {
  29. #ifdef CONFIG_PPC_FPU_REGS
  30. unsigned int fpidx = index - PT_FPR0;
  31. #endif
  32. if (index > PT_FPSCR)
  33. return -EIO;
  34. #ifdef CONFIG_PPC_FPU_REGS
  35. flush_fp_to_thread(child);
  36. if (fpidx < (PT_FPSCR - PT_FPR0)) {
  37. if (IS_ENABLED(CONFIG_PPC32))
  38. // On 32-bit the index we are passed refers to 32-bit words
  39. ((u32 *)child->thread.fp_state.fpr)[fpidx] = data;
  40. else
  41. memcpy(&child->thread.TS_FPR(fpidx), &data, sizeof(long));
  42. } else
  43. child->thread.fp_state.fpscr = data;
  44. #endif
  45. return 0;
  46. }