ptrace.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Copyright (C) 2001 PPC64 Team, IBM Corp
  3. *
  4. * This struct defines the way the registers are stored on the
  5. * kernel stack during a system call or other kernel entry.
  6. *
  7. * this should only contain volatile regs
  8. * since we can keep non-volatile in the thread_struct
  9. * should set this up when only volatiles are saved
  10. * by intr code.
  11. *
  12. * Since this is going on the stack, *CARE MUST BE TAKEN* to insure
  13. * that the overall structure is a multiple of 16 bytes in length.
  14. *
  15. * Note that the offsets of the fields in this struct correspond with
  16. * the PT_* values below. This simplifies arch/powerpc/kernel/ptrace.c.
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License
  20. * as published by the Free Software Foundation; either version
  21. * 2 of the License, or (at your option) any later version.
  22. */
  23. #ifndef _ASM_POWERPC_PTRACE_H
  24. #define _ASM_POWERPC_PTRACE_H
  25. #include <uapi/asm/ptrace.h>
  26. #ifdef __powerpc64__
  27. /*
  28. * Size of redzone that userspace is allowed to use below the stack
  29. * pointer. This is 288 in the 64-bit big-endian ELF ABI, and 512 in
  30. * the new ELFv2 little-endian ABI, so we allow the larger amount.
  31. *
  32. * For kernel code we allow a 288-byte redzone, in order to conserve
  33. * kernel stack space; gcc currently only uses 288 bytes, and will
  34. * hopefully allow explicit control of the redzone size in future.
  35. */
  36. #define USER_REDZONE_SIZE 512
  37. #define KERNEL_REDZONE_SIZE 288
  38. #define STACK_FRAME_OVERHEAD 112 /* size of minimum stack frame */
  39. #define STACK_FRAME_LR_SAVE 2 /* Location of LR in stack frame */
  40. #define STACK_FRAME_REGS_MARKER ASM_CONST(0x7265677368657265)
  41. #define STACK_INT_FRAME_SIZE (sizeof(struct pt_regs) + \
  42. STACK_FRAME_OVERHEAD + KERNEL_REDZONE_SIZE)
  43. #define STACK_FRAME_MARKER 12
  44. /* Size of dummy stack frame allocated when calling signal handler. */
  45. #define __SIGNAL_FRAMESIZE 128
  46. #define __SIGNAL_FRAMESIZE32 64
  47. #else /* __powerpc64__ */
  48. #define USER_REDZONE_SIZE 0
  49. #define KERNEL_REDZONE_SIZE 0
  50. #define STACK_FRAME_OVERHEAD 16 /* size of minimum stack frame */
  51. #define STACK_FRAME_LR_SAVE 1 /* Location of LR in stack frame */
  52. #define STACK_FRAME_REGS_MARKER ASM_CONST(0x72656773)
  53. #define STACK_INT_FRAME_SIZE (sizeof(struct pt_regs) + STACK_FRAME_OVERHEAD)
  54. #define STACK_FRAME_MARKER 2
  55. /* Size of stack frame allocated when calling signal handler. */
  56. #define __SIGNAL_FRAMESIZE 64
  57. #endif /* __powerpc64__ */
  58. #ifndef __ASSEMBLY__
  59. #define GET_IP(regs) ((regs)->nip)
  60. #define GET_USP(regs) ((regs)->gpr[1])
  61. #define GET_FP(regs) (0)
  62. #define SET_FP(regs, val)
  63. #ifdef CONFIG_SMP
  64. extern unsigned long profile_pc(struct pt_regs *regs);
  65. #define profile_pc profile_pc
  66. #endif
  67. #include <asm-generic/ptrace.h>
  68. #define kernel_stack_pointer(regs) ((regs)->gpr[1])
  69. static inline int is_syscall_success(struct pt_regs *regs)
  70. {
  71. return !(regs->ccr & 0x10000000);
  72. }
  73. static inline long regs_return_value(struct pt_regs *regs)
  74. {
  75. if (is_syscall_success(regs))
  76. return regs->gpr[3];
  77. else
  78. return -regs->gpr[3];
  79. }
  80. #ifdef __powerpc64__
  81. #define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1)
  82. #else
  83. #define user_mode(regs) (((regs)->msr & MSR_PR) != 0)
  84. #endif
  85. #define force_successful_syscall_return() \
  86. do { \
  87. set_thread_flag(TIF_NOERROR); \
  88. } while(0)
  89. struct task_struct;
  90. extern int ptrace_get_reg(struct task_struct *task, int regno,
  91. unsigned long *data);
  92. extern int ptrace_put_reg(struct task_struct *task, int regno,
  93. unsigned long data);
  94. #define current_pt_regs() \
  95. ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
  96. /*
  97. * We use the least-significant bit of the trap field to indicate
  98. * whether we have saved the full set of registers, or only a
  99. * partial set. A 1 there means the partial set.
  100. * On 4xx we use the next bit to indicate whether the exception
  101. * is a critical exception (1 means it is).
  102. */
  103. #define FULL_REGS(regs) (((regs)->trap & 1) == 0)
  104. #ifndef __powerpc64__
  105. #define IS_CRITICAL_EXC(regs) (((regs)->trap & 2) != 0)
  106. #define IS_MCHECK_EXC(regs) (((regs)->trap & 4) != 0)
  107. #define IS_DEBUG_EXC(regs) (((regs)->trap & 8) != 0)
  108. #endif /* ! __powerpc64__ */
  109. #define TRAP(regs) ((regs)->trap & ~0xF)
  110. #ifdef __powerpc64__
  111. #define NV_REG_POISON 0xdeadbeefdeadbeefUL
  112. #define CHECK_FULL_REGS(regs) BUG_ON(regs->trap & 1)
  113. #else
  114. #define NV_REG_POISON 0xdeadbeef
  115. #define CHECK_FULL_REGS(regs) \
  116. do { \
  117. if ((regs)->trap & 1) \
  118. printk(KERN_CRIT "%s: partial register set\n", __func__); \
  119. } while (0)
  120. #endif /* __powerpc64__ */
  121. #define arch_has_single_step() (1)
  122. #define arch_has_block_step() (!cpu_has_feature(CPU_FTR_601))
  123. #define ARCH_HAS_USER_SINGLE_STEP_INFO
  124. /*
  125. * kprobe-based event tracer support
  126. */
  127. #include <linux/stddef.h>
  128. #include <linux/thread_info.h>
  129. extern int regs_query_register_offset(const char *name);
  130. extern const char *regs_query_register_name(unsigned int offset);
  131. #define MAX_REG_OFFSET (offsetof(struct pt_regs, dsisr))
  132. /**
  133. * regs_get_register() - get register value from its offset
  134. * @regs: pt_regs from which register value is gotten
  135. * @offset: offset number of the register.
  136. *
  137. * regs_get_register returns the value of a register whose offset from @regs.
  138. * The @offset is the offset of the register in struct pt_regs.
  139. * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
  140. */
  141. static inline unsigned long regs_get_register(struct pt_regs *regs,
  142. unsigned int offset)
  143. {
  144. if (unlikely(offset > MAX_REG_OFFSET))
  145. return 0;
  146. return *(unsigned long *)((unsigned long)regs + offset);
  147. }
  148. /**
  149. * regs_within_kernel_stack() - check the address in the stack
  150. * @regs: pt_regs which contains kernel stack pointer.
  151. * @addr: address which is checked.
  152. *
  153. * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
  154. * If @addr is within the kernel stack, it returns true. If not, returns false.
  155. */
  156. static inline bool regs_within_kernel_stack(struct pt_regs *regs,
  157. unsigned long addr)
  158. {
  159. return ((addr & ~(THREAD_SIZE - 1)) ==
  160. (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
  161. }
  162. /**
  163. * regs_get_kernel_stack_nth() - get Nth entry of the stack
  164. * @regs: pt_regs which contains kernel stack pointer.
  165. * @n: stack entry number.
  166. *
  167. * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
  168. * is specified by @regs. If the @n th entry is NOT in the kernel stack,
  169. * this returns 0.
  170. */
  171. static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
  172. unsigned int n)
  173. {
  174. unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
  175. addr += n;
  176. if (regs_within_kernel_stack(regs, (unsigned long)addr))
  177. return *addr;
  178. else
  179. return 0;
  180. }
  181. #endif /* __ASSEMBLY__ */
  182. #ifndef __powerpc64__
  183. #else /* __powerpc64__ */
  184. #define PT_FPSCR32 (PT_FPR0 + 2*32 + 1) /* each FP reg occupies 2 32-bit userspace slots */
  185. #define PT_VR0_32 164 /* each Vector reg occupies 4 slots in 32-bit */
  186. #define PT_VSCR_32 (PT_VR0 + 32*4 + 3)
  187. #define PT_VRSAVE_32 (PT_VR0 + 33*4)
  188. #define PT_VSR0_32 300 /* each VSR reg occupies 4 slots in 32-bit */
  189. #endif /* __powerpc64__ */
  190. #endif /* _ASM_POWERPC_PTRACE_H */