From c6c9aa4e5f3e5a01fcb9ccabf6dbd2f6da277650 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 15 Jul 2024 08:55:57 +0200 Subject: Add the notion of mapping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mappings and segments are fundamental blocks on how code is distributed both on the actual ROM File and in the memory layout. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/instruction.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'lib/xixanta/src/instruction.rs') diff --git a/lib/xixanta/src/instruction.rs b/lib/xixanta/src/instruction.rs index fac6d8e..227a3e1 100644 --- a/lib/xixanta/src/instruction.rs +++ b/lib/xixanta/src/instruction.rs @@ -268,10 +268,50 @@ impl Encodable for Literal { } } +#[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd)] +pub struct Fill { + pub value: u8, +} + +impl Encodable for Fill { + fn size(&self) -> u8 { + 1 + } + + fn to_hex(&self) -> Vec { + let mut ret = vec![]; + ret.push(format!("{:02X}", self.value)); + + ret + } + + fn to_bytes(&self) -> [u8; 3] { + [self.value, 0, 0] + } + + fn to_human(&self) -> String { + format!("${:02X}", self.value) + } + + fn to_verbose(&self) -> String { + format!("{:#?}", self) + } +} + #[derive(Debug, Clone, PartialEq)] pub enum Node { Generic(Generic), Instruction(Instruction), Scoped(Scoped), Literal(Literal), + Fill(Fill), +} + +impl Node { + pub fn is_encodeable(&self) -> bool { + matches!( + self, + &Node::Instruction(_) | &Node::Literal(_) | &Node::Fill(_) + ) + } } -- cgit v1.2.3