ptrace-common.h 4.1 KB

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