ptrace-common.h 4.2 KB

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