ptrace-common.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (c) 2002 Stephen Rothwell, IBM Coproration
  3. * Copyright (c) 2007 Benjamin Herrenschmidt, IBM Coproration
  4. * Extracted from ptrace.c and ptrace32.c
  5. *
  6. * This file is subject to the terms and conditions of the GNU General
  7. * Public License. See the file README.legal in the main directory of
  8. * this archive for more details.
  9. */
  10. #ifndef _POWERPC_PTRACE_COMMON_H
  11. #define _POWERPC_PTRACE_COMMON_H
  12. /*
  13. * Get contents of register REGNO in task TASK.
  14. */
  15. static inline unsigned long get_reg(struct task_struct *task, int regno)
  16. {
  17. unsigned long tmp = 0;
  18. if (task->thread.regs == NULL)
  19. return -EIO;
  20. if (regno == PT_MSR) {
  21. tmp = ((unsigned long *)task->thread.regs)[PT_MSR];
  22. return PT_MUNGE_MSR(tmp, task);
  23. }
  24. if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long)))
  25. return ((unsigned long *)task->thread.regs)[regno];
  26. return -EIO;
  27. }
  28. /*
  29. * Write contents of register REGNO in task TASK.
  30. */
  31. static inline int put_reg(struct task_struct *task, int regno,
  32. unsigned long data)
  33. {
  34. if (task->thread.regs == NULL)
  35. return -EIO;
  36. if (regno <= PT_MAX_PUT_REG) {
  37. if (regno == PT_MSR)
  38. data = (data & MSR_DEBUGCHANGE)
  39. | (task->thread.regs->msr & ~MSR_DEBUGCHANGE);
  40. ((unsigned long *)task->thread.regs)[regno] = data;
  41. return 0;
  42. }
  43. return -EIO;
  44. }
  45. #ifdef CONFIG_ALTIVEC
  46. /*
  47. * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
  48. * The transfer totals 34 quadword. Quadwords 0-31 contain the
  49. * corresponding vector registers. Quadword 32 contains the vscr as the
  50. * last word (offset 12) within that quadword. Quadword 33 contains the
  51. * vrsave as the first word (offset 0) within the quadword.
  52. *
  53. * This definition of the VMX state is compatible with the current PPC32
  54. * ptrace interface. This allows signal handling and ptrace to use the
  55. * same structures. This also simplifies the implementation of a bi-arch
  56. * (combined (32- and 64-bit) gdb.
  57. */
  58. /*
  59. * Get contents of AltiVec register state in task TASK
  60. */
  61. static inline int get_vrregs(unsigned long __user *data,
  62. struct task_struct *task)
  63. {
  64. unsigned long regsize;
  65. /* copy AltiVec registers VR[0] .. VR[31] */
  66. regsize = 32 * sizeof(vector128);
  67. if (copy_to_user(data, task->thread.vr, regsize))
  68. return -EFAULT;
  69. data += (regsize / sizeof(unsigned long));
  70. /* copy VSCR */
  71. regsize = 1 * sizeof(vector128);
  72. if (copy_to_user(data, &task->thread.vscr, regsize))
  73. return -EFAULT;
  74. data += (regsize / sizeof(unsigned long));
  75. /* copy VRSAVE */
  76. if (put_user(task->thread.vrsave, (u32 __user *)data))
  77. return -EFAULT;
  78. return 0;
  79. }
  80. /*
  81. * Write contents of AltiVec register state into task TASK.
  82. */
  83. static inline int set_vrregs(struct task_struct *task,
  84. unsigned long __user *data)
  85. {
  86. unsigned long regsize;
  87. /* copy AltiVec registers VR[0] .. VR[31] */
  88. regsize = 32 * sizeof(vector128);
  89. if (copy_from_user(task->thread.vr, data, regsize))
  90. return -EFAULT;
  91. data += (regsize / sizeof(unsigned long));
  92. /* copy VSCR */
  93. regsize = 1 * sizeof(vector128);
  94. if (copy_from_user(&task->thread.vscr, data, regsize))
  95. return -EFAULT;
  96. data += (regsize / sizeof(unsigned long));
  97. /* copy VRSAVE */
  98. if (get_user(task->thread.vrsave, (u32 __user *)data))
  99. return -EFAULT;
  100. return 0;
  101. }
  102. #endif /* CONFIG_ALTIVEC */
  103. static inline void set_single_step(struct task_struct *task)
  104. {
  105. struct pt_regs *regs = task->thread.regs;
  106. if (regs != NULL) {
  107. #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
  108. task->thread.dbcr0 = DBCR0_IDM | DBCR0_IC;
  109. regs->msr |= MSR_DE;
  110. #else
  111. regs->msr |= MSR_SE;
  112. #endif
  113. }
  114. set_tsk_thread_flag(task, TIF_SINGLESTEP);
  115. }
  116. static inline void clear_single_step(struct task_struct *task)
  117. {
  118. struct pt_regs *regs = task->thread.regs;
  119. if (regs != NULL) {
  120. #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
  121. task->thread.dbcr0 = 0;
  122. regs->msr &= ~MSR_DE;
  123. #else
  124. regs->msr &= ~MSR_SE;
  125. #endif
  126. }
  127. clear_tsk_thread_flag(task, TIF_SINGLESTEP);
  128. }
  129. #endif /* _POWERPC_PTRACE_COMMON_H */