summaryrefslogtreecommitdiff
path: root/arch/mips/arch_mips.cpp
diff options
context:
space:
mode:
authorGalen Williamson <galen@vector35.com>2025-02-10 14:57:07 -0500
committerGalen Williamson <galen@vector35.com>2025-02-10 17:36:14 -0500
commit840072d5603a454db162ffcaf8e6dc2311f0d012 (patch)
treecdb02a9fdbdab82e64ea0c1e11eb4115494b696e /arch/mips/arch_mips.cpp
parentb4e75ef9995500049f90a2569eee07c1b3505c21 (diff)
[mips] Merging PR https://github.com/Vector35/binaryninja-api/pull/6013: adding mips3 support
Diffstat (limited to 'arch/mips/arch_mips.cpp')
-rw-r--r--arch/mips/arch_mips.cpp59
1 files changed, 40 insertions, 19 deletions
diff --git a/arch/mips/arch_mips.cpp b/arch/mips/arch_mips.cpp
index 4079519a..ddb78e42 100644
--- a/arch/mips/arch_mips.cpp
+++ b/arch/mips/arch_mips.cpp
@@ -181,20 +181,25 @@ class MipsArchitecture: public Architecture
protected:
size_t m_bits;
BNEndianness m_endian;
+ MipsVersion version_overwrite;
uint32_t m_decomposeFlags;
virtual bool Disassemble(const uint8_t* data, uint64_t addr, size_t maxLen, Instruction& result)
{
+ MipsVersion version = version_overwrite;
+
memset(&result, 0, sizeof(result));
- if (mips_decompose((uint32_t*)data, maxLen, &result, m_bits == 64 ? MIPS_64 : MIPS_32, addr, m_endian, m_decomposeFlags) != 0)
+ if (m_bits == 64)
+ {
+ version = MIPS_64;
+ }
+
+ if (mips_decompose((uint32_t*)data, maxLen, &result, version, addr, m_endian, m_decomposeFlags) != 0)
return false;
return true;
}
- virtual size_t GetAddressSize() const override
- {
- return m_bits / 8;
- }
+ virtual size_t GetAddressSize() const override { return m_bits / 8; }
size_t InstructionHasBranchDelay(const Instruction& instr)
{
@@ -402,8 +407,8 @@ protected:
}
public:
- MipsArchitecture(const std::string& name, BNEndianness endian, size_t bits, uint32_t decomposeFlags = 0)
- : Architecture(name), m_bits(bits), m_endian(endian), m_decomposeFlags(decomposeFlags)
+ MipsArchitecture(const std::string& name, BNEndianness endian, size_t bits, MipsVersion version_in, uint32_t decomposeFlags = 0)
+ : Architecture(name), m_bits(bits), m_endian(endian), version_overwrite(version_in), m_decomposeFlags(decomposeFlags)
{
Ref<Settings> settings = Settings::Instance();
uint32_t flag_pseudo_ops = settings->Get<bool>("arch.mips.disassembly.pseudoOps") ? DECOMPOSE_FLAGS_PSEUDO_OP : 0;
@@ -3258,14 +3263,18 @@ extern "C"
{
InitMipsSettings();
- Architecture* mipsel = new MipsArchitecture("mipsel32", LittleEndian, 32);
- Architecture* mipseb = new MipsArchitecture("mips32", BigEndian, 32);
- Architecture* mips64el = new MipsArchitecture("mipsel64", LittleEndian, 64);
- Architecture* mips64eb = new MipsArchitecture("mips64", BigEndian, 64);
- Architecture* cnmips64eb = new MipsArchitecture("cavium-mips64", BigEndian, 64, DECOMPOSE_FLAGS_CAVIUM);
+ Architecture* mipseb = new MipsArchitecture("mips32", BigEndian, 32, MIPS_32);
+ Architecture* mipsel = new MipsArchitecture("mipsel32", LittleEndian, 32, MIPS_32);
+ Architecture* mips3 = new MipsArchitecture("mips3", BigEndian, 32, MIPS_3);
+ Architecture* mips3el = new MipsArchitecture("mipsel3", LittleEndian, 32, MIPS_3);
+ Architecture* mips64el = new MipsArchitecture("mipsel64", LittleEndian, 64, MIPS_64);
+ Architecture* mips64eb = new MipsArchitecture("mips64", BigEndian, 64, MIPS_64);
+ Architecture* cnmips64eb = new MipsArchitecture("cavium-mips64", BigEndian, 64, MIPS_64, DECOMPOSE_FLAGS_CAVIUM);
- Architecture::Register(mipsel);
Architecture::Register(mipseb);
+ Architecture::Register(mipsel);
+ Architecture::Register(mips3);
+ Architecture::Register(mips3el);
Architecture::Register(mips64el);
Architecture::Register(mips64eb);
Architecture::Register(cnmips64eb);
@@ -3277,10 +3286,14 @@ extern "C"
MipsN64CallingConvention* n64BE = new MipsN64CallingConvention(mips64eb);
MipsN64CallingConvention* n64BEc = new MipsN64CallingConvention(cnmips64eb);
- mipsel->RegisterCallingConvention(o32LE);
mipseb->RegisterCallingConvention(o32BE);
- mipsel->SetDefaultCallingConvention(o32LE);
mipseb->SetDefaultCallingConvention(o32BE);
+ mipsel->RegisterCallingConvention(o32LE);
+ mipsel->SetDefaultCallingConvention(o32LE);
+ mips3->RegisterCallingConvention(o32BE);
+ mips3->SetDefaultCallingConvention(o32BE);
+ mips3->RegisterCallingConvention(o32LE);
+ mips3->SetDefaultCallingConvention(o32LE);
mips64el->RegisterCallingConvention(n64LE);
mips64el->SetDefaultCallingConvention(n64LE);
mips64eb->RegisterCallingConvention(n64BE);
@@ -3290,21 +3303,29 @@ extern "C"
MipsLinuxSyscallCallingConvention* linuxSyscallLE = new MipsLinuxSyscallCallingConvention(mipsel);
MipsLinuxSyscallCallingConvention* linuxSyscallBE = new MipsLinuxSyscallCallingConvention(mipseb);
- mipsel->RegisterCallingConvention(linuxSyscallLE);
mipseb->RegisterCallingConvention(linuxSyscallBE);
+ mipsel->RegisterCallingConvention(linuxSyscallLE);
+ mips3->RegisterCallingConvention(linuxSyscallBE);
+ mips3el->RegisterCallingConvention(linuxSyscallLE);
- mipsel->RegisterCallingConvention(new MipsLinuxRtlResolveCallingConvention(mipsel));
mipseb->RegisterCallingConvention(new MipsLinuxRtlResolveCallingConvention(mipseb));
+ mipsel->RegisterCallingConvention(new MipsLinuxRtlResolveCallingConvention(mipsel));
+ mips3->RegisterCallingConvention(new MipsLinuxRtlResolveCallingConvention(mips3));
+ mips3el->RegisterCallingConvention(new MipsLinuxRtlResolveCallingConvention(mips3el));
mips64el->RegisterCallingConvention(new MipsLinuxRtlResolveCallingConvention(mips64el));
mips64eb->RegisterCallingConvention(new MipsLinuxRtlResolveCallingConvention(mips64eb));
cnmips64eb->RegisterCallingConvention(new MipsLinuxRtlResolveCallingConvention(cnmips64eb));
/* function recognizers */
- mipsel->RegisterFunctionRecognizer(new MipsImportedFunctionRecognizer());
mipseb->RegisterFunctionRecognizer(new MipsImportedFunctionRecognizer());
+ mipsel->RegisterFunctionRecognizer(new MipsImportedFunctionRecognizer());
+ mips3->RegisterFunctionRecognizer(new MipsImportedFunctionRecognizer());
+ mips3el->RegisterFunctionRecognizer(new MipsImportedFunctionRecognizer());
- mipsel->RegisterRelocationHandler("ELF", new MipsElfRelocationHandler());
mipseb->RegisterRelocationHandler("ELF", new MipsElfRelocationHandler());
+ mipsel->RegisterRelocationHandler("ELF", new MipsElfRelocationHandler());
+ mips3->RegisterRelocationHandler("ELF", new MipsElfRelocationHandler());
+ mips3el->RegisterRelocationHandler("ELF", new MipsElfRelocationHandler());
mips64el->RegisterRelocationHandler("ELF", new MipsElfRelocationHandler());
mips64eb->RegisterRelocationHandler("ELF", new MipsElfRelocationHandler());
cnmips64eb->RegisterRelocationHandler("ELF", new MipsElfRelocationHandler());