Skip to content

Commit

Permalink
Promote segment overlapping warning to error (#429)
Browse files Browse the repository at this point in the history
* Add more information to the segment overlap warning

* version

* black

* reword stuff
  • Loading branch information
AngheloAlf authored Dec 2, 2024
1 parent 0a29471 commit 8cbfcc1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* Tag `PSYQ` as a compiler that uses `j` instructions as branches.
* Fixes incorrect detection of non existing functions under the mentioned compiler.
* Try to tell the users what segments are causing the overlapping issue.
* The overlap warning has been promoted to an error.

### 0.31.0

Expand Down
3 changes: 2 additions & 1 deletion docs/Adding-Symbols.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ osInitialize = 0x801378C0; // type:func

:information_source: The file used can be overridden via the `symbol_addrs_path` setting in the global `options` section of the splat yaml. This option can also accept a list of paths, allowing for symbols to be organized in multiple files.

:warning: **NOTE:** This file is an input to splat, it should **NOT** be passed to the linker (pass `undefined_syms_*.txt` files to the linker) :warning:
> [!WARNING]
> :warning: **NOTE:** This file is an input to splat, it should **NOT** be passed to the linker (pass `undefined_syms_*.txt` files to the linker) :warning:
## symbol

Expand Down
27 changes: 26 additions & 1 deletion src/splat/util/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ def initialize_spim_context(all_segments: "List[Segment]") -> None:

from ..segtypes.common.code import CommonSegCode

global_segments_after_overlays: List[CommonSegCode] = []

for segment in all_segments:
if not isinstance(segment, CommonSegCode):
# We only care about the VRAMs of code segments
Expand Down Expand Up @@ -364,6 +366,10 @@ def initialize_spim_context(all_segments: "List[Segment]") -> None:
elif global_vram_end < segment.vram_end:
global_vram_end = segment.vram_end

if len(overlay_segments) > 0:
# Global segment *after* overlay segments?
global_segments_after_overlays.append(segment)

if global_vrom_start is None:
global_vrom_start = segment.rom_start
elif segment.rom_start < global_vrom_start:
Expand Down Expand Up @@ -401,6 +407,7 @@ def initialize_spim_context(all_segments: "List[Segment]") -> None:
global_vrom_start, global_vrom_end, global_vram_start, global_vram_end
)

overlaps_found = False
# Check the vram range of the global segment does not overlap with any overlay segment
for ovl_segment in overlay_segments:
assert (
Expand All @@ -411,9 +418,27 @@ def initialize_spim_context(all_segments: "List[Segment]") -> None:
and global_vram_end > ovl_segment.vramStart
):
log.write(
f"Warning: the vram range ([0x{ovl_segment.vramStart:08X}, 0x{ovl_segment.vramEnd:08X}]) of the non-global segment at rom address 0x{ovl_segment.vromStart:X} overlaps with the global vram range ([0x{global_vram_start:08X}, 0x{global_vram_end:08X}])",
f"Error: the vram range ([0x{ovl_segment.vramStart:08X}, 0x{ovl_segment.vramEnd:08X}]) of the non-global segment at rom address 0x{ovl_segment.vromStart:X} overlaps with the global vram range ([0x{global_vram_start:08X}, 0x{global_vram_end:08X}])",
status="warn",
)
overlaps_found = True
if overlaps_found:
log.write(
f"Many overlaps between non-global and global segments were found.",
)
log.write(
f"This is usually caused by missing `exclusive_ram_id` tags on segments that have a higher vram address than other `exclusive_ram_id`-tagged segments"
)
if len(global_segments_after_overlays) > 0:
log.write(
f"These segments are the main suspects for missing a `exclusive_ram_id` tag:",
status="warn",
)
for seg in global_segments_after_overlays:
log.write(f" '{seg.name}', rom: 0x{seg.rom_start:06X}")
else:
log.write(f"No suspected segments??", status="warn")
log.error("Stopping due to the above errors")

# pass the global symbols to spimdisasm
for segment in all_segments:
Expand Down

0 comments on commit 8cbfcc1

Please sign in to comment.