perf_regs.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * This file is subject to the terms and conditions of the GNU General Public
  4. * License. See the file "COPYING" in the main directory of this archive
  5. * for more details.
  6. *
  7. * Some parts derived from x86 version of this file.
  8. *
  9. * Copyright (C) 2013 Cavium, Inc.
  10. */
  11. #include <linux/perf_event.h>
  12. #include <asm/ptrace.h>
  13. #ifdef CONFIG_32BIT
  14. u64 perf_reg_abi(struct task_struct *tsk)
  15. {
  16. return PERF_SAMPLE_REGS_ABI_32;
  17. }
  18. #else /* Must be CONFIG_64BIT */
  19. u64 perf_reg_abi(struct task_struct *tsk)
  20. {
  21. if (test_tsk_thread_flag(tsk, TIF_32BIT_REGS))
  22. return PERF_SAMPLE_REGS_ABI_32;
  23. else
  24. return PERF_SAMPLE_REGS_ABI_64;
  25. }
  26. #endif /* CONFIG_32BIT */
  27. int perf_reg_validate(u64 mask)
  28. {
  29. if (!mask)
  30. return -EINVAL;
  31. if (mask & ~((1ull << PERF_REG_MIPS_MAX) - 1))
  32. return -EINVAL;
  33. return 0;
  34. }
  35. u64 perf_reg_value(struct pt_regs *regs, int idx)
  36. {
  37. long v;
  38. switch (idx) {
  39. case PERF_REG_MIPS_PC:
  40. v = regs->cp0_epc;
  41. break;
  42. case PERF_REG_MIPS_R1 ... PERF_REG_MIPS_R25:
  43. v = regs->regs[idx - PERF_REG_MIPS_R1 + 1];
  44. break;
  45. case PERF_REG_MIPS_R28 ... PERF_REG_MIPS_R31:
  46. v = regs->regs[idx - PERF_REG_MIPS_R28 + 28];
  47. break;
  48. default:
  49. WARN_ON_ONCE(1);
  50. return 0;
  51. }
  52. return (s64)v; /* Sign extend if 32-bit. */
  53. }
  54. void perf_get_regs_user(struct perf_regs *regs_user,
  55. struct pt_regs *regs)
  56. {
  57. regs_user->regs = task_pt_regs(current);
  58. regs_user->abi = perf_reg_abi(current);
  59. }