6 #define DEFINE_ASM(_name, _code) \
7 extern const char _name[]; \
8 extern const char _name ## _end[]; \
9 asm(" .globl " #_name "\n" \
12 " .globl " #_name "_end\n" \
15 DEFINE_ASM(br_r14
, "br %r14");
16 DEFINE_ASM(brasl_r0
, "brasl %r0,-0x100000000");
17 DEFINE_ASM(brcl_0xf
, "brcl 0xf,-0x100000000");
24 static const struct test tests
[] = {
27 .code_end
= brasl_r0_end
,
31 .code_end
= brcl_0xf_end
,
41 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++) {
42 size_t test_length
= 0x100000000 + (tests
[i
].code_end
- tests
[i
].code
);
44 if (test_length
> length
) {
49 buf
= mmap(NULL
, length
, PROT_READ
| PROT_WRITE
| PROT_EXEC
,
50 MAP_PRIVATE
| MAP_ANONYMOUS
| MAP_NORESERVE
, -1, 0);
51 if (buf
== MAP_FAILED
) {
52 perror("SKIP: mmap() failed");
56 memcpy(buf
, br_r14
, br_r14_end
- br_r14
);
57 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++) {
58 void (*code
)(void) = (void *)(buf
+ 0x100000000);
60 memcpy(code
, tests
[i
].code
, tests
[i
].code_end
- tests
[i
].code
);
62 memset(code
, 0, tests
[i
].code_end
- tests
[i
].code
);