From 0689a9d1bbe5ab481672a030c0d0ca6ec4bba9ec Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Thu, 4 Jul 2024 14:26:03 -0400 Subject: [PATCH] Allow to manually specify the vram start and end for the global segment (#377) * Turn off symbol filtering on psp and ps2 * `global_vram_start` and `global_vram_end` * version bump * typo * typo 2 * Pass symbols to spimdisasm that are not part of the current binary * a bit of docs * Do not ignore symbols with addends * global memory range --- CHANGELOG.md | 3 +++ README.md | 4 ++-- docs/Configuration.md | 5 +++++ src/splat/segtypes/common/codesubsegment.py | 4 +--- src/splat/util/options.py | 6 ++++++ src/splat/util/symbols.py | 17 +++++++++++++++-- 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07dccdce..27d6817f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ * New `use_src_path` option for incbins segments. * Allows to make the generated assembly files relative to the `src_path` directory instead of the default `data_path`. +* New yaml option: `global_vram_start` and `global_vram_end`. + * Allow specifying that the global memory range may be larger than what was automatically detected. + * Useful for projects where splat is used in multiple individual files, meaning the expected global segment may not be properly detected because each instance of splat can't see the info from other files (like in PSX and PSP projects). ### 0.24.4 diff --git a/README.md b/README.md index 3208841a..af8220e1 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,9 @@ splat64[mips]>=0.24.5,<1.0.0 ### Optional dependencies -- `mips`: Required when using the N64, PSX, PS2 or PSp platforms. +- `mips`: Required when using the N64, PSX, PS2 or PSP platforms. - `dev`: Installs all the available dependencies groups and other packages for development. ### Gamecube / Wii -For Gamecube / Wii projects, see [decomp-toolkit](https://github.com/encounter/decomp-toolkit)! \ No newline at end of file +For Gamecube / Wii projects, see [decomp-toolkit](https://github.com/encounter/decomp-toolkit)! diff --git a/docs/Configuration.md b/docs/Configuration.md index 6111876b..afc679e4 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -623,6 +623,11 @@ Tries to detect redundant and unreferenced functions ends and merge them togethe Don't skip disassembling already matched functions and migrated sections +### global_vram_start and global_vram_end + +Allow specifying that the global memory range may be larger than what was automatically detected. + +Useful for projects where splat is used in multiple individual files, meaning the expected global segment may not be properly detected because each instance of splat can't see the info from other files, like in PSX and PSP projects. ## N64-specific options diff --git a/src/splat/segtypes/common/codesubsegment.py b/src/splat/segtypes/common/codesubsegment.py index ec4de8d8..e903879b 100644 --- a/src/splat/segtypes/common/codesubsegment.py +++ b/src/splat/segtypes/common/codesubsegment.py @@ -144,9 +144,7 @@ def process_insns( if instr_offset in func_spim.instrAnalyzer.symbolInstrOffset: sym_address = func_spim.instrAnalyzer.symbolInstrOffset[instr_offset] - context_sym = self.spim_section.get_section().getSymbol( - sym_address, tryPlusOffset=False - ) + context_sym = self.spim_section.get_section().getSymbol(sym_address) if context_sym is not None: symbols.create_symbol_from_spim_symbol( self.get_most_parent(), context_sym diff --git a/src/splat/util/options.py b/src/splat/util/options.py index f3155865..e610acba 100644 --- a/src/splat/util/options.py +++ b/src/splat/util/options.py @@ -220,6 +220,10 @@ class SplatOpts: detect_redundant_function_end: bool # Don't skip disassembling already matched functions and migrated sections disassemble_all: bool + # Allow specifying that the global memory range may be larger than what was automatically detected. + # Useful for projects where splat is used in multiple individual files, meaning the expected global segment may not be properly detected because each instance of splat can't see the info from other files. + global_vram_start: Optional[int] + global_vram_end: Optional[int] ################################################################################ # N64-specific options @@ -539,6 +543,8 @@ def parse_endianness() -> Literal["big", "little"]: disassemble_all=( disasm_all if disasm_all else p.parse_opt("disassemble_all", bool, False) ), + global_vram_start=p.parse_optional_opt("global_vram_start", int), + global_vram_end=p.parse_optional_opt("global_vram_end", int), ) p.check_no_unread_opts() return ret diff --git a/src/splat/util/symbols.py b/src/splat/util/symbols.py index 850f38be..bb0b0434 100644 --- a/src/splat/util/symbols.py +++ b/src/splat/util/symbols.py @@ -317,8 +317,8 @@ def initialize(all_segments: "List[Segment]"): def initialize_spim_context(all_segments: "List[Segment]") -> None: global_vrom_start = None global_vrom_end = None - global_vram_start = None - global_vram_end = None + global_vram_start = options.opts.global_vram_start + global_vram_end = options.opts.global_vram_end overlay_segments: Set[spimdisasm.common.SymbolsSegment] = set() spim_context.bannedSymbols |= ignored_addresses @@ -418,6 +418,19 @@ def initialize_spim_context(all_segments: "List[Segment]") -> None: for sym in symbols_list: add_symbol_to_spim_segment(spim_context.globalSegment, sym) + if global_vram_start and global_vram_end: + # Pass global symbols to spimdisasm that are not part of any segment on the binary we are splitting (for psx and psp) + for sym in all_symbols: + if sym.segment is not None: + # We already handled this symbol somewhere else + continue + + if sym.vram_start < global_vram_start or sym.vram_end > global_vram_end: + # Not global + continue + + add_symbol_to_spim_segment(spim_context.globalSegment, sym) + def add_symbol_to_spim_segment( segment: spimdisasm.common.SymbolsSegment, sym: "Symbol"