2 * Ptrace test for TAR, PPR, DSCR registers in the TM Suspend context
4 * Copyright (C) 2015 Anshuman Khandual, IBM Corporation.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
13 #include "ptrace-tar.h"
18 __attribute__((used)) void wait_parent(void)
22 asm volatile("" : : : "memory");
27 unsigned long result, texasr;
28 unsigned long regs[3];
31 cptr = (int *)shmat(shm_id, NULL, 0);
37 "mtspr %[sprn_tar], 4;" /* TAR_1 */
39 "mtspr %[sprn_dscr], 4;" /* DSCR_1 */
40 "or 31,31,31;" /* PPR_1*/
47 "mtspr %[sprn_tar], 4;" /* TAR_2 */
49 "mtspr %[sprn_dscr], 4;" /* DSCR_2 */
50 "or 1,1,1;" /* PPR_2 */
54 "mtspr %[sprn_tar], 4;" /* TAR_3 */
56 "mtspr %[sprn_dscr], 4;" /* DSCR_3 */
57 "or 6,6,6;" /* PPR_3 */
66 /* Transaction abort handler */
70 "mfspr %[texasr], %[sprn_texasr];"
74 : [res] "=r" (result), [texasr] "=r" (texasr)
75 : [val] "r" (cptr[1]), [sprn_dscr]"i"(SPRN_DSCR),
76 [sprn_tar]"i"(SPRN_TAR), [sprn_ppr]"i"(SPRN_PPR),
77 [sprn_texasr]"i"(SPRN_TEXASR), [tar_1]"i"(TAR_1),
78 [dscr_1]"i"(DSCR_1), [tar_2]"i"(TAR_2), [dscr_2]"i"(DSCR_2),
79 [tar_3]"i"(TAR_3), [dscr_3]"i"(DSCR_3)
80 : "memory", "r0", "r1", "r3", "r4", "r5", "r6"
83 /* TM failed, analyse */
88 regs[0] = mfspr(SPRN_TAR);
89 regs[1] = mfspr(SPRN_PPR);
90 regs[2] = mfspr(SPRN_DSCR);
93 printf("%-30s TAR: %lu PPR: %lx DSCR: %lu\n",
94 user_read, regs[0], regs[1], regs[2]);
96 ret = validate_tar_registers(regs, TAR_4, PPR_4, DSCR_4);
105 int trace_tm_spd_tar(pid_t child)
107 unsigned long regs[3];
109 FAIL_IF(start_trace(child));
110 FAIL_IF(show_tar_registers(child, regs));
111 printf("%-30s TAR: %lu PPR: %lx DSCR: %lu\n",
112 ptrace_read_running, regs[0], regs[1], regs[2]);
114 FAIL_IF(validate_tar_registers(regs, TAR_3, PPR_3, DSCR_3));
115 FAIL_IF(show_tm_checkpointed_state(child, regs));
116 printf("%-30s TAR: %lu PPR: %lx DSCR: %lu\n",
117 ptrace_read_ckpt, regs[0], regs[1], regs[2]);
119 FAIL_IF(validate_tar_registers(regs, TAR_1, PPR_1, DSCR_1));
120 FAIL_IF(write_ckpt_tar_registers(child, TAR_4, PPR_4, DSCR_4));
121 printf("%-30s TAR: %u PPR: %lx DSCR: %u\n",
122 ptrace_write_ckpt, TAR_4, PPR_4, DSCR_4);
126 FAIL_IF(stop_trace(child));
130 int ptrace_tm_spd_tar(void)
135 SKIP_IF(!have_htm());
136 shm_id = shmget(IPC_PRIVATE, sizeof(int) * 3, 0777|IPC_CREAT);
141 pptr = (int *)shmat(shm_id, NULL, 0);
147 asm volatile("" : : : "memory");
148 ret = trace_tm_spd_tar(pid);
152 shmctl(shm_id, IPC_RMID, NULL);
159 shmctl(shm_id, IPC_RMID, NULL);
161 printf("Child's exit status not captured\n");
165 return (WIFEXITED(status) && WEXITSTATUS(status)) ? TEST_FAIL :
171 int main(int argc, char *argv[])
173 return test_harness(ptrace_tm_spd_tar, "ptrace_tm_spd_tar");