/* * libbinrec: a recompiling translator for machine code * Copyright (c) 2016 Andrew Church * * This software may be copied and redistributed under certain conditions; * see the file "COPYING" in the source code distribution for details. * NO WARRANTY is provided with this software. */ #include "tests/common.h" #include "tests/host-x86/common.h" static const binrec_setup_t setup = { .host = BINREC_ARCH_X86_64_SYSV, }; static const unsigned int host_opt = BINREC_OPT_H_X86_FIXED_REGS; static int add_rtl(RTLUnit *unit) { int reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8; EXPECT(reg1 = rtl_alloc_register(unit, RTLTYPE_ADDRESS)); EXPECT(rtl_add_insn(unit, RTLOP_LOAD_IMM, reg1, 0, 0, 1)); EXPECT(reg2 = rtl_alloc_register(unit, RTLTYPE_INT32)); EXPECT(rtl_add_insn(unit, RTLOP_LOAD_IMM, reg2, 0, 0, 2)); EXPECT(reg3 = rtl_alloc_register(unit, RTLTYPE_INT32)); EXPECT(rtl_add_insn(unit, RTLOP_LOAD_IMM, reg3, 0, 0, 3)); EXPECT(reg4 = rtl_alloc_register(unit, RTLTYPE_INT32)); EXPECT(rtl_add_insn(unit, RTLOP_CMPXCHG, reg4, reg1, reg2, reg3)); EXPECT(reg5 = rtl_alloc_register(unit, RTLTYPE_INT32)); EXPECT(rtl_add_insn(unit, RTLOP_LOAD_IMM, reg5, 0, 0, 5)); EXPECT(reg6 = rtl_alloc_register(unit, RTLTYPE_INT32)); EXPECT(rtl_add_insn(unit, RTLOP_MODU, reg6, reg5, reg4, 0)); EXPECT(reg7 = rtl_alloc_register(unit, RTLTYPE_INT32)); EXPECT(rtl_add_insn(unit, RTLOP_LOAD_IMM, reg7, 0, 0, 7)); EXPECT(reg8 = rtl_alloc_register(unit, RTLTYPE_INT32)); /* reg4 should not get EAX since it's also a CMPXCHG output, or EDX * since it's the divisor in a MODU instruction. */ EXPECT(rtl_add_insn(unit, RTLOP_MULHU, reg8, reg7, reg4, 0)); return EXIT_SUCCESS; } static const uint8_t expected_code[] = { 0x41,0x57, // push %r15 0xB9,0x01,0x00,0x00,0x00, // mov $1,%ecx 0xB8,0x02,0x00,0x00,0x00, // mov $2,%eax 0xBA,0x03,0x00,0x00,0x00, // mov $3,%edx 0xF0,0x0F,0xB1,0x11, // lock cmpxchg %edx,(%rcx) 0x8B,0xF0, // mov %eax,%esi 0xB8,0x05,0x00,0x00,0x00, // mov $5,%eax 0x33,0xD2, // xor %edx,%edx 0xF7,0xF6, // div %esi 0xB8,0x07,0x00,0x00,0x00, // mov $7,%eax 0xF7,0xE6, // mul %esi 0x41,0x5F, // pop %r15 0xC3, // ret }; static const char expected_log[] = ""; #include "tests/rtl-translate-test.i"