From b93267c56565582b9a85e7a1255568e16abcafd2 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Thu, 28 Aug 2025 08:39:08 +0200 Subject: nasm: Error out when using WRAM when not available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit introduces the ability to inspect the temptative header before producing the actual output, and with that it checks whether the Working RAM is being advertised or not. If it is not being advertised but the assembler detected memory accesses to that region, then we are in trouble and we should error out. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/assembler.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lib/xixanta/src') diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index 23d4219..5ab0e3d 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -83,6 +83,10 @@ struct Assembler<'a> { // Sources that have been evaluated for the current session. This is // directly tied to `Parser::sources`. sources: Vec, + + // Whether the assembler has detected accesses to Working RAM or not + // (0x6000-0x7FFF). + accessing_working_ram: bool, } /// All the information that a caller needs after calling either @@ -104,6 +108,10 @@ pub struct AssemblerResult { /// The resulting mappings after assembling a source. You can count on /// fields like `offset` if `errors` is empty. pub mappings: Vec, + + /// Whether the resulting ROM needs Working RAM to be available in order to + /// work. Ignore this field if `errors` is not empty. + pub accessing_working_ram: bool, } /// Read the contents from the `reader` as a source file and produce a list of @@ -131,6 +139,7 @@ pub fn assemble( }], warnings: vec![], mappings: vec![], + accessing_working_ram: false, }; } }; @@ -161,6 +170,7 @@ pub fn assemble_with_mapping( errors, warnings: asm.warnings, mappings: asm.mappings, + accessing_working_ram: asm.accessing_working_ram, }; } @@ -176,6 +186,7 @@ pub fn assemble_with_mapping( errors: e.into(), warnings: vec![], mappings: asm.mappings, + accessing_working_ram: asm.accessing_working_ram, }; } } @@ -188,6 +199,7 @@ pub fn assemble_with_mapping( errors, warnings: asm.warnings, mappings: asm.mappings, + accessing_working_ram: asm.accessing_working_ram, }; } @@ -201,6 +213,7 @@ pub fn assemble_with_mapping( errors, warnings: asm.warnings, mappings: asm.mappings, + accessing_working_ram: asm.accessing_working_ram, }; } @@ -212,6 +225,7 @@ pub fn assemble_with_mapping( errors, warnings: asm.warnings, mappings: asm.mappings, + accessing_working_ram: asm.accessing_working_ram, }; } @@ -222,12 +236,14 @@ pub fn assemble_with_mapping( errors: vec![], warnings: asm.warnings, mappings: asm.mappings, + accessing_working_ram: asm.accessing_working_ram, }, Err(errors) => AssemblerResult { bundles: vec![], errors, warnings: asm.warnings, mappings: asm.mappings, + accessing_working_ram: asm.accessing_working_ram, }, } } @@ -249,6 +265,7 @@ impl<'a> Assembler<'a> { repeats_seen: 0, warnings: vec![], sources: vec![], + accessing_working_ram: false, } } @@ -2003,6 +2020,15 @@ impl<'a> Assembler<'a> { None => (AddressingMode::Implied, Bundle::new(true)), }; + // If the instruction is accessing memory and the bundle is resolved, we + // can start gathering info on the memory being used. + if bundle.resolved && !matches!(mode, AddressingMode::Implied | AddressingMode::Immediate) { + let value = bundle.value() as usize; + if (0x6000..0x8000).contains(&value) { + self.accessing_working_ram = true; + } + } + let mnemonic = node.value.value.to_lowercase(); match INSTRUCTIONS.get(&mnemonic) { Some(entries) => match entries.get(&mode) { -- cgit v1.2.3