From da63e8df700520ad396b754427f90ef92cc2425d Mon Sep 17 00:00:00 2001 From: iximeow Date: Sun, 1 Dec 2019 05:15:59 -0800 Subject: down to one failing test, for now --- src/lib.rs | 61 +++++++++++++++++++++++++++++++++++++++++++----------------- test/test.rs | 24 +++++++++++++++++++----- 2 files changed, 63 insertions(+), 22 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 815f51b..c827dfb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1134,7 +1134,6 @@ pub enum OperandCode { Yv_AX, Yv_Xv, G_E_q, - G_U_mm, G_M_q, E_G_q, Rv_Gmm_Ib, @@ -1238,6 +1237,7 @@ pub enum OperandCode { E_G_mm = 0xeb, G_xmm_E_mm = 0xed, G_xmm_Edq = 0xef, + G_U_mm = 0xf1, } fn base_opcode_map(v: u8) -> Opcode { @@ -2247,22 +2247,22 @@ const OPCODE_0F_MAP: [OpcodeRecord; 256] = [ OpcodeRecord(Interpretation::Instruction(Opcode::PUNPCKLBW), OperandCode::G_E_mm), OpcodeRecord(Interpretation::Instruction(Opcode::PUNPCKLWD), OperandCode::G_E_mm), OpcodeRecord(Interpretation::Instruction(Opcode::PUNPCKLDQ), OperandCode::G_E_mm), - OpcodeRecord(Interpretation::Instruction(Opcode::PACKSSWB), OperandCode::Unsupported), - OpcodeRecord(Interpretation::Instruction(Opcode::PCMPGTB), OperandCode::Unsupported), - OpcodeRecord(Interpretation::Instruction(Opcode::PCMPGTW), OperandCode::Unsupported), - OpcodeRecord(Interpretation::Instruction(Opcode::PCMPGTD), OperandCode::Unsupported), - OpcodeRecord(Interpretation::Instruction(Opcode::PACKUSWB), OperandCode::Unsupported), - OpcodeRecord(Interpretation::Instruction(Opcode::PUNPCKHBW), OperandCode::Unsupported), - OpcodeRecord(Interpretation::Instruction(Opcode::PUNPCKHWD), OperandCode::Unsupported), - OpcodeRecord(Interpretation::Instruction(Opcode::PUNPCKHDQ), OperandCode::Unsupported), - OpcodeRecord(Interpretation::Instruction(Opcode::PACKSSDW), OperandCode::Unsupported), + OpcodeRecord(Interpretation::Instruction(Opcode::PACKSSWB), OperandCode::G_E_mm), + OpcodeRecord(Interpretation::Instruction(Opcode::PCMPGTB), OperandCode::G_E_mm), + OpcodeRecord(Interpretation::Instruction(Opcode::PCMPGTW), OperandCode::G_E_mm), + OpcodeRecord(Interpretation::Instruction(Opcode::PCMPGTD), OperandCode::G_E_mm), + OpcodeRecord(Interpretation::Instruction(Opcode::PACKUSWB), OperandCode::G_E_mm), + OpcodeRecord(Interpretation::Instruction(Opcode::PUNPCKHBW), OperandCode::G_E_mm), + OpcodeRecord(Interpretation::Instruction(Opcode::PUNPCKHWD), OperandCode::G_E_mm), + OpcodeRecord(Interpretation::Instruction(Opcode::PUNPCKHDQ), OperandCode::G_E_mm), + OpcodeRecord(Interpretation::Instruction(Opcode::PACKSSDW), OperandCode::G_E_mm), OpcodeRecord(Interpretation::Instruction(Opcode::Invalid), OperandCode::Nothing), OpcodeRecord(Interpretation::Instruction(Opcode::Invalid), OperandCode::Nothing), OpcodeRecord(Interpretation::Instruction(Opcode::MOVD), OperandCode::G_mm_Edq), OpcodeRecord(Interpretation::Instruction(Opcode::MOVQ), OperandCode::G_mm_E), // 0x70 - OpcodeRecord(Interpretation::Instruction(Opcode::PSHUFW), OperandCode::Unsupported), + OpcodeRecord(Interpretation::Instruction(Opcode::PSHUFW), OperandCode::G_E_xmm_Ib), OpcodeRecord(Interpretation::Instruction(Opcode::Invalid), OperandCode::ModRM_0x0f71), OpcodeRecord(Interpretation::Instruction(Opcode::Invalid), OperandCode::ModRM_0x0f72), OpcodeRecord(Interpretation::Instruction(Opcode::Invalid), OperandCode::ModRM_0x0f73), @@ -3444,27 +3444,54 @@ pub fn read_operands>(mut bytes_iter: T, instruction: &mut instruction.operand_count = 2; }, OperandCode::G_E_mm => { + instruction.operands[1] = mem_oper; + instruction.modrm_rrr.bank = RegisterBank::MM; + instruction.modrm_rrr.num &= 0b111; + if mem_oper == OperandSpec::RegMMM { + instruction.modrm_mmm.bank = RegisterBank::MM; + instruction.modrm_mmm.num &= 0b111; + } + instruction.operand_count = 2; + }, + OperandCode::G_U_mm => { + instruction.operands[1] = mem_oper; + instruction.modrm_rrr.bank = RegisterBank::D; + if mem_oper != OperandSpec::RegMMM { + return Err(()); + } + instruction.modrm_mmm.bank = RegisterBank::MM; + instruction.modrm_mmm.num &= 0b111; + instruction.operand_count = 2; + }, + OperandCode::G_E_xmm => { let modrm = read_modrm(&mut bytes_iter, instruction, length)?; bytes_read = 1; // println!("mod_bits: {:2b}, r: {:3b}, m: {:3b}", mod_bits, r, m); instruction.operands[1] = read_E_xmm(&mut bytes_iter, instruction, modrm, length)?; instruction.modrm_rrr = - RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.rex().r(), RegisterBank::MM); + RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.rex().r(), RegisterBank::X); instruction.operands[0] = OperandSpec::RegRRR; instruction.operand_count = 2; }, - OperandCode::G_E_xmm => { + OperandCode::G_mm_Ew_Ib => { let modrm = read_modrm(&mut bytes_iter, instruction, length)?; bytes_read = 1; // println!("mod_bits: {:2b}, r: {:3b}, m: {:3b}", mod_bits, r, m); - instruction.operands[1] = read_E_xmm(&mut bytes_iter, instruction, modrm, length)?; + instruction.operands[1] = read_E(&mut bytes_iter, instruction, modrm, 4, length)?; instruction.modrm_rrr = - RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.rex().r(), RegisterBank::X); + RegSpec::from_parts((modrm >> 3) & 7, false, RegisterBank::MM); instruction.operands[0] = OperandSpec::RegRRR; - instruction.operand_count = 2; - }, + if instruction.operands[1] == OperandSpec::RegMMM { + instruction.modrm_mmm.bank = RegisterBank::D; + } + instruction.imm = + read_num(&mut bytes_iter, 1)? as u8 as u64; + *length += 1; + instruction.operands[2] = OperandSpec::ImmI8; + instruction.operand_count = 3; + } OperandCode::AL_Ib => { instruction.modrm_rrr = RegSpec::al(); diff --git a/test/test.rs b/test/test.rs index 4fd08c1..e3ffa30 100644 --- a/test/test.rs +++ b/test/test.rs @@ -52,9 +52,9 @@ fn test_mmx() { test_display(&[0x4f, 0x0f, 0x7f, 0xcf], "movq mm7, mm1"); test_display(&[0x0f, 0xc4, 0xc0, 0x14], "pinsrw mm0, eax, 0x14"); test_display(&[0x4f, 0x0f, 0xc4, 0xc0, 0x14], "pinsrw mm0, r8d, 0x14"); - test_display(&[0x4f, 0x0f, 0xc4, 0x00, 0x14], "pinsrw mm0, word [r8], 0x14"); + test_display(&[0x4f, 0x0f, 0xc4, 0x00, 0x14], "pinsrw mm0, [r8], 0x14"); test_display(&[0x4f, 0x0f, 0xd1, 0xcf], "psrlw mm1, mm7"); - test_display(&[0x4f, 0x0f, 0xd1, 0x00], "psrlw mm0, qword [r8]"); + test_display(&[0x4f, 0x0f, 0xd1, 0x00], "psrlw mm0, [r8]"); test_invalid(&[0x4f, 0x0f, 0xd7, 0x00]); test_display(&[0x4f, 0x0f, 0xd7, 0xcf], "pmovmskb r9d, mm7"); } @@ -338,21 +338,35 @@ fn prefixed_0f() { test_invalid(&[0x0f, 0x36]); test_display(&[0x0f, 0x37], "getsec"); test_display(&[0x0f, 0x60, 0x00], "punpcklbw mm0, [rax]"); + test_display(&[0x0f, 0x60, 0xc2], "punpcklbw mm0, mm2"); test_display(&[0x0f, 0x61, 0x00], "punpcklwd mm0, [rax]"); + test_display(&[0x0f, 0x61, 0xc2], "punpcklwd mm0, mm2"); test_display(&[0x0f, 0x62, 0x00], "punpckldq mm0, [rax]"); + test_display(&[0x0f, 0x62, 0xc2], "punpckldq mm0, mm2"); test_display(&[0x0f, 0x63, 0x00], "packsswb mm0, [rax]"); + test_display(&[0x0f, 0x63, 0xc2], "packsswb mm0, mm2"); test_display(&[0x0f, 0x64, 0x00], "pcmpgtb mm0, [rax]"); + test_display(&[0x0f, 0x64, 0xc2], "pcmpgtb mm0, mm2"); test_display(&[0x0f, 0x65, 0x00], "pcmpgtw mm0, [rax]"); + test_display(&[0x0f, 0x65, 0xc2], "pcmpgtw mm0, mm2"); test_display(&[0x0f, 0x66, 0x00], "pcmpgtd mm0, [rax]"); + test_display(&[0x0f, 0x66, 0xc2], "pcmpgtd mm0, mm2"); test_display(&[0x0f, 0x67, 0x00], "packuswb mm0, [rax]"); + test_display(&[0x0f, 0x67, 0xc2], "packuswb mm0, mm2"); test_display(&[0x0f, 0x68, 0x00], "punpckhbw mm0, [rax]"); - test_display(&[0x0f, 0x69, 0x00], "punpckhbd mm0, [rax]"); + test_display(&[0x0f, 0x68, 0xc2], "punpckhbw mm0, mm2"); + test_display(&[0x0f, 0x69, 0x00], "punpckhwd mm0, [rax]"); + test_display(&[0x0f, 0x69, 0xc2], "punpckhwd mm0, mm2"); test_display(&[0x0f, 0x6a, 0x00], "punpckhdq mm0, [rax]"); + test_display(&[0x0f, 0x6a, 0xc2], "punpckhdq mm0, mm2"); test_display(&[0x0f, 0x6b, 0x00], "packssdw mm0, [rax]"); + test_display(&[0x0f, 0x6b, 0xc2], "packssdw mm0, mm2"); test_invalid(&[0x0f, 0x6c]); test_invalid(&[0x0f, 0x6d]); - test_display(&[0x0f, 0x6e], "movd mm0, dword [rax]"); - test_display(&[0x0f, 0x6f], "movd mm0, qword [rax]"); + test_display(&[0x0f, 0x6e, 0x00], "movd mm0, [rax]"); + test_display(&[0x0f, 0x6e, 0xc2], "movd mm0, edx"); + test_display(&[0x0f, 0x6f, 0x00], "movq mm0, [rax]"); + test_display(&[0x0f, 0x6f, 0xc2], "movq mm0, mm2"); test_display(&[0x0f, 0x70, 0x00, 0x7f], "pshufw mm0, qword [rax], 0x7f"); test_display(&[0x0f, 0x71, 0xd0, 0x7f], "psrlw mm0, 0x7f"); test_display(&[0x0f, 0x71, 0xe0, 0x7f], "psraw mm0, 0x7f"); -- cgit v1.1