1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Ptrace test for VMX/VSX registers in the TM context
5 * Copyright (C) 2015 Anshuman Khandual, IBM Corporation.
9 #include "ptrace-vsx.h"
12 unsigned long *cptr, *pptr;
14 unsigned long fp_load[VEC_MAX];
15 unsigned long fp_store[VEC_MAX];
16 unsigned long fp_load_ckpt[VEC_MAX];
17 unsigned long fp_load_ckpt_new[VEC_MAX];
19 __attribute__((used)) void load_vsx(void)
24 __attribute__((used)) void load_vsx_ckpt(void)
26 loadvsx(fp_load_ckpt, 0);
31 unsigned long result, texasr;
34 cptr = (unsigned long *)shmat(shm_id, NULL, 0);
60 "mfspr %[texasr], %[sprn_texasr];"
63 : [res] "=r" (result), [texasr] "=r" (texasr)
64 : [sprn_texasr] "i" (SPRN_TEXASR), [cptr1] "b" (&cptr[1])
65 : "memory", "r0", "r1", "r3", "r4",
66 "r7", "r8", "r9", "r10", "r11"
74 storevsx(fp_store, 0);
75 ret = compare_vsx_vmx(fp_store, fp_load_ckpt_new);
84 int trace_tm_vsx(pid_t child)
86 unsigned long vsx[VSX_MAX];
87 unsigned long vmx[VMX_MAX + 2][2];
89 FAIL_IF(start_trace(child));
90 FAIL_IF(show_vsx(child, vsx));
91 FAIL_IF(validate_vsx(vsx, fp_load));
92 FAIL_IF(show_vmx(child, vmx));
93 FAIL_IF(validate_vmx(vmx, fp_load));
94 FAIL_IF(show_vsx_ckpt(child, vsx));
95 FAIL_IF(validate_vsx(vsx, fp_load_ckpt));
96 FAIL_IF(show_vmx_ckpt(child, vmx));
97 FAIL_IF(validate_vmx(vmx, fp_load_ckpt));
98 memset(vsx, 0, sizeof(vsx));
99 memset(vmx, 0, sizeof(vmx));
101 load_vsx_vmx(fp_load_ckpt_new, vsx, vmx);
103 FAIL_IF(write_vsx_ckpt(child, vsx));
104 FAIL_IF(write_vmx_ckpt(child, vmx));
106 FAIL_IF(stop_trace(child));
110 int ptrace_tm_vsx(void)
115 SKIP_IF(!have_htm());
116 shm_id = shmget(IPC_PRIVATE, sizeof(int) * 2, 0777|IPC_CREAT);
118 for (i = 0; i < 128; i++) {
119 fp_load[i] = 1 + rand();
120 fp_load_ckpt[i] = 1 + 2 * rand();
121 fp_load_ckpt_new[i] = 1 + 3 * rand();
126 perror("fork() failed");
134 pptr = (unsigned long *)shmat(shm_id, NULL, 0);
136 asm volatile("" : : : "memory");
138 ret = trace_tm_vsx(pid);
142 shmctl(shm_id, IPC_RMID, NULL);
148 shmctl(shm_id, IPC_RMID, NULL);
150 printf("Child's exit status not captured\n");
154 return (WIFEXITED(status) && WEXITSTATUS(status)) ? TEST_FAIL :
160 int main(int argc, char *argv[])
162 return test_harness(ptrace_tm_vsx, "ptrace_tm_vsx");