Skip to content

Commit

Permalink
Merge pull request #7 from em-eight/ppc2cpp
Browse files Browse the repository at this point in the history
Ppc2cpp
  • Loading branch information
em-eight authored Oct 22, 2023
2 parents 40c587a + 00b57ac commit a5acfeb
Show file tree
Hide file tree
Showing 57 changed files with 588 additions and 34,771 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
- run: pip install -r requirements.txt
if: steps.cache-virtualenv.outputs.cache-hit != 'true'

- name: Install Ninja
run: choco install -y ninja

- name: Extract tooling
env:
TOOLS_URL: 'https://www.dropbox.com/s/4b0hwciadfk8yuo/tools.zip?dl=1'
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ expected
build.ninja
.ninja_deps
.ninja_log

# ppc2cpp
*.ppc2cpp
ppc2cpp
ppc2cpp.zip
32 changes: 32 additions & 0 deletions asm/macros.inc
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,35 @@
.set qr5, 5
.set qr6, 6
.set qr7, 7
.set cr0lt, 0
.set cr0gt, 1
.set cr0eq, 2
.set cr0un, 3
.set cr1lt, 4
.set cr1gt, 5
.set cr1eq, 6
.set cr1un, 7
.set cr2lt, 8
.set cr2gt, 9
.set cr2eq, 10
.set cr2un, 11
.set cr3lt, 12
.set cr3gt, 13
.set cr3eq, 14
.set cr3un, 15
.set cr4lt, 16
.set cr4gt, 17
.set cr4eq, 18
.set cr4un, 19
.set cr5lt, 20
.set cr5gt, 21
.set cr5eq, 22
.set cr5un, 23
.set cr6lt, 24
.set cr6gt, 25
.set cr6eq, 26
.set cr6un, 27
.set cr7lt, 28
.set cr7gt, 29
.set cr7eq, 30
.set cr7un, 31
68 changes: 62 additions & 6 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def __native_binary(path):
GCC = __native_binary(os.path.join(DEVKITPPC, "bin", "powerpc-eabi-gcc"))

MWLD = os.path.join("tools", "mwldeppc.exe")
PPC2CPP = __native_binary(os.path.join("tools", "ppc2cpp", "bin", "ppc2cpp"))
ALLOW_CHAIN = "cmd /c " if os.name == "nt" else ""

CWCC_PATHS = {
"default": os.path.join(".", "tools", "4199_60831", "mwcceppc.exe"),
Expand Down Expand Up @@ -287,7 +289,6 @@ def add_compile_rules(args, n: Writer):
n.variable("gcc", GCC)
n.variable("asflags", "-mgekko -Iasm")

ALLOW_CHAIN = "cmd /c " if os.name == "nt" else ""
n.rule(
"as",
command = ALLOW_CHAIN + "$as $in $asflags -o $out && python -m mkwutil.postprocess -fno-ctor_realign -fsymbol-fixup -fprologue-fixup=none $out",
Expand Down Expand Up @@ -354,7 +355,6 @@ def link_dol(dol_objects_path: Path, n: Writer):
link(elf_path, dol_objects, dst_lcf_path, map_path, n)
# Convert ELF to DOL.
dol_path = dest_dir / "main.dol"
ALLOW_CHAIN = "cmd /c " if os.name == "nt" else ""
n.rule(
"pack_dol",
command = ALLOW_CHAIN + "python -m mkwutil.mkw_binary_patch $in && python -m mkwutil.pack_main_dol -o $out $in",
Expand All @@ -365,7 +365,7 @@ def link_dol(dol_objects_path: Path, n: Writer):
rule = "pack_dol",
inputs = str(elf_path)
)
return dol_path
return dol_path, elf_path


def link_rel(rel_objects_path: Path, n: Writer):
Expand Down Expand Up @@ -400,7 +400,57 @@ def link_rel(rel_objects_path: Path, n: Writer):
"dolelf" : str(dol_elf_path),
}
)
return rel_path
return rel_path, elf_path


def provide_ppc2cpp():
if not os.path.exists(PPC2CPP):
import urllib.request
import zipfile
ppc2cpp_zip = "ppc2cpp.zip"
print("Downloading ppc2cpp...")
if sys.platform == "win32" or sys.platform == "msys":
ppc2cpp_url = "https://github.com/em-eight/ppc2cpp/releases/download/v1.0-rc1/ppc2cpp-Windows.zip"
else:
ppc2cpp_url = "https://github.com/em-eight/ppc2cpp/releases/download/v1.0-rc1/ppc2cpp-Linux.zip"
urllib.request.urlretrieve(ppc2cpp_url, ppc2cpp_zip)
with zipfile.ZipFile(ppc2cpp_zip, 'r') as zip_ref:
zip_ref.extractall("tools/ppc2cpp")
print(PPC2CPP)
st = os.stat(str(PPC2CPP))
import stat
os.chmod(str(PPC2CPP), st.st_mode | stat.S_IEXEC)



def add_ppc2cpp_rules(orig_files, target_files, orig_out, target_out, n: Writer):
provide_ppc2cpp()
n.variable("ppc2cpp", str(PPC2CPP))
n.variable("ppcdis_dir", "mkwutil/ppcdis_adapter")
symmap = Path("pack/symbols.yml")
n.variable("symmap", str(symmap))
importcmd = "$ppc2cpp importppcdis -s $symmap -i $out -p $ppcdis_dir/dol.yaml $ppcdis_dir/dol_labels.pickle $ppcdis_dir/dol_relocs.pickle -p $ppcdis_dir/rel.yaml $ppcdis_dir/rel_labels.pickle $ppcdis_dir/rel_relocs.pickle"
n.rule(
"ppc2cppcreateorig",
command=ALLOW_CHAIN + "$ppc2cpp create -o $out $in && " + importcmd,
description="PPC2CPP CREATE ORIG"
)
n.rule(
"ppc2cppcreatetarget",
command="$ppc2cpp create -o $out $in",
description="PPC2CPP CREATE TARGET"
)
n.build(
str(orig_out),
rule="ppc2cppcreateorig",
inputs=list(str(pth) for pth in orig_files),
implicit=[str(symmap)]
)
n.build(
str(target_out),
rule="ppc2cppcreatetarget",
inputs=list(str(pth) for pth in target_files)
)


def configure(args):
Expand Down Expand Up @@ -434,8 +484,12 @@ def configure(args):
command = "$ld $in $ldflags -o $out",
description = "LD $out"
)
target_dol_path = link_dol(dol_objects_path, n)
target_rel_path = link_rel(rel_objects_path, n)
target_dol_path, target_dol_elf_path = link_dol(dol_objects_path, n)
target_rel_path, target_rel_elf_path = link_rel(rel_objects_path, n)

orig_ppc2cpp_proj = Path("artifacts", "orig", "pal", "orig.ppc2cpp")
target_ppc2cpp_proj = Path("artifacts", "orig", "pal", "target.ppc2cpp")
add_ppc2cpp_rules([orig_dol_path, orig_rel_path], [target_dol_elf_path, target_rel_elf_path], orig_ppc2cpp_proj, target_ppc2cpp_proj, n)

n.rule(
"verify",
Expand All @@ -447,6 +501,7 @@ def configure(args):
dol_ok,
rule = "verify",
inputs = str(target_dol_path),
implicit = [str(orig_ppc2cpp_proj), str(target_ppc2cpp_proj), str(target_dol_elf_path)],
variables = {
"verifyscript" : "mkwutil.verify_main_dol",
"ref" : str(orig_dol_path),
Expand All @@ -457,6 +512,7 @@ def configure(args):
rel_ok,
rule = "verify",
inputs = str(target_rel_path),
implicit = [str(orig_ppc2cpp_proj), str(target_ppc2cpp_proj), str(target_rel_elf_path)],
variables = {
"verifyscript" : "mkwutil.verify_staticr_rel",
"ref" : str(orig_rel_path),
Expand Down
Loading

0 comments on commit a5acfeb

Please sign in to comment.