Skip to content

Commit

Permalink
Add arch settings for PPC (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
snuffysasa authored May 26, 2022
1 parent a1aa28d commit d40565d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
File renamed without changes.
9 changes: 9 additions & 0 deletions mwcc_compile_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

### Set this to path to mwcc and version on your PC
cd /home/user/tools/mwcc_compiler/1.2.5

### change any compile flags here, and remove wine if you are using windows ofc.
wine mwcceppc.exe -Cpp_exceptions off -proc gekko -fp hard -fp_contract on -O4,p -enum int -nodefaults -inline auto -c -o $3 $1

### Also ensure that `powerpc-eabi-objdump` is in your environment PATH var
45 changes: 43 additions & 2 deletions src/objdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,33 @@ class ArchSettings:
"bc1f",
}.union(MIPS_BRANCH_LIKELY_INSTRUCTIONS)

PPC_BRANCH_INSTRUCTIONS = {
"b",
"beq",
"beq+",
"beq-",
"bne",
"bne+",
"bne-",
"blt",
"blt+",
"blt-",
"ble",
"ble+",
"ble-",
"bdnz",
"bdnz+",
"bdnz-",
"bge",
"bge+",
"bge-",
"bgt",
"bgt+",
"bgt-",
}

PPC_BRANCH_LIKELY_INSTRUCTIONS = {}

MIPS_SETTINGS: ArchSettings = ArchSettings(
re_comment=re.compile(r"<.*?>"),
re_reg=re.compile(
Expand All @@ -76,6 +103,17 @@ class ArchSettings:
)


PPC_SETTINGS: ArchSettings = ArchSettings(
re_includes_sp=re.compile(r"\b(r1)\b"),
re_comment=re.compile(r"(<.*>|//.*$)"),
re_reg=re.compile(r"\$?\b([rf][0-9]+)\b"),
re_sprel=re.compile(r"(?<=,)(-?[0-9]+|-?0x[0-9a-f]+)\(r1\)"),
objdump=["powerpc-eabi-objdump", "-d", "-EB", "-mpowerpc", "-M", "broadway"],
branch_instructions=PPC_BRANCH_INSTRUCTIONS,
branch_likely_instructions=PPC_BRANCH_LIKELY_INSTRUCTIONS,
)


def get_arch(o_file: str) -> ArchSettings:
# https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html
with open(o_file, "rb") as f:
Expand All @@ -86,7 +124,9 @@ def get_arch(o_file: str) -> ArchSettings:
arch = (data[19] << 8) + data[18]
if arch == 8:
return MIPS_SETTINGS
# TODO: support PPC (0x14), ARM (0x28)
if arch == 20:
return PPC_SETTINGS
# TODO: support ARM (0x28)
raise Exception("Bad ELF")


Expand Down Expand Up @@ -161,7 +201,8 @@ def simplify_objdump(
row = "<skipped>"
if ign_regs:
row = re.sub(arch.re_reg, "<reg>", row)
row_parts = row.split("\t")

row_parts = row.split(None, 1)
if len(row_parts) == 1:
row_parts.append("")
mnemonic, instr_args = row_parts
Expand Down

0 comments on commit d40565d

Please sign in to comment.