From ade1415ed8ee14a12ed3392c0861b0991a8e7d0a Mon Sep 17 00:00:00 2001 From: alessamothdream Date: Sat, 25 Jul 2026 14:27:16 -0700 Subject: [PATCH] macOS support, small fixes --- Makefile | 8 ++++++-- config/SLUS_210.07.inc.lcf | 31 ++++++++++++++++++++++++++++--- configure.py | 33 +++++++++++++++++++-------------- include/macro.inc | 20 -------------------- 4 files changed, 53 insertions(+), 39 deletions(-) delete mode 100644 include/macro.inc diff --git a/Makefile b/Makefile index 00b8a80..260e6df 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,11 @@ # Disable printing "Entering/Leaving directory ..." MAKEFLAGS += --no-print-directory -NUMPROC ?= $(shell nproc) +ARCH ?= $(shell uname -m) +KERNEL ?= $(shell uname -s) +PLATFORM ?= $(if $(filter $(KERNEL),Darwin),macos,linux) +OS ?= $(PLATFORM)-$(subst _,-,$(ARCH)) +NUMPROC ?= $(if $(filter $(PLATFORM),linux),$(shell nproc),$(shell sysctl -n hw.logicalcpu)) CHECK_ENV_CMDS := \ python3 \ @@ -97,7 +101,7 @@ configure: ## Configure project (needs SLUS_210.07) .build-only: @cd config/; \ ninja -t clean; \ - ninja -j$(NUMPROC) + ninja -v -j$(NUMPROC) .check-files-on-error: ls -l config/build/SLUS_210.07 config/SLUS_210.07 diff --git a/config/SLUS_210.07.inc.lcf b/config/SLUS_210.07.inc.lcf index 5e5103b..90ab6b4 100644 --- a/config/SLUS_210.07.inc.lcf +++ b/config/SLUS_210.07.inc.lcf @@ -1,3 +1,28 @@ -INCLUDE "undefined_syms.txt" -INCLUDE "undefined_syms_auto.txt" -INCLUDE "undefined_funcs_auto.txt" \ No newline at end of file +MEMORY +{ + main (RWX) : ORIGIN = 0x100000, LENGTH = 0x0 +} + +KEEP_SECTION +{ + .rodata, + .data, + .vutext, + .vudata, + .vubss +} + +SECTIONS +{ + + .main : + { + _gp = 0x25f4f0; + . = ALIGN(0x80); + + __start = .; + ### 🔴 code 🔴 ### + + . = ALIGN(0x80); + } > main +} diff --git a/configure.py b/configure.py index 59e2525..8943ab2 100755 --- a/configure.py +++ b/configure.py @@ -64,8 +64,10 @@ CROSS = "mips-ps2-decompals-" COMPILER = "mwcps2-3.0b52-030722" COMPILER_FLAGS = "-O3,p -sym on -str readonly" -WIBO = f"{TOOLS_DIR}/wibo-x86_64" - +PLATFORM = "x86_64" # @todo get this from makefile +# PLATFORM = "macos" +WIBO = f"{TOOLS_DIR}/wibo-{PLATFORM}" +LCF = "SLUS_210.07.lcf" LANGUAGES: dict[str, str] = { "SLUS_210.07": "", @@ -209,7 +211,7 @@ def build_stuff( ninja = ninja_syntax.Writer(open(str(ROOT / config_dir / "build.ninja"), "w"), width=9999) # Rules - ld_args = "-map -lcf $in -o $out" + ld_args = "-map -sym on,elf -noinhibit-exec -main ENTRYPOINT -o $out $lcf $objects" ld = Path("..", (Path("tools") / "cc" / COMPILER / "mwldps2.exe")) cpp = Path("..", (Path("tools") / "cc" / COMPILER / "mwccps2.exe")) @@ -220,7 +222,7 @@ def build_stuff( # NOTE: Japanese strings are EUC-JP encoded!! # We need to convert them from (-f) UTF-8 to (-t) EUC-JP while compiling, # otherwise Japanese strings will be compiled wrong! - command=f"{WIBO} {cpp} {common_includes} $in -o - | iconv -f=UTF-8 -t=EUC-JP | {CROSS}as -no-pad-sections -EL -march=5900 -mabi=eabi -I{src_path.parent / 'include'} -o $out", + command=f"{CROSS}as -no-pad-sections -EL -march=5900 -mabi=eabi -mno-branch-relocs -I{src_path.parent / 'include'} -Iinclude -o $out $in", ) ninja.rule( @@ -275,7 +277,7 @@ def build_stuff( ninja.rule( "elf", description="elf $out", - command=f"{ld}objcopy $in $out -O binary && python3 {ROOT}/tools/python/fix_bin_matching.py {language} $out", + command=f"{CROSS}objcopy $in $out -O binary && python3 {ROOT}/tools/python/fix_bin_matching.py {language} $out", ) for entry in linker_entries: @@ -320,12 +322,18 @@ def build_stuff( print(f"ERROR: Unsupported build segment type {seg.type}") sys.exit(1) + built_object_paths = [str(obj) for obj in built_objects] + ninja.build( pre_elf_path, "ld", - ld_path, - implicit=[str(obj) for obj in built_objects], - variables={"mapfile": map_path}, + ld_path.replace(".ld",".lcf"), + implicit=built_object_paths, + variables={ + "mapfile": map_path, + "objects": [str(obj) for obj in built_objects], + "lcf": LCF + }, ) ninja.build( @@ -782,8 +790,6 @@ def generate_lcf(): objects = entries_by_section_type[section_type] if not objects: continue - if section_type == ".bss": - alignment = args.bss_alignment block = [ f"\t\t# {section_type}", @@ -802,8 +808,8 @@ def generate_lcf(): generated_lcf = "\n\n".join(lcf_blocks) - template_path = args.template_path - output_path = args.lcf_output_path + template_path = Path("config") / LCF.replace(".lcf", ".inc.lcf") + output_path = Path("config") / LCF template = template_path.read_text() output = template.replace( @@ -812,8 +818,7 @@ def generate_lcf(): ) output_path.write_text(output) - if args.verbose: - print(f"✅ Mullberry/generate: wrote LCF to {output_path}") + print(f"✅ Mulberry/generate: wrote LCF to {output_path}") def main(): diff --git a/include/macro.inc b/include/macro.inc deleted file mode 100644 index f6ea9f1..0000000 --- a/include/macro.inc +++ /dev/null @@ -1,20 +0,0 @@ -.macro glabel label - .global \label - .type \label, @function - \label: -.endm - -.macro dlabel label - .global \label - \label: -.endm - -.macro jlabel label - .global \label - \label: -.endm - -.macro llabel label - .local \label - \label: -.endm