papermario/tools/build/ld/multilink_calc.py
Ethan Roseman a37f30dc94
Modern gcc + shiftability work (#942)
* wip changes for modern gcc

* more

* wip

* blah

* Define explicit size for symbol

* Clean up evt_handle_exec1

* wip

* .

* fixes & VLA macro

* VLA innit

* wipz

* Fix potential UB

* meowp

* meowp2

* fixies

* git subrepo pull --force tools/splat

subrepo:
  subdir:   "tools/splat"
  merged:   "e1f0b17917"
upstream:
  origin:   "https://github.com/ethteck/splat.git"
  branch:   "master"
  commit:   "e1f0b17917"
git-subrepo:
  version:  "0.4.5"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "aa416e4"

* fixules

* git subrepo pull --force tools/splat

subrepo:
  subdir:   "tools/splat"
  merged:   "3ba3277e57"
upstream:
  origin:   "https://github.com/ethteck/splat.git"
  branch:   "master"
  commit:   "3ba3277e57"
git-subrepo:
  version:  "0.4.5"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "aa416e4"

* more shiftability + symbols work

* git subrepo pull --force tools/splat

subrepo:
  subdir:   "tools/splat"
  merged:   "02879e52a7"
upstream:
  origin:   "https://github.com/ethteck/splat.git"
  branch:   "master"
  commit:   "02879e52a7"
git-subrepo:
  version:  "0.4.5"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "aa416e4"

* more

* revert bss changes for now, new heaps overlay for aligning stuff to 0x1000 (not sure how necessary that is, so maybe will revert later on)

* 'fixing' jp shift build

* more

* more syms

* more progress

* more

* ididid

* git subrepo pull --force tools/splat

subrepo:
  subdir:   "tools/splat"
  merged:   "de54da38f5"
upstream:
  origin:   "https://github.com/ethteck/splat.git"
  branch:   "master"
  commit:   "de54da38f5"
git-subrepo:
  version:  "0.4.5"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "aa416e4"

* git subrepo pull --force tools/splat

subrepo:
  subdir:   "tools/splat"
  merged:   "a27dc436a6"
upstream:
  origin:   "https://github.com/ethteck/splat.git"
  branch:   "master"
  commit:   "a27dc436a6"
git-subrepo:
  version:  "0.4.5"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "aa416e4"

* blah

* stuff's broken, but at least it's maybe cleaner

* modern gcc back

* revert

* shifting all overlays - works so far

* progs

* another

* modern gcc flag, re-enabled all ifdef shift stuff

* fixies

* progress

* fixes, matching build

* heaps3 overlay and some symbol names

* changies

* PR comments & cleanup
2023-02-14 22:14:14 +09:00

89 lines
2.8 KiB
Python
Executable File

#! /usr/bin/python3
import os
from pathlib import Path
import sys
from typing import Dict, List
script_dir = Path(os.path.dirname(os.path.realpath(__file__)))
root_dir = script_dir / "../../.."
HARDCODED_ADDR = 0x80000000
if __name__ == "__main__":
if len(sys.argv) != 3:
print(f"Usage: {sys.argv[0]} <version> <mode>")
print("mode: hardcode, calc")
sys.exit(1)
version = sys.argv[1]
mode = sys.argv[2]
syms_to_max = {
"entity_data_vram_end" : [
"entity_default_VRAM_END",
"entity_jan_iwa_VRAM_END",
"entity_sbk_omo_VRAM_END",
],
"world_action_vram_end": [
"world_action_idle_VRAM_END",
"world_action_walk_VRAM_END",
"world_action_jump_VRAM_END",
"world_action_step_up_VRAM_END",
"world_action_land_VRAM_END",
"world_action_hammer_VRAM_END",
"world_action_spin_VRAM_END",
"world_action_tornado_jump_VRAM_END",
"world_action_spin_jump_VRAM_END",
"world_action_slide_VRAM_END",
"world_action_hit_fire_VRAM_END",
"world_action_hit_lava_VRAM_END",
"world_action_knockback_VRAM_END",
"world_action_misc_VRAM_END",
"world_action_use_munchlesia_VRAM_END",
"world_action_use_spinning_flower_VRAM_END",
"world_action_use_tweester_VRAM_END",
"world_action_sneaky_parasol_VRAM_END",
]
}
addrs: Dict[str, List[int]] = {}
if mode == "hardcode":
out = ""
for sym in syms_to_max:
addrs[sym] = [HARDCODED_ADDR]
elif mode == "calc":
with open(root_dir / "ver" / version / "build/papermario.map") as f:
lines = f.readlines()
finished = False
syms_to_go = set(syms_to_max.keys())
for line in lines:
for sym in syms_to_max:
for max_sym in syms_to_max[sym]:
if f"{max_sym} = ." in line:
if sym not in addrs:
addrs[sym] = []
addrs[sym].append(int(line.strip().split()[0], 16))
syms_to_max[sym].remove(max_sym)
if len(syms_to_max[sym]) == 0:
syms_to_go.remove(sym)
if not syms_to_go:
finished = True
if finished:
break
if syms_to_go:
print(f"Error: {syms_to_max} not found in map file")
sys.exit(1)
out_addrs = {sym: max(addrs[sym]) for sym in addrs}
out_addrs["entity_data_vram_end"] = out_addrs["entity_data_vram_end"] + out_addrs["world_action_vram_end"] - HARDCODED_ADDR
out = ""
for sym in out_addrs:
out += f" --defsym {sym}=0x{out_addrs[sym]:X}"
print(out)