Skip to content

Commit 613d245

Browse files
committed
insb/w/d/q
X86_REG_EDI was removed from the explicit set of read registers because it was causing duplicate entries in 'detail->regs_read'. The 'ds' register should only be read from in 16- and 32-bit mode. From the SDM for insd: Input doubleword from I/O port specified in DX into memory location specified in ES:(E)DI or RDI.
1 parent 15d32da commit 613d245

File tree

6 files changed

+159
-13
lines changed

6 files changed

+159
-13
lines changed

arch/X86/X86Mapping.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,6 @@ void X86_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id)
11151115
insn->detail->regs_read,
11161116
insn->detail->regs_read_count,
11171117
X86_REG_ESP, X86_REG_SP);
1118-
11191118
arr_replace(
11201119
insn->detail->regs_write,
11211120
insn->detail->regs_write_count,
@@ -1142,6 +1141,34 @@ void X86_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id)
11421141
insn->detail->regs_write,
11431142
insn->detail->regs_write_count,
11441143
X86_REG_ESP, X86_REG_RSP);
1144+
}
1145+
break;
1146+
1147+
case X86_INS_INSB:
1148+
case X86_INS_INSW:
1149+
case X86_INS_INSD:
1150+
switch (h->mode) {
1151+
default:
1152+
break;
1153+
case CS_MODE_16:
1154+
arr_replace(
1155+
insn->detail->regs_read,
1156+
insn->detail->regs_read_count,
1157+
X86_REG_EDI, X86_REG_DI);
1158+
arr_replace(
1159+
insn->detail->regs_write,
1160+
insn->detail->regs_write_count,
1161+
X86_REG_EDI, X86_REG_DI);
1162+
break;
1163+
case CS_MODE_64:
1164+
arr_replace(
1165+
insn->detail->regs_read,
1166+
insn->detail->regs_read_count,
1167+
X86_REG_EDI, X86_REG_RDI);
1168+
arr_replace(
1169+
insn->detail->regs_write,
1170+
insn->detail->regs_write_count,
1171+
X86_REG_EDI, X86_REG_RDI);
11451172
break;
11461173
}
11471174
break;

arch/X86/X86MappingInsn.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6229,7 +6229,7 @@
62296229
{
62306230
X86_INSB, X86_INS_INSB, 0,
62316231
#ifndef CAPSTONE_DIET
6232-
{ X86_REG_DX, X86_REG_EDI, X86_REG_EFLAGS, 0 }, { X86_REG_EDI, 0 }, { 0 }, 0, 0
6232+
{ X86_REG_DX, X86_REG_EFLAGS, 0 }, { X86_REG_EDI, 0 }, { 0 }, 0, 0
62336233
#endif
62346234
},
62356235

@@ -6271,7 +6271,7 @@
62716271
{
62726272
X86_INSW, X86_INS_INSW, 0,
62736273
#ifndef CAPSTONE_DIET
6274-
{ X86_REG_DX, X86_REG_EDI, X86_REG_EFLAGS, 0 }, { X86_REG_EDI, 0 }, { 0 }, 0, 0
6274+
{ X86_REG_DX, X86_REG_EFLAGS, 0 }, { X86_REG_EDI, 0 }, { 0 }, 0, 0
62756275
#endif
62766276
},
62776277

arch/X86/X86MappingInsnOp.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4449,7 +4449,7 @@
44494449
},
44504450

44514451
{ /* X86_INSB, X86_INS_INSB: insb */
4452-
0,
4452+
X86_EFLAGS_TEST_DF,
44534453
{ CS_AC_IGNORE, CS_AC_READ, 0 }
44544454
},
44554455

@@ -4474,12 +4474,12 @@
44744474
},
44754475

44764476
{ /* X86_INSL, X86_INS_INSD: insd */
4477-
0,
4477+
X86_EFLAGS_TEST_DF,
44784478
{ CS_AC_IGNORE, 0 }
44794479
},
44804480

44814481
{ /* X86_INSW, X86_INS_INSW: insw */
4482-
0,
4482+
X86_EFLAGS_TEST_DF,
44834483
{ CS_AC_IGNORE, CS_AC_READ, 0 }
44844484
},
44854485

arch/X86/X86MappingInsnOp_reduce.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,17 +2564,17 @@
25642564
},
25652565

25662566
{ /* X86_INSB, X86_INS_INSB: insb */
2567-
0,
2567+
X86_EFLAGS_TEST_DF,
25682568
{ CS_AC_IGNORE, CS_AC_READ, 0 }
25692569
},
25702570

25712571
{ /* X86_INSL, X86_INS_INSD: insd */
2572-
0,
2572+
X86_EFLAGS_TEST_DF,
25732573
{ CS_AC_IGNORE, 0 }
25742574
},
25752575

25762576
{ /* X86_INSW, X86_INS_INSW: insw */
2577-
0,
2577+
X86_EFLAGS_TEST_DF,
25782578
{ CS_AC_IGNORE, CS_AC_READ, 0 }
25792579
},
25802580

arch/X86/X86MappingInsn_reduce.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,7 +3590,7 @@
35903590
{
35913591
X86_INSB, X86_INS_INSB, 0,
35923592
#ifndef CAPSTONE_DIET
3593-
{ X86_REG_DX, X86_REG_EDI, X86_REG_EFLAGS, 0 }, { X86_REG_EDI, 0 }, { 0 }, 0, 0
3593+
{ X86_REG_DX, X86_REG_EFLAGS, 0 }, { X86_REG_EDI, 0 }, { 0 }, 0, 0
35943594
#endif
35953595
},
35963596

@@ -3604,7 +3604,7 @@
36043604
{
36053605
X86_INSW, X86_INS_INSW, 0,
36063606
#ifndef CAPSTONE_DIET
3607-
{ X86_REG_DX, X86_REG_EDI, X86_REG_EFLAGS, 0 }, { X86_REG_EDI, 0 }, { 0 }, 0, 0
3607+
{ X86_REG_DX, X86_REG_EFLAGS, 0 }, { X86_REG_EDI, 0 }, { 0 }, 0, 0
36083608
#endif
36093609
},
36103610

tests/details/x86.yaml

Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3317,7 +3317,11 @@ test_cases:
33173317
0xa4, # movsb byte ptr es:[di], byte ptr [si]
33183318
0xf3,0xa4, # rep movsb byte ptr es:[di], byte ptr [si]
33193319
0xa5, # movsw word ptr es:[di], word ptr [si{}}
3320-
0xf3,0xa5 # rep movsw word ptr es:[di], word ptr [si]
3320+
0xf3,0xa5, # rep movsw word ptr es:[di], word ptr [si]
3321+
0x6c, # insb byte ptr es:[di], dx
3322+
0xf3, 0x6c, # rep insb byte ptr es:[di], dx
3323+
0x6d, # insw word ptr es:[di], dx
3324+
0xf3, 0x6d, # rep insw word ptr es:[di], dx
33213325
]
33223326
arch: "x86"
33233327
options: [ CS_OPT_DETAIL, CS_MODE_16 ]
@@ -3540,6 +3544,42 @@ test_cases:
35403544
eflags: [ X86_EFLAGS_TEST_DF ]
35413545
regs_read: [ di, si, flags, ds, cx, es ]
35423546
regs_write: [ di, si, cx ]
3547+
-
3548+
asm_text: "insb byte ptr es:[di], dx"
3549+
details:
3550+
x86:
3551+
prefix: [ X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3552+
opcode: [ 0x6c, 0x00, 0x00, 0x00 ]
3553+
eflags: [ X86_EFLAGS_TEST_DF ]
3554+
regs_read: [ dx, flags, es, di ]
3555+
regs_write: [ di ]
3556+
-
3557+
asm_text: "rep insb byte ptr es:[di], dx"
3558+
details:
3559+
x86:
3560+
prefix: [ X86_PREFIX_REP, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3561+
opcode: [ 0x6c, 0x00, 0x00, 0x00 ]
3562+
eflags: [ X86_EFLAGS_TEST_DF ]
3563+
regs_read: [ dx, flags, cx, es, di ]
3564+
regs_write: [ di, cx ]
3565+
-
3566+
asm_text: "insw word ptr es:[di], dx"
3567+
details:
3568+
x86:
3569+
prefix: [ X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3570+
opcode: [ 0x6d, 0x00, 0x00, 0x00 ]
3571+
eflags: [ X86_EFLAGS_TEST_DF ]
3572+
regs_read: [ dx, flags, es, di ]
3573+
regs_write: [ di ]
3574+
-
3575+
asm_text: "rep insw word ptr es:[di], dx"
3576+
details:
3577+
x86:
3578+
prefix: [ X86_PREFIX_REP, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3579+
opcode: [ 0x6d, 0x00, 0x00, 0x00 ]
3580+
eflags: [ X86_EFLAGS_TEST_DF ]
3581+
regs_read: [ dx, flags, cx, es, di ]
3582+
regs_write: [ di, cx ]
35433583

35443584
-
35453585
input:
@@ -3569,7 +3609,10 @@ test_cases:
35693609
0xf3, 0xa4, # rep movsb byte ptr es:[edi], byte ptr [esi]
35703610
0xa5, # movsw dword ptr es:[edi], dword ptr [esi]
35713611
0xf3, 0xa5, # rep movsw dword ptr es:[edi], dword ptr [esi]
3572-
3612+
0x6c, # insb byte ptr es:[edi], dx
3613+
0xf3, 0x6c, # rep insb byte ptr es:[edi], dx
3614+
0x6d, # insd dword ptr es:[edi], dx
3615+
0xf3, 0x6d, # rep insd dword ptr es:[edi], dx
35733616
]
35743617
arch: "x86"
35753618
options: [ CS_OPT_DETAIL, CS_MODE_32 ]
@@ -3792,6 +3835,42 @@ test_cases:
37923835
eflags: [ X86_EFLAGS_TEST_DF ]
37933836
regs_read: [ edi, esi, eflags, ds, ecx, es ]
37943837
regs_write: [ edi, esi, ecx ]
3838+
-
3839+
asm_text: "insb byte ptr es:[edi], dx"
3840+
details:
3841+
x86:
3842+
prefix: [ X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3843+
opcode: [ 0x6c, 0x00, 0x00, 0x00 ]
3844+
eflags: [ X86_EFLAGS_TEST_DF ]
3845+
regs_read: [ dx, eflags, es, edi ]
3846+
regs_write: [ edi ]
3847+
-
3848+
asm_text: "rep insb byte ptr es:[edi], dx"
3849+
details:
3850+
x86:
3851+
prefix: [ X86_PREFIX_REP, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3852+
opcode: [ 0x6c, 0x00, 0x00, 0x00 ]
3853+
eflags: [ X86_EFLAGS_TEST_DF ]
3854+
regs_read: [ dx, eflags, ecx, es, edi ]
3855+
regs_write: [ edi, ecx ]
3856+
-
3857+
asm_text: "insd dword ptr es:[edi], dx"
3858+
details:
3859+
x86:
3860+
prefix: [ X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3861+
opcode: [ 0x6d, 0x00, 0x00, 0x00 ]
3862+
eflags: [ X86_EFLAGS_TEST_DF ]
3863+
regs_read: [ dx, edi, eflags, es ]
3864+
regs_write: [ edi ]
3865+
-
3866+
asm_text: "rep insd dword ptr es:[edi], dx"
3867+
details:
3868+
x86:
3869+
prefix: [ X86_PREFIX_REP, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3870+
opcode: [ 0x6d, 0x00, 0x00, 0x00 ]
3871+
eflags: [ X86_EFLAGS_TEST_DF ]
3872+
regs_read: [ dx, edi, eflags, ecx, es ]
3873+
regs_write: [ edi, ecx ]
37953874

37963875
-
37973876
input:
@@ -3833,6 +3912,10 @@ test_cases:
38333912
0xf3, 0xa5, # rep movsd dword ptr [rdi], dword ptr [rsi]
38343913
0x48, 0xa5, # REX.W movsq qword ptr [rdi], qword ptr [rsi]
38353914
0xf3, 0x48, 0xa5, # rep REX.W movsq qword ptr [rdi], qword ptr [rsi]
3915+
0x6c, # insb byte ptr [rdi], dx
3916+
0xf3, 0x6c, # rep insb byte ptr [rdi], dx
3917+
0x6d, # insd dword ptr [rdi], dx
3918+
0xf3, 0x6d, # rep insd dword ptr [rdi], dx
38363919
]
38373920
arch: "x86"
38383921
options: [ CS_OPT_DETAIL, CS_MODE_64 ]
@@ -4175,3 +4258,39 @@ test_cases:
41754258
eflags: [ X86_EFLAGS_TEST_DF ]
41764259
regs_read: [ rdi, rsi, rflags, rcx ]
41774260
regs_write: [ rdi, rsi, rcx ]
4261+
-
4262+
asm_text: "insb byte ptr [rdi], dx"
4263+
details:
4264+
x86:
4265+
prefix: [ X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
4266+
opcode: [ 0x6c, 0x00, 0x00, 0x00 ]
4267+
eflags: [ X86_EFLAGS_TEST_DF ]
4268+
regs_read: [ dx, rflags, rdi ]
4269+
regs_write: [ rdi ]
4270+
-
4271+
asm_text: "rep insb byte ptr [rdi], dx"
4272+
details:
4273+
x86:
4274+
prefix: [ X86_PREFIX_REP, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
4275+
opcode: [ 0x6c, 0x00, 0x00, 0x00 ]
4276+
eflags: [ X86_EFLAGS_TEST_DF ]
4277+
regs_read: [ dx, rflags, rcx, rdi ]
4278+
regs_write: [ rdi, rcx ]
4279+
-
4280+
asm_text: "insd dword ptr [rdi], dx"
4281+
details:
4282+
x86:
4283+
prefix: [ X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
4284+
opcode: [ 0x6d, 0x00, 0x00, 0x00 ]
4285+
eflags: [ X86_EFLAGS_TEST_DF ]
4286+
regs_read: [ dx, rdi, rflags ]
4287+
regs_write: [ rdi ]
4288+
-
4289+
asm_text: "rep insd dword ptr [rdi], dx"
4290+
details:
4291+
x86:
4292+
prefix: [ X86_PREFIX_REP, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
4293+
opcode: [ 0x6d, 0x00, 0x00, 0x00 ]
4294+
eflags: [ X86_EFLAGS_TEST_DF ]
4295+
regs_read: [ dx, rdi, rflags, rcx ]
4296+
regs_write: [ rdi, rcx ]

0 commit comments

Comments
 (0)