unicorn/tests/unit/test_s390x.c

37 lines
1.0 KiB
C
Raw Normal View History

2021-12-05 23:28:13 +03:00
#include "unicorn_test.h"
const uint64_t code_start = 0x1000;
const uint64_t code_len = 0x4000;
2021-12-28 01:59:53 +03:00
static void uc_common_setup(uc_engine **uc, uc_arch arch, uc_mode mode,
const char *code, uint64_t size)
{
OK(uc_open(arch, mode, uc));
OK(uc_mem_map(*uc, code_start, code_len, UC_PROT_ALL));
OK(uc_mem_write(*uc, code_start, code, size));
}
static void test_s390x_lr(void)
2021-12-28 01:59:53 +03:00
{
char code[] = "\x18\x23"; // lr %r2, %r3
2022-01-10 17:45:56 +03:00
uint64_t r_pc, r_r2, r_r3 = 0x114514;
2021-12-28 01:59:53 +03:00
uc_engine *uc;
uc_common_setup(&uc, UC_ARCH_S390X, UC_MODE_BIG_ENDIAN, code,
sizeof(code) - 1);
OK(uc_reg_write(uc, UC_S390X_REG_R3, &r_r3));
OK(uc_emu_start(uc, code_start, code_start + sizeof(code) - 1, 0, 0));
OK(uc_reg_read(uc, UC_S390X_REG_R2, &r_r2));
2022-01-10 17:45:56 +03:00
OK(uc_reg_read(uc, UC_S390X_REG_PC, &r_pc));
2021-12-28 01:59:53 +03:00
TEST_CHECK(r_r2 == 0x114514);
2022-01-10 17:45:56 +03:00
TEST_CHECK(r_pc == code_start + sizeof(code) - 1);
2021-12-28 01:59:53 +03:00
OK(uc_close(uc));
}
2021-12-30 01:10:21 +03:00
TEST_LIST = {{"test_s390x_lr", test_s390x_lr}, {NULL, NULL}};