Skip to content

Commit

Permalink
Update dtk-template, dtk, and objdiff
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Jan 28, 2025
1 parent 901bc51 commit d6c3081
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 96 deletions.
12 changes: 6 additions & 6 deletions config/GZLE01/splits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ m_Do/m_Do_machine_exception.cpp:
.rodata start:0x803396F8 end:0x803398D8
.sbss start:0x803F69B0 end:0x803F69B8

dolphin/os/__start.c:
.init start:0x80003100 end:0x800033A8

c/c_damagereaction.cpp:
.text start:0x8001BEDC end:0x800227A0
.ctors start:0x803386A4 end:0x803386A8
Expand Down Expand Up @@ -1704,9 +1701,6 @@ d/d_wpot_water.cpp:
.sbss start:0x803F7300 end:0x803F7308
.sdata2 start:0x803FBB00 end:0x803FBB20

PowerPC_EABI_Support/Runtime/Src/__mem.c:
.init start:0x800033A8 end:0x800034E0

DynamicLink.cpp:
.text start:0x80240098 end:0x80241278
.text start:0x80241278 end:0x802412C4
Expand Down Expand Up @@ -4008,6 +4002,12 @@ TRK_MINNOW_DOLPHIN/Portable/notify.c:
TRK_MINNOW_DOLPHIN/ppc/Generic/flush_cache.c:
.text start:0x80335690 end:0x803356C8

dolphin/os/__start.c:
.init start:0x80003100 end:0x800033A8

PowerPC_EABI_Support/Runtime/Src/__mem.c:
.init start:0x800033A8 end:0x800034E0

TRK_MINNOW_DOLPHIN/Portable/mem_TRK.c:
.init start:0x800034E0 end:0x80003534
.text start:0x803356C8 end:0x80335784
Expand Down
12 changes: 6 additions & 6 deletions config/GZLJ01/splits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ m_Do/m_Do_machine_exception.cpp:
.rodata start:0x80337158 end:0x80337338
.sbss start:0x803E9E90 end:0x803E9E98

dolphin/os/__start.c:
.init start:0x80003100 end:0x800033A8

c/c_damagereaction.cpp:
.text start:0x8001BB70 end:0x80022430
.ctors start:0x803360A0 end:0x803360A4
Expand Down Expand Up @@ -1704,9 +1701,6 @@ d/d_wpot_water.cpp:
.sbss start:0x803EA7A0 end:0x803EA7A8
.sdata2 start:0x803EEFD8 end:0x803EEFF8

PowerPC_EABI_Support/Runtime/Src/__mem.c:
.init start:0x800033A8 end:0x800034E0

DynamicLink.cpp:
.text start:0x8023D828 end:0x8023EA08
.text start:0x8023EA08 end:0x8023EA54
Expand Down Expand Up @@ -4004,6 +3998,12 @@ TRK_MINNOW_DOLPHIN/Portable/notify.c:
TRK_MINNOW_DOLPHIN/ppc/Generic/flush_cache.c:
.text start:0x80333094 end:0x803330CC

dolphin/os/__start.c:
.init start:0x80003100 end:0x800033A8

PowerPC_EABI_Support/Runtime/Src/__mem.c:
.init start:0x800033A8 end:0x800034E0

TRK_MINNOW_DOLPHIN/Portable/mem_TRK.c:
.init start:0x800034E0 end:0x80003534
.text start:0x803330CC end:0x80333188
Expand Down
12 changes: 6 additions & 6 deletions config/GZLP01/splits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ m_Do/m_Do_machine_exception.cpp:
.rodata start:0x8033EC90 end:0x8033EE70
.sbss start:0x803FE1B0 end:0x803FE1B8

dolphin/os/__start.c:
.init start:0x80003100 end:0x800033A8

c/c_damagereaction.cpp:
.text start:0x8001C22C end:0x80022AF0
.ctors start:0x8033DBE4 end:0x8033DBE8
Expand Down Expand Up @@ -1704,9 +1701,6 @@ d/d_wpot_water.cpp:
.sbss start:0x803FEB20 end:0x803FEB28
.sdata2 start:0x80403350 end:0x80403370

PowerPC_EABI_Support/Runtime/Src/__mem.c:
.init start:0x800033A8 end:0x800034E0

DynamicLink.cpp:
.text start:0x80245238 end:0x80246418
.text start:0x80246418 end:0x80246464
Expand Down Expand Up @@ -4008,6 +4002,12 @@ TRK_MINNOW_DOLPHIN/Portable/notify.c:
TRK_MINNOW_DOLPHIN/ppc/Generic/flush_cache.c:
.text start:0x8033ABE8 end:0x8033AC20

dolphin/os/__start.c:
.init start:0x80003100 end:0x800033A8

PowerPC_EABI_Support/Runtime/Src/__mem.c:
.init start:0x800033A8 end:0x800034E0

TRK_MINNOW_DOLPHIN/Portable/mem_TRK.c:
.init start:0x800034E0 end:0x80003534
.text start:0x8033AC20 end:0x8033ACDC
Expand Down
21 changes: 19 additions & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@
# Tool versions
config.binutils_tag = "2.42-1"
config.compilers_tag = "20240706"
config.dtk_tag = "v1.3.0"
config.objdiff_tag = "v2.4.0"
config.dtk_tag = "v1.4.0"
config.objdiff_tag = "v2.7.1"
config.sjiswrap_tag = "v1.2.0"
config.wibo_tag = "0.6.11"

Expand Down Expand Up @@ -1799,6 +1799,23 @@ def emit_build_rule(asset):
emit_build_rule(asset)


# Optional callback to adjust link order. This can be used to add, remove, or reorder objects.
# This is called once per module, with the module ID and the current link order.
#
# For example, this adds "dummy.c" to the end of the DOL link order if configured with --non-matching.
# "dummy.c" *must* be configured as a Matching (or Equivalent) object in order to be linked.
def link_order_callback(module_id: int, objects: List[str]) -> List[str]:
# Don't modify the link order for matching builds
if not config.non_matching:
return objects
if module_id == 0: # DOL
return objects + ["dummy.c"]
return objects

# Uncomment to enable the link order callback.
# config.link_order_callback = link_order_callback


# Optional extra categories for progress tracking
config.progress_categories = [
ProgressCategory("game", "TWW Game Code"),
Expand Down
55 changes: 32 additions & 23 deletions tools/decompctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,63 +18,63 @@
script_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = os.path.abspath(os.path.join(script_dir, ".."))
src_dir = os.path.join(root_dir, "src")
include_dirs = [
os.path.join(root_dir, "include"),
os.path.join(root_dir, "src"),
os.path.join(root_dir, "src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include"),
os.path.join(root_dir, "src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common_Embedded/Math/Include"),
os.path.join(root_dir, "src/PowerPC_EABI_Support/MSL/MSL_C/PPC_EABI/Include"),
os.path.join(root_dir, "src/PowerPC_EABI_Support/MSL/MSL_C++/MSL_Common/Include"),
os.path.join(root_dir, "src/PowerPC_EABI_Support/Runtime/Inc"),
]

include_pattern = re.compile(r'^#include\s*[<"](.+?)[>"]')
guard_pattern = re.compile(r"^#ifndef\s+(.*)$")
include_dirs: List[str] = [] # Set with -I flag

include_pattern = re.compile(r'^#\s*include\s*[<"](.+?)[>"]')
guard_pattern = re.compile(r"^#\s*ifndef\s+(.*)$")
once_pattern = re.compile(r"^#\s*pragma\s+once$")

defines = set()
deps = []


def import_h_file(in_file: str, r_path: str, deps: List[str]) -> str:
def import_h_file(in_file: str, r_path: str) -> str:
rel_path = os.path.join(root_dir, r_path, in_file)
if os.path.exists(rel_path):
return import_c_file(rel_path, deps)
return import_c_file(rel_path)
for include_dir in include_dirs:
inc_path = os.path.join(include_dir, in_file)
if os.path.exists(inc_path):
return import_c_file(inc_path, deps)
return import_c_file(inc_path)
else:
print("Failed to locate", in_file)
return ""


def import_c_file(in_file: str, deps: List[str]) -> str:
def import_c_file(in_file: str) -> str:
in_file = os.path.relpath(in_file, root_dir)
deps.append(in_file)
out_text = ""

try:
with open(in_file, encoding="utf-8") as file:
out_text += process_file(in_file, list(file), deps)
out_text += process_file(in_file, list(file))
except Exception:
with open(in_file) as file:
out_text += process_file(in_file, list(file), deps)
out_text += process_file(in_file, list(file))
return out_text


def process_file(in_file: str, lines: List[str], deps: List[str]) -> str:
def process_file(in_file: str, lines: List[str]) -> str:
out_text = ""
for idx, line in enumerate(lines):
guard_match = guard_pattern.match(line.strip())
if idx == 0:
guard_match = guard_pattern.match(line.strip())
if guard_match:
if guard_match[1] in defines:
break
defines.add(guard_match[1])
else:
once_match = once_pattern.match(line.strip())
if once_match:
if in_file in defines:
break
defines.add(in_file)
print("Processing file", in_file)
include_match = include_pattern.match(line.strip())
if include_match and not include_match[1].endswith(".s"):
out_text += f'/* "{in_file}" line {idx} "{include_match[1]}" */\n'
out_text += import_h_file(include_match[1], os.path.dirname(in_file), deps)
out_text += import_h_file(include_match[1], os.path.dirname(in_file))
out_text += f'/* end "{include_match[1]}" */\n'
else:
out_text += line
Expand Down Expand Up @@ -105,10 +105,19 @@ def main():
"--depfile",
help="""Dependency file""",
)
parser.add_argument(
"-I",
"--include",
help="""Include directory""",
action="append",
)
args = parser.parse_args()

deps = []
output = import_c_file(args.c_file, deps)
if args.include is None:
exit("No include directories specified")
global include_dirs
include_dirs = args.include
output = import_c_file(args.c_file)

with open(os.path.join(root_dir, args.output), "w", encoding="utf-8") as f:
f.write(output)
Expand Down
46 changes: 30 additions & 16 deletions tools/download_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ def wibo_url(tag: str) -> str:
"wibo": wibo_url,
}

def download(url, response, output) -> None:
if url.endswith(".zip"):
data = io.BytesIO(response.read())
with zipfile.ZipFile(data) as f:
f.extractall(output)
# Make all files executable
for root, _, files in os.walk(output):
for name in files:
os.chmod(os.path.join(root, name), 0o755)
output.touch(mode=0o755) # Update dir modtime
else:
with open(output, "wb") as f:
shutil.copyfileobj(response, f)
st = os.stat(output)
os.chmod(output, st.st_mode | stat.S_IEXEC)

def main() -> None:
parser = argparse.ArgumentParser()
Expand All @@ -104,22 +119,21 @@ def main() -> None:

print(f"Downloading {url} to {output}")
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
with urllib.request.urlopen(req) as response:
if url.endswith(".zip"):
data = io.BytesIO(response.read())
with zipfile.ZipFile(data) as f:
f.extractall(output)
# Make all files executable
for root, _, files in os.walk(output):
for name in files:
os.chmod(os.path.join(root, name), 0o755)
output.touch(mode=0o755) # Update dir modtime
else:
with open(output, "wb") as f:
shutil.copyfileobj(response, f)
st = os.stat(output)
os.chmod(output, st.st_mode | stat.S_IEXEC)

try:
with urllib.request.urlopen(req) as response:
download(url, response, output)
except urllib.error.URLError as e:
if str(e).find("CERTIFICATE_VERIFY_FAILED") == -1:
raise e
try:
import certifi
import ssl
except:
print("\"certifi\" module not found. Please install it using \"python -m pip install certifi\".")
return

with urllib.request.urlopen(req, context=ssl.create_default_context(cafile=certifi.where())) as response:
download(url, response, output)

if __name__ == "__main__":
main()
Loading

0 comments on commit d6c3081

Please sign in to comment.