From 0c114f958f0081b984b29211276ab4f8ae4ae82c Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Tue, 8 Feb 2022 11:27:00 -0500 Subject: [PATCH 1/3] Update the score to show NON_EQUIVALENT as well --- tools/python/score.py | 6 +++++- tools/python/score_display.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/python/score.py b/tools/python/score.py index c2cb6e70..93912948 100644 --- a/tools/python/score.py +++ b/tools/python/score.py @@ -34,6 +34,7 @@ FUNCTION_REGEX = r'(? 0: if showTopFiles > len(scoreFiles): diff --git a/tools/python/score_display.py b/tools/python/score_display.py index 4cc6c75b..73670111 100644 --- a/tools/python/score_display.py +++ b/tools/python/score_display.py @@ -106,7 +106,7 @@ class ScoreDisplay: out += self.makeLine(' ', dashLen, status['Msg']) return [out, dashLen] - def getDisplay(self, advOnePer, advTwoPer, showFlags=3, totalDecompFunctions=0, totalGlobalAsm=0, totalNonMatching=0, totalDocumented=0, totalUndocumented=0): + def getDisplay(self, advOnePer, advTwoPer, showFlags=3, totalDecompFunctions=0, totalGlobalAsm=0, totalNonMatching=0, totalNonEquivalent=0, totalDocumented=0, totalUndocumented=0): advOneStatus = self.getStatus(advOnePer) advTwoStatus = self.getStatus(advTwoPer) if showFlags == 3: @@ -130,6 +130,7 @@ class ScoreDisplay: out += self.makeLine(' ', dashLen, '# Decompiled functions: ' + str(totalDecompFunctions)) out += self.makeLine(' ', dashLen, '# GLOBAL_ASM remaining: ' + str(totalGlobalAsm)) out += self.makeLine(' ', dashLen, '# NON_MATCHING functions: ' + str(totalNonMatching)) + out += self.makeLine(' ', dashLen, '# NON_EQUIVALENT WIP functions: ' + str(totalNonEquivalent)) out += advOneGameStatusDisplay[0] if showFlags & 2: out += self.makeLine('=', dashLen) From b87fc3a47aa122e0db5c8ac573a1444254fa81f8 Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Tue, 8 Feb 2022 11:30:50 -0500 Subject: [PATCH 2/3] Update diff.py --- tools/python/diff.py | 347 +++++++++++++++++++++------------- tools/python/diff_settings.py | 1 - 2 files changed, 213 insertions(+), 135 deletions(-) diff --git a/tools/python/diff.py b/tools/python/diff.py index 22dff4eb..e57eea22 100644 --- a/tools/python/diff.py +++ b/tools/python/diff.py @@ -132,6 +132,14 @@ if __name__ == "__main__": help="""Tweak --source handling to make it work with binutils < 2.33. Implies --source.""", ) + parser.add_argument( + "-j", + "--section", + dest="diff_section", + default=".text", + metavar="SECTION", + help="Diff restricted to a given output section.", + ) parser.add_argument( "-L", "--line-numbers", @@ -365,6 +373,7 @@ class ProjectSettings: source_directories: Optional[List[str]] source_extensions: List[str] show_line_numbers_default: bool + disassemble_all: bool @dataclass @@ -381,6 +390,7 @@ class Config: diff_obj: bool make: bool source_old_binutils: bool + diff_section: str inlines: bool max_function_size_lines: int max_function_size_bytes: int @@ -425,6 +435,7 @@ def create_project_settings(settings: Dict[str, Any]) -> ProjectSettings: map_format=settings.get("map_format", "gnu"), mw_build_dir=settings.get("mw_build_dir", "build/"), show_line_numbers_default=settings.get("show_line_numbers_default", True), + disassemble_all=settings.get("disassemble_all", False) ) @@ -463,6 +474,7 @@ def create_config(args: argparse.Namespace, project: ProjectSettings) -> Config: diff_obj=args.diff_obj, make=args.make, source_old_binutils=args.source_old_binutils, + diff_section=args.diff_section, inlines=args.inlines, max_function_size_lines=args.max_lines, max_function_size_bytes=args.max_lines * 4, @@ -1009,11 +1021,11 @@ def run_objdump(cmd: ObjdumpCommand, config: Config, project: ProjectSettings) - with open(target, "rb") as f: obj_data = f.read() - return preprocess_objdump_out(restrict, obj_data, out) + return preprocess_objdump_out(restrict, obj_data, out, config) def preprocess_objdump_out( - restrict: Optional[str], obj_data: Optional[bytes], objdump_out: str + restrict: Optional[str], obj_data: Optional[bytes], objdump_out: str, config: Config ) -> str: """ Preprocess the output of objdump into a format that `process()` expects. @@ -1033,13 +1045,13 @@ def preprocess_objdump_out( out = out.rstrip("\n") if obj_data: - out = serialize_data_references(parse_elf_data_references(obj_data)) + out + out = serialize_data_references(parse_elf_data_references(obj_data, config)) + out return out def search_map_file( - fn_name: str, project: ProjectSettings + fn_name: str, project: ProjectSettings, config: Config ) -> Tuple[Optional[str], Optional[int]]: if not project.mapfile: fail(f"No map file configured; cannot find function {fn_name}.") @@ -1059,7 +1071,7 @@ def search_map_file( cands = [] last_line = "" for line in lines: - if line.startswith(" .text"): + if line.startswith(" " + config.diff_section): cur_objfile = line.split()[3] if "load address" in line: tokens = last_line.split() + line.split() @@ -1080,13 +1092,14 @@ def search_map_file( if len(cands) == 1: return cands[0] elif project.map_format == "mw": + section_pattern = re.escape(config.diff_section) find = re.findall( re.compile( # ram elf rom r" \S+ \S+ (\S+) (\S+) . " + fn_name # object name - + r"(?: \(entry of \.(?:init|text)\))? \t(\S+)" + + r"(?: \(entry of " + section_pattern + r"\))? \t(\S+)" ), contents, ) @@ -1121,7 +1134,7 @@ def search_map_file( return None, None -def parse_elf_data_references(data: bytes) -> List[Tuple[int, int, str]]: +def parse_elf_data_references(data: bytes, config: Config) -> List[Tuple[int, int, str]]: e_ident = data[:16] if e_ident[:4] != b"\x7FELF": return [] @@ -1134,7 +1147,6 @@ def parse_elf_data_references(data: bytes) -> List[Tuple[int, int, str]]: is_little_endian = e_ident[5] == 1 str_end = "<" if is_little_endian else ">" str_off = "I" if is_32bit else "Q" - sym_size = {"B": 1, "H": 2, "I": 4, "Q": 8} def read(spec: str, offset: int) -> Tuple[int, ...]: spec = spec.replace("P", str_off) @@ -1186,17 +1198,22 @@ def parse_elf_data_references(data: bytes) -> List[Tuple[int, int, str]]: assert len(symtab_sections) == 1 symtab = sections[symtab_sections[0]] - text_sections = [i for i in range(e_shnum) if sec_names[i] == b".text"] - assert len(text_sections) == 1 + section_name = config.diff_section.encode("utf-8") + text_sections = [i for i in range(e_shnum) if sec_names[i] == section_name and sections[i].sh_size != 0] + if len(text_sections) != 1: + return [] text_section = text_sections[0] ret: List[Tuple[int, int, str]] = [] for s in sections: if s.sh_type == SHT_REL or s.sh_type == SHT_RELA: if s.sh_info == text_section: - # Skip .text -> .text references + # Skip section_name -> section_name references continue sec_name = sec_names[s.sh_info].decode("latin1") + if sec_name == ".mwcats.text": + # Skip Metrowerks CATS Utility section + continue sec_base = sections[s.sh_info].sh_offset for i in range(0, s.sh_size, s.sh_entsize): if s.sh_type == SHT_REL: @@ -1253,11 +1270,16 @@ def dump_elf( f"--stop-address={end_addr}", ] + if project.disassemble_all: + disassemble_flag = "-D" + else: + disassemble_flag = "-d" + flags2 = [ f"--disassemble={diff_elf_symbol}", ] - objdump_flags = ["-drz", "-j", ".text"] + objdump_flags = [disassemble_flag, "-rz", "-j", config.diff_section] return ( project.myimg, (objdump_flags + flags1, project.baseimg, None), @@ -1279,7 +1301,7 @@ def dump_objfile( if start.startswith("0"): fail("numerical start address not supported with -o; pass a function name") - objfile, _ = search_map_file(start, project) + objfile, _ = search_map_file(start, project, config) if not objfile: fail("Not able to find .o file for function.") @@ -1293,7 +1315,12 @@ def dump_objfile( if not os.path.isfile(refobjfile): fail(f'Please ensure an OK .o file exists at "{refobjfile}".') - objdump_flags = ["-drz", "-j", ".text"] + if project.disassemble_all: + disassemble_flag = "-D" + else: + disassemble_flag = "-d" + + objdump_flags = [disassemble_flag, "-rz", "-j", config.diff_section] return ( objfile, (objdump_flags, refobjfile, start), @@ -1310,7 +1337,7 @@ def dump_binary( run_make(project.myimg, project) start_addr = maybe_eval_int(start) if start_addr is None: - _, start_addr = search_map_file(start, project) + _, start_addr = search_map_file(start, project, config) if start_addr is None: fail("Not able to find function in map file.") if end is not None: @@ -1329,11 +1356,18 @@ def dump_binary( (objdump_flags + flags2, project.myimg, None), ) +# Example: "ldr r4, [pc, #56] ; (4c )" +ARM32_LOAD_POOL_PATTERN = r"(ldr\s+r([0-9]|1[0-3]),\s+\[pc,.*;\s*)(\([a-fA-F0-9]+.*\))" -class DifferenceNormalizer: + +# The base class is a no-op. +class AsmProcessor: def __init__(self, config: Config) -> None: self.config = config + def process_reloc(self, row: str, prev: str) -> str: + return prev + def normalize(self, mnemonic: str, row: str) -> str: """This should be called exactly once for each line.""" arch = self.config.arch @@ -1345,8 +1379,132 @@ class DifferenceNormalizer: def _normalize_arch_specific(self, mnemonic: str, row: str) -> str: return row + def post_process(self, lines: List["Line"]) -> None: + return -class DifferenceNormalizerAArch64(DifferenceNormalizer): + +class AsmProcessorMIPS(AsmProcessor): + def process_reloc(self, row: str, prev: str) -> str: + arch = self.config.arch + if "R_MIPS_NONE" in row or "R_MIPS_JALR" in row: + # GNU as emits no-op relocations immediately after real ones when + # assembling with -mabi=64. Return without trying to parse 'imm' as an + # integer. + return prev + before, imm, after = parse_relocated_line(prev) + repl = row.split()[-1] + if imm != "0": + # MIPS uses relocations with addends embedded in the code as immediates. + # If there is an immediate, show it as part of the relocation. Ideally + # we'd show this addend in both %lo/%hi, but annoyingly objdump's output + # doesn't include enough information to pair up %lo's and %hi's... + # TODO: handle unambiguous cases where all addends for a symbol are the + # same, or show "+???". + mnemonic = prev.split()[0] + if ( + mnemonic in arch.instructions_with_address_immediates + and not imm.startswith("0x") + ): + imm = "0x" + imm + repl += "+" + imm if int(imm, 0) > 0 else imm + if "R_MIPS_LO16" in row: + repl = f"%lo({repl})" + elif "R_MIPS_HI16" in row: + # Ideally we'd pair up R_MIPS_LO16 and R_MIPS_HI16 to generate a + # correct addend for each, but objdump doesn't give us the order of + # the relocations, so we can't find the right LO16. :( + repl = f"%hi({repl})" + elif "R_MIPS_26" in row: + # Function calls + pass + elif "R_MIPS_PC16" in row: + # Branch to glabel. This gives confusing output, but there's not much + # we can do here. + pass + elif "R_MIPS_GPREL16" in row: + repl = f"%gp_rel({repl})" + elif "R_MIPS_GOT16" in row: + repl = f"%got({repl})" + elif "R_MIPS_CALL16" in row: + repl = f"%call16({repl})" + else: + assert False, f"unknown relocation type '{row}' for line '{prev}'" + return before + repl + after + + +class AsmProcessorPPC(AsmProcessor): + def process_reloc(self, row: str, prev: str) -> str: + arch = self.config.arch + assert any( + r in row for r in ["R_PPC_REL24", "R_PPC_ADDR16", "R_PPC_EMB_SDA21"] + ), f"unknown relocation type '{row}' for line '{prev}'" + before, imm, after = parse_relocated_line(prev) + repl = row.split()[-1] + if "R_PPC_REL24" in row: + # function calls + pass + elif "R_PPC_ADDR16_HI" in row: + # absolute hi of addr + repl = f"{repl}@h" + elif "R_PPC_ADDR16_HA" in row: + # adjusted hi of addr + repl = f"{repl}@ha" + elif "R_PPC_ADDR16_LO" in row: + # lo of addr + repl = f"{repl}@l" + elif "R_PPC_ADDR16" in row: + # 16-bit absolute addr + if "+0x7" in repl: + # remove the very large addends as they are an artifact of (label-_SDA(2)_BASE_) + # computations and are unimportant in a diff setting. + if int(repl.split("+")[1], 16) > 0x70000000: + repl = repl.split("+")[0] + elif "R_PPC_EMB_SDA21" in row: + # small data area + pass + return before + repl + after + + +class AsmProcessorARM32(AsmProcessor): + def process_reloc(self, row: str, prev: str) -> str: + arch = self.config.arch + before, imm, after = parse_relocated_line(prev) + repl = row.split()[-1] + return before + repl + after + + def _normalize_arch_specific(self, mnemonic: str, row: str) -> str: + if self.config.ignore_addr_diffs: + row = self._normalize_bl(mnemonic, row) + row = self._normalize_data_pool(row) + return row + + def _normalize_bl(self, mnemonic: str, row: str) -> str: + if mnemonic != "bl": + return row + + row, _ = split_off_address(row) + return row + "" + + def _normalize_data_pool(self, row: str) -> str: + pool_match = re.search(ARM32_LOAD_POOL_PATTERN, row) + return pool_match.group(1) if pool_match else row + + def post_process(self, lines: List["Line"]) -> None: + lines_by_line_number = {} + for line in lines: + lines_by_line_number[line.line_num] = line + for line in lines: + if line.data_pool_addr is None: + continue + + # Add data symbol and its address to the line. + line_original = lines_by_line_number[line.data_pool_addr].original + value = line_original.split()[1] + addr = "{:x}".format(line.data_pool_addr) + line.original = line.normalized_original + f"={value} ({addr})" + + +class AsmProcessorAArch64(AsmProcessor): def __init__(self, config: Config) -> None: super().__init__(config) self._adrp_pair_registers: Set[str] = set() @@ -1396,23 +1554,6 @@ class DifferenceNormalizerAArch64(DifferenceNormalizer): return row -class DifferenceNormalizerARM32(DifferenceNormalizer): - def __init__(self, config: Config) -> None: - super().__init__(config) - - def _normalize_arch_specific(self, mnemonic: str, row: str) -> str: - if self.config.ignore_addr_diffs: - row = self._normalize_bl(mnemonic, row) - return row - - def _normalize_bl(self, mnemonic: str, row: str) -> str: - if mnemonic != "bl": - return row - - row, _ = split_off_address(row) - return row + "" - - @dataclass class ArchSettings: name: str @@ -1422,12 +1563,13 @@ class ArchSettings: re_sprel: Pattern[str] re_large_imm: Pattern[str] re_imm: Pattern[str] + re_reloc: Pattern[str] branch_instructions: Set[str] instructions_with_address_immediates: Set[str] forbidden: Set[str] = field(default_factory=lambda: set(string.ascii_letters + "_")) arch_flags: List[str] = field(default_factory=list) branch_likely_instructions: Set[str] = field(default_factory=set) - difference_normalizer: Type[DifferenceNormalizer] = DifferenceNormalizer + proc: Type[AsmProcessor] = AsmProcessor big_endian: Optional[bool] = True delay_slot_instructions: Set[str] = field(default_factory=set) @@ -1538,18 +1680,20 @@ PPC_BRANCH_INSTRUCTIONS = { MIPS_SETTINGS = ArchSettings( name="mips", re_int=re.compile(r"[0-9]+"), - re_comment=re.compile(r"<.*?>"), + re_comment=re.compile(r"<.*>"), re_reg=re.compile( r"\$?\b(a[0-7]|t[0-9]|s[0-8]|at|v[01]|f[12]?[0-9]|f3[01]|kt?[01]|fp|ra|zero)\b" ), re_sprel=re.compile(r"(?<=,)([0-9]+|0x[0-9a-f]+)\(sp\)"), re_large_imm=re.compile(r"-?[1-9][0-9]{2,}|-?0x[0-9a-f]{3,}"), re_imm=re.compile(r"(\b|-)([0-9]+|0x[0-9a-fA-F]+)\b(?!\(sp)|%(lo|hi)\([^)]*\)"), + re_reloc=re.compile(r"R_MIPS_"), arch_flags=["-m", "mips:4300"], branch_likely_instructions=MIPS_BRANCH_LIKELY_INSTRUCTIONS, branch_instructions=MIPS_BRANCH_INSTRUCTIONS, instructions_with_address_immediates=MIPS_BRANCH_INSTRUCTIONS.union({"jal", "j"}), delay_slot_instructions=MIPS_BRANCH_INSTRUCTIONS.union({"j", "jal", "jr", "jalr"}), + proc=AsmProcessorMIPS, ) MIPSEL_SETTINGS = replace(MIPS_SETTINGS, name="mipsel", big_endian=False) @@ -1557,7 +1701,7 @@ MIPSEL_SETTINGS = replace(MIPS_SETTINGS, name="mipsel", big_endian=False) ARM32_SETTINGS = ArchSettings( name="arm32", re_int=re.compile(r"[0-9]+"), - re_comment=re.compile(r"(<.*?>|//.*$)"), + re_comment=re.compile(r"(<.*>|//.*$)"), # Includes: # - General purpose registers: r0..13 # - Frame pointer registers: lr (r14), pc (r15) @@ -1569,42 +1713,50 @@ ARM32_SETTINGS = ArchSettings( re_sprel=re.compile(r"sp, #-?(0x[0-9a-fA-F]+|[0-9]+)\b"), re_large_imm=re.compile(r"-?[1-9][0-9]{2,}|-?0x[0-9a-f]{3,}"), re_imm=re.compile(r"(?|//.*$)"), - # GPRs and FP registers: X0-X30, W0-W30, [DSHQ]0..31 + re_comment=re.compile(r"(<.*>|//.*$)"), + # GPRs and FP registers: X0-X30, W0-W30, [BHSDVQ]0..31 + # (FP registers may be followed by data width and number of elements, e.g. V0.4S) # The zero registers and SP should not be in this list. - re_reg=re.compile(r"\$?\b([dshq][12]?[0-9]|[dshq]3[01]|[xw][12]?[0-9]|[xw]30)\b"), + re_reg=re.compile(r"\$?\b([bhsdvq]([12]?[0-9]|3[01])(\.\d\d?[bhsdvq])?|[xw][12]?[0-9]|[xw]30)\b"), re_sprel=re.compile(r"sp, #-?(0x[0-9a-fA-F]+|[0-9]+)\b"), re_large_imm=re.compile(r"-?[1-9][0-9]{2,}|-?0x[0-9a-f]{3,}"), re_imm=re.compile(r"(?|//.*$)"), + 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\)"), re_large_imm=re.compile(r"-?[1-9][0-9]{2,}|-?0x[0-9a-f]{3,}"), re_imm=re.compile(r"(\b|-)([0-9]+|0x[0-9a-fA-F]+)\b(?!\(r1)|[^@]*@(ha|h|lo)"), + re_reloc=re.compile(r"R_PPC_"), branch_instructions=PPC_BRANCH_INSTRUCTIONS, instructions_with_address_immediates=PPC_BRANCH_INSTRUCTIONS.union({"bl"}), + proc=AsmProcessorPPC, ) ARCH_SETTINGS = [ MIPS_SETTINGS, MIPSEL_SETTINGS, ARM32_SETTINGS, + ARMEL_SETTINGS, AARCH64_SETTINGS, PPC_SETTINGS, ] @@ -1642,84 +1794,6 @@ def parse_relocated_line(line: str) -> Tuple[str, str, str]: return before, imm, after -def process_mips_reloc(row: str, prev: str, arch: ArchSettings) -> str: - if "R_MIPS_NONE" in row: - # GNU as emits no-op relocations immediately after real ones when - # assembling with -mabi=64. Return without trying to parse 'imm' as an - # integer. - return prev - before, imm, after = parse_relocated_line(prev) - repl = row.split()[-1] - if imm != "0": - # MIPS uses relocations with addends embedded in the code as immediates. - # If there is an immediate, show it as part of the relocation. Ideally - # we'd show this addend in both %lo/%hi, but annoyingly objdump's output - # doesn't include enough information to pair up %lo's and %hi's... - # TODO: handle unambiguous cases where all addends for a symbol are the - # same, or show "+???". - mnemonic = prev.split()[0] - if ( - mnemonic in arch.instructions_with_address_immediates - and not imm.startswith("0x") - ): - imm = "0x" + imm - repl += "+" + imm if int(imm, 0) > 0 else imm - if "R_MIPS_LO16" in row: - repl = f"%lo({repl})" - elif "R_MIPS_HI16" in row: - # Ideally we'd pair up R_MIPS_LO16 and R_MIPS_HI16 to generate a - # correct addend for each, but objdump doesn't give us the order of - # the relocations, so we can't find the right LO16. :( - repl = f"%hi({repl})" - elif "R_MIPS_26" in row: - # Function calls - pass - elif "R_MIPS_PC16" in row: - # Branch to glabel. This gives confusing output, but there's not much - # we can do here. - pass - else: - assert False, f"unknown relocation type '{row}' for line '{prev}'" - return before + repl + after - - -def process_ppc_reloc(row: str, prev: str) -> str: - assert any( - r in row for r in ["R_PPC_REL24", "R_PPC_ADDR16", "R_PPC_EMB_SDA21"] - ), f"unknown relocation type '{row}' for line '{prev}'" - before, imm, after = parse_relocated_line(prev) - repl = row.split()[-1] - if "R_PPC_REL24" in row: - # function calls - pass - elif "R_PPC_ADDR16_HI" in row: - # absolute hi of addr - repl = f"{repl}@h" - elif "R_PPC_ADDR16_HA" in row: - # adjusted hi of addr - repl = f"{repl}@ha" - elif "R_PPC_ADDR16_LO" in row: - # lo of addr - repl = f"{repl}@l" - elif "R_PPC_ADDR16" in row: - # 16-bit absolute addr - if "+0x7" in repl: - # remove the very large addends as they are an artifact of (label-_SDA(2)_BASE_) - # computations and are unimportant in a diff setting. - if int(repl.split("+")[1], 16) > 0x70000000: - repl = repl.split("+")[0] - elif "R_PPC_EMB_SDA21" in row: - # small data area - pass - return before + repl + after - - -def process_arm_reloc(row: str, prev: str, arch: ArchSettings) -> str: - before, imm, after = parse_relocated_line(prev) - repl = row.split()[-1] - return before + repl + after - - def pad_mnemonic(line: str) -> str: if "\t" not in line: return line @@ -1736,6 +1810,7 @@ class Line: scorable_line: str line_num: Optional[int] = None branch_target: Optional[int] = None + data_pool_addr: Optional[int] = None source_filename: Optional[str] = None source_line_num: Optional[int] = None source_lines: List[str] = field(default_factory=list) @@ -1744,7 +1819,7 @@ class Line: def process(dump: str, config: Config) -> List[Line]: arch = config.arch - normalizer = arch.difference_normalizer(config) + processor = arch.proc(config) skip_next = False source_lines = [] source_filename = None @@ -1786,7 +1861,7 @@ def process(dump: str, config: Config) -> List[Line]: ) break - if not re.match(r"^ +[0-9a-f]+:\t", row): + if not re.match(r"^\s+[0-9a-f]+:\s+", row): # This regex is conservative, and assumes the file path does not contain "weird" # characters like colons, tabs, or angle brackets. if re.match( @@ -1797,13 +1872,22 @@ def process(dump: str, config: Config) -> List[Line]: source_lines.append(row) continue + # If the instructions loads a data pool symbol, extract the address of + # the symbol. + data_pool_addr = None + pool_match = re.search(ARM32_LOAD_POOL_PATTERN, row) + if pool_match: + offset = pool_match.group(3).split(" ")[0][1:] + data_pool_addr = int(offset, 16) + m_comment = re.search(arch.re_comment, row) comment = m_comment[0] if m_comment else None row = re.sub(arch.re_comment, "", row) + line_num_str = row.split(":")[0] row = row.rstrip() tabs = row.split("\t") row = "\t".join(tabs[2:]) - line_num = eval_line_num(tabs[0].strip()) + line_num = eval_line_num(line_num_str.strip()) if line_num in data_refs: refs = data_refs[line_num] @@ -1838,20 +1922,13 @@ def process(dump: str, config: Config) -> List[Line]: while i < len(lines): reloc_row = lines[i] - if "R_AARCH64_" in reloc_row: - # TODO: handle relocation - pass - elif "R_MIPS_" in reloc_row: - original = process_mips_reloc(reloc_row, original, arch) - elif "R_PPC_" in reloc_row: - original = process_ppc_reloc(reloc_row, original) - elif "R_ARM_" in reloc_row: - original = process_arm_reloc(reloc_row, original, arch) + if re.search(arch.re_reloc, reloc_row): + original = processor.process_reloc(reloc_row, original) else: break i += 1 - normalized_original = normalizer.normalize(mnemonic, original) + normalized_original = processor.normalize(mnemonic, original) scorable_line = normalized_original if not config.score_stack_differences: @@ -1893,6 +1970,7 @@ def process(dump: str, config: Config) -> List[Line]: scorable_line=scorable_line, line_num=line_num, branch_target=branch_target, + data_pool_addr=data_pool_addr, source_filename=source_filename, source_line_num=source_line_num, source_lines=source_lines, @@ -1907,6 +1985,7 @@ def process(dump: str, config: Config) -> List[Line]: elif stop_after_delay_slot: break + processor.post_process(output) return output diff --git a/tools/python/diff_settings.py b/tools/python/diff_settings.py index 54214cbc..689e3644 100644 --- a/tools/python/diff_settings.py +++ b/tools/python/diff_settings.py @@ -14,7 +14,6 @@ def apply(config, args): config['mapfile'] = f'build/' + version + '/dkr.map' config['myimg'] = f'build/' + version + '/dkr.z64' config['baseimg'] = find_baserom(version) - config['makeflags'] = [f''] config['source_directories'] = ['src'] ######################################################################################## From 4a231449a243f43e0ee593060db2696e3f1bd6af Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Tue, 8 Feb 2022 13:09:54 -0500 Subject: [PATCH 3/3] Matched menu_game_select_loop by adding a void definition for func_8008C168 --- .../menu/menu_game_select_loop.s | 214 ------------------ src/menu.c | 7 - src/menu.h | 1 + 3 files changed, 1 insertion(+), 221 deletions(-) delete mode 100644 asm/non_matchings/menu/menu_game_select_loop.s diff --git a/asm/non_matchings/menu/menu_game_select_loop.s b/asm/non_matchings/menu/menu_game_select_loop.s deleted file mode 100644 index d3e9260f..00000000 --- a/asm/non_matchings/menu/menu_game_select_loop.s +++ /dev/null @@ -1,214 +0,0 @@ -glabel menu_game_select_loop -/* 08D3BC 8008C7BC 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 08D3C0 8008C7C0 AFBF0014 */ sw $ra, 0x14($sp) -/* 08D3C4 8008C7C4 0C02305A */ jal func_8008C168 -/* 08D3C8 8008C7C8 AFA40028 */ sw $a0, 0x28($sp) -/* 08D3CC 8008C7CC 3C038012 */ lui $v1, %hi(D_801263BC) # $v1, 0x8012 -/* 08D3D0 8008C7D0 246363BC */ addiu $v1, %lo(D_801263BC) # addiu $v1, $v1, 0x63bc -/* 08D3D4 8008C7D4 8FA40028 */ lw $a0, 0x28($sp) -/* 08D3D8 8008C7D8 8C6E0000 */ lw $t6, ($v1) -/* 08D3DC 8008C7DC 3C058012 */ lui $a1, %hi(D_801263D8) # $a1, 0x8012 -/* 08D3E0 8008C7E0 24A563D8 */ addiu $a1, %lo(D_801263D8) # addiu $a1, $a1, 0x63d8 -/* 08D3E4 8008C7E4 8CA20000 */ lw $v0, ($a1) -/* 08D3E8 8008C7E8 01C47821 */ addu $t7, $t6, $a0 -/* 08D3EC 8008C7EC 31F8003F */ andi $t8, $t7, 0x3f -/* 08D3F0 8008C7F0 1040000B */ beqz $v0, .L8008C820 -/* 08D3F4 8008C7F4 AC780000 */ sw $t8, ($v1) -/* 08D3F8 8008C7F8 24590001 */ addiu $t9, $v0, 1 -/* 08D3FC 8008C7FC 2B210003 */ slti $at, $t9, 3 -/* 08D400 8008C800 14200007 */ bnez $at, .L8008C820 -/* 08D404 8008C804 ACB90000 */ sw $t9, ($a1) -/* 08D408 8008C808 0C020A2E */ jal func_800828B8 -/* 08D40C 8008C80C AFA40028 */ sw $a0, 0x28($sp) -/* 08D410 8008C810 3C058012 */ lui $a1, %hi(D_801263D8) # $a1, 0x8012 -/* 08D414 8008C814 24A563D8 */ addiu $a1, %lo(D_801263D8) # addiu $a1, $a1, 0x63d8 -/* 08D418 8008C818 8FA40028 */ lw $a0, 0x28($sp) -/* 08D41C 8008C81C ACA00000 */ sw $zero, ($a1) -.L8008C820: -/* 08D420 8008C820 3C03800E */ lui $v1, %hi(gMenuDelay) # $v1, 0x800e -/* 08D424 8008C824 2463F47C */ addiu $v1, %lo(gMenuDelay) # addiu $v1, $v1, -0xb84 -/* 08D428 8008C828 8C620000 */ lw $v0, ($v1) -/* 08D42C 8008C82C 00000000 */ nop -/* 08D430 8008C830 1040000A */ beqz $v0, .L8008C85C -/* 08D434 8008C834 2841001F */ slti $at, $v0, 0x1f -/* 08D438 8008C838 04410005 */ bgez $v0, .L8008C850 -/* 08D43C 8008C83C 00445021 */ addu $t2, $v0, $a0 -/* 08D440 8008C840 00444823 */ subu $t1, $v0, $a0 -/* 08D444 8008C844 AC690000 */ sw $t1, ($v1) -/* 08D448 8008C848 10000003 */ b .L8008C858 -/* 08D44C 8008C84C 01201025 */ move $v0, $t1 -.L8008C850: -/* 08D450 8008C850 AC6A0000 */ sw $t2, ($v1) -/* 08D454 8008C854 01401025 */ move $v0, $t2 -.L8008C858: -/* 08D458 8008C858 2841001F */ slti $at, $v0, 0x1f -.L8008C85C: -/* 08D45C 8008C85C 14200023 */ bnez $at, .L8008C8EC -/* 08D460 8008C860 2841FFE2 */ slti $at, $v0, -0x1e -/* 08D464 8008C864 0C0232B3 */ jal func_8008CACC -/* 08D468 8008C868 00000000 */ nop -/* 08D46C 8008C86C 3C02800E */ lui $v0, %hi(D_800DF460) # $v0, 0x800e -/* 08D470 8008C870 3C0B8012 */ lui $t3, %hi(D_801263E0) # $t3, 0x8012 -/* 08D474 8008C874 8D6B63E0 */ lw $t3, %lo(D_801263E0)($t3) -/* 08D478 8008C878 8C42F460 */ lw $v0, %lo(D_800DF460)($v0) -/* 08D47C 8008C87C 3C01800E */ lui $at, %hi(gIsInAdventureTwo) # $at, 0x800e -/* 08D480 8008C880 1562000F */ bne $t3, $v0, .L8008C8C0 -/* 08D484 8008C884 00002025 */ move $a0, $zero -/* 08D488 8008C888 0C0002CA */ jal func_80000B28 -/* 08D48C 8008C88C 00000000 */ nop -/* 08D490 8008C890 240C0001 */ li $t4, 1 -/* 08D494 8008C894 3C01800E */ lui $at, %hi(gIsInAdventureTwo) # $at, 0x800e -/* 08D498 8008C898 0C01B96F */ jal func_8006E5BC -/* 08D49C 8008C89C AC2CF4B8 */ sw $t4, %lo(gIsInTracksMode)($at) -/* 08D4A0 8008C8A0 2404FFFF */ li $a0, -1 -/* 08D4A4 8008C8A4 2405FFFF */ li $a1, -1 -/* 08D4A8 8008C8A8 0C01B8BA */ jal load_level_for_menu -/* 08D4AC 8008C8AC 00003025 */ move $a2, $zero -/* 08D4B0 8008C8B0 0C0204F4 */ jal menu_init -/* 08D4B4 8008C8B4 2404000F */ li $a0, 15 -/* 08D4B8 8008C8B8 10000080 */ b .L8008CABC -/* 08D4BC 8008C8BC 00001025 */ move $v0, $zero -.L8008C8C0: -/* 08D4C0 8008C8C0 AC22F494 */ sw $v0, %lo(gIsInAdventureTwo)($at) -/* 08D4C4 8008C8C4 3C01800E */ lui $at, %hi(gIsInTracksMode) # $at, 0x800e -/* 08D4C8 8008C8C8 AC20F4B8 */ sw $zero, %lo(gIsInTracksMode)($at) -/* 08D4CC 8008C8CC 3C018012 */ lui $at, %hi(gPlayerSelectVehicle) # $at, 0x8012 -/* 08D4D0 8008C8D0 0C01B6C5 */ jal func_8006DB14 -/* 08D4D4 8008C8D4 A02069C0 */ sb $zero, %lo(gPlayerSelectVehicle)($at) -/* 08D4D8 8008C8D8 0C0204F4 */ jal menu_init -/* 08D4DC 8008C8DC 24040006 */ li $a0, 6 -/* 08D4E0 8008C8E0 10000076 */ b .L8008CABC -/* 08D4E4 8008C8E4 00001025 */ move $v0, $zero -/* 08D4E8 8008C8E8 2841FFE2 */ slti $at, $v0, -0x1e -.L8008C8EC: -/* 08D4EC 8008C8EC 10200019 */ beqz $at, .L8008C954 -/* 08D4F0 8008C8F0 00000000 */ nop -/* 08D4F4 8008C8F4 0C0232B3 */ jal func_8008CACC -/* 08D4F8 8008C8F8 00000000 */ nop -/* 08D4FC 8008C8FC 0C027B34 */ jal is_drumstick_unlocked -/* 08D500 8008C900 AFA0001C */ sw $zero, 0x1c($sp) -/* 08D504 8008C904 8FA6001C */ lw $a2, 0x1c($sp) -/* 08D508 8008C908 10400002 */ beqz $v0, .L8008C914 -/* 08D50C 8008C90C 00000000 */ nop -/* 08D510 8008C910 24060001 */ li $a2, 1 -.L8008C914: -/* 08D514 8008C914 0C027B2E */ jal is_tt_unlocked -/* 08D518 8008C918 AFA6001C */ sw $a2, 0x1c($sp) -/* 08D51C 8008C91C 8FA6001C */ lw $a2, 0x1c($sp) -/* 08D520 8008C920 10400003 */ beqz $v0, .L8008C930 -/* 08D524 8008C924 24040016 */ li $a0, 22 -/* 08D528 8008C928 38CD0003 */ xori $t5, $a2, 3 -/* 08D52C 8008C92C 01A03025 */ move $a2, $t5 -.L8008C930: -/* 08D530 8008C930 0C01B8BA */ jal load_level_for_menu -/* 08D534 8008C934 2405FFFF */ li $a1, -1 -/* 08D538 8008C938 00002025 */ move $a0, $zero -/* 08D53C 8008C93C 0C022BAD */ jal func_8008AEB4 -/* 08D540 8008C940 00002825 */ move $a1, $zero -/* 08D544 8008C944 0C0204F4 */ jal menu_init -/* 08D548 8008C948 24040003 */ li $a0, 3 -/* 08D54C 8008C94C 1000005B */ b .L8008CABC -/* 08D550 8008C950 00001025 */ move $v0, $zero -.L8008C954: -/* 08D554 8008C954 0C0231A6 */ jal func_8008C698 -/* 08D558 8008C958 00000000 */ nop -/* 08D55C 8008C95C 3C0E800E */ lui $t6, %hi(gMenuDelay) # $t6, 0x800e -/* 08D560 8008C960 8DCEF47C */ lw $t6, %lo(gMenuDelay)($t6) -/* 08D564 8008C964 3C058012 */ lui $a1, %hi(D_801263D8) # $a1, 0x8012 -/* 08D568 8008C968 15C00051 */ bnez $t6, .L8008CAB0 -/* 08D56C 8008C96C 24A563D8 */ addiu $a1, %lo(D_801263D8) # addiu $a1, $a1, 0x63d8 -/* 08D570 8008C970 8CAF0000 */ lw $t7, ($a1) -/* 08D574 8008C974 00000000 */ nop -/* 08D578 8008C978 15E0004D */ bnez $t7, .L8008CAB0 -/* 08D57C 8008C97C 00000000 */ nop -/* 08D580 8008C980 0C01A955 */ jal get_buttons_pressed_from_player -/* 08D584 8008C984 00002025 */ move $a0, $zero -/* 08D588 8008C988 3C18800E */ lui $t8, %hi(gNumberOfActivePlayers) # $t8, 0x800e -/* 08D58C 8008C98C 8F18F4BC */ lw $t8, %lo(gNumberOfActivePlayers)($t8) -/* 08D590 8008C990 3C068012 */ lui $a2, %hi(gControllersYAxisDirection) # $a2, 0x8012 -/* 08D594 8008C994 80C66464 */ lb $a2, %lo(gControllersYAxisDirection)($a2) -/* 08D598 8008C998 24010002 */ li $at, 2 -/* 08D59C 8008C99C 1701000B */ bne $t8, $at, .L8008C9CC -/* 08D5A0 8008C9A0 00401825 */ move $v1, $v0 -/* 08D5A4 8008C9A4 24040001 */ li $a0, 1 -/* 08D5A8 8008C9A8 AFA20024 */ sw $v0, 0x24($sp) -/* 08D5AC 8008C9AC 0C01A955 */ jal get_buttons_pressed_from_player -/* 08D5B0 8008C9B0 AFA60020 */ sw $a2, 0x20($sp) -/* 08D5B4 8008C9B4 3C198012 */ lui $t9, %hi(gControllersYAxisDirection+1) # $t9, 0x8012 -/* 08D5B8 8008C9B8 8FA30024 */ lw $v1, 0x24($sp) -/* 08D5BC 8008C9BC 8FA60020 */ lw $a2, 0x20($sp) -/* 08D5C0 8008C9C0 83396465 */ lb $t9, %lo(gControllersYAxisDirection+1)($t9) -/* 08D5C4 8008C9C4 00621825 */ or $v1, $v1, $v0 -/* 08D5C8 8008C9C8 00D93021 */ addu $a2, $a2, $t9 -.L8008C9CC: -/* 08D5CC 8008C9CC 30689000 */ andi $t0, $v1, 0x9000 -/* 08D5D0 8008C9D0 11000015 */ beqz $t0, .L8008CA28 -/* 08D5D4 8008C9D4 306C4000 */ andi $t4, $v1, 0x4000 -/* 08D5D8 8008C9D8 3C098012 */ lui $t1, %hi(D_801263E0) # $t1, 0x8012 -/* 08D5DC 8008C9DC 3C0A800E */ lui $t2, %hi(D_800DF460) # $t2, 0x800e -/* 08D5E0 8008C9E0 8D4AF460 */ lw $t2, %lo(D_800DF460)($t2) -/* 08D5E4 8008C9E4 8D2963E0 */ lw $t1, %lo(D_801263E0)($t1) -/* 08D5E8 8008C9E8 00000000 */ nop -/* 08D5EC 8008C9EC 152A0003 */ bne $t1, $t2, .L8008C9FC -/* 08D5F0 8008C9F0 00000000 */ nop -/* 08D5F4 8008C9F4 0C000326 */ jal set_music_fade_timer -/* 08D5F8 8008C9F8 2404FF80 */ li $a0, -128 -.L8008C9FC: -/* 08D5FC 8008C9FC 3C04800E */ lui $a0, %hi(sMenuTransitionFadeIn) # $a0, 0x800e -/* 08D600 8008CA00 0C030076 */ jal func_800C01D8 -/* 08D604 8008CA04 2484F774 */ addiu $a0, %lo(sMenuTransitionFadeIn) # addiu $a0, $a0, -0x88c -/* 08D608 8008CA08 240B0001 */ li $t3, 1 -/* 08D60C 8008CA0C 3C01800E */ lui $at, %hi(gMenuDelay) # $at, 0x800e -/* 08D610 8008CA10 AC2BF47C */ sw $t3, %lo(gMenuDelay)($at) -/* 08D614 8008CA14 240400EF */ li $a0, 239 -/* 08D618 8008CA18 0C000741 */ jal func_80001D04 -/* 08D61C 8008CA1C 00002825 */ move $a1, $zero -/* 08D620 8008CA20 10000023 */ b .L8008CAB0 -/* 08D624 8008CA24 00000000 */ nop -.L8008CA28: -/* 08D628 8008CA28 11800007 */ beqz $t4, .L8008CA48 -/* 08D62C 8008CA2C 3C04800E */ lui $a0, %hi(sMenuTransitionFadeIn) # $a0, 0x800e -/* 08D630 8008CA30 0C030076 */ jal func_800C01D8 -/* 08D634 8008CA34 2484F774 */ addiu $a0, %lo(sMenuTransitionFadeIn) # addiu $a0, $a0, -0x88c -/* 08D638 8008CA38 240DFFFF */ li $t5, -1 -/* 08D63C 8008CA3C 3C01800E */ lui $at, %hi(gMenuDelay) # $at, 0x800e -/* 08D640 8008CA40 1000001B */ b .L8008CAB0 -/* 08D644 8008CA44 AC2DF47C */ sw $t5, %lo(gMenuDelay)($at) -.L8008CA48: -/* 08D648 8008CA48 04C1000F */ bgez $a2, .L8008CA88 -/* 08D64C 8008CA4C 3C03800E */ lui $v1, %hi(D_800DF460) # $v1, 0x800e -/* 08D650 8008CA50 2463F460 */ addiu $v1, %lo(D_800DF460) # addiu $v1, $v1, -0xba0 -/* 08D654 8008CA54 3C0E8012 */ lui $t6, %hi(D_801263E0) # $t6, 0x8012 -/* 08D658 8008CA58 8DCE63E0 */ lw $t6, %lo(D_801263E0)($t6) -/* 08D65C 8008CA5C 8C620000 */ lw $v0, ($v1) -/* 08D660 8008CA60 240400EB */ li $a0, 235 -/* 08D664 8008CA64 004E082A */ slt $at, $v0, $t6 -/* 08D668 8008CA68 10200007 */ beqz $at, .L8008CA88 -/* 08D66C 8008CA6C 244F0001 */ addiu $t7, $v0, 1 -/* 08D670 8008CA70 AC6F0000 */ sw $t7, ($v1) -/* 08D674 8008CA74 00002825 */ move $a1, $zero -/* 08D678 8008CA78 0C000741 */ jal func_80001D04 -/* 08D67C 8008CA7C AFA60020 */ sw $a2, 0x20($sp) -/* 08D680 8008CA80 8FA60020 */ lw $a2, 0x20($sp) -/* 08D684 8008CA84 00000000 */ nop -.L8008CA88: -/* 08D688 8008CA88 3C03800E */ lui $v1, %hi(D_800DF460) # $v1, 0x800e -/* 08D68C 8008CA8C 18C00008 */ blez $a2, .L8008CAB0 -/* 08D690 8008CA90 2463F460 */ addiu $v1, %lo(D_800DF460) # addiu $v1, $v1, -0xba0 -/* 08D694 8008CA94 8C620000 */ lw $v0, ($v1) -/* 08D698 8008CA98 240400EB */ li $a0, 235 -/* 08D69C 8008CA9C 18400004 */ blez $v0, .L8008CAB0 -/* 08D6A0 8008CAA0 2458FFFF */ addiu $t8, $v0, -1 -/* 08D6A4 8008CAA4 AC780000 */ sw $t8, ($v1) -/* 08D6A8 8008CAA8 0C000741 */ jal func_80001D04 -/* 08D6AC 8008CAAC 00002825 */ move $a1, $zero -.L8008CAB0: -/* 08D6B0 8008CAB0 3C018012 */ lui $at, %hi(gIgnorePlayerInput) # $at, 0x8012 -/* 08D6B4 8008CAB4 AC2063C4 */ sw $zero, %lo(gIgnorePlayerInput)($at) -/* 08D6B8 8008CAB8 00001025 */ move $v0, $zero -.L8008CABC: -/* 08D6BC 8008CABC 8FBF0014 */ lw $ra, 0x14($sp) -/* 08D6C0 8008CAC0 27BD0028 */ addiu $sp, $sp, 0x28 -/* 08D6C4 8008CAC4 03E00008 */ jr $ra -/* 08D6C8 8008CAC8 00000000 */ nop - diff --git a/src/menu.c b/src/menu.c index 31d19877..22ad7ff1 100644 --- a/src/menu.c +++ b/src/menu.c @@ -4056,17 +4056,13 @@ void func_8008C698(s32 arg0) { GLOBAL_ASM("asm/non_matchings/menu/func_8008C698.s") #endif -#ifdef NON_EQUIVALENT - s32 menu_game_select_loop(s32 arg0) { s32 playerInputs; s32 playerYDir; s32 charSelectScene; - s32 temp; func_8008C168(); - // Regalloc issue: This needs to use v1, not a2! D_801263BC = (D_801263BC + arg0) & 0x3F; if (D_801263D8 != 0) { @@ -4151,9 +4147,6 @@ s32 menu_game_select_loop(s32 arg0) { return 0; } } -#else -GLOBAL_ASM("asm/non_matchings/menu/menu_game_select_loop.s") -#endif void func_8008CACC(void) { func_800C422C(2); diff --git a/src/menu.h b/src/menu.h index c0ec0fb9..ca495d75 100644 --- a/src/menu.h +++ b/src/menu.h @@ -798,5 +798,6 @@ void menu_track_select_init(void); void menu_trophy_race_rankings_init(void); void func_8009E3D0(void); s32 func_800C3564(void); +void func_8008C168(void); #endif