ptrace.h 2.8 KB

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