ptrace.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. #ifndef _ASM_IA64_PTRACE_H
  2. #define _ASM_IA64_PTRACE_H
  3. /*
  4. * Copyright (C) 1998-2004 Hewlett-Packard Co
  5. * David Mosberger-Tang <davidm@hpl.hp.com>
  6. * Stephane Eranian <eranian@hpl.hp.com>
  7. * Copyright (C) 2003 Intel Co
  8. * Suresh Siddha <suresh.b.siddha@intel.com>
  9. * Fenghua Yu <fenghua.yu@intel.com>
  10. * Arun Sharma <arun.sharma@intel.com>
  11. *
  12. * 12/07/98 S. Eranian added pt_regs & switch_stack
  13. * 12/21/98 D. Mosberger updated to match latest code
  14. * 6/17/99 D. Mosberger added second unat member to "struct switch_stack"
  15. *
  16. */
  17. /*
  18. * When a user process is blocked, its state looks as follows:
  19. *
  20. * +----------------------+ ------- IA64_STK_OFFSET
  21. * | | ^
  22. * | struct pt_regs | |
  23. * | | |
  24. * +----------------------+ |
  25. * | | |
  26. * | memory stack | |
  27. * | (growing downwards) | |
  28. * //.....................// |
  29. * |
  30. * //.....................// |
  31. * | | |
  32. * +----------------------+ |
  33. * | struct switch_stack | |
  34. * | | |
  35. * +----------------------+ |
  36. * | | |
  37. * //.....................// |
  38. * |
  39. * //.....................// |
  40. * | | |
  41. * | register stack | |
  42. * | (growing upwards) | |
  43. * | | |
  44. * +----------------------+ | --- IA64_RBS_OFFSET
  45. * | struct thread_info | | ^
  46. * +----------------------+ | |
  47. * | | | |
  48. * | struct task_struct | | |
  49. * current -> | | | |
  50. * +----------------------+ -------
  51. *
  52. * Note that ar.ec is not saved explicitly in pt_reg or switch_stack.
  53. * This is because ar.ec is saved as part of ar.pfs.
  54. */
  55. #include <asm/fpu.h>
  56. #ifdef __KERNEL__
  57. #ifndef ASM_OFFSETS_C
  58. #include <asm/asm-offsets.h>
  59. #endif
  60. /*
  61. * Base-2 logarithm of number of pages to allocate per task structure
  62. * (including register backing store and memory stack):
  63. */
  64. #if defined(CONFIG_IA64_PAGE_SIZE_4KB)
  65. # define KERNEL_STACK_SIZE_ORDER 3
  66. #elif defined(CONFIG_IA64_PAGE_SIZE_8KB)
  67. # define KERNEL_STACK_SIZE_ORDER 2
  68. #elif defined(CONFIG_IA64_PAGE_SIZE_16KB)
  69. # define KERNEL_STACK_SIZE_ORDER 1
  70. #else
  71. # define KERNEL_STACK_SIZE_ORDER 0
  72. #endif
  73. #define IA64_RBS_OFFSET ((IA64_TASK_SIZE + IA64_THREAD_INFO_SIZE + 31) & ~31)
  74. #define IA64_STK_OFFSET ((1 << KERNEL_STACK_SIZE_ORDER)*PAGE_SIZE)
  75. #define KERNEL_STACK_SIZE IA64_STK_OFFSET
  76. #endif /* __KERNEL__ */
  77. #ifndef __ASSEMBLY__
  78. /*
  79. * This struct defines the way the registers are saved on system
  80. * calls.
  81. *
  82. * We don't save all floating point register because the kernel
  83. * is compiled to use only a very small subset, so the other are
  84. * untouched.
  85. *
  86. * THIS STRUCTURE MUST BE A MULTIPLE 16-BYTE IN SIZE
  87. * (because the memory stack pointer MUST ALWAYS be aligned this way)
  88. *
  89. */
  90. struct pt_regs {
  91. /* The following registers are saved by SAVE_MIN: */
  92. unsigned long b6; /* scratch */
  93. unsigned long b7; /* scratch */
  94. unsigned long ar_csd; /* used by cmp8xchg16 (scratch) */
  95. unsigned long ar_ssd; /* reserved for future use (scratch) */
  96. unsigned long r8; /* scratch (return value register 0) */
  97. unsigned long r9; /* scratch (return value register 1) */
  98. unsigned long r10; /* scratch (return value register 2) */
  99. unsigned long r11; /* scratch (return value register 3) */
  100. unsigned long cr_ipsr; /* interrupted task's psr */
  101. unsigned long cr_iip; /* interrupted task's instruction pointer */
  102. /*
  103. * interrupted task's function state; if bit 63 is cleared, it
  104. * contains syscall's ar.pfs.pfm:
  105. */
  106. unsigned long cr_ifs;
  107. unsigned long ar_unat; /* interrupted task's NaT register (preserved) */
  108. unsigned long ar_pfs; /* prev function state */
  109. unsigned long ar_rsc; /* RSE configuration */
  110. /* The following two are valid only if cr_ipsr.cpl > 0 || ti->flags & _TIF_MCA_INIT */
  111. unsigned long ar_rnat; /* RSE NaT */
  112. unsigned long ar_bspstore; /* RSE bspstore */
  113. unsigned long pr; /* 64 predicate registers (1 bit each) */
  114. unsigned long b0; /* return pointer (bp) */
  115. unsigned long loadrs; /* size of dirty partition << 16 */
  116. unsigned long r1; /* the gp pointer */
  117. unsigned long r12; /* interrupted task's memory stack pointer */
  118. unsigned long r13; /* thread pointer */
  119. unsigned long ar_fpsr; /* floating point status (preserved) */
  120. unsigned long r15; /* scratch */
  121. /* The remaining registers are NOT saved for system calls. */
  122. unsigned long r14; /* scratch */
  123. unsigned long r2; /* scratch */
  124. unsigned long r3; /* scratch */
  125. /* The following registers are saved by SAVE_REST: */
  126. unsigned long r16; /* scratch */
  127. unsigned long r17; /* scratch */
  128. unsigned long r18; /* scratch */
  129. unsigned long r19; /* scratch */
  130. unsigned long r20; /* scratch */
  131. unsigned long r21; /* scratch */
  132. unsigned long r22; /* scratch */
  133. unsigned long r23; /* scratch */
  134. unsigned long r24; /* scratch */
  135. unsigned long r25; /* scratch */
  136. unsigned long r26; /* scratch */
  137. unsigned long r27; /* scratch */
  138. unsigned long r28; /* scratch */
  139. unsigned long r29; /* scratch */
  140. unsigned long r30; /* scratch */
  141. unsigned long r31; /* scratch */
  142. unsigned long ar_ccv; /* compare/exchange value (scratch) */
  143. /*
  144. * Floating point registers that the kernel considers scratch:
  145. */
  146. struct ia64_fpreg f6; /* scratch */
  147. struct ia64_fpreg f7; /* scratch */
  148. struct ia64_fpreg f8; /* scratch */
  149. struct ia64_fpreg f9; /* scratch */
  150. struct ia64_fpreg f10; /* scratch */
  151. struct ia64_fpreg f11; /* scratch */
  152. };
  153. /*
  154. * This structure contains the addition registers that need to
  155. * preserved across a context switch. This generally consists of
  156. * "preserved" registers.
  157. */
  158. struct switch_stack {
  159. unsigned long caller_unat; /* user NaT collection register (preserved) */
  160. unsigned long ar_fpsr; /* floating-point status register */
  161. struct ia64_fpreg f2; /* preserved */
  162. struct ia64_fpreg f3; /* preserved */
  163. struct ia64_fpreg f4; /* preserved */
  164. struct ia64_fpreg f5; /* preserved */
  165. struct ia64_fpreg f12; /* scratch, but untouched by kernel */
  166. struct ia64_fpreg f13; /* scratch, but untouched by kernel */
  167. struct ia64_fpreg f14; /* scratch, but untouched by kernel */
  168. struct ia64_fpreg f15; /* scratch, but untouched by kernel */
  169. struct ia64_fpreg f16; /* preserved */
  170. struct ia64_fpreg f17; /* preserved */
  171. struct ia64_fpreg f18; /* preserved */
  172. struct ia64_fpreg f19; /* preserved */
  173. struct ia64_fpreg f20; /* preserved */
  174. struct ia64_fpreg f21; /* preserved */
  175. struct ia64_fpreg f22; /* preserved */
  176. struct ia64_fpreg f23; /* preserved */
  177. struct ia64_fpreg f24; /* preserved */
  178. struct ia64_fpreg f25; /* preserved */
  179. struct ia64_fpreg f26; /* preserved */
  180. struct ia64_fpreg f27; /* preserved */
  181. struct ia64_fpreg f28; /* preserved */
  182. struct ia64_fpreg f29; /* preserved */
  183. struct ia64_fpreg f30; /* preserved */
  184. struct ia64_fpreg f31; /* preserved */
  185. unsigned long r4; /* preserved */
  186. unsigned long r5; /* preserved */
  187. unsigned long r6; /* preserved */
  188. unsigned long r7; /* preserved */
  189. unsigned long b0; /* so we can force a direct return in copy_thread */
  190. unsigned long b1;
  191. unsigned long b2;
  192. unsigned long b3;
  193. unsigned long b4;
  194. unsigned long b5;
  195. unsigned long ar_pfs; /* previous function state */
  196. unsigned long ar_lc; /* loop counter (preserved) */
  197. unsigned long ar_unat; /* NaT bits for r4-r7 */
  198. unsigned long ar_rnat; /* RSE NaT collection register */
  199. unsigned long ar_bspstore; /* RSE dirty base (preserved) */
  200. unsigned long pr; /* 64 predicate registers (1 bit each) */
  201. };
  202. #ifdef __KERNEL__
  203. #include <asm/current.h>
  204. #include <asm/page.h>
  205. /*
  206. * We use the ia64_psr(regs)->ri to determine which of the three
  207. * instructions in bundle (16 bytes) took the sample. Generate
  208. * the canonical representation by adding to instruction pointer.
  209. */
  210. # define instruction_pointer(regs) ((regs)->cr_iip + ia64_psr(regs)->ri)
  211. static inline unsigned long user_stack_pointer(struct pt_regs *regs)
  212. {
  213. /* FIXME: should this be bspstore + nr_dirty regs? */
  214. return regs->ar_bspstore;
  215. }
  216. static inline int is_syscall_success(struct pt_regs *regs)
  217. {
  218. return regs->r10 != -1;
  219. }
  220. static inline long regs_return_value(struct pt_regs *regs)
  221. {
  222. if (is_syscall_success(regs))
  223. return regs->r8;
  224. else
  225. return -regs->r8;
  226. }
  227. /* Conserve space in histogram by encoding slot bits in address
  228. * bits 2 and 3 rather than bits 0 and 1.
  229. */
  230. #define profile_pc(regs) \
  231. ({ \
  232. unsigned long __ip = instruction_pointer(regs); \
  233. (__ip & ~3UL) + ((__ip & 3UL) << 2); \
  234. })
  235. /* given a pointer to a task_struct, return the user's pt_regs */
  236. # define task_pt_regs(t) (((struct pt_regs *) ((char *) (t) + IA64_STK_OFFSET)) - 1)
  237. # define ia64_psr(regs) ((struct ia64_psr *) &(regs)->cr_ipsr)
  238. # define user_mode(regs) (((struct ia64_psr *) &(regs)->cr_ipsr)->cpl != 0)
  239. # define user_stack(task,regs) ((long) regs - (long) task == IA64_STK_OFFSET - sizeof(*regs))
  240. # define fsys_mode(task,regs) \
  241. ({ \
  242. struct task_struct *_task = (task); \
  243. struct pt_regs *_regs = (regs); \
  244. !user_mode(_regs) && user_stack(_task, _regs); \
  245. })
  246. /*
  247. * System call handlers that, upon successful completion, need to return a negative value
  248. * should call force_successful_syscall_return() right before returning. On architectures
  249. * where the syscall convention provides for a separate error flag (e.g., alpha, ia64,
  250. * ppc{,64}, sparc{,64}, possibly others), this macro can be used to ensure that the error
  251. * flag will not get set. On architectures which do not support a separate error flag,
  252. * the macro is a no-op and the spurious error condition needs to be filtered out by some
  253. * other means (e.g., in user-level, by passing an extra argument to the syscall handler,
  254. * or something along those lines).
  255. *
  256. * On ia64, we can clear the user's pt_regs->r8 to force a successful syscall.
  257. */
  258. # define force_successful_syscall_return() (task_pt_regs(current)->r8 = 0)
  259. struct task_struct; /* forward decl */
  260. struct unw_frame_info; /* forward decl */
  261. extern void ia64_do_show_stack (struct unw_frame_info *, void *);
  262. extern unsigned long ia64_get_user_rbs_end (struct task_struct *, struct pt_regs *,
  263. unsigned long *);
  264. extern long ia64_peek (struct task_struct *, struct switch_stack *, unsigned long,
  265. unsigned long, long *);
  266. extern long ia64_poke (struct task_struct *, struct switch_stack *, unsigned long,
  267. unsigned long, long);
  268. extern void ia64_flush_fph (struct task_struct *);
  269. extern void ia64_sync_fph (struct task_struct *);
  270. extern void ia64_sync_krbs(void);
  271. extern long ia64_sync_user_rbs (struct task_struct *, struct switch_stack *,
  272. unsigned long, unsigned long);
  273. /* get nat bits for scratch registers such that bit N==1 iff scratch register rN is a NaT */
  274. extern unsigned long ia64_get_scratch_nat_bits (struct pt_regs *pt, unsigned long scratch_unat);
  275. /* put nat bits for scratch registers such that scratch register rN is a NaT iff bit N==1 */
  276. extern unsigned long ia64_put_scratch_nat_bits (struct pt_regs *pt, unsigned long nat);
  277. extern void ia64_increment_ip (struct pt_regs *pt);
  278. extern void ia64_decrement_ip (struct pt_regs *pt);
  279. extern void ia64_ptrace_stop(void);
  280. #define arch_ptrace_stop(code, info) \
  281. ia64_ptrace_stop()
  282. #define arch_ptrace_stop_needed(code, info) \
  283. (!test_thread_flag(TIF_RESTORE_RSE))
  284. extern void ptrace_attach_sync_user_rbs (struct task_struct *);
  285. #define arch_ptrace_attach(child) \
  286. ptrace_attach_sync_user_rbs(child)
  287. #define arch_has_single_step() (1)
  288. #define arch_has_block_step() (1)
  289. #endif /* !__KERNEL__ */
  290. /* pt_all_user_regs is used for PTRACE_GETREGS PTRACE_SETREGS */
  291. struct pt_all_user_regs {
  292. unsigned long nat;
  293. unsigned long cr_iip;
  294. unsigned long cfm;
  295. unsigned long cr_ipsr;
  296. unsigned long pr;
  297. unsigned long gr[32];
  298. unsigned long br[8];
  299. unsigned long ar[128];
  300. struct ia64_fpreg fr[128];
  301. };
  302. #endif /* !__ASSEMBLY__ */
  303. /* indices to application-registers array in pt_all_user_regs */
  304. #define PT_AUR_RSC 16
  305. #define PT_AUR_BSP 17
  306. #define PT_AUR_BSPSTORE 18
  307. #define PT_AUR_RNAT 19
  308. #define PT_AUR_CCV 32
  309. #define PT_AUR_UNAT 36
  310. #define PT_AUR_FPSR 40
  311. #define PT_AUR_PFS 64
  312. #define PT_AUR_LC 65
  313. #define PT_AUR_EC 66
  314. /*
  315. * The numbers chosen here are somewhat arbitrary but absolutely MUST
  316. * not overlap with any of the number assigned in <linux/ptrace.h>.
  317. */
  318. #define PTRACE_SINGLEBLOCK 12 /* resume execution until next branch */
  319. #define PTRACE_OLD_GETSIGINFO 13 /* (replaced by PTRACE_GETSIGINFO in <linux/ptrace.h>) */
  320. #define PTRACE_OLD_SETSIGINFO 14 /* (replaced by PTRACE_SETSIGINFO in <linux/ptrace.h>) */
  321. #define PTRACE_GETREGS 18 /* get all registers (pt_all_user_regs) in one shot */
  322. #define PTRACE_SETREGS 19 /* set all registers (pt_all_user_regs) in one shot */
  323. #define PTRACE_OLDSETOPTIONS 21
  324. #endif /* _ASM_IA64_PTRACE_H */