chore: remove Immediate from Immediate::{Word, Byte, Operand}
It's already clear that its an Immediate value without the prefix.
This commit is contained in:
@@ -2,7 +2,7 @@ use core::fmt;
|
||||
use std::{fs::File, io::Read, process::exit};
|
||||
|
||||
use crate::aout::Aout;
|
||||
use crate::instructions::{ImmediateOperand, MemoryIndex, ModRmTarget, Pointer};
|
||||
use crate::instructions::{MemoryIndex, ModRmTarget, Operand, Pointer};
|
||||
use crate::register::{Register, RegisterId, SegmentRegister};
|
||||
use crate::{
|
||||
Args,
|
||||
@@ -108,7 +108,7 @@ impl Disassembler {
|
||||
|
||||
/// Parse a single modrm byte, return the resulting MemoryIndex and advance the offset.
|
||||
/// Returns the parsed modrm target and the source register
|
||||
pub fn parse_modrm_byte(&mut self, width: ImmediateOperand) -> (ModRmTarget, RegisterId) {
|
||||
pub fn parse_modrm_byte(&mut self, width: Operand) -> (ModRmTarget, RegisterId) {
|
||||
// advance to operand
|
||||
self.offset += 1;
|
||||
let modrm = self.text[self.offset];
|
||||
@@ -129,28 +129,26 @@ impl Disassembler {
|
||||
0b00 => {
|
||||
if rm == 0b110 {
|
||||
log::debug!("Additional word during ModRM parsing was read with mod 0.");
|
||||
displacement = Some(ImmediateOperand::Word(self.parse_word()));
|
||||
displacement = Some(Operand::Word(self.parse_word()));
|
||||
} else {
|
||||
displacement = None;
|
||||
}
|
||||
}
|
||||
0b01 => {
|
||||
log::debug!("Additional byte during ModRM parsing was read.");
|
||||
displacement = Some(ImmediateOperand::Byte(self.parse_byte()))
|
||||
displacement = Some(Operand::Byte(self.parse_byte()))
|
||||
}
|
||||
0b10 => {
|
||||
log::debug!("Additional word during ModRM parsing was read.");
|
||||
displacement = Some(ImmediateOperand::Word(self.parse_word()));
|
||||
displacement = Some(Operand::Word(self.parse_word()));
|
||||
}
|
||||
0b11 => {
|
||||
log::debug!("ModRM (0b{:b}) to/from Register (0b{:b})", rm, reg);
|
||||
// XXX: find a nicer way instead of using Byte(0) and Word(0)
|
||||
let target = match width {
|
||||
ImmediateOperand::Byte(_) => {
|
||||
ModRmTarget::Register(Register::by_id(ImmediateOperand::Byte(rm)))
|
||||
}
|
||||
ImmediateOperand::Word(_) => {
|
||||
ModRmTarget::Register(Register::by_id(ImmediateOperand::Word(rm.into())))
|
||||
Operand::Byte(_) => ModRmTarget::Register(Register::by_id(Operand::Byte(rm))),
|
||||
Operand::Word(_) => {
|
||||
ModRmTarget::Register(Register::by_id(Operand::Word(rm.into())))
|
||||
}
|
||||
};
|
||||
return (target, reg);
|
||||
@@ -208,9 +206,9 @@ impl Disassembler {
|
||||
/// Match the modrm reg bits to the GPR1 mnemonics.
|
||||
/// GPR always has an imm value as second operand, but is available in both
|
||||
/// Byte and Word length.
|
||||
pub fn modrm_reg_to_mnemonic(reg: u8, target: ModRmTarget, imm: ImmediateOperand) -> Mnemonic {
|
||||
pub fn modrm_reg_to_mnemonic(reg: u8, target: ModRmTarget, imm: Operand) -> Mnemonic {
|
||||
match imm {
|
||||
ImmediateOperand::Byte(b) => match reg {
|
||||
Operand::Byte(b) => match reg {
|
||||
0b000 => Mnemonic::ADD_Ib(target, b),
|
||||
0b001 => Mnemonic::OR_Ib(target, b),
|
||||
0b010 => Mnemonic::ADC_Ib(target, b),
|
||||
@@ -221,7 +219,7 @@ impl Disassembler {
|
||||
0b111 => Mnemonic::CMP_Ib(target, b),
|
||||
_ => panic!("Illegal GPR1 mnemonic"),
|
||||
},
|
||||
ImmediateOperand::Word(w) => match reg {
|
||||
Operand::Word(w) => match reg {
|
||||
0b000 => Mnemonic::ADD_Iv(target, w),
|
||||
0b001 => Mnemonic::OR_Iv(target, w),
|
||||
0b010 => Mnemonic::ADC_Iv(target, w),
|
||||
@@ -410,7 +408,7 @@ impl Disassembler {
|
||||
0x8D => modrmv!(self, LEA),
|
||||
|
||||
0x8F => {
|
||||
let target = self.parse_modrm_byte(ImmediateOperand::Word(0)).0;
|
||||
let target = self.parse_modrm_byte(Operand::Word(0)).0;
|
||||
let mem = match target {
|
||||
ModRmTarget::Memory(idx) => idx,
|
||||
_ => panic!("POP_M instruction given a register to pop into"),
|
||||
|
||||
Reference in New Issue
Block a user