ptrace.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 by Ralf Baechle
  4. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  5. */
  6. #ifndef _ASM_PTRACE_H
  7. #define _ASM_PTRACE_H
  8. #include <linux/compiler.h>
  9. #include <linux/types.h>
  10. #include <asm/isadep.h>
  11. /*
  12. * This struct defines the way the registers are stored on the stack during a
  13. * system call/exception. As usual the registers k0/k1 aren't being saved.
  14. *
  15. * If you add a register here, also add it to regoffset_table[] in
  16. * arch/mips/kernel/ptrace.c.
  17. */
  18. struct pt_regs {
  19. #ifdef CONFIG_32BIT
  20. /* Pad bytes for argument save space on the stack. */
  21. unsigned long pad0[8];
  22. #endif
  23. /* Saved main processor registers. */
  24. unsigned long regs[32];
  25. /* Saved special registers. */
  26. unsigned long cp0_status;
  27. unsigned long hi;
  28. unsigned long lo;
  29. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  30. unsigned long acx;
  31. #endif
  32. unsigned long cp0_badvaddr;
  33. unsigned long cp0_cause;
  34. unsigned long cp0_epc;
  35. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  36. unsigned long long mpl[6]; /* MTM{0-5} */
  37. unsigned long long mtp[6]; /* MTP{0-5} */
  38. #endif
  39. unsigned long __last[0];
  40. } __aligned(8);
  41. static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
  42. {
  43. return regs->regs[31];
  44. }
  45. /*
  46. * Don't use asm-generic/ptrace.h it defines FP accessors that don't make
  47. * sense on MIPS. We rather want an error if they get invoked.
  48. */
  49. static inline void instruction_pointer_set(struct pt_regs *regs,
  50. unsigned long val)
  51. {
  52. regs->cp0_epc = val;
  53. }
  54. /* Query offset/name of register from its name/offset */
  55. extern int regs_query_register_offset(const char *name);
  56. #define MAX_REG_OFFSET (offsetof(struct pt_regs, __last))
  57. /**
  58. * regs_get_register() - get register value from its offset
  59. * @regs: pt_regs from which register value is gotten.
  60. * @offset: offset number of the register.
  61. *
  62. * regs_get_register returns the value of a register. The @offset is the
  63. * offset of the register in struct pt_regs address which specified by @regs.
  64. * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
  65. */
  66. static inline unsigned long regs_get_register(struct pt_regs *regs,
  67. unsigned int offset)
  68. {
  69. if (unlikely(offset > MAX_REG_OFFSET))
  70. return 0;
  71. return *(unsigned long *)((unsigned long)regs + offset);
  72. }
  73. /*
  74. * Does the process account for user or for system time?
  75. */
  76. #define user_mode(regs) (((regs)->cp0_status & KU_MASK) == KU_USER)
  77. #define instruction_pointer(regs) ((regs)->cp0_epc)
  78. #define profile_pc(regs) instruction_pointer(regs)
  79. /* Helpers for working with the user stack pointer */
  80. static inline unsigned long user_stack_pointer(struct pt_regs *regs)
  81. {
  82. return regs->regs[29];
  83. }
  84. static inline void user_stack_pointer_set(struct pt_regs *regs,
  85. unsigned long val)
  86. {
  87. regs->regs[29] = val;
  88. }
  89. #endif /* _ASM_PTRACE_H */