ptrace.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. /*
  2. * S390 version
  3. * Copyright IBM Corp. 1999, 2000
  4. * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
  5. */
  6. #ifndef _S390_PTRACE_H
  7. #define _S390_PTRACE_H
  8. /*
  9. * Offsets in the user_regs_struct. They are used for the ptrace
  10. * system call and in entry.S
  11. */
  12. #ifndef __s390x__
  13. #define PT_PSWMASK 0x00
  14. #define PT_PSWADDR 0x04
  15. #define PT_GPR0 0x08
  16. #define PT_GPR1 0x0C
  17. #define PT_GPR2 0x10
  18. #define PT_GPR3 0x14
  19. #define PT_GPR4 0x18
  20. #define PT_GPR5 0x1C
  21. #define PT_GPR6 0x20
  22. #define PT_GPR7 0x24
  23. #define PT_GPR8 0x28
  24. #define PT_GPR9 0x2C
  25. #define PT_GPR10 0x30
  26. #define PT_GPR11 0x34
  27. #define PT_GPR12 0x38
  28. #define PT_GPR13 0x3C
  29. #define PT_GPR14 0x40
  30. #define PT_GPR15 0x44
  31. #define PT_ACR0 0x48
  32. #define PT_ACR1 0x4C
  33. #define PT_ACR2 0x50
  34. #define PT_ACR3 0x54
  35. #define PT_ACR4 0x58
  36. #define PT_ACR5 0x5C
  37. #define PT_ACR6 0x60
  38. #define PT_ACR7 0x64
  39. #define PT_ACR8 0x68
  40. #define PT_ACR9 0x6C
  41. #define PT_ACR10 0x70
  42. #define PT_ACR11 0x74
  43. #define PT_ACR12 0x78
  44. #define PT_ACR13 0x7C
  45. #define PT_ACR14 0x80
  46. #define PT_ACR15 0x84
  47. #define PT_ORIGGPR2 0x88
  48. #define PT_FPC 0x90
  49. /*
  50. * A nasty fact of life that the ptrace api
  51. * only supports passing of longs.
  52. */
  53. #define PT_FPR0_HI 0x98
  54. #define PT_FPR0_LO 0x9C
  55. #define PT_FPR1_HI 0xA0
  56. #define PT_FPR1_LO 0xA4
  57. #define PT_FPR2_HI 0xA8
  58. #define PT_FPR2_LO 0xAC
  59. #define PT_FPR3_HI 0xB0
  60. #define PT_FPR3_LO 0xB4
  61. #define PT_FPR4_HI 0xB8
  62. #define PT_FPR4_LO 0xBC
  63. #define PT_FPR5_HI 0xC0
  64. #define PT_FPR5_LO 0xC4
  65. #define PT_FPR6_HI 0xC8
  66. #define PT_FPR6_LO 0xCC
  67. #define PT_FPR7_HI 0xD0
  68. #define PT_FPR7_LO 0xD4
  69. #define PT_FPR8_HI 0xD8
  70. #define PT_FPR8_LO 0XDC
  71. #define PT_FPR9_HI 0xE0
  72. #define PT_FPR9_LO 0xE4
  73. #define PT_FPR10_HI 0xE8
  74. #define PT_FPR10_LO 0xEC
  75. #define PT_FPR11_HI 0xF0
  76. #define PT_FPR11_LO 0xF4
  77. #define PT_FPR12_HI 0xF8
  78. #define PT_FPR12_LO 0xFC
  79. #define PT_FPR13_HI 0x100
  80. #define PT_FPR13_LO 0x104
  81. #define PT_FPR14_HI 0x108
  82. #define PT_FPR14_LO 0x10C
  83. #define PT_FPR15_HI 0x110
  84. #define PT_FPR15_LO 0x114
  85. #define PT_CR_9 0x118
  86. #define PT_CR_10 0x11C
  87. #define PT_CR_11 0x120
  88. #define PT_IEEE_IP 0x13C
  89. #define PT_LASTOFF PT_IEEE_IP
  90. #define PT_ENDREGS 0x140-1
  91. #define GPR_SIZE 4
  92. #define CR_SIZE 4
  93. #define STACK_FRAME_OVERHEAD 96 /* size of minimum stack frame */
  94. #else /* __s390x__ */
  95. #define PT_PSWMASK 0x00
  96. #define PT_PSWADDR 0x08
  97. #define PT_GPR0 0x10
  98. #define PT_GPR1 0x18
  99. #define PT_GPR2 0x20
  100. #define PT_GPR3 0x28
  101. #define PT_GPR4 0x30
  102. #define PT_GPR5 0x38
  103. #define PT_GPR6 0x40
  104. #define PT_GPR7 0x48
  105. #define PT_GPR8 0x50
  106. #define PT_GPR9 0x58
  107. #define PT_GPR10 0x60
  108. #define PT_GPR11 0x68
  109. #define PT_GPR12 0x70
  110. #define PT_GPR13 0x78
  111. #define PT_GPR14 0x80
  112. #define PT_GPR15 0x88
  113. #define PT_ACR0 0x90
  114. #define PT_ACR1 0x94
  115. #define PT_ACR2 0x98
  116. #define PT_ACR3 0x9C
  117. #define PT_ACR4 0xA0
  118. #define PT_ACR5 0xA4
  119. #define PT_ACR6 0xA8
  120. #define PT_ACR7 0xAC
  121. #define PT_ACR8 0xB0
  122. #define PT_ACR9 0xB4
  123. #define PT_ACR10 0xB8
  124. #define PT_ACR11 0xBC
  125. #define PT_ACR12 0xC0
  126. #define PT_ACR13 0xC4
  127. #define PT_ACR14 0xC8
  128. #define PT_ACR15 0xCC
  129. #define PT_ORIGGPR2 0xD0
  130. #define PT_FPC 0xD8
  131. #define PT_FPR0 0xE0
  132. #define PT_FPR1 0xE8
  133. #define PT_FPR2 0xF0
  134. #define PT_FPR3 0xF8
  135. #define PT_FPR4 0x100
  136. #define PT_FPR5 0x108
  137. #define PT_FPR6 0x110
  138. #define PT_FPR7 0x118
  139. #define PT_FPR8 0x120
  140. #define PT_FPR9 0x128
  141. #define PT_FPR10 0x130
  142. #define PT_FPR11 0x138
  143. #define PT_FPR12 0x140
  144. #define PT_FPR13 0x148
  145. #define PT_FPR14 0x150
  146. #define PT_FPR15 0x158
  147. #define PT_CR_9 0x160
  148. #define PT_CR_10 0x168
  149. #define PT_CR_11 0x170
  150. #define PT_IEEE_IP 0x1A8
  151. #define PT_LASTOFF PT_IEEE_IP
  152. #define PT_ENDREGS 0x1B0-1
  153. #define GPR_SIZE 8
  154. #define CR_SIZE 8
  155. #define STACK_FRAME_OVERHEAD 160 /* size of minimum stack frame */
  156. #endif /* __s390x__ */
  157. #define NUM_GPRS 16
  158. #define NUM_FPRS 16
  159. #define NUM_CRS 16
  160. #define NUM_ACRS 16
  161. #define NUM_CR_WORDS 3
  162. #define FPR_SIZE 8
  163. #define FPC_SIZE 4
  164. #define FPC_PAD_SIZE 4 /* gcc insists on aligning the fpregs */
  165. #define ACR_SIZE 4
  166. #define PTRACE_OLDSETOPTIONS 21
  167. #ifndef __ASSEMBLY__
  168. #include <linux/stddef.h>
  169. #include <linux/types.h>
  170. typedef union
  171. {
  172. float f;
  173. double d;
  174. __u64 ui;
  175. struct
  176. {
  177. __u32 hi;
  178. __u32 lo;
  179. } fp;
  180. } freg_t;
  181. typedef struct
  182. {
  183. __u32 fpc;
  184. freg_t fprs[NUM_FPRS];
  185. } s390_fp_regs;
  186. #define FPC_EXCEPTION_MASK 0xF8000000
  187. #define FPC_FLAGS_MASK 0x00F80000
  188. #define FPC_DXC_MASK 0x0000FF00
  189. #define FPC_RM_MASK 0x00000003
  190. #define FPC_VALID_MASK 0xF8F8FF03
  191. /* this typedef defines how a Program Status Word looks like */
  192. typedef struct
  193. {
  194. unsigned long mask;
  195. unsigned long addr;
  196. } __attribute__ ((aligned(8))) psw_t;
  197. typedef struct
  198. {
  199. __u32 mask;
  200. __u32 addr;
  201. } __attribute__ ((aligned(8))) psw_compat_t;
  202. #ifndef __s390x__
  203. #define PSW_MASK_PER 0x40000000UL
  204. #define PSW_MASK_DAT 0x04000000UL
  205. #define PSW_MASK_IO 0x02000000UL
  206. #define PSW_MASK_EXT 0x01000000UL
  207. #define PSW_MASK_KEY 0x00F00000UL
  208. #define PSW_MASK_BASE 0x00080000UL /* always one */
  209. #define PSW_MASK_MCHECK 0x00040000UL
  210. #define PSW_MASK_WAIT 0x00020000UL
  211. #define PSW_MASK_PSTATE 0x00010000UL
  212. #define PSW_MASK_ASC 0x0000C000UL
  213. #define PSW_MASK_CC 0x00003000UL
  214. #define PSW_MASK_PM 0x00000F00UL
  215. #define PSW_MASK_EA 0x00000000UL
  216. #define PSW_MASK_BA 0x00000000UL
  217. #define PSW_MASK_USER 0x00003F00UL
  218. #define PSW_ADDR_AMODE 0x80000000UL
  219. #define PSW_ADDR_INSN 0x7FFFFFFFUL
  220. #define PSW_DEFAULT_KEY (((unsigned long) PAGE_DEFAULT_ACC) << 20)
  221. #define PSW_ASC_PRIMARY 0x00000000UL
  222. #define PSW_ASC_ACCREG 0x00004000UL
  223. #define PSW_ASC_SECONDARY 0x00008000UL
  224. #define PSW_ASC_HOME 0x0000C000UL
  225. #else /* __s390x__ */
  226. #define PSW_MASK_PER 0x4000000000000000UL
  227. #define PSW_MASK_DAT 0x0400000000000000UL
  228. #define PSW_MASK_IO 0x0200000000000000UL
  229. #define PSW_MASK_EXT 0x0100000000000000UL
  230. #define PSW_MASK_BASE 0x0000000000000000UL
  231. #define PSW_MASK_KEY 0x00F0000000000000UL
  232. #define PSW_MASK_MCHECK 0x0004000000000000UL
  233. #define PSW_MASK_WAIT 0x0002000000000000UL
  234. #define PSW_MASK_PSTATE 0x0001000000000000UL
  235. #define PSW_MASK_ASC 0x0000C00000000000UL
  236. #define PSW_MASK_CC 0x0000300000000000UL
  237. #define PSW_MASK_PM 0x00000F0000000000UL
  238. #define PSW_MASK_EA 0x0000000100000000UL
  239. #define PSW_MASK_BA 0x0000000080000000UL
  240. #define PSW_MASK_USER 0x00003F0180000000UL
  241. #define PSW_ADDR_AMODE 0x0000000000000000UL
  242. #define PSW_ADDR_INSN 0xFFFFFFFFFFFFFFFFUL
  243. #define PSW_DEFAULT_KEY (((unsigned long) PAGE_DEFAULT_ACC) << 52)
  244. #define PSW_ASC_PRIMARY 0x0000000000000000UL
  245. #define PSW_ASC_ACCREG 0x0000400000000000UL
  246. #define PSW_ASC_SECONDARY 0x0000800000000000UL
  247. #define PSW_ASC_HOME 0x0000C00000000000UL
  248. #endif /* __s390x__ */
  249. #ifdef __KERNEL__
  250. extern long psw_kernel_bits;
  251. extern long psw_user_bits;
  252. #endif
  253. /*
  254. * The s390_regs structure is used to define the elf_gregset_t.
  255. */
  256. typedef struct
  257. {
  258. psw_t psw;
  259. unsigned long gprs[NUM_GPRS];
  260. unsigned int acrs[NUM_ACRS];
  261. unsigned long orig_gpr2;
  262. } s390_regs;
  263. typedef struct
  264. {
  265. psw_compat_t psw;
  266. __u32 gprs[NUM_GPRS];
  267. __u32 acrs[NUM_ACRS];
  268. __u32 orig_gpr2;
  269. } s390_compat_regs;
  270. typedef struct
  271. {
  272. __u32 gprs_high[NUM_GPRS];
  273. } s390_compat_regs_high;
  274. #ifdef __KERNEL__
  275. /*
  276. * The pt_regs struct defines the way the registers are stored on
  277. * the stack during a system call.
  278. */
  279. struct pt_regs
  280. {
  281. unsigned long args[1];
  282. psw_t psw;
  283. unsigned long gprs[NUM_GPRS];
  284. unsigned long orig_gpr2;
  285. unsigned int int_code;
  286. unsigned long int_parm_long;
  287. };
  288. /*
  289. * Program event recording (PER) register set.
  290. */
  291. struct per_regs {
  292. unsigned long control; /* PER control bits */
  293. unsigned long start; /* PER starting address */
  294. unsigned long end; /* PER ending address */
  295. };
  296. /*
  297. * PER event contains information about the cause of the last PER exception.
  298. */
  299. struct per_event {
  300. unsigned short cause; /* PER code, ATMID and AI */
  301. unsigned long address; /* PER address */
  302. unsigned char paid; /* PER access identification */
  303. };
  304. /*
  305. * Simplified per_info structure used to decode the ptrace user space ABI.
  306. */
  307. struct per_struct_kernel {
  308. unsigned long cr9; /* PER control bits */
  309. unsigned long cr10; /* PER starting address */
  310. unsigned long cr11; /* PER ending address */
  311. unsigned long bits; /* Obsolete software bits */
  312. unsigned long starting_addr; /* User specified start address */
  313. unsigned long ending_addr; /* User specified end address */
  314. unsigned short perc_atmid; /* PER trap ATMID */
  315. unsigned long address; /* PER trap instruction address */
  316. unsigned char access_id; /* PER trap access identification */
  317. };
  318. #define PER_EVENT_MASK 0xE9000000UL
  319. #define PER_EVENT_BRANCH 0x80000000UL
  320. #define PER_EVENT_IFETCH 0x40000000UL
  321. #define PER_EVENT_STORE 0x20000000UL
  322. #define PER_EVENT_STORE_REAL 0x08000000UL
  323. #define PER_EVENT_NULLIFICATION 0x01000000UL
  324. #define PER_CONTROL_MASK 0x00a00000UL
  325. #define PER_CONTROL_BRANCH_ADDRESS 0x00800000UL
  326. #define PER_CONTROL_ALTERATION 0x00200000UL
  327. #endif
  328. /*
  329. * Now for the user space program event recording (trace) definitions.
  330. * The following structures are used only for the ptrace interface, don't
  331. * touch or even look at it if you don't want to modify the user-space
  332. * ptrace interface. In particular stay away from it for in-kernel PER.
  333. */
  334. typedef struct
  335. {
  336. unsigned long cr[NUM_CR_WORDS];
  337. } per_cr_words;
  338. #define PER_EM_MASK 0xE8000000UL
  339. typedef struct
  340. {
  341. #ifdef __s390x__
  342. unsigned : 32;
  343. #endif /* __s390x__ */
  344. unsigned em_branching : 1;
  345. unsigned em_instruction_fetch : 1;
  346. /*
  347. * Switching on storage alteration automatically fixes
  348. * the storage alteration event bit in the users std.
  349. */
  350. unsigned em_storage_alteration : 1;
  351. unsigned em_gpr_alt_unused : 1;
  352. unsigned em_store_real_address : 1;
  353. unsigned : 3;
  354. unsigned branch_addr_ctl : 1;
  355. unsigned : 1;
  356. unsigned storage_alt_space_ctl : 1;
  357. unsigned : 21;
  358. unsigned long starting_addr;
  359. unsigned long ending_addr;
  360. } per_cr_bits;
  361. typedef struct
  362. {
  363. unsigned short perc_atmid;
  364. unsigned long address;
  365. unsigned char access_id;
  366. } per_lowcore_words;
  367. typedef struct
  368. {
  369. unsigned perc_branching : 1;
  370. unsigned perc_instruction_fetch : 1;
  371. unsigned perc_storage_alteration : 1;
  372. unsigned perc_gpr_alt_unused : 1;
  373. unsigned perc_store_real_address : 1;
  374. unsigned : 3;
  375. unsigned atmid_psw_bit_31 : 1;
  376. unsigned atmid_validity_bit : 1;
  377. unsigned atmid_psw_bit_32 : 1;
  378. unsigned atmid_psw_bit_5 : 1;
  379. unsigned atmid_psw_bit_16 : 1;
  380. unsigned atmid_psw_bit_17 : 1;
  381. unsigned si : 2;
  382. unsigned long address;
  383. unsigned : 4;
  384. unsigned access_id : 4;
  385. } per_lowcore_bits;
  386. typedef struct
  387. {
  388. union {
  389. per_cr_words words;
  390. per_cr_bits bits;
  391. } control_regs;
  392. /*
  393. * Use these flags instead of setting em_instruction_fetch
  394. * directly they are used so that single stepping can be
  395. * switched on & off while not affecting other tracing
  396. */
  397. unsigned single_step : 1;
  398. unsigned instruction_fetch : 1;
  399. unsigned : 30;
  400. /*
  401. * These addresses are copied into cr10 & cr11 if single
  402. * stepping is switched off
  403. */
  404. unsigned long starting_addr;
  405. unsigned long ending_addr;
  406. union {
  407. per_lowcore_words words;
  408. per_lowcore_bits bits;
  409. } lowcore;
  410. } per_struct;
  411. typedef struct
  412. {
  413. unsigned int len;
  414. unsigned long kernel_addr;
  415. unsigned long process_addr;
  416. } ptrace_area;
  417. /*
  418. * S/390 specific non posix ptrace requests. I chose unusual values so
  419. * they are unlikely to clash with future ptrace definitions.
  420. */
  421. #define PTRACE_PEEKUSR_AREA 0x5000
  422. #define PTRACE_POKEUSR_AREA 0x5001
  423. #define PTRACE_PEEKTEXT_AREA 0x5002
  424. #define PTRACE_PEEKDATA_AREA 0x5003
  425. #define PTRACE_POKETEXT_AREA 0x5004
  426. #define PTRACE_POKEDATA_AREA 0x5005
  427. #define PTRACE_GET_LAST_BREAK 0x5006
  428. #define PTRACE_PEEK_SYSTEM_CALL 0x5007
  429. #define PTRACE_POKE_SYSTEM_CALL 0x5008
  430. /*
  431. * PT_PROT definition is loosely based on hppa bsd definition in
  432. * gdb/hppab-nat.c
  433. */
  434. #define PTRACE_PROT 21
  435. typedef enum
  436. {
  437. ptprot_set_access_watchpoint,
  438. ptprot_set_write_watchpoint,
  439. ptprot_disable_watchpoint
  440. } ptprot_flags;
  441. typedef struct
  442. {
  443. unsigned long lowaddr;
  444. unsigned long hiaddr;
  445. ptprot_flags prot;
  446. } ptprot_area;
  447. /* Sequence of bytes for breakpoint illegal instruction. */
  448. #define S390_BREAKPOINT {0x0,0x1}
  449. #define S390_BREAKPOINT_U16 ((__u16)0x0001)
  450. #define S390_SYSCALL_OPCODE ((__u16)0x0a00)
  451. #define S390_SYSCALL_SIZE 2
  452. /*
  453. * The user_regs_struct defines the way the user registers are
  454. * store on the stack for signal handling.
  455. */
  456. struct user_regs_struct
  457. {
  458. psw_t psw;
  459. unsigned long gprs[NUM_GPRS];
  460. unsigned int acrs[NUM_ACRS];
  461. unsigned long orig_gpr2;
  462. s390_fp_regs fp_regs;
  463. /*
  464. * These per registers are in here so that gdb can modify them
  465. * itself as there is no "official" ptrace interface for hardware
  466. * watchpoints. This is the way intel does it.
  467. */
  468. per_struct per_info;
  469. unsigned long ieee_instruction_pointer; /* obsolete, always 0 */
  470. };
  471. #ifdef __KERNEL__
  472. /*
  473. * These are defined as per linux/ptrace.h, which see.
  474. */
  475. #define arch_has_single_step() (1)
  476. #define user_mode(regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0)
  477. #define instruction_pointer(regs) ((regs)->psw.addr & PSW_ADDR_INSN)
  478. #define user_stack_pointer(regs)((regs)->gprs[15])
  479. #define profile_pc(regs) instruction_pointer(regs)
  480. static inline long regs_return_value(struct pt_regs *regs)
  481. {
  482. return regs->gprs[2];
  483. }
  484. int regs_query_register_offset(const char *name);
  485. const char *regs_query_register_name(unsigned int offset);
  486. unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset);
  487. unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n);
  488. static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
  489. {
  490. return regs->gprs[15] & PSW_ADDR_INSN;
  491. }
  492. #endif /* __KERNEL__ */
  493. #endif /* __ASSEMBLY__ */
  494. #endif /* _S390_PTRACE_H */