Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to manually specify the vram start and end for the global segment #377

Merged
merged 11 commits into from
Jul 4, 2024
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)!
For Gamecube / Wii projects, see [decomp-toolkit](https://github.com/encounter/decomp-toolkit)!
5 changes: 5 additions & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions src/splat/segtypes/common/codesubsegment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/splat/util/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
ethteck marked this conversation as resolved.
Show resolved Hide resolved
global_vram_end: Optional[int]

################################################################################
# N64-specific options
Expand Down Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions src/splat/util/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down