From cef4feeaf9c64e03a6728f267750ac2fb32eb9ff Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 21 Aug 2021 12:13:01 -0700 Subject: report memory sizes for push, pop, call, ret these instructions had memory sizes reported for the operand, if it was a memory operand, but for versions with non-memory operands the decoded `Instruction` would imply that non memory access would happen at all. now, decoded instructions in these cases will report a more useful memory size. --- src/lib.rs | 7 +++++++ src/long_mode/mod.rs | 32 +++++++++++++++++++++++++++++++- src/protected_mode/mod.rs | 28 +++++++++++++++++++++++++++- src/real_mode/mod.rs | 29 +++++++++++++++++++++++++++-- 4 files changed, 92 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 84353ba..46bebdb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -185,3 +185,10 @@ impl core::fmt::Display for MemoryAccessSize { f.write_str(self.size_name()) } } + +#[cfg(feature = "fmt")] +impl core::fmt::Debug for MemoryAccessSize { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + core::fmt::Display::fmt(self, f) + } +} diff --git a/src/long_mode/mod.rs b/src/long_mode/mod.rs index 039d550..a01e854 100644 --- a/src/long_mode/mod.rs +++ b/src/long_mode/mod.rs @@ -7396,6 +7396,9 @@ fn read_operands::Address, ::Address, { @@ -7615,12 +7619,27 @@ fn read_operands::Address, ::Address, ::Address, { diff --git a/src/protected_mode/mod.rs b/src/protected_mode/mod.rs index a06af4c..8381d68 100644 --- a/src/protected_mode/mod.rs +++ b/src/protected_mode/mod.rs @@ -7235,6 +7235,7 @@ fn read_operands::Address, { @@ -7328,6 +7329,9 @@ fn read_operands::Address, ::Address, ::Address, { + if instruction.opcode == Opcode::Invalid { + return Err(DecodeError::InvalidOpcode); + } + if instruction.opcode == Opcode::RETURN { + instruction.mem_size = 4; + } else { + instruction.mem_size = 6; + } instruction.operands[0] = OperandSpec::Nothing; instruction.operand_count = 0; return Ok(()); @@ -9132,6 +9153,11 @@ fn unlikely_operands::Address, { diff --git a/src/real_mode/mod.rs b/src/real_mode/mod.rs index fbfc687..548c42e 100644 --- a/src/real_mode/mod.rs +++ b/src/real_mode/mod.rs @@ -7236,6 +7236,7 @@ fn read_operands::Address, { @@ -7329,6 +7330,9 @@ fn read_operands::Address, ::Address, ::Address, { + if instruction.opcode == Opcode::Invalid { + return Err(DecodeError::InvalidOpcode); + } + if instruction.opcode == Opcode::RETURN { + instruction.mem_size = 2; + } else { + instruction.mem_size = 4; + } instruction.operands[0] = OperandSpec::Nothing; instruction.operand_count = 0; return Ok(()); @@ -9140,6 +9160,11 @@ fn unlikely_operands::Address, { -- cgit v1.1