Commit aefa97c4 authored by Josua Mayer's avatar Josua Mayer
Browse files

x86: implement IN and OUT instructions

The IN instructions read from an IO-Channel to either AL or AX,
while OUT write to an IO-Channel from either AL or AX.

IO is commonly indeterministic. Therefore after IN the respective register
value is undefined.

OUT can be ignored because they only change the isolated IO-Buffer and no
registers or system memory.
parent d4e98a71
......@@ -416,5 +416,11 @@ type instruction_kind =
| Lidt of sizeMode * genop32
| Ltr of genop16
| Iret of sizeMode
| OutPortImm of int
| OutPortDx
| InPortImmAl of int
| InPortImmAx of int
| OutPortImmAl of int
| OutPortImmAx of int
| InPortDxAl
| InPortDxAx
| OutPortDxAl
| OutPortDxAx
......@@ -1615,12 +1615,18 @@ let read lr =
let v = signed_displacement lr rel8 |> Int64.of_int in
Jcxz (of_mode mode, v)
| 0xe4 -> unsupported_imm "in al imm8" 1 lr
| 0xe5 -> unsupported_imm "in eax imm8" 1 lr
| 0xe4 ->
let imm8 = Lreader.Read.u8 lr in
InPortImmAl imm8
| 0xe5 ->
let imm8 = Lreader.Read.u8 lr in
InPortImmAx imm8
| 0xe6 ->
let imm8 = Lreader.Read.u8 lr in
OutPortImm imm8
| 0xe7 -> unsupported_imm "out imm8 eax" 1 lr
OutPortImmAl imm8
| 0xe7 ->
let imm8 = Lreader.Read.u8 lr in
OutPortImmAx imm8
| 0xe8 ->
let rel32 = Lreader.Read.u32 lr in
......@@ -1641,11 +1647,10 @@ let read lr =
let v = signed_displacement lr rel8 |> Int64.of_int in
Jmp v
| 0xec -> unsupported "in al dx"
| 0xed -> unsupported "in eax dx"
| 0xee ->
OutPortDx
| 0xef -> unsupported "out dx eax"
| 0xec -> InPortDxAl
| 0xed -> InPortDxAx
| 0xee -> OutPortDxAl
| 0xef -> OutPortDxAx
| 0xf0 -> aux_read_instr mode address_mode lr
......
......@@ -371,10 +371,14 @@ let pp_instr instr ppf rep =
fprintf ppf "@[ltr@ %a@]" pp_genop16 src
| Iret _ ->
fprintf ppf "@[iret@]"
| OutPortImm imm8 ->
fprintf ppf "@[outb@ %x,@ al@]" imm8
| OutPortDx ->
fprintf ppf "@[outb@ dx,@ al@]"
| InPortImmAl imm8 -> fprintf ppf "@[in@ %x,@ al@" imm8
| InPortImmAx imm8 -> fprintf ppf "@[in@ %x,@ ax@" imm8
| OutPortImmAl imm8 -> fprintf ppf "@[out@ %x,@ al@]" imm8
| OutPortImmAx imm8 -> fprintf ppf "@[out@ %x,@ ax@]" imm8
| InPortDxAl -> fprintf ppf "@[in@ dx,@, al@]"
| InPortDxAx -> fprintf ppf "@[in@ dx,@, ax@]"
| OutPortDxAl -> fprintf ppf "@[out@ dx,@, al@]"
| OutPortDxAx -> fprintf ppf "@[out@ dx,@, ax@]"
| Unsupported descr -> fprintf ppf "@[binsec_unsupported %s@]" descr
......
......@@ -2983,12 +2983,16 @@ let instruction_to_dba rep sreg nextaddr opcode instruction =
| Lidt (mode, gop) -> lift_ldt "idt" mode gop sreg
| Ltr op16 -> lift_ltr op16 sreg
| Iret mode -> lift_iret mode
| OutPortImm _imm8 ->
(* FIXME: treat as noop for now. *)
[]
| OutPortDx ->
(* FIXME: treat as noop for now. *)
[]
(* IO-Channels are not simulated: all reads undefined *)
| InPortImmAl _-> [ Predba.undefined (lhs_of_reg8 AL) ]
| InPortImmAx _ -> [ Predba.undefined (lhs_of_reg16 AX) ]
| InPortDxAl -> [ Predba.undefined (lhs_of_reg8 AL) ]
| InPortDxAx -> [ Predba.undefined (lhs_of_reg16 AX) ]
(* Fixme: IO-Channels are not simulated: all writes are nop *)
| OutPortImmAl _ -> []
| OutPortImmAx _ -> []
| OutPortDxAl -> []
| OutPortDxAx -> []
(* End instruction_to_dba *)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment