master
c 44 lines 1.2 KB
Raw
1 /*
2 * Test that a faulting STORE CLOCK FAST does not clobber the condition code.
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 #include <assert.h>
7 #include <signal.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10
11 static void handle_sigsegv(int sig, siginfo_t *info, void *ucontext)
12 {
13 mcontext_t *mcontext = &((ucontext_t *)ucontext)->uc_mcontext;
14
15 /* The condition code must be the one set by SLGR, not garbage. */
16 _exit(((mcontext->psw.mask >> 44) & 3) == 3 ? EXIT_SUCCESS : EXIT_FAILURE);
17 }
18
19 int main(void)
20 {
21 struct sigaction act = {
22 .sa_sigaction = handle_sigsegv,
23 .sa_flags = SA_SIGINFO,
24 };
25 int err;
26
27 err = sigaction(SIGSEGV, &act, NULL);
28 assert(err == 0);
29
30 asm volatile(
31 "lghi %%r1,100\n"
32 "lghi %%r2,0\n"
33 "clgr %%r1,%%r2\n" /* CC_OP_LTUGTU_64 */
34 /* cc_src=100 is not valid for CC_OP_SUBU */
35 "ipm %%r0\n" /* force cc_src to env */
36 "lghi %%r3,5\n"
37 "lghi %%r4,3\n"
38 "slgr %%r3,%%r4\n" /* CC_OP_SUBU, cc=3 */
39 "lghi %%r5,0\n"
40 "stckf 0(%%r5)\n" /* faults; cc must stay 3 */
41 : : : "r0", "r1", "r2", "r3", "r4", "r5", "cc", "memory");
42
43 return EXIT_FAILURE;
44 }