Skip to content

Commit

Permalink
little more
Browse files Browse the repository at this point in the history
  • Loading branch information
ethteck committed Mar 25, 2024
1 parent d6c885e commit f403938
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 10 additions & 3 deletions m2c/arch_mips.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,8 @@ def match(self, matcher: AsmMatcher) -> Optional[Replacement]:
class MipsArch(Arch):
arch = Target.ArchEnum.MIPS

num_function_arg_registers = 4

stack_pointer_reg = Register("sp")
frame_pointer_reg = Register("fp")
return_address_reg = Register("ra")
Expand Down Expand Up @@ -1718,6 +1720,7 @@ def function_abi(
offset = (offset + align - 1) & -align
name = param.name
reg2: Optional[Register]
# TODO EABI: support eabi float args
if ind < 2 and only_floats:
reg = Register("f12" if ind == 0 else "f14")
is_double = (
Expand All @@ -1740,7 +1743,11 @@ def function_abi(
else:
for i in range(offset // 4, (offset + size) // 4):
unk_offset = 4 * i - offset
reg2 = Register(f"a{i}") if i < 4 else None
reg2 = (
Register(f"a{i}")
if i < self.num_function_arg_registers
else None
)
if size > 4:
name2 = f"{name}_unk{unk_offset:X}" if name else None
sub_type = Type.any()
Expand All @@ -1762,7 +1769,7 @@ def function_abi(
offset += size

if fn_sig.is_variadic:
for i in range(offset // 4, 4):
for i in range(offset // 4, self.num_function_arg_registers):
candidate_slots.append(
AbiArgSlot(i * 4, Register(f"a{i}"), Type.any_reg())
)
Expand Down Expand Up @@ -1854,7 +1861,7 @@ def function_return(expr: Expression) -> Dict[Register, Expression]:


class MipseeArch(MipsArch):
arch = Target.ArchEnum.MIPS
num_function_arg_registers = 8

stack_pointer_reg = Register("sp")

Expand Down
5 changes: 4 additions & 1 deletion m2c/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def print_exception_as_comment(
def run(options: Options) -> int:
arch: Arch
if options.target.arch == Target.ArchEnum.MIPS:
arch = MipsArch()
if options.target.platform == Target.PlatformEnum.MIPSEE:
arch = MipseeArch()
else:
arch = MipsArch()
elif options.target.arch == Target.ArchEnum.PPC:
arch = PpcArch()
else:
Expand Down

0 comments on commit f403938

Please sign in to comment.