1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Ptrace test for VMX/VSX registers in the TM Suspend context
5 * Copyright (C) 2015 Anshuman Khandual, IBM Corporation.
9 #include "ptrace-vsx.h"
14 unsigned long fp_load
[VEC_MAX
];
15 unsigned long fp_load_new
[VEC_MAX
];
16 unsigned long fp_store
[VEC_MAX
];
17 unsigned long fp_load_ckpt
[VEC_MAX
];
18 unsigned long fp_load_ckpt_new
[VEC_MAX
];
20 __attribute__((used
)) void load_vsx(void)
25 __attribute__((used
)) void load_vsx_new(void)
27 loadvsx(fp_load_new
, 0);
30 __attribute__((used
)) void load_vsx_ckpt(void)
32 loadvsx(fp_load_ckpt
, 0);
35 __attribute__((used
)) void wait_parent(void)
39 asm volatile("" : : : "memory");
44 unsigned long result
, texasr
;
47 cptr
= (int *)shmat(shm_id
, NULL
, 0);
72 "mfspr %[texasr], %[sprn_texasr];"
75 : [res
] "=r" (result
), [texasr
] "=r" (texasr
)
76 : [sprn_texasr
] "i" (SPRN_TEXASR
)
77 : "memory", "r0", "r3", "r4",
78 "r7", "r8", "r9", "r10", "r11", "lr"
86 storevsx(fp_store
, 0);
87 ret
= compare_vsx_vmx(fp_store
, fp_load_ckpt_new
);
96 int trace_tm_spd_vsx(pid_t child
)
98 unsigned long vsx
[VSX_MAX
];
99 unsigned long vmx
[VMX_MAX
+ 2][2];
101 FAIL_IF(start_trace(child
));
102 FAIL_IF(show_vsx(child
, vsx
));
103 FAIL_IF(validate_vsx(vsx
, fp_load
));
104 FAIL_IF(show_vmx(child
, vmx
));
105 FAIL_IF(validate_vmx(vmx
, fp_load
));
106 FAIL_IF(show_vsx_ckpt(child
, vsx
));
107 FAIL_IF(validate_vsx(vsx
, fp_load_ckpt
));
108 FAIL_IF(show_vmx_ckpt(child
, vmx
));
109 FAIL_IF(validate_vmx(vmx
, fp_load_ckpt
));
111 memset(vsx
, 0, sizeof(vsx
));
112 memset(vmx
, 0, sizeof(vmx
));
114 load_vsx_vmx(fp_load_ckpt_new
, vsx
, vmx
);
116 FAIL_IF(write_vsx_ckpt(child
, vsx
));
117 FAIL_IF(write_vmx_ckpt(child
, vmx
));
121 FAIL_IF(stop_trace(child
));
126 int ptrace_tm_spd_vsx(void)
131 SKIP_IF(!have_htm());
132 shm_id
= shmget(IPC_PRIVATE
, sizeof(int) * 3, 0777|IPC_CREAT
);
134 for (i
= 0; i
< 128; i
++) {
135 fp_load
[i
] = 1 + rand();
136 fp_load_new
[i
] = 1 + 2 * rand();
137 fp_load_ckpt
[i
] = 1 + 3 * rand();
138 fp_load_ckpt_new
[i
] = 1 + 4 * rand();
143 perror("fork() failed");
151 pptr
= (int *)shmat(shm_id
, NULL
, 0);
153 asm volatile("" : : : "memory");
155 ret
= trace_tm_spd_vsx(pid
);
159 shmctl(shm_id
, IPC_RMID
, NULL
);
165 shmctl(shm_id
, IPC_RMID
, NULL
);
167 printf("Child's exit status not captured\n");
171 return (WIFEXITED(status
) && WEXITSTATUS(status
)) ? TEST_FAIL
:
177 int main(int argc
, char *argv
[])
179 return test_harness(ptrace_tm_spd_vsx
, "ptrace_tm_spd_vsx");