Bug 497723 - forgot to restore callgrind output cleanup
[valgrind.git] / none / tests / s390x / exrl.c
blob927476e819d9f6a853cb4b805dedc0dbd0bb213b
1 #include <stdio.h>
3 char buffer[] ="0123456789abcdef";
4 char target[] ="XXXXXXXXXXXXXXXX";
6 int main(void)
8 unsigned long offset;
10 setbuf(stdout, NULL);
12 printf("------- Copy 10+1 bytes from buffer to target\n");
13 printf("------- EXRL to OR in the length\n");
14 printf("before: buffer = |%s|\n", buffer);
15 printf("before: target = |%s|\n", target);
16 asm volatile( "lghi 2, 10\n\t"
17 ".insn ril,0xc60000000000,2,1f\n\t" // exrl 2, 1f
18 "j 2f\n\t"
19 "1:\n\t"
20 "mvc 0(1,%0),0(%1)\n\t"
21 "2:\n\t"
22 : : "a" (target), "a" (buffer) : "1", "2", "memory");
23 printf("after: buffer = |%s|\n", buffer);
24 printf("after: target = |%s|\n", target);
25 printf("\n");
27 printf("------- EXRL 0,... has no effect (writes out target)\n");
28 printf(" target = |");
29 asm volatile( "lghi 0, 0xff\n\t" // fill nonsense in r0
30 "lghi 2, 1\n\t" // stdout
31 "lgr 3, %0\n\t" // target
32 "lghi 4, %1\n\t" // len
33 ".insn ril,0xc60000000000,0,1f\n\t" // exrl 0, 1f
34 "j 2f\n\t"
35 "1:\n\t"
36 "svc 4\n\t" // NR_write
37 "2:\n\t"
38 : : "a" (target), "i" (sizeof target - 1)
39 : "0", "2", "3", "4");
40 printf("|\n");
41 printf("\n");
43 printf("------- EXRL to OR in the syscall number (writes out target)\n");
44 printf(" target = |");
45 asm volatile( "lghi 1, 4\n\t" // NR_write
46 "lghi 2, 1\n\t" // stdout
47 "lgr 3, %0\n\t" // target
48 "lghi 4, %1\n\t" // len
49 ".insn ril,0xc60000000000,1,1f\n\t" // exrl 1, 1f
50 "j 2f\n\t"
51 "1:\n\t"
52 "svc 0\n\t" // changed to NR_write
53 "2:\n\t"
54 : : "a" (target), "i" (sizeof target - 1)
55 : "1", "2", "3", "4");
56 printf("|\n");
57 printf("\n");
59 printf("------- EXRL with negative offset\n");
60 asm volatile( "j 2f\n\t"
61 "1:\n\t"
62 "mvc 2(1,%0),0(%0)\n\t"
63 "2:\n\t"
64 "lghi 1,8\n\t"
65 ".insn ril,0xc60000000000,1,1b\n\t" // exrl 1, 1b
66 : : "a" (target)
67 : "1", "2", "3", "4");
68 printf(" target = |%s|\n", target);
69 printf("\n");
71 printf("------- EXRL targeting a PC-relative instruction\n");
72 asm volatile( "basr 1,0\n\t"
73 "j 2f\n\t"
74 "1:\n\t"
75 "larl 2,1b\n\t"
76 "2:\n\t"
77 ".insn ril,0xc60000000000,0,1b\n\t" // exrl 0, 1b
78 "sgrk %0,2,1\n\t"
79 : "=d" (offset) :
80 : "1", "2");
81 printf(" offset = |%016lx|\n", offset);
82 printf("\n");
84 printf("------- EXRL targeting a branch-and-link instruction\n");
85 asm volatile( "1:\n\t"
86 "basr 1,0\n\t"
87 "lgr 2,1\n\t"
88 ".insn ril,0xc60000000000,0,1b\n\t" // exrl 0, 1b
89 "sgrk %0,1,2\n\t"
90 : "=&d" (offset) :
91 : "1", "2");
92 printf(" offset = |%016lx|\n", offset);
94 return 0;