Skip to content

Commit 2bea2dd

Browse files
committed
outsb/w/d/q
The 'ds' register should only be read from in 16- and 32-bit mode. From the SDM for outsd: Output word from memory location specified in DS:(E)SI or RSI to I/O port specified in DX.
1 parent 613d245 commit 2bea2dd

File tree

2 files changed

+153
-1
lines changed

2 files changed

+153
-1
lines changed

arch/X86/X86Mapping.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,35 @@ void X86_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id)
11721172
break;
11731173
}
11741174
break;
1175+
1176+
case X86_INS_OUTSB:
1177+
case X86_INS_OUTSW:
1178+
case X86_INS_OUTSD:
1179+
switch (h->mode) {
1180+
default:
1181+
break;
1182+
case CS_MODE_64:
1183+
arr_replace(
1184+
insn->detail->regs_read,
1185+
insn->detail->regs_read_count,
1186+
X86_REG_ESI, X86_REG_RSI);
1187+
arr_replace(
1188+
insn->detail->regs_write,
1189+
insn->detail->regs_write_count,
1190+
X86_REG_ESI, X86_REG_RSI);
1191+
break;
1192+
case CS_MODE_16:
1193+
arr_replace(
1194+
insn->detail->regs_read,
1195+
insn->detail->regs_read_count,
1196+
X86_REG_ESI, X86_REG_SI);
1197+
arr_replace(
1198+
insn->detail->regs_write,
1199+
insn->detail->regs_write_count,
1200+
X86_REG_ESI, X86_REG_SI);
1201+
break;
1202+
}
1203+
break;
11751204
}
11761205

11771206
switch (insn->id) {
@@ -1186,6 +1215,9 @@ void X86_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id)
11861215
case X86_INS_MOVSB:
11871216
case X86_INS_MOVSW:
11881217
case X86_INS_MOVSD:
1218+
case X86_INS_OUTSB:
1219+
case X86_INS_OUTSW:
1220+
case X86_INS_OUTSD:
11891221
switch (h->mode) {
11901222
default:
11911223
break;

tests/details/x86.yaml

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3322,6 +3322,10 @@ test_cases:
33223322
0xf3, 0x6c, # rep insb byte ptr es:[di], dx
33233323
0x6d, # insw word ptr es:[di], dx
33243324
0xf3, 0x6d, # rep insw word ptr es:[di], dx
3325+
0x6e, # outsb dx, byte ptr [si]
3326+
0xf3, 0x6e, # rep outsb dx, byte ptr [si]
3327+
0x6f, # outsw dx, word ptr [si]
3328+
0xf3, 0x6f, # rep outsb dx, word ptr [si]
33253329
]
33263330
arch: "x86"
33273331
options: [ CS_OPT_DETAIL, CS_MODE_16 ]
@@ -3578,8 +3582,44 @@ test_cases:
35783582
prefix: [ X86_PREFIX_REP, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
35793583
opcode: [ 0x6d, 0x00, 0x00, 0x00 ]
35803584
eflags: [ X86_EFLAGS_TEST_DF ]
3581-
regs_read: [ dx, flags, cx, es, di ]
3585+
regs_read: [ dx, flags, cx, es, di]
35823586
regs_write: [ di, cx ]
3587+
-
3588+
asm_text: "outsb dx, byte ptr [si]"
3589+
details:
3590+
x86:
3591+
prefix: [ X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3592+
opcode: [ 0x6e, 0x00, 0x00, 0x00 ]
3593+
eflags: [ X86_EFLAGS_TEST_DF ]
3594+
regs_read: [ dx, si, flags, ds ]
3595+
regs_write: [ si ]
3596+
-
3597+
asm_text: "rep outsb dx, byte ptr [si]"
3598+
details:
3599+
x86:
3600+
prefix: [ X86_PREFIX_REP, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3601+
opcode: [ 0x6e, 0x00, 0x00, 0x00 ]
3602+
eflags: [ X86_EFLAGS_TEST_DF ]
3603+
regs_read: [ dx, si, flags, ds, cx]
3604+
regs_write: [ si, cx ]
3605+
-
3606+
asm_text: "outsw dx, word ptr [si]"
3607+
details:
3608+
x86:
3609+
prefix: [ X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3610+
opcode: [ 0x6f, 0x00, 0x00, 0x00 ]
3611+
eflags: [ X86_EFLAGS_TEST_DF ]
3612+
regs_read: [ dx, si, flags, ds ]
3613+
regs_write: [ si ]
3614+
-
3615+
asm_text: "rep outsw dx, word ptr [si]"
3616+
details:
3617+
x86:
3618+
prefix: [ X86_PREFIX_REP, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3619+
opcode: [ 0x6f, 0x00, 0x00, 0x00 ]
3620+
eflags: [ X86_EFLAGS_TEST_DF ]
3621+
regs_read: [ dx, si, flags, ds, cx]
3622+
regs_write: [ si, cx ]
35833623

35843624
-
35853625
input:
@@ -3613,6 +3653,10 @@ test_cases:
36133653
0xf3, 0x6c, # rep insb byte ptr es:[edi], dx
36143654
0x6d, # insd dword ptr es:[edi], dx
36153655
0xf3, 0x6d, # rep insd dword ptr es:[edi], dx
3656+
0x6e, # outsb dx, byte ptr [esi]
3657+
0xf3, 0x6e, # rep outsb dx, byte ptr [esi]
3658+
0x6f, # outsd dx, dword ptr [esi]
3659+
0xf3, 0x6f, # rep outsd dx, dword ptr [esi]
36163660
]
36173661
arch: "x86"
36183662
options: [ CS_OPT_DETAIL, CS_MODE_32 ]
@@ -3871,6 +3915,42 @@ test_cases:
38713915
eflags: [ X86_EFLAGS_TEST_DF ]
38723916
regs_read: [ dx, edi, eflags, ecx, es ]
38733917
regs_write: [ edi, ecx ]
3918+
-
3919+
asm_text: "outsb dx, byte ptr [esi]"
3920+
details:
3921+
x86:
3922+
prefix: [ X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3923+
opcode: [ 0x6e, 0x00, 0x00, 0x00 ]
3924+
eflags: [ X86_EFLAGS_TEST_DF ]
3925+
regs_read: [ dx, esi, eflags, ds ]
3926+
regs_write: [ esi ]
3927+
-
3928+
asm_text: "rep outsb dx, byte ptr [esi]"
3929+
details:
3930+
x86:
3931+
prefix: [ X86_PREFIX_REP, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3932+
opcode: [ 0x6e, 0x00, 0x00, 0x00 ]
3933+
eflags: [ X86_EFLAGS_TEST_DF ]
3934+
regs_read: [ dx, esi, eflags, ds, ecx ]
3935+
regs_write: [ esi, ecx ]
3936+
-
3937+
asm_text: "outsd dx, dword ptr [esi]"
3938+
details:
3939+
x86:
3940+
prefix: [ X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3941+
opcode: [ 0x6f, 0x00, 0x00, 0x00 ]
3942+
eflags: [ X86_EFLAGS_TEST_DF ]
3943+
regs_read: [ dx, esi, eflags, ds ]
3944+
regs_write: [ esi ]
3945+
-
3946+
asm_text: "rep outsd dx, dword ptr [esi]"
3947+
details:
3948+
x86:
3949+
prefix: [ X86_PREFIX_REP, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
3950+
opcode: [ 0x6f, 0x00, 0x00, 0x00 ]
3951+
eflags: [ X86_EFLAGS_TEST_DF ]
3952+
regs_read: [ dx, esi, eflags, ds, ecx ]
3953+
regs_write: [ esi, ecx ]
38743954

38753955
-
38763956
input:
@@ -3916,6 +3996,10 @@ test_cases:
39163996
0xf3, 0x6c, # rep insb byte ptr [rdi], dx
39173997
0x6d, # insd dword ptr [rdi], dx
39183998
0xf3, 0x6d, # rep insd dword ptr [rdi], dx
3999+
0x6e, # outsb dx, byte ptr [rsi]
4000+
0xf3, 0x6e, # rep outsb dx, byte ptr [rsi]
4001+
0x6f, # outsd dx, dword ptr [rsi]
4002+
0xf3, 0x6f, # rep outsd dx, dword ptr [rsi]
39194003
]
39204004
arch: "x86"
39214005
options: [ CS_OPT_DETAIL, CS_MODE_64 ]
@@ -4294,3 +4378,39 @@ test_cases:
42944378
eflags: [ X86_EFLAGS_TEST_DF ]
42954379
regs_read: [ dx, rdi, rflags, rcx ]
42964380
regs_write: [ rdi, rcx ]
4381+
-
4382+
asm_text: "outsb dx, byte ptr [rsi]"
4383+
details:
4384+
x86:
4385+
prefix: [ X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
4386+
opcode: [ 0x6e, 0x00, 0x00, 0x00 ]
4387+
eflags: [ X86_EFLAGS_TEST_DF ]
4388+
regs_read: [ dx, rsi, rflags ]
4389+
regs_write: [ rsi ]
4390+
-
4391+
asm_text: "rep outsb dx, byte ptr [rsi]"
4392+
details:
4393+
x86:
4394+
prefix: [ X86_PREFIX_REP, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
4395+
opcode: [ 0x6e, 0x00, 0x00, 0x00 ]
4396+
eflags: [ X86_EFLAGS_TEST_DF ]
4397+
regs_read: [ dx, rsi, rflags, rcx ]
4398+
regs_write: [ rsi, rcx ]
4399+
-
4400+
asm_text: "outsd dx, dword ptr [rsi]"
4401+
details:
4402+
x86:
4403+
prefix: [ X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
4404+
opcode: [ 0x6f, 0x00, 0x00, 0x00 ]
4405+
eflags: [ X86_EFLAGS_TEST_DF ]
4406+
regs_read: [ dx, rsi, rflags ]
4407+
regs_write: [ rsi ]
4408+
-
4409+
asm_text: "rep outsd dx, dword ptr [rsi]"
4410+
details:
4411+
x86:
4412+
prefix: [ X86_PREFIX_REP, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0 ]
4413+
opcode: [ 0x6f, 0x00, 0x00, 0x00 ]
4414+
eflags: [ X86_EFLAGS_TEST_DF ]
4415+
regs_read: [ dx, rsi, rflags, rcx ]
4416+
regs_write: [ rsi, rcx ]

0 commit comments

Comments
 (0)