2 * Ptrace test TM SPR registers
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.
14 /* Tracee and tracer shared data */
17 struct tm_spr_regs regs;
22 struct shared *cptr, *pptr;
27 #define TM_KVM_SCHED 0xe0000001ac000001
28 int validate_tm_spr(struct tm_spr_regs *regs)
30 FAIL_IF(regs->tm_tfhar != tfhar);
31 FAIL_IF((regs->tm_texasr == TM_KVM_SCHED) && (regs->tm_tfiar != 0));
38 unsigned long result, texasr;
41 cptr = (struct shared *)shmat(shm_id, NULL, 0);
42 cptr1 = (int *)shmat(shm_id1, NULL, 0);
48 /* TM failover handler should follow "tbegin.;" */
50 "bl 4f;" /* $ = TFHAR - 12 */
73 "mfspr %[texasr], %[sprn_texasr];"
76 : [tfhar] "=r" (tfhar), [res] "=r" (result),
77 [texasr] "=r" (texasr), [cptr1] "=r" (cptr1)
78 : [sprn_texasr] "i" (SPRN_TEXASR)
79 : "memory", "r0", "r1", "r2", "r3", "r4",
80 "r8", "r9", "r10", "r11", "r31"
83 /* There are 2 32bit instructions before tbegin. */
90 ret = validate_tm_spr((struct tm_spr_regs *)&cptr->regs);
102 int trace_tm_spr(pid_t child)
104 FAIL_IF(start_trace(child));
105 FAIL_IF(show_tm_spr(child, (struct tm_spr_regs *)&pptr->regs));
107 printf("TFHAR: %lx TEXASR: %lx TFIAR: %lx\n", pptr->regs.tm_tfhar,
108 pptr->regs.tm_texasr, pptr->regs.tm_tfiar);
111 FAIL_IF(stop_trace(child));
116 int ptrace_tm_spr(void)
121 SKIP_IF(!have_htm());
122 shm_id = shmget(IPC_PRIVATE, sizeof(struct shared), 0777|IPC_CREAT);
123 shm_id1 = shmget(IPC_PRIVATE, sizeof(int), 0777|IPC_CREAT);
126 perror("fork() failed");
134 pptr = (struct shared *)shmat(shm_id, NULL, 0);
135 pptr1 = (int *)shmat(shm_id1, NULL, 0);
138 asm volatile("" : : : "memory");
139 ret = trace_tm_spr(pid);
143 shmdt((void *)pptr1);
144 shmctl(shm_id, IPC_RMID, NULL);
145 shmctl(shm_id1, IPC_RMID, NULL);
150 shmdt((void *)pptr1);
152 shmctl(shm_id, IPC_RMID, NULL);
153 shmctl(shm_id1, IPC_RMID, NULL);
155 printf("Child's exit status not captured\n");
159 return (WIFEXITED(status) && WEXITSTATUS(status)) ? TEST_FAIL :
165 int main(int argc, char *argv[])
167 return test_harness(ptrace_tm_spr, "ptrace_tm_spr");