2 * Ptrace test for TAR, PPR, DSCR registers in the TM 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"
16 unsigned long *cptr, *pptr;
21 unsigned long result, texasr;
22 unsigned long regs[3];
25 cptr = (unsigned long *)shmat(shm_id, NULL, 0);
31 "mtspr %[sprn_tar], 4;" /* TAR_1 */
33 "mtspr %[sprn_dscr], 4;" /* DSCR_1 */
34 "or 31,31,31;" /* PPR_1*/
41 "mtspr %[sprn_tar], 4;" /* TAR_2 */
43 "mtspr %[sprn_dscr], 4;" /* DSCR_2 */
44 "or 1,1,1;" /* PPR_2 */
56 /* Transaction abort handler */
60 "mfspr %[texasr], %[sprn_texasr];"
64 : [res] "=r" (result), [texasr] "=r" (texasr)
65 : [sprn_dscr]"i"(SPRN_DSCR), [sprn_tar]"i"(SPRN_TAR),
66 [sprn_ppr]"i"(SPRN_PPR), [sprn_texasr]"i"(SPRN_TEXASR),
67 [tar_1]"i"(TAR_1), [dscr_1]"i"(DSCR_1), [tar_2]"i"(TAR_2),
68 [dscr_2]"i"(DSCR_2), [cptr1] "r" (&cptr[1])
69 : "memory", "r0", "r1", "r3", "r4", "r5", "r6"
72 /* TM failed, analyse */
77 regs[0] = mfspr(SPRN_TAR);
78 regs[1] = mfspr(SPRN_PPR);
79 regs[2] = mfspr(SPRN_DSCR);
82 printf("%-30s TAR: %lu PPR: %lx DSCR: %lu\n",
83 user_read, regs[0], regs[1], regs[2]);
85 ret = validate_tar_registers(regs, TAR_4, PPR_4, DSCR_4);
94 int trace_tm_tar(pid_t child)
96 unsigned long regs[3];
98 FAIL_IF(start_trace(child));
99 FAIL_IF(show_tar_registers(child, regs));
100 printf("%-30s TAR: %lu PPR: %lx DSCR: %lu\n",
101 ptrace_read_running, regs[0], regs[1], regs[2]);
103 FAIL_IF(validate_tar_registers(regs, TAR_2, PPR_2, DSCR_2));
104 FAIL_IF(show_tm_checkpointed_state(child, regs));
105 printf("%-30s TAR: %lu PPR: %lx DSCR: %lu\n",
106 ptrace_read_ckpt, regs[0], regs[1], regs[2]);
108 FAIL_IF(validate_tar_registers(regs, TAR_1, PPR_1, DSCR_1));
109 FAIL_IF(write_ckpt_tar_registers(child, TAR_4, PPR_4, DSCR_4));
110 printf("%-30s TAR: %u PPR: %lx DSCR: %u\n",
111 ptrace_write_ckpt, TAR_4, PPR_4, DSCR_4);
114 FAIL_IF(stop_trace(child));
118 int ptrace_tm_tar(void)
123 SKIP_IF(!have_htm());
124 shm_id = shmget(IPC_PRIVATE, sizeof(int) * 2, 0777|IPC_CREAT);
129 pptr = (unsigned long *)shmat(shm_id, NULL, 0);
134 asm volatile("" : : : "memory");
135 ret = trace_tm_tar(pid);
139 shmctl(shm_id, IPC_RMID, NULL);
145 shmctl(shm_id, IPC_RMID, NULL);
147 printf("Child's exit status not captured\n");
151 return (WIFEXITED(status) && WEXITSTATUS(status)) ? TEST_FAIL :
157 int main(int argc, char *argv[])
159 return test_harness(ptrace_tm_tar, "ptrace_tm_tar");