3 char buffer
[] ="0123456789abcdef";
4 char target
[] ="XXXXXXXXXXXXXXXX";
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
20 "mvc 0(1,%0),0(%1)\n\t"
22 : : "a" (target
), "a" (buffer
) : "1", "2", "memory");
23 printf("after: buffer = |%s|\n", buffer
);
24 printf("after: target = |%s|\n", target
);
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
36 "svc 4\n\t" // NR_write
38 : : "a" (target
), "i" (sizeof target
- 1)
39 : "0", "2", "3", "4");
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
52 "svc 0\n\t" // changed to NR_write
54 : : "a" (target
), "i" (sizeof target
- 1)
55 : "1", "2", "3", "4");
59 printf("------- EXRL with negative offset\n");
60 asm volatile( "j 2f\n\t"
62 "mvc 2(1,%0),0(%0)\n\t"
65 ".insn ril,0xc60000000000,1,1b\n\t" // exrl 1, 1b
67 : "1", "2", "3", "4");
68 printf(" target = |%s|\n", target
);
71 printf("------- EXRL targeting a PC-relative instruction\n");
72 asm volatile( "basr 1,0\n\t"
77 ".insn ril,0xc60000000000,0,1b\n\t" // exrl 0, 1b
81 printf(" offset = |%016lx|\n", offset
);
84 printf("------- EXRL targeting a branch-and-link instruction\n");
85 asm volatile( "1:\n\t"
88 ".insn ril,0xc60000000000,0,1b\n\t" // exrl 0, 1b
92 printf(" offset = |%016lx|\n", offset
);