Skip to content

Commit

Permalink
Added support for new Intel AVX 10.2 instructions.
Browse files Browse the repository at this point in the history
Added support for AMD RMPREAD instruction.
Improved EVEX decoding, including the new U bit.
Fixed ENTER & LEAVE operands.
  • Loading branch information
vlutas committed Sep 16, 2024
1 parent c877b50 commit 767bf2e
Show file tree
Hide file tree
Showing 28 changed files with 15,199 additions and 11,731 deletions.
229 changes: 139 additions & 90 deletions bddisasm/bdx86_decoder.c

Large diffs are not rendered by default.

15,637 changes: 8,995 additions & 6,642 deletions bddisasm/include/bdx86_instructions.h

Large diffs are not rendered by default.

236 changes: 127 additions & 109 deletions bddisasm/include/bdx86_mnemonics.h

Large diffs are not rendered by default.

6,444 changes: 3,641 additions & 2,803 deletions bddisasm/include/bdx86_table_evex.h

Large diffs are not rendered by default.

2,652 changes: 1,329 additions & 1,323 deletions bddisasm/include/bdx86_table_root.h

Large diffs are not rendered by default.

1,218 changes: 609 additions & 609 deletions bddisasm/include/bdx86_table_vex.h

Large diffs are not rendered by default.

170 changes: 85 additions & 85 deletions bddisasm/include/bdx86_table_xop.h

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bddisasm/include/bdx86_tabledefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ typedef enum _ND_OPERAND_TYPE_SPEC
ND_OPT_pCX, // [rCX]
ND_OPT_pBXAL, // [rBX + AL]
ND_OPT_pDI, // [rDI]
ND_OPT_pBP, // [rBP]
ND_OPT_SHS, // Shadow stack.
ND_OPT_SHSP, // Shadow stack pointed by the SSP.
ND_OPT_SHS0, // Shadow stack pointed by the SSP.
Expand Down
20 changes: 9 additions & 11 deletions bdshemu/bdshemu.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ shemu_memcpy(
ND_SIZET Size
)
{
void *start = Dest;
ND_UINT32 index = 0;

if (ND_NULL == Dest)
{
return ND_NULL;
Expand All @@ -76,14 +73,12 @@ shemu_memcpy(
return ND_NULL;
}

while (Size--)
for (ND_SIZET index = 0; index < Size; index++)
{
*(char *)Dest = *((char *)Source + index);
Dest = (char *)Dest + 1;
index++;
((char *)Dest)[index] = ((const char *)Source)[index];
}

return start;
return Dest;
}


Expand Down Expand Up @@ -206,7 +201,8 @@ ShemuIsShellcodePtr(
)
{
return (Gla >= Context->ShellcodeBase && Gla < Context->ShellcodeBase + Context->ShellcodeSize &&
Gla + Size > Context->ShellcodeBase && Gla + Size <= Context->ShellcodeBase + Context->ShellcodeSize);
Gla + Size > Context->ShellcodeBase && Gla + Size <= Context->ShellcodeBase + Context->ShellcodeSize &&
Size <= Context->ShellcodeSize);
}


Expand All @@ -221,7 +217,8 @@ ShemuIsStackPtr(
)
{
return (Gla >= Context->StackBase && Gla < Context->StackBase + Context->StackSize &&
Gla + Size > Context->StackBase && Gla + Size <= Context->StackBase + Context->StackSize);
Gla + Size > Context->StackBase && Gla + Size <= Context->StackBase + Context->StackSize &&
Size <= Context->StackSize);
}


Expand All @@ -236,7 +233,8 @@ ShemuIsIcachePtr(
)
{
return (Gla >= Context->Icache.Address && Gla < Context->Icache.Address + Context->Icache.Size &&
Gla + Size > Context->Icache.Address && Gla + Size <= Context->Icache.Address + Context->Icache.Size);
Gla + Size > Context->Icache.Address && Gla + Size <= Context->Icache.Address + Context->Icache.Size &&
Size <= Context->Icache.Size);
}


Expand Down
20 changes: 10 additions & 10 deletions bdshemu/bdshemu_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -2240,7 +2240,7 @@ ShemuX86Emulate(
}
else
{
ND_SINT64 val = ND_SIGN_EX(dst.Size, dst.Value.Qwords[0]);
ND_SINT64 val = (ND_SINT64)ND_SIGN_EX(dst.Size, dst.Value.Qwords[0]);
val = val >> src.Value.Qwords[0];
res.Value.Qwords[0] = (ND_UINT64)val;
}
Expand Down Expand Up @@ -2761,7 +2761,7 @@ ShemuX86Emulate(
}
else
{
res.Value.Words[0] = (ND_SINT8)dst.Value.Bytes[0] * (ND_SINT8)src.Value.Bytes[0];
res.Value.Words[0] = (ND_UINT16)((ND_SINT8)dst.Value.Bytes[0] * (ND_SINT8)src.Value.Bytes[0]);
}
}
else if (dst.Size == 2)
Expand All @@ -2772,7 +2772,7 @@ ShemuX86Emulate(
}
else
{
res.Value.Dwords[0] = (ND_SINT16)dst.Value.Words[0] * (ND_SINT16)src.Value.Words[0];
res.Value.Dwords[0] = (ND_UINT32)((ND_SINT16)dst.Value.Words[0] * (ND_SINT16)src.Value.Words[0]);
}
}
else if (dst.Size == 4)
Expand All @@ -2783,7 +2783,7 @@ ShemuX86Emulate(
}
else
{
res.Value.Qwords[0] = (ND_SINT64)(ND_SINT32)dst.Value.Dwords[0] * (ND_SINT64)(ND_SINT32)src.Value.Dwords[0];
res.Value.Qwords[0] = (ND_UINT64)((ND_SINT64)(ND_SINT32)dst.Value.Dwords[0] * (ND_SINT64)(ND_SINT32)src.Value.Dwords[0]);
}
}
else
Expand Down Expand Up @@ -2916,8 +2916,8 @@ ShemuX86Emulate(
break;
}

res.Value.Bytes[0] = (ND_SINT8)((ND_SINT16)divident / (ND_SINT8)src.Value.Bytes[0]);
res.Value.Bytes[1] = (ND_SINT8)((ND_SINT16)divident % (ND_SINT8)src.Value.Bytes[0]);
res.Value.Bytes[0] = (ND_UINT8)(ND_SINT8)((ND_SINT16)divident / (ND_SINT8)src.Value.Bytes[0]);
res.Value.Bytes[1] = (ND_UINT8)(ND_SINT8)((ND_SINT16)divident % (ND_SINT8)src.Value.Bytes[0]);
}

// Result in AX (AL - quotient, AH - reminder).
Expand Down Expand Up @@ -2949,8 +2949,8 @@ ShemuX86Emulate(
break;
}

res.Value.Words[0] = (ND_SINT16)((ND_SINT32)divident / (ND_SINT16)src.Value.Words[0]);
res.Value.Words[1] = (ND_SINT16)((ND_SINT32)divident % (ND_SINT16)src.Value.Words[0]);
res.Value.Words[0] = (ND_UINT16)(ND_SINT16)((ND_SINT32)divident / (ND_SINT16)src.Value.Words[0]);
res.Value.Words[1] = (ND_UINT16)(ND_SINT16)((ND_SINT32)divident % (ND_SINT16)src.Value.Words[0]);
}

ShemuX86SetGprValue(Context, NDR_DX, 2, res.Value.Words[1], ND_FALSE);
Expand Down Expand Up @@ -2982,8 +2982,8 @@ ShemuX86Emulate(
break;
}

res.Value.Dwords[0] = (ND_SINT32)((ND_SINT64)divident / (ND_SINT32)src.Value.Dwords[0]);
res.Value.Dwords[1] = (ND_SINT32)((ND_SINT64)divident % (ND_SINT32)src.Value.Dwords[0]);
res.Value.Dwords[0] = (ND_UINT32)(ND_SINT32)((ND_SINT64)divident / (ND_SINT32)src.Value.Dwords[0]);
res.Value.Dwords[1] = (ND_UINT32)(ND_SINT32)((ND_SINT64)divident % (ND_SINT32)src.Value.Dwords[0]);
}

ShemuX86SetGprValue(Context, NDR_EDX, 4, res.Value.Dwords[1], ND_FALSE);
Expand Down
2 changes: 1 addition & 1 deletion bindings/pybddisasm/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from codecs import open

VERSION = (0, 3, 0)
LIBRARY_VERSION = (2, 1, 5)
LIBRARY_VERSION = (2, 2, 0)
DIR_INCLUDE = '../../inc'

here = os.path.abspath(os.path.dirname(__file__))
Expand Down
8 changes: 8 additions & 0 deletions disasmtool/disasmtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ set_to_string(
case ND_SET_AMXTILE: return "AMX-TILE";
case ND_SET_AMXCOMPLEX: return "AMX-COMPLEX";
case ND_SET_AVX: return "AVX";
case ND_SET_AVX102: return "AVX10_2";
case ND_SET_AVX2: return "AVX2";
case ND_SET_AVX2GATHER: return "AVX2GATHER";
case ND_SET_AVX5124FMAPS: return "AVX5124FMAPS";
Expand Down Expand Up @@ -332,6 +333,13 @@ category_to_string(
case ND_CAT_AMX: return "AMX";
case ND_CAT_APX: return "APX";
case ND_CAT_AVX: return "AVX";
case ND_CAT_AVX10BF16: return "AVX10BF16";
case ND_CAT_AVX10CMPSFP: return "AVX10CMPSFP";
case ND_CAT_AVX10CONVERT: return "AVX10CONVERT";
case ND_CAT_AVX10INT: return "AVX10INT";
case ND_CAT_AVX10MINMAX: return "AVX10MINMAX";
case ND_CAT_AVX10PARTCOPY: return "AVX10PARTCOPY";
case ND_CAT_AVX10SCONVERT: return "AVX10SCONVERT";
case ND_CAT_AVX2: return "AVX2";
case ND_CAT_AVX2GATHER: return "AVX2GATHER";
case ND_CAT_AVX512: return "AVX512";
Expand Down
1 change: 1 addition & 0 deletions inc/bddisasm_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ typedef ND_UINT32 NDSTATUS;
#define ND_STATUS_INVALID_TILE_REGS 0x80000043 // Tile registers are not unique.
#define ND_STATUS_INVALID_DEST_REGS 0x80000044 // Destination register is not unique (used as src).
#define ND_STATUS_INVALID_EVEX_BYTE3 0x80000045 // EVEX payload byte 3 is invalid.
#define ND_STATUS_BAD_EVEX_U 0x80000046 // EVEX.U field is invalid.


// Not encoding specific.
Expand Down
4 changes: 2 additions & 2 deletions inc/bddisasm_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#define BDDISASM_VERSION_H

#define DISASM_VERSION_MAJOR 2
#define DISASM_VERSION_MINOR 1
#define DISASM_VERSION_REVISION 5
#define DISASM_VERSION_MINOR 2
#define DISASM_VERSION_REVISION 0

#define SHEMU_VERSION_MAJOR DISASM_VERSION_MAJOR
#define SHEMU_VERSION_MINOR DISASM_VERSION_MINOR
Expand Down
Loading

0 comments on commit 767bf2e

Please sign in to comment.