ptrace.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Port on Texas Instruments TMS320C6x architecture
  3. *
  4. * Copyright (C) 2004, 2006, 2009, 2010, 2011 Texas Instruments Incorporated
  5. * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
  6. *
  7. * Updated for 2.6.34: Mark Salter <msalter@redhat.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/ptrace.h>
  14. #include <linux/tracehook.h>
  15. #include <linux/regset.h>
  16. #include <linux/elf.h>
  17. #include <asm/cacheflush.h>
  18. #define PT_REG_SIZE (sizeof(struct pt_regs))
  19. /*
  20. * Called by kernel/ptrace.c when detaching.
  21. */
  22. void ptrace_disable(struct task_struct *child)
  23. {
  24. /* nothing to do */
  25. }
  26. /*
  27. * Get a register number from live pt_regs for the specified task.
  28. */
  29. static inline long get_reg(struct task_struct *task, int regno)
  30. {
  31. long *addr = (long *)task_pt_regs(task);
  32. if (regno == PT_TSR || regno == PT_CSR)
  33. return 0;
  34. return addr[regno];
  35. }
  36. /*
  37. * Write contents of register REGNO in task TASK.
  38. */
  39. static inline int put_reg(struct task_struct *task,
  40. int regno,
  41. unsigned long data)
  42. {
  43. unsigned long *addr = (unsigned long *)task_pt_regs(task);
  44. if (regno != PT_TSR && regno != PT_CSR)
  45. addr[regno] = data;
  46. return 0;
  47. }
  48. /* regset get/set implementations */
  49. static int gpr_get(struct task_struct *target,
  50. const struct user_regset *regset,
  51. unsigned int pos, unsigned int count,
  52. void *kbuf, void __user *ubuf)
  53. {
  54. struct pt_regs *regs = task_pt_regs(target);
  55. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  56. regs,
  57. 0, sizeof(*regs));
  58. }
  59. enum c6x_regset {
  60. REGSET_GPR,
  61. };
  62. static const struct user_regset c6x_regsets[] = {
  63. [REGSET_GPR] = {
  64. .core_note_type = NT_PRSTATUS,
  65. .n = ELF_NGREG,
  66. .size = sizeof(u32),
  67. .align = sizeof(u32),
  68. .get = gpr_get,
  69. },
  70. };
  71. static const struct user_regset_view user_c6x_native_view = {
  72. .name = "tic6x",
  73. .e_machine = EM_TI_C6000,
  74. .regsets = c6x_regsets,
  75. .n = ARRAY_SIZE(c6x_regsets),
  76. };
  77. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  78. {
  79. return &user_c6x_native_view;
  80. }
  81. /*
  82. * Perform ptrace request
  83. */
  84. long arch_ptrace(struct task_struct *child, long request,
  85. unsigned long addr, unsigned long data)
  86. {
  87. int ret = 0;
  88. switch (request) {
  89. /*
  90. * write the word at location addr.
  91. */
  92. case PTRACE_POKETEXT:
  93. ret = generic_ptrace_pokedata(child, addr, data);
  94. if (ret == 0 && request == PTRACE_POKETEXT)
  95. flush_icache_range(addr, addr + 4);
  96. break;
  97. default:
  98. ret = ptrace_request(child, request, addr, data);
  99. break;
  100. }
  101. return ret;
  102. }
  103. /*
  104. * handle tracing of system call entry
  105. * - return the revised system call number or ULONG_MAX to cause ENOSYS
  106. */
  107. asmlinkage unsigned long syscall_trace_entry(struct pt_regs *regs)
  108. {
  109. if (tracehook_report_syscall_entry(regs))
  110. /* tracing decided this syscall should not happen, so
  111. * We'll return a bogus call number to get an ENOSYS
  112. * error, but leave the original number in
  113. * regs->orig_a4
  114. */
  115. return ULONG_MAX;
  116. return regs->b0;
  117. }
  118. /*
  119. * handle tracing of system call exit
  120. */
  121. asmlinkage void syscall_trace_exit(struct pt_regs *regs)
  122. {
  123. tracehook_report_syscall_exit(regs, 0);
  124. }