ptrace.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. #ifndef __SPARC_PTRACE_H
  2. #define __SPARC_PTRACE_H
  3. #if defined(__sparc__) && defined(__arch64__)
  4. /* 64 bit sparc */
  5. #include <asm/pstate.h>
  6. /* This struct defines the way the registers are stored on the
  7. * stack during a system call and basically all traps.
  8. */
  9. /* This magic value must have the low 9 bits clear,
  10. * as that is where we encode the %tt value, see below.
  11. */
  12. #define PT_REGS_MAGIC 0x57ac6c00
  13. #ifndef __ASSEMBLY__
  14. #include <linux/types.h>
  15. struct pt_regs {
  16. unsigned long u_regs[16]; /* globals and ins */
  17. unsigned long tstate;
  18. unsigned long tpc;
  19. unsigned long tnpc;
  20. unsigned int y;
  21. /* We encode a magic number, PT_REGS_MAGIC, along
  22. * with the %tt (trap type) register value at trap
  23. * entry time. The magic number allows us to identify
  24. * accurately a trap stack frame in the stack
  25. * unwinder, and the %tt value allows us to test
  26. * things like "in a system call" etc. for an arbitray
  27. * process.
  28. *
  29. * The PT_REGS_MAGIC is choosen such that it can be
  30. * loaded completely using just a sethi instruction.
  31. */
  32. unsigned int magic;
  33. };
  34. struct pt_regs32 {
  35. unsigned int psr;
  36. unsigned int pc;
  37. unsigned int npc;
  38. unsigned int y;
  39. unsigned int u_regs[16]; /* globals and ins */
  40. };
  41. /* A V9 register window */
  42. struct reg_window {
  43. unsigned long locals[8];
  44. unsigned long ins[8];
  45. };
  46. /* A 32-bit register window. */
  47. struct reg_window32 {
  48. unsigned int locals[8];
  49. unsigned int ins[8];
  50. };
  51. /* A V9 Sparc stack frame */
  52. struct sparc_stackf {
  53. unsigned long locals[8];
  54. unsigned long ins[6];
  55. struct sparc_stackf *fp;
  56. unsigned long callers_pc;
  57. char *structptr;
  58. unsigned long xargs[6];
  59. unsigned long xxargs[1];
  60. };
  61. /* A 32-bit Sparc stack frame */
  62. struct sparc_stackf32 {
  63. unsigned int locals[8];
  64. unsigned int ins[6];
  65. unsigned int fp;
  66. unsigned int callers_pc;
  67. unsigned int structptr;
  68. unsigned int xargs[6];
  69. unsigned int xxargs[1];
  70. };
  71. struct sparc_trapf {
  72. unsigned long locals[8];
  73. unsigned long ins[8];
  74. unsigned long _unused;
  75. struct pt_regs *regs;
  76. };
  77. #endif /* (!__ASSEMBLY__) */
  78. #else
  79. /* 32 bit sparc */
  80. #include <asm/psr.h>
  81. /* This struct defines the way the registers are stored on the
  82. * stack during a system call and basically all traps.
  83. */
  84. #ifndef __ASSEMBLY__
  85. struct pt_regs {
  86. unsigned long psr;
  87. unsigned long pc;
  88. unsigned long npc;
  89. unsigned long y;
  90. unsigned long u_regs[16]; /* globals and ins */
  91. };
  92. /* A 32-bit register window. */
  93. struct reg_window32 {
  94. unsigned long locals[8];
  95. unsigned long ins[8];
  96. };
  97. /* A Sparc stack frame */
  98. struct sparc_stackf {
  99. unsigned long locals[8];
  100. unsigned long ins[6];
  101. struct sparc_stackf *fp;
  102. unsigned long callers_pc;
  103. char *structptr;
  104. unsigned long xargs[6];
  105. unsigned long xxargs[1];
  106. };
  107. #endif /* (!__ASSEMBLY__) */
  108. #endif /* (defined(__sparc__) && defined(__arch64__))*/
  109. #ifndef __ASSEMBLY__
  110. #define TRACEREG_SZ sizeof(struct pt_regs)
  111. #define STACKFRAME_SZ sizeof(struct sparc_stackf)
  112. #define TRACEREG32_SZ sizeof(struct pt_regs32)
  113. #define STACKFRAME32_SZ sizeof(struct sparc_stackf32)
  114. #endif /* (!__ASSEMBLY__) */
  115. #define UREG_G0 0
  116. #define UREG_G1 1
  117. #define UREG_G2 2
  118. #define UREG_G3 3
  119. #define UREG_G4 4
  120. #define UREG_G5 5
  121. #define UREG_G6 6
  122. #define UREG_G7 7
  123. #define UREG_I0 8
  124. #define UREG_I1 9
  125. #define UREG_I2 10
  126. #define UREG_I3 11
  127. #define UREG_I4 12
  128. #define UREG_I5 13
  129. #define UREG_I6 14
  130. #define UREG_I7 15
  131. #define UREG_FP UREG_I6
  132. #define UREG_RETPC UREG_I7
  133. #if defined(__sparc__) && defined(__arch64__)
  134. /* 64 bit sparc */
  135. #ifndef __ASSEMBLY__
  136. #ifdef __KERNEL__
  137. #include <linux/threads.h>
  138. #include <asm/system.h>
  139. static inline int pt_regs_trap_type(struct pt_regs *regs)
  140. {
  141. return regs->magic & 0x1ff;
  142. }
  143. static inline bool pt_regs_is_syscall(struct pt_regs *regs)
  144. {
  145. return (regs->tstate & TSTATE_SYSCALL);
  146. }
  147. static inline bool pt_regs_clear_syscall(struct pt_regs *regs)
  148. {
  149. return (regs->tstate &= ~TSTATE_SYSCALL);
  150. }
  151. #define arch_ptrace_stop_needed(exit_code, info) \
  152. ({ flush_user_windows(); \
  153. get_thread_wsaved() != 0; \
  154. })
  155. #define arch_ptrace_stop(exit_code, info) \
  156. synchronize_user_stack()
  157. struct global_reg_snapshot {
  158. unsigned long tstate;
  159. unsigned long tpc;
  160. unsigned long tnpc;
  161. unsigned long o7;
  162. unsigned long i7;
  163. unsigned long rpc;
  164. struct thread_info *thread;
  165. unsigned long pad1;
  166. };
  167. extern struct global_reg_snapshot global_reg_snapshot[NR_CPUS];
  168. #define force_successful_syscall_return() \
  169. do { current_thread_info()->syscall_noerror = 1; \
  170. } while (0)
  171. #define user_mode(regs) (!((regs)->tstate & TSTATE_PRIV))
  172. #define instruction_pointer(regs) ((regs)->tpc)
  173. #define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP])
  174. #define regs_return_value(regs) ((regs)->u_regs[UREG_I0])
  175. #ifdef CONFIG_SMP
  176. extern unsigned long profile_pc(struct pt_regs *);
  177. #else
  178. #define profile_pc(regs) instruction_pointer(regs)
  179. #endif
  180. extern void show_regs(struct pt_regs *);
  181. #endif /* (__KERNEL__) */
  182. #else /* __ASSEMBLY__ */
  183. /* For assembly code. */
  184. #define TRACEREG_SZ 0xa0
  185. #define STACKFRAME_SZ 0xc0
  186. #define TRACEREG32_SZ 0x50
  187. #define STACKFRAME32_SZ 0x60
  188. #endif /* __ASSEMBLY__ */
  189. #else /* (defined(__sparc__) && defined(__arch64__)) */
  190. /* 32 bit sparc */
  191. #ifndef __ASSEMBLY__
  192. #ifdef __KERNEL__
  193. #include <asm/system.h>
  194. static inline bool pt_regs_is_syscall(struct pt_regs *regs)
  195. {
  196. return (regs->psr & PSR_SYSCALL);
  197. }
  198. static inline bool pt_regs_clear_syscall(struct pt_regs *regs)
  199. {
  200. return (regs->psr &= ~PSR_SYSCALL);
  201. }
  202. #define arch_ptrace_stop_needed(exit_code, info) \
  203. ({ flush_user_windows(); \
  204. current_thread_info()->w_saved != 0; \
  205. })
  206. #define arch_ptrace_stop(exit_code, info) \
  207. synchronize_user_stack()
  208. #define user_mode(regs) (!((regs)->psr & PSR_PS))
  209. #define instruction_pointer(regs) ((regs)->pc)
  210. #define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP])
  211. unsigned long profile_pc(struct pt_regs *);
  212. extern void show_regs(struct pt_regs *);
  213. #endif /* (__KERNEL__) */
  214. #else /* (!__ASSEMBLY__) */
  215. /* For assembly code. */
  216. #define TRACEREG_SZ 0x50
  217. #define STACKFRAME_SZ 0x60
  218. #endif /* (!__ASSEMBLY__) */
  219. #endif /* (defined(__sparc__) && defined(__arch64__)) */
  220. #ifdef __KERNEL__
  221. #define STACK_BIAS 2047
  222. #endif
  223. /* These are for pt_regs. */
  224. #define PT_V9_G0 0x00
  225. #define PT_V9_G1 0x08
  226. #define PT_V9_G2 0x10
  227. #define PT_V9_G3 0x18
  228. #define PT_V9_G4 0x20
  229. #define PT_V9_G5 0x28
  230. #define PT_V9_G6 0x30
  231. #define PT_V9_G7 0x38
  232. #define PT_V9_I0 0x40
  233. #define PT_V9_I1 0x48
  234. #define PT_V9_I2 0x50
  235. #define PT_V9_I3 0x58
  236. #define PT_V9_I4 0x60
  237. #define PT_V9_I5 0x68
  238. #define PT_V9_I6 0x70
  239. #define PT_V9_FP PT_V9_I6
  240. #define PT_V9_I7 0x78
  241. #define PT_V9_TSTATE 0x80
  242. #define PT_V9_TPC 0x88
  243. #define PT_V9_TNPC 0x90
  244. #define PT_V9_Y 0x98
  245. #define PT_V9_MAGIC 0x9c
  246. #define PT_TSTATE PT_V9_TSTATE
  247. #define PT_TPC PT_V9_TPC
  248. #define PT_TNPC PT_V9_TNPC
  249. /* These for pt_regs32. */
  250. #define PT_PSR 0x0
  251. #define PT_PC 0x4
  252. #define PT_NPC 0x8
  253. #define PT_Y 0xc
  254. #define PT_G0 0x10
  255. #define PT_WIM PT_G0
  256. #define PT_G1 0x14
  257. #define PT_G2 0x18
  258. #define PT_G3 0x1c
  259. #define PT_G4 0x20
  260. #define PT_G5 0x24
  261. #define PT_G6 0x28
  262. #define PT_G7 0x2c
  263. #define PT_I0 0x30
  264. #define PT_I1 0x34
  265. #define PT_I2 0x38
  266. #define PT_I3 0x3c
  267. #define PT_I4 0x40
  268. #define PT_I5 0x44
  269. #define PT_I6 0x48
  270. #define PT_FP PT_I6
  271. #define PT_I7 0x4c
  272. /* Reg_window offsets */
  273. #define RW_V9_L0 0x00
  274. #define RW_V9_L1 0x08
  275. #define RW_V9_L2 0x10
  276. #define RW_V9_L3 0x18
  277. #define RW_V9_L4 0x20
  278. #define RW_V9_L5 0x28
  279. #define RW_V9_L6 0x30
  280. #define RW_V9_L7 0x38
  281. #define RW_V9_I0 0x40
  282. #define RW_V9_I1 0x48
  283. #define RW_V9_I2 0x50
  284. #define RW_V9_I3 0x58
  285. #define RW_V9_I4 0x60
  286. #define RW_V9_I5 0x68
  287. #define RW_V9_I6 0x70
  288. #define RW_V9_I7 0x78
  289. #define RW_L0 0x00
  290. #define RW_L1 0x04
  291. #define RW_L2 0x08
  292. #define RW_L3 0x0c
  293. #define RW_L4 0x10
  294. #define RW_L5 0x14
  295. #define RW_L6 0x18
  296. #define RW_L7 0x1c
  297. #define RW_I0 0x20
  298. #define RW_I1 0x24
  299. #define RW_I2 0x28
  300. #define RW_I3 0x2c
  301. #define RW_I4 0x30
  302. #define RW_I5 0x34
  303. #define RW_I6 0x38
  304. #define RW_I7 0x3c
  305. /* Stack_frame offsets */
  306. #define SF_V9_L0 0x00
  307. #define SF_V9_L1 0x08
  308. #define SF_V9_L2 0x10
  309. #define SF_V9_L3 0x18
  310. #define SF_V9_L4 0x20
  311. #define SF_V9_L5 0x28
  312. #define SF_V9_L6 0x30
  313. #define SF_V9_L7 0x38
  314. #define SF_V9_I0 0x40
  315. #define SF_V9_I1 0x48
  316. #define SF_V9_I2 0x50
  317. #define SF_V9_I3 0x58
  318. #define SF_V9_I4 0x60
  319. #define SF_V9_I5 0x68
  320. #define SF_V9_FP 0x70
  321. #define SF_V9_PC 0x78
  322. #define SF_V9_RETP 0x80
  323. #define SF_V9_XARG0 0x88
  324. #define SF_V9_XARG1 0x90
  325. #define SF_V9_XARG2 0x98
  326. #define SF_V9_XARG3 0xa0
  327. #define SF_V9_XARG4 0xa8
  328. #define SF_V9_XARG5 0xb0
  329. #define SF_V9_XXARG 0xb8
  330. #define SF_L0 0x00
  331. #define SF_L1 0x04
  332. #define SF_L2 0x08
  333. #define SF_L3 0x0c
  334. #define SF_L4 0x10
  335. #define SF_L5 0x14
  336. #define SF_L6 0x18
  337. #define SF_L7 0x1c
  338. #define SF_I0 0x20
  339. #define SF_I1 0x24
  340. #define SF_I2 0x28
  341. #define SF_I3 0x2c
  342. #define SF_I4 0x30
  343. #define SF_I5 0x34
  344. #define SF_FP 0x38
  345. #define SF_PC 0x3c
  346. #define SF_RETP 0x40
  347. #define SF_XARG0 0x44
  348. #define SF_XARG1 0x48
  349. #define SF_XARG2 0x4c
  350. #define SF_XARG3 0x50
  351. #define SF_XARG4 0x54
  352. #define SF_XARG5 0x58
  353. #define SF_XXARG 0x5c
  354. #ifdef __KERNEL__
  355. /* global_reg_snapshot offsets */
  356. #define GR_SNAP_TSTATE 0x00
  357. #define GR_SNAP_TPC 0x08
  358. #define GR_SNAP_TNPC 0x10
  359. #define GR_SNAP_O7 0x18
  360. #define GR_SNAP_I7 0x20
  361. #define GR_SNAP_RPC 0x28
  362. #define GR_SNAP_THREAD 0x30
  363. #define GR_SNAP_PAD1 0x38
  364. #endif /* __KERNEL__ */
  365. /* Stuff for the ptrace system call */
  366. #define PTRACE_SPARC_DETACH 11
  367. #define PTRACE_GETREGS 12
  368. #define PTRACE_SETREGS 13
  369. #define PTRACE_GETFPREGS 14
  370. #define PTRACE_SETFPREGS 15
  371. #define PTRACE_READDATA 16
  372. #define PTRACE_WRITEDATA 17
  373. #define PTRACE_READTEXT 18
  374. #define PTRACE_WRITETEXT 19
  375. #define PTRACE_GETFPAREGS 20
  376. #define PTRACE_SETFPAREGS 21
  377. /* There are for debugging 64-bit processes, either from a 32 or 64 bit
  378. * parent. Thus their complements are for debugging 32-bit processes only.
  379. */
  380. #define PTRACE_GETREGS64 22
  381. #define PTRACE_SETREGS64 23
  382. /* PTRACE_SYSCALL is 24 */
  383. #define PTRACE_GETFPREGS64 25
  384. #define PTRACE_SETFPREGS64 26
  385. #endif /* !(__SPARC_PTRACE_H) */