ptrace-common.h 4.1 KB

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