Handle blx instructions in extract_function.py

Handle function calls via blx, e.g., `blx SVC_WaitByLoop`.

The enumerated exceptions are the only ones currently present in the
repository.
This commit is contained in:
UsernameFodder
2023-12-27 00:04:56 -06:00
parent 76e5d10e24
commit 75934d8e45

View File

@@ -113,8 +113,8 @@ for i, line in enumerate(lsf_lines):
lsf_lines[i] += f'\tObject asm/{file_prefix}{new_file_address}.o\n'
break
BRANCH_LABEL_INSTRUCTION = '\tbl '
BRANCH_LINK_INSTRUCTION = '\tbl '
BRANCH_LINK_EXCHANGE_INSTRUCTION = '\tblx '
BRANCH_INSTRUCTION = '\tb '
WORD_KEY = '.word '
WORD_PLUS_OFFSET = ' + 0x'
@@ -124,13 +124,19 @@ def write_inc_file(lines: List[str], file_path: str):
for line in lines:
if line.startswith(ARM_FUNC_START):
defined_functions.add(line[len(ARM_FUNC_START) : -1])
elif line.startswith(BRANCH_LABEL_INSTRUCTION):
used_functions.add(line[len(BRANCH_LABEL_INSTRUCTION) : -1])
elif line.startswith(BRANCH_LINK_INSTRUCTION):
used_functions.add(line[len(BRANCH_LINK_INSTRUCTION) : -1])
elif line.startswith(BRANCH_INSTRUCTION):
function = line[len(BRANCH_INSTRUCTION) : -1]
if function[0] != '_':
semicolon_index = function.index(' ; ')
used_functions.add(function[:semicolon_index])
elif line.startswith(BRANCH_LINK_EXCHANGE_INSTRUCTION):
function = line[len(BRANCH_LINK_EXCHANGE_INSTRUCTION) : -1]
if function not in {'fp', 'ip', 'lr', 'sb', 'sl'} and not (
function.startswith('r') and function[1:].isdigit() # rN
):
used_functions.add(function)
else:
word_index = line.find(WORD_KEY)
if word_index >= 0 and f'{WORD_KEY}0x' not in line: