ptrace.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Ptrace support for Hexagon
  3. *
  4. * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. */
  20. #include <generated/compile.h>
  21. #include <linux/kernel.h>
  22. #include <linux/sched.h>
  23. #include <linux/mm.h>
  24. #include <linux/smp.h>
  25. #include <linux/errno.h>
  26. #include <linux/ptrace.h>
  27. #include <linux/regset.h>
  28. #include <linux/user.h>
  29. #include <asm/user.h>
  30. static int genregs_get(struct task_struct *target,
  31. const struct user_regset *regset,
  32. unsigned int pos, unsigned int count,
  33. void *kbuf, void __user *ubuf)
  34. {
  35. int ret;
  36. unsigned int dummy;
  37. struct pt_regs *regs = task_pt_regs(target);
  38. if (!regs)
  39. return -EIO;
  40. /* The general idea here is that the copyout must happen in
  41. * exactly the same order in which the userspace expects these
  42. * regs. Now, the sequence in userspace does not match the
  43. * sequence in the kernel, so everything past the 32 gprs
  44. * happens one at a time.
  45. */
  46. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  47. &regs->r00, 0, 32*sizeof(unsigned long));
  48. #define ONEXT(KPT_REG, USR_REG) \
  49. if (!ret) \
  50. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, \
  51. KPT_REG, offsetof(struct user_regs_struct, USR_REG), \
  52. offsetof(struct user_regs_struct, USR_REG) + \
  53. sizeof(unsigned long));
  54. /* Must be exactly same sequence as struct user_regs_struct */
  55. ONEXT(&regs->sa0, sa0);
  56. ONEXT(&regs->lc0, lc0);
  57. ONEXT(&regs->sa1, sa1);
  58. ONEXT(&regs->lc1, lc1);
  59. ONEXT(&regs->m0, m0);
  60. ONEXT(&regs->m1, m1);
  61. ONEXT(&regs->usr, usr);
  62. ONEXT(&regs->preds, p3_0);
  63. ONEXT(&regs->gp, gp);
  64. ONEXT(&regs->ugp, ugp);
  65. ONEXT(&pt_elr(regs), pc);
  66. dummy = pt_cause(regs);
  67. ONEXT(&dummy, cause);
  68. ONEXT(&pt_badva(regs), badva);
  69. /* Pad the rest with zeros, if needed */
  70. if (!ret)
  71. ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  72. offsetof(struct user_regs_struct, pad1), -1);
  73. return ret;
  74. }
  75. static int genregs_set(struct task_struct *target,
  76. const struct user_regset *regset,
  77. unsigned int pos, unsigned int count,
  78. const void *kbuf, const void __user *ubuf)
  79. {
  80. int ret;
  81. unsigned long bucket;
  82. struct pt_regs *regs = task_pt_regs(target);
  83. if (!regs)
  84. return -EIO;
  85. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  86. &regs->r00, 0, 32*sizeof(unsigned long));
  87. #define INEXT(KPT_REG, USR_REG) \
  88. if (!ret) \
  89. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
  90. KPT_REG, offsetof(struct user_regs_struct, USR_REG), \
  91. offsetof(struct user_regs_struct, USR_REG) + \
  92. sizeof(unsigned long));
  93. /* Must be exactly same sequence as struct user_regs_struct */
  94. INEXT(&regs->sa0, sa0);
  95. INEXT(&regs->lc0, lc0);
  96. INEXT(&regs->sa1, sa1);
  97. INEXT(&regs->lc1, lc1);
  98. INEXT(&regs->m0, m0);
  99. INEXT(&regs->m1, m1);
  100. INEXT(&regs->usr, usr);
  101. INEXT(&regs->preds, p3_0);
  102. INEXT(&regs->gp, gp);
  103. INEXT(&regs->ugp, ugp);
  104. INEXT(&pt_elr(regs), pc);
  105. /* CAUSE and BADVA aren't writeable. */
  106. INEXT(&bucket, cause);
  107. INEXT(&bucket, badva);
  108. /* Ignore the rest, if needed */
  109. if (!ret)
  110. ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  111. offsetof(struct user_regs_struct, pad1), -1);
  112. if (ret)
  113. return ret;
  114. /*
  115. * This is special; SP is actually restored by the VM via the
  116. * special event record which is set by the special trap.
  117. */
  118. regs->hvmer.vmpsp = regs->r29;
  119. return 0;
  120. }
  121. enum hexagon_regset {
  122. REGSET_GENERAL,
  123. };
  124. static const struct user_regset hexagon_regsets[] = {
  125. [REGSET_GENERAL] = {
  126. .core_note_type = NT_PRSTATUS,
  127. .n = ELF_NGREG,
  128. .size = sizeof(unsigned long),
  129. .align = sizeof(unsigned long),
  130. .get = genregs_get,
  131. .set = genregs_set,
  132. },
  133. };
  134. static const struct user_regset_view hexagon_user_view = {
  135. .name = UTS_MACHINE,
  136. .e_machine = ELF_ARCH,
  137. .ei_osabi = ELF_OSABI,
  138. .regsets = hexagon_regsets,
  139. .n = ARRAY_SIZE(hexagon_regsets)
  140. };
  141. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  142. {
  143. return &hexagon_user_view;
  144. }
  145. void ptrace_disable(struct task_struct *child)
  146. {
  147. /* Boilerplate - resolves to null inline if no HW single-step */
  148. user_disable_single_step(child);
  149. }
  150. long arch_ptrace(struct task_struct *child, long request,
  151. unsigned long addr, unsigned long data)
  152. {
  153. return ptrace_request(child, request, addr, data);
  154. }