ptrace.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Ptrace support for Hexagon
  3. *
  4. * Copyright (c) 2010-2011, The Linux Foundation. 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 <linux/elf.h>
  30. #include <asm/user.h>
  31. static int genregs_get(struct task_struct *target,
  32. const struct user_regset *regset,
  33. unsigned int pos, unsigned int count,
  34. void *kbuf, void __user *ubuf)
  35. {
  36. int ret;
  37. unsigned int dummy;
  38. struct pt_regs *regs = task_pt_regs(target);
  39. if (!regs)
  40. return -EIO;
  41. /* The general idea here is that the copyout must happen in
  42. * exactly the same order in which the userspace expects these
  43. * regs. Now, the sequence in userspace does not match the
  44. * sequence in the kernel, so everything past the 32 gprs
  45. * happens one at a time.
  46. */
  47. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  48. &regs->r00, 0, 32*sizeof(unsigned long));
  49. #define ONEXT(KPT_REG, USR_REG) \
  50. if (!ret) \
  51. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, \
  52. KPT_REG, offsetof(struct user_regs_struct, USR_REG), \
  53. offsetof(struct user_regs_struct, USR_REG) + \
  54. sizeof(unsigned long));
  55. /* Must be exactly same sequence as struct user_regs_struct */
  56. ONEXT(&regs->sa0, sa0);
  57. ONEXT(&regs->lc0, lc0);
  58. ONEXT(&regs->sa1, sa1);
  59. ONEXT(&regs->lc1, lc1);
  60. ONEXT(&regs->m0, m0);
  61. ONEXT(&regs->m1, m1);
  62. ONEXT(&regs->usr, usr);
  63. ONEXT(&regs->preds, p3_0);
  64. ONEXT(&regs->gp, gp);
  65. ONEXT(&regs->ugp, ugp);
  66. ONEXT(&pt_elr(regs), pc);
  67. dummy = pt_cause(regs);
  68. ONEXT(&dummy, cause);
  69. ONEXT(&pt_badva(regs), badva);
  70. /* Pad the rest with zeros, if needed */
  71. if (!ret)
  72. ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  73. offsetof(struct user_regs_struct, pad1), -1);
  74. return ret;
  75. }
  76. static int genregs_set(struct task_struct *target,
  77. const struct user_regset *regset,
  78. unsigned int pos, unsigned int count,
  79. const void *kbuf, const void __user *ubuf)
  80. {
  81. int ret;
  82. unsigned long bucket;
  83. struct pt_regs *regs = task_pt_regs(target);
  84. if (!regs)
  85. return -EIO;
  86. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  87. &regs->r00, 0, 32*sizeof(unsigned long));
  88. #define INEXT(KPT_REG, USR_REG) \
  89. if (!ret) \
  90. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
  91. KPT_REG, offsetof(struct user_regs_struct, USR_REG), \
  92. offsetof(struct user_regs_struct, USR_REG) + \
  93. sizeof(unsigned long));
  94. /* Must be exactly same sequence as struct user_regs_struct */
  95. INEXT(&regs->sa0, sa0);
  96. INEXT(&regs->lc0, lc0);
  97. INEXT(&regs->sa1, sa1);
  98. INEXT(&regs->lc1, lc1);
  99. INEXT(&regs->m0, m0);
  100. INEXT(&regs->m1, m1);
  101. INEXT(&regs->usr, usr);
  102. INEXT(&regs->preds, p3_0);
  103. INEXT(&regs->gp, gp);
  104. INEXT(&regs->ugp, ugp);
  105. INEXT(&pt_elr(regs), pc);
  106. /* CAUSE and BADVA aren't writeable. */
  107. INEXT(&bucket, cause);
  108. INEXT(&bucket, badva);
  109. /* Ignore the rest, if needed */
  110. if (!ret)
  111. ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  112. offsetof(struct user_regs_struct, pad1), -1);
  113. if (ret)
  114. return ret;
  115. /*
  116. * This is special; SP is actually restored by the VM via the
  117. * special event record which is set by the special trap.
  118. */
  119. regs->hvmer.vmpsp = regs->r29;
  120. return 0;
  121. }
  122. enum hexagon_regset {
  123. REGSET_GENERAL,
  124. };
  125. static const struct user_regset hexagon_regsets[] = {
  126. [REGSET_GENERAL] = {
  127. .core_note_type = NT_PRSTATUS,
  128. .n = ELF_NGREG,
  129. .size = sizeof(unsigned long),
  130. .align = sizeof(unsigned long),
  131. .get = genregs_get,
  132. .set = genregs_set,
  133. },
  134. };
  135. static const struct user_regset_view hexagon_user_view = {
  136. .name = UTS_MACHINE,
  137. .e_machine = ELF_ARCH,
  138. .ei_osabi = ELF_OSABI,
  139. .regsets = hexagon_regsets,
  140. .n = ARRAY_SIZE(hexagon_regsets)
  141. };
  142. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  143. {
  144. return &hexagon_user_view;
  145. }
  146. void ptrace_disable(struct task_struct *child)
  147. {
  148. /* Boilerplate - resolves to null inline if no HW single-step */
  149. user_disable_single_step(child);
  150. }
  151. long arch_ptrace(struct task_struct *child, long request,
  152. unsigned long addr, unsigned long data)
  153. {
  154. return ptrace_request(child, request, addr, data);
  155. }