From 9f295bbc4249a01cc8d47b7c477737b61357fc35 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 19 Oct 2019 18:11:50 -0700 Subject: extend prefixed opcode support, add tests for alternate opcode maps --- test/test.rs | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) (limited to 'test') diff --git a/test/test.rs b/test/test.rs index 5d5f3b0..722be16 100644 --- a/test/test.rs +++ b/test/test.rs @@ -70,6 +70,14 @@ fn test_E_decode() { #[test] fn test_sse() { test_display(&[0x0f, 0x28, 0xd0], "movaps xmm2, xmm0"); + test_display(&[0x66, 0x0f, 0x28, 0xd0], "movapd xmm2, xmm0"); + test_display(&[0x66, 0x0f, 0x28, 0x00], "movapd xmm0, xmmword [rax]"); + test_display(&[0x4f, 0x66, 0x0f, 0x28, 0x00], "movapd xmm0, xmmword [rax]"); + test_display(&[0x66, 0x4f, 0x0f, 0x28, 0x00], "movapd xmm8, xmmword [r8]"); + test_display(&[0x66, 0x4f, 0x0f, 0x28, 0x00], "movapd xmm8, xmmword [r8]"); + test_display(&[0x67, 0x4f, 0x66, 0x0f, 0x28, 0x00], "movapd xmm0, xmmword [eax]"); + test_display(&[0x67, 0x66, 0x4f, 0x0f, 0x28, 0x00], "movapd xmm8, xmmword [r8d]"); + test_display(&[0x66, 0x0f, 0x29, 0x00], "movapd xmmword [rax], xmm0"); test_display(&[0x66, 0x0f, 0xef, 0xc0], "pxor xmm0, xmm0"); test_display(&[0xf2, 0x0f, 0x10, 0x0c, 0xc6], "movsd xmm1, [rsi + rax * 8]"); test_display(&[0xf3, 0x0f, 0x10, 0x04, 0x86], "movss xmm0, [rsi + rax * 4]"); @@ -150,6 +158,7 @@ fn test_push_pop() { fn test_bitwise() { test_display(&[0x41, 0x0f, 0xbc, 0xd3], "bsf edx, r11d"); test_display(&[0x48, 0x0f, 0xa3, 0xd0], "bt rax, rdx"); + test_display(&[0x48, 0x0f, 0xab, 0xd0], "bts rax, rdx"); } #[test] @@ -170,3 +179,123 @@ fn test_misc() { test_display(&[0xf3, 0x48, 0xa5], "rep movsq"); test_display(&[0xf3, 0x45, 0x0f, 0xbc, 0xd7], "tzcnt r10d, r15d"); } + +#[test] +fn evex() { + test_display(&[0x62, 0xf2, 0x7d, 0x48, 0x2a, 0x44, 0x40, 0x01], "vmovntdqa zmm0, zmmword [rax + rax*2 + 0x40]"); + test_display(&[0x62, 0xf2, 0x7d, 0x08, 0x2a, 0x44, 0x40, 0x01], "vmovntdqa xmm0, xmmword [rax + rax*2 + 0x10]"); +} + +#[test] +fn vex() { +} + +#[test] +fn prefixed_0f() { + test_display(&[0x0f, 0x02, 0xc0], "lar eax, eax"); + test_display(&[0x48, 0x0f, 0x02, 0xc0], "lar rax, eax"); + test_display(&[0x0f, 0x03, 0xc0], "lsl eax, eax"); + test_display(&[0x48, 0x0f, 0x03, 0xc0], "lsl rax, rax"); + test_display(&[0x0f, 0x05], "syscall"); + test_display(&[0x48, 0x0f, 0x05], "syscall"); + test_display(&[0x66, 0x0f, 0x05], "syscall"); + test_display(&[0x0f, 0x05], "sysret"); + test_display(&[0xf2, 0x0f, 0x05], "sysret"); + test_display(&[0x0f, 0x12, 0x0f], "movlps xmm1, qword [rdi]"); + test_display(&[0x0f, 0x12, 0xc0], "movhlps xmm0, xmm0"); + test_display(&[0x0f, 0x13, 0xc0], "invalid"); + test_display(&[0x0f, 0x14, 0x00], "unpcklps xmm1, xmmword [rax]"); + test_display(&[0x0f, 0x15, 0x00], "unpckhps xmm1, xmmword [rax]"); + test_display(&[0x0f, 0x16, 0x0f], "movhps xmm1, qword [rdi]"); + test_display(&[0x0f, 0x16, 0xc0], "movlhps xmm0, xmm0"); + test_display(&[0x0f, 0x17, 0xc0], "invalid"); + test_display(&[0x0f, 0x18, 0xc0], "invalid"); + test_display(&[0x0f, 0x18, 0x00], "prefetchnta byte [rax]"); + test_display(&[0x0f, 0x18, 0x08], "prefetch1 byte [rax]"); + test_display(&[0x0f, 0x18, 0x10], "prefetch2 byte [rax]"); + test_display(&[0x0f, 0x18, 0x18], "prefetch2 byte [rax]"); + test_display(&[0x0f, 0x18, 0x20], "nop dword [rax]"); + test_display(&[0x4f, 0x0f, 0x18, 0x20], "nop dword [rax]"); + test_display(&[0x0f, 0x19, 0x20], "nop dword [rax]"); + test_display(&[0x0f, 0x1a, 0x20], "nop dword [rax]"); + test_display(&[0x0f, 0x1b, 0x20], "nop dword [rax]"); + test_display(&[0x0f, 0x1c, 0x20], "nop dword [rax]"); + test_display(&[0x0f, 0x1d, 0x20], "nop dword [rax]"); + test_display(&[0x0f, 0x1e, 0x20], "nop dword [rax]"); + test_display(&[0x0f, 0x1f, 0x20], "nop dword [rax]"); + test_display(&[0x45, 0x0f, 0x20, 0xc8], "mov r8, cr9"); + test_display(&[0x0f, 0x20, 0xc8], "mov rax, cr1"); + test_display(&[0x45, 0x0f, 0x21, 0xc8], "mov r8, dr9"); + test_display(&[0x0f, 0x21, 0xc8], "mov rax, dr1"); + test_display(&[0x45, 0x0f, 0x22, 0xc8], "mov cr9, r8"); + test_display(&[0x40, 0x0f, 0x22, 0xc8], "mov cr1, rax"); + test_display(&[0x0f, 0x22, 0xc8], "mov cr1, rax"); + test_display(&[0x44, 0x0f, 0x22, 0xcf], "mov cr9, rdi"); + test_display(&[0x0f, 0x22, 0xcf], "mov cr1, rdi"); + test_display(&[0x45, 0x0f, 0x23, 0xc8], "mov dr9, r8"); + test_display(&[0x40, 0x0f, 0x23, 0xc8], "mov dr1, rax"); + test_display(&[0x0f, 0x23, 0xc8], "mov dr1, rax"); + test_display(&[0x44, 0x0f, 0x23, 0xcf], "mov dr9, rdi"); + test_display(&[0x0f, 0x23, 0xcf], "mov dr1, rdi"); + test_display(&[0x0f, 0x30], "wrmsr"); + test_display(&[0x0f, 0x31], "rdtsc"); + test_display(&[0x0f, 0x32], "rdmsr"); + test_display(&[0x0f, 0x33], "rdpmc"); + test_display(&[0x0f, 0x34], "sysenter"); + test_display(&[0x0f, 0x35], "sysret"); + test_display(&[0x0f, 0x36], "invalid"); + test_display(&[0x0f, 0x37], "getsec"); + test_display(&[0x0f, 0x60, 0x00], "punpcklbw mm0, qword [rax]"); + test_display(&[0x0f, 0x61, 0x00], "punpcklwd mm0, qword [rax]"); + test_display(&[0x0f, 0x62, 0x00], "punpckldq mm0, qword [rax]"); + test_display(&[0x0f, 0x63, 0x00], "packsswb mm0, qword [rax]"); + test_display(&[0x0f, 0x64, 0x00], "pcmpgtb mm0, qword [rax]"); + test_display(&[0x0f, 0x65, 0x00], "pcmpgtw mm0, qword [rax]"); + test_display(&[0x0f, 0x66, 0x00], "pcmpgtd mm0, qword [rax]"); + test_display(&[0x0f, 0x67, 0x00], "packuswb mm0, qword [rax]"); + test_display(&[0x0f, 0x68, 0x00], "punpckhbw mm0, qword [rax]"); + test_display(&[0x0f, 0x69, 0x00], "punpckhbd mm0, qword [rax]"); + test_display(&[0x0f, 0x6a, 0x00], "punpckhdq mm0, qword [rax]"); + test_display(&[0x0f, 0x6b, 0x00], "packssdw mm0, qword [rax]"); + test_display(&[0x0f, 0x6c], "invalid"); + test_display(&[0x0f, 0x6d], "invalid"); + test_display(&[0x0f, 0x6e], "movd mm0, dword [rax]"); + test_display(&[0x0f, 0x6f], "movd mm0, qword [rax]"); + 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"); + test_display(&[0x0f, 0x71, 0xf0, 0x7f], "psllw mm0, 0x7f"); + test_display(&[0x0f, 0x72, 0xd0, 0x7f], "psrld mm0, 0x7f"); + test_display(&[0x0f, 0x72, 0xe0, 0x7f], "psrad mm0, 0x7f"); + test_display(&[0x0f, 0x72, 0xf0, 0x7f], "pslld mm0, 0x7f"); + test_display(&[0x0f, 0xa0], "push fs"); + test_display(&[0x0f, 0xa1], "pop fs"); + test_display(&[0x0f, 0xa2], "cpuid"); + test_display(&[0x0f, 0xa4, 0xc0, 0x11], "shld eax, eax, 0x11"); + test_display(&[0x0f, 0xa5, 0xc0], "shld eax, eax, cl"); + test_display(&[0x0f, 0xa5, 0xc9], "shld ecx, ecx, cl"); +} + +#[test] +fn prefixed_660f() { + test_display(&[0x66, 0x0f, 0x10, 0xc0], "movupd xmm0, xmm0"); + test_display(&[0x66, 0x48, 0x0f, 0x10, 0xc0], "movupd xmm0, xmm0"); + test_display(&[0x66, 0x49, 0x0f, 0x10, 0xc0], "movupd xmm0, xmm8"); + test_display(&[0x66, 0x4a, 0x0f, 0x10, 0xc0], "movupd xmm0, xmm8"); + test_display(&[0x66, 0x4c, 0x0f, 0x10, 0xc0], "movupd xmm8, xmm0"); + test_display(&[0x66, 0x4d, 0x0f, 0x10, 0xc0], "movupd xmm8, xmm8"); + test_display(&[0xf2, 0x66, 0x66, 0x4d, 0x0f, 0x10, 0xc0], "movupd xmm8, xmm8"); +} + +#[test] +fn prefixed_f20f() { + test_display(&[0xf2, 0x0f, 0x16, 0xcf], "movlhps xmm1, xmm7"); + test_display(&[0xf2, 0x4d, 0x0f, 0x16, 0xcf], "movlhps xmm9, xmm15"); + test_display(&[0x40, 0x66, 0xf2, 0x66, 0x4d, 0x0f, 0x16, 0xcf], "movlhps xmm9, xmm15"); +} + +#[test] +fn prefixed_f30f() { + test_display(&[0xf3, 0x0f, 0x16, 0xcf], "movshdup xmm1, xmm7"); + test_display(&[0xf3, 0x4d, 0x0f, 0x16, 0xcf], "movshdup xmm9, xmm15"); +} -- cgit v1.1