xref: /openbmc/qemu/tests/tcg/s390x/ex-smc.c (revision e5a00700)
1 /*
2  * Test modifying an EXECUTE target.
3  *
4  * SPDX-License-Identifier: GPL-2.0-or-later
5  */
6 #include <assert.h>
7 #include <stdlib.h>
8 
9 /* Make sure we exercise the same EXECUTE instruction. */
10 extern void execute(unsigned char *insn, unsigned char mask,
11                     unsigned long *r1_r5);
12 asm(".globl execute\n"
13     "execute:\n"
14     "lg %r1,0(%r4)\n"
15     "lg %r5,8(%r4)\n"
16     "ex %r3,0(%r2)\n"
17     "stg %r5,8(%r4)\n"
18     "stg %r1,0(%r4)\n"
19     "br %r14\n");
20 
21 /* Define an RWX EXECUTE target. */
22 extern unsigned char lgfi[];
23 asm(".pushsection .rwx,\"awx\",@progbits\n"
24     ".globl lgfi\n"
25     "lgfi: lgfi %r0,0\n"
26     ".popsection\n");
27 
main(void)28 int main(void)
29 {
30     unsigned long r1_r5[2];
31 
32     /* Create an initial TB. */
33     r1_r5[0] = -1;
34     r1_r5[1] = -1;
35     execute(lgfi, 1 << 4, r1_r5);
36     assert(r1_r5[0] == 0);
37     assert(r1_r5[1] == -1);
38 
39     /* Test changing the mask. */
40     execute(lgfi, 5 << 4, r1_r5);
41     assert(r1_r5[0] == 0);
42     assert(r1_r5[1] == 0);
43 
44     /* Test changing the target. */
45     lgfi[5] = 42;
46     execute(lgfi, 5 << 4, r1_r5);
47     assert(r1_r5[0] == 0);
48     assert(r1_r5[1] == 42);
49 
50     /* Test changing both the mask and the target. */
51     lgfi[5] = 24;
52     execute(lgfi, 1 << 4, r1_r5);
53     assert(r1_r5[0] == 24);
54     assert(r1_r5[1] == 42);
55 
56     return EXIT_SUCCESS;
57 }
58