aboutsummaryrefslogtreecommitdiff
path: root/src/real_mode/display.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2024-06-24 13:51:12 -0700
committeriximeow <me@iximeow.net>2024-06-24 13:51:12 -0700
commitddde47c4c8c2058379b448894bebb3e099ea0585 (patch)
tree85db28304858df5061f433e9b1c076769576f119 /src/real_mode/display.rs
parentf4ae2edd1a9733eee8b33a7937d07054256533a2 (diff)
consistently enter register/number/opcode spans
Diffstat (limited to 'src/real_mode/display.rs')
-rw-r--r--src/real_mode/display.rs113
1 files changed, 40 insertions, 73 deletions
diff --git a/src/real_mode/display.rs b/src/real_mode/display.rs
index bea11fc..e8bd191 100644
--- a/src/real_mode/display.rs
+++ b/src/real_mode/display.rs
@@ -65,6 +65,8 @@ trait DisplaySinkExt {
fn write_opcode(&mut self, opcode: super::Opcode) -> Result<(), core::fmt::Error>;
fn write_reg(&mut self, reg: RegSpec) -> Result<(), core::fmt::Error>;
+ fn write_displacement(&mut self, disp: i32) -> Result<(), core::fmt::Error>;
+ fn write_scale(&mut self, scale: u8) -> Result<(), core::fmt::Error>;
fn write_mem_size_label(&mut self, mem_size: u8) -> Result<(), core::fmt::Error>;
fn write_sae_mode(&mut self, sae: super::SaeMode) -> Result<(), core::fmt::Error>;
}
@@ -89,6 +91,29 @@ impl<T: DisplaySink> DisplaySinkExt for T {
}
#[inline(always)]
+ fn write_displacement(&mut self, disp: i32) -> Result<(), core::fmt::Error> {
+ let mut v = disp as u32;
+ if disp < 0 {
+ self.write_fixed_size("- ")?;
+ v = disp.unsigned_abs();
+ } else {
+ self.write_fixed_size("+ ")?;
+ }
+ self.span_start_number();
+ self.write_prefixed_u32(v)?;
+ self.span_end_number();
+ Ok(())
+ }
+
+ #[inline(always)]
+ fn write_scale(&mut self, scale: u8) -> Result<(), core::fmt::Error> {
+ self.span_start_number();
+ self.write_char((0x30 + scale) as char)?; // translate scale=1 to '1', scale=2 to '2', etc
+ self.span_end_number();
+ Ok(())
+ }
+
+ #[inline(always)]
fn write_mem_size_label(&mut self, mem_size: u8) -> Result<(), core::fmt::Error> {
let label = mem_size_label(mem_size);
let _ = Self::MEM_SIZE_LABEL_LT_8;
@@ -410,17 +435,7 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_char('[')?;
self.f.write_reg(base)?;
self.f.write_fixed_size(" ")?;
-
- {
- let mut v = disp as u32;
- if disp < 0 {
- self.f.write_fixed_size("- 0x")?;
- v = disp.unsigned_abs();
- } else {
- self.f.write_fixed_size("+ 0x")?;
- }
- self.f.write_u32(v)?;
- }
+ self.f.write_displacement(disp)?;
self.f.write_fixed_size("]")
}
fn visit_deref(&mut self, base: RegSpec) -> Result<Self::Ok, Self::Error> {
@@ -432,7 +447,7 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_fixed_size("[")?;
self.f.write_reg(index)?;
self.f.write_fixed_size(" * ")?;
- self.f.write_char((0x30 + scale) as char)?; // translate scale=1 to '1', scale=2 to '2', etc
+ self.f.write_scale(scale)?;
self.f.write_fixed_size("]")?;
Ok(())
@@ -441,19 +456,9 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_fixed_size("[")?;
self.f.write_reg(index)?;
self.f.write_fixed_size(" * ")?;
- self.f.write_char((0x30 + scale) as char)?; // translate scale=1 to '1', scale=2 to '2', etc
+ self.f.write_scale(scale)?;
self.f.write_fixed_size(" ")?;
-
- {
- let mut v = disp as u32;
- if disp < 0 {
- self.f.write_fixed_size("- 0x")?;
- v = disp.unsigned_abs();
- } else {
- self.f.write_fixed_size("+ 0x")?;
- }
- self.f.write_u32(v)?;
- }
+ self.f.write_displacement(disp)?;
self.f.write_char(']')
}
fn visit_base_index_scale(&mut self, base: RegSpec, index: RegSpec, scale: u8) -> Result<Self::Ok, Self::Error> {
@@ -462,7 +467,7 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_fixed_size(" + ")?;
self.f.write_reg(index)?;
self.f.write_fixed_size(" * ")?;
- self.f.write_char((0x30 + scale) as char)?; // translate scale=1 to '1', scale=2 to '2', etc
+ self.f.write_scale(scale)?;
self.f.write_fixed_size("]")
}
fn visit_base_index_scale_disp(&mut self, base: RegSpec, index: RegSpec, scale: u8, disp: i32) -> Result<Self::Ok, Self::Error> {
@@ -471,33 +476,16 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_fixed_size(" + ")?;
self.f.write_reg(index)?;
self.f.write_fixed_size(" * ")?;
- self.f.write_char((0x30 + scale) as char)?; // translate scale=1 to '1', scale=2 to '2', etc
+ self.f.write_scale(scale)?;
self.f.write_fixed_size(" ")?;
-
- {
- let mut v = disp as u32;
- if disp < 0 {
- self.f.write_fixed_size("- 0x")?;
- v = disp.unsigned_abs();
- } else {
- self.f.write_fixed_size("+ 0x")?;
- }
- self.f.write_u32(v)?;
- }
+ self.f.write_displacement(disp)?;
self.f.write_fixed_size("]")
}
fn visit_disp_masked(&mut self, base: RegSpec, disp: i32, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
self.f.write_char('[')?;
self.f.write_reg(base)?;
self.f.write_char(' ')?;
- let mut v = disp as u32;
- if disp < 0 {
- self.f.write_fixed_size("- 0x")?;
- v = disp.unsigned_abs();
- } else {
- self.f.write_fixed_size("+ 0x")?;
- }
- self.f.write_u32(v)?;
+ self.f.write_displacement(disp)?;
self.f.write_char(']')?;
self.f.write_char('{')?;
self.f.write_reg(mask_reg)?;
@@ -517,7 +505,7 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_fixed_size("[")?;
self.f.write_reg(index)?;
self.f.write_fixed_size(" * ")?;
- self.f.write_char((0x30 + scale) as char)?; // translate scale=1 to '1', scale=2 to '2', etc
+ self.f.write_scale(scale)?;
self.f.write_fixed_size("]")?;
self.f.write_char('{')?;
self.f.write_reg(mask_reg)?;
@@ -528,16 +516,9 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_fixed_size("[")?;
self.f.write_reg(index)?;
self.f.write_fixed_size(" * ")?;
- self.f.write_char((0x30 + scale) as char)?; // translate scale=1 to '1', scale=2 to '2', etc
+ self.f.write_scale(scale)?;
self.f.write_fixed_size(" ")?;
- let mut v = disp as u32;
- if disp < 0 {
- self.f.write_fixed_size("- 0x")?;
- v = disp.unsigned_abs();
- } else {
- self.f.write_fixed_size("+ 0x")?;
- }
- self.f.write_u32(v)?;
+ self.f.write_displacement(disp)?;
self.f.write_char(']')?;
self.f.write_char('{')?;
self.f.write_reg(mask_reg)?;
@@ -561,14 +542,7 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_fixed_size(" + ")?;
self.f.write_reg(index)?;
self.f.write_fixed_size(" ")?;
- let mut v = disp as u32;
- if disp < 0 {
- self.f.write_fixed_size("- 0x")?;
- v = disp.unsigned_abs();
- } else {
- self.f.write_fixed_size("+ 0x")?;
- }
- self.f.write_u32(v)?;
+ self.f.write_displacement(disp)?;
self.f.write_char(']')?;
self.f.write_char('{')?;
self.f.write_reg(mask_reg)?;
@@ -581,7 +555,7 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_fixed_size(" + ")?;
self.f.write_reg(index)?;
self.f.write_fixed_size(" * ")?;
- self.f.write_char((0x30 + scale) as char)?; // translate scale=1 to '1', scale=2 to '2', etc
+ self.f.write_scale(scale)?;
self.f.write_fixed_size("]")?;
self.f.write_char('{')?;
self.f.write_reg(mask_reg)?;
@@ -594,16 +568,9 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_fixed_size(" + ")?;
self.f.write_reg(index)?;
self.f.write_fixed_size(" * ")?;
- self.f.write_char((0x30 + scale) as char)?; // translate scale=1 to '1', scale=2 to '2', etc
+ self.f.write_scale(scale)?;
self.f.write_char(' ')?;
- let mut v = disp as u32;
- if disp < 0 {
- self.f.write_fixed_size("- 0x")?;
- v = disp.unsigned_abs();
- } else {
- self.f.write_fixed_size("+ 0x")?;
- }
- self.f.write_u32(v)?;
+ self.f.write_displacement(disp)?;
self.f.write_char(']')?;
self.f.write_char('{')?;
self.f.write_reg(mask_reg)?;