@@ -3674,6 +3674,21 @@ static Ref<Platform> ElfFlagsRecognize(BinaryView* view, Metadata* metadata)
36743674 if (!flagsMetadata || !flagsMetadata->IsUnsignedInteger ())
36753675 return nullptr ;
36763676
3677+ Ref<Metadata> endiannessMetadata = metadata->Get (" EI_DATA" );
3678+ if (!endiannessMetadata || !endiannessMetadata->IsUnsignedInteger ())
3679+ return nullptr ;
3680+
3681+ uint64_t endiannessValue = endiannessMetadata->GetUnsignedInteger ();
3682+ BNEndianness endianness;
3683+ if (endiannessValue == 1 )
3684+ endianness = LittleEndian;
3685+ else if (endiannessValue == 2 )
3686+ endianness = BigEndian;
3687+ else {
3688+ LogError (" ELF endianness value 0x%" PRIx64 " doesn't map to valid value" , endiannessValue);
3689+ return nullptr ;
3690+ }
3691+
36773692 uint64_t flagsValue = flagsMetadata->GetUnsignedInteger ();
36783693 uint8_t machineVariant = (flagsValue >> 16 ) & 0xff ;
36793694
@@ -3683,7 +3698,7 @@ static Ref<Platform> ElfFlagsRecognize(BinaryView* view, Metadata* metadata)
36833698 case 0x8d : // EF_MIPS_MACH_OCTEON2
36843699 case 0x8e : // EF_MIPS_MACH_OCTEON3
36853700 LogInfo (" ELF flags 0x%08" PRIx64 " machine variant 0x%02x: using cavium architecture" , flagsValue, machineVariant);
3686- return Platform::GetByName (" linux-cnmips64" );
3701+ return Platform::GetByName (endianness == BigEndian ? " linux-cnmips64" : " linux-cnmipsel64 " );
36873702 case 0x92 : // E_MIPS_MACH_5900
36883703 LogInfo (" ELF flags 0x%08" PRIx64 " machine variant 0x%02x: using R5900 architecture" , flagsValue, machineVariant);
36893704 return Platform::GetByName (" r5900l" );
@@ -3715,6 +3730,7 @@ extern "C"
37153730 Architecture* mips64el = new MipsArchitecture (" mipsel64" , MIPS_64 , LittleEndian, 64 );
37163731 Architecture* mips64eb = new MipsArchitecture (" mips64" , MIPS_64 , BigEndian, 64 );
37173732 Architecture* cnmips64eb = new MipsArchitecture (" cavium-mips64" , MIPS_64 , BigEndian, 64 , DECOMPOSE_FLAGS_CAVIUM );
3733+ Architecture* cnmips64el = new MipsArchitecture (" cavium-mipsel64" , MIPS_64 , LittleEndian, 64 , DECOMPOSE_FLAGS_CAVIUM );
37183734 Architecture* r5900l = new MipsArchitecture (" r5900l" , MIPS_R5900 , LittleEndian, 32 );
37193735 // R5900 should only be Little-Endian, so until someone complains, I'm leaving the Big-Endian variant disabled.
37203736 // Architecture* r5900b = new MipsArchitecture("r5900b", MIPS_R5900, BigEndian, 32);
@@ -3728,13 +3744,15 @@ extern "C"
37283744 Architecture::Register (mips64el);
37293745 Architecture::Register (mips64eb);
37303746 Architecture::Register (cnmips64eb);
3747+ Architecture::Register (cnmips64el);
37313748
37323749 /* calling conventions */
37333750 MipsO32CallingConvention* o32LE = new MipsO32CallingConvention (mipsel);
37343751 MipsO32CallingConvention* o32BE = new MipsO32CallingConvention (mipseb);
37353752 MipsN64CallingConvention* n64LE = new MipsN64CallingConvention (mips64el);
37363753 MipsN64CallingConvention* n64BE = new MipsN64CallingConvention (mips64eb);
37373754 MipsN64CallingConvention* n64BEc = new MipsN64CallingConvention (cnmips64eb);
3755+ MipsN64CallingConvention* n64LEc = new MipsN64CallingConvention (cnmips64el);
37383756 MipsPS2CallingConvention* ps2LE = new MipsPS2CallingConvention (r5900l);
37393757 // MipsPS2CallingConvention* ps2BE = new MipsPS2CallingConvention(r5900b);
37403758
@@ -3752,6 +3770,8 @@ extern "C"
37523770 mips64eb->SetDefaultCallingConvention (n64BE);
37533771 cnmips64eb->RegisterCallingConvention (n64BEc);
37543772 cnmips64eb->SetDefaultCallingConvention (n64BEc);
3773+ cnmips64el->RegisterCallingConvention (n64LEc);
3774+ cnmips64el->SetDefaultCallingConvention (n64LEc);
37553775 r5900l->RegisterCallingConvention (ps2LE);
37563776 r5900l->SetDefaultCallingConvention (ps2LE);
37573777 // r5900b->RegisterCallingConvention(ps2BE);
@@ -3779,6 +3799,7 @@ extern "C"
37793799 mips64el->RegisterCallingConvention (new MipsLinuxRtlResolveCallingConvention (mips64el));
37803800 mips64eb->RegisterCallingConvention (new MipsLinuxRtlResolveCallingConvention (mips64eb));
37813801 cnmips64eb->RegisterCallingConvention (new MipsLinuxRtlResolveCallingConvention (cnmips64eb));
3802+ cnmips64el->RegisterCallingConvention (new MipsLinuxRtlResolveCallingConvention (cnmips64el));
37823803
37833804 /* function recognizers */
37843805 mipsel->RegisterFunctionRecognizer (new MipsImportedFunctionRecognizer ());
@@ -3788,6 +3809,7 @@ extern "C"
37883809 mips64el->RegisterFunctionRecognizer (new MipsImportedFunctionRecognizer ());
37893810 mips64eb->RegisterFunctionRecognizer (new MipsImportedFunctionRecognizer ());
37903811 cnmips64eb->RegisterFunctionRecognizer (new MipsImportedFunctionRecognizer ());
3812+ cnmips64el->RegisterFunctionRecognizer (new MipsImportedFunctionRecognizer ());
37913813
37923814 mipseb->RegisterRelocationHandler (" ELF" , new MipsElfRelocationHandler ());
37933815 mipsel->RegisterRelocationHandler (" ELF" , new MipsElfRelocationHandler ());
@@ -3798,6 +3820,7 @@ extern "C"
37983820 r5900l->RegisterRelocationHandler (" ELF" , new MipsElfRelocationHandler ());
37993821 // r5900b->RegisterRelocationHandler("ELF", new MipsElfRelocationHandler());
38003822 cnmips64eb->RegisterRelocationHandler (" ELF" , new MipsElfRelocationHandler ());
3823+ cnmips64el->RegisterRelocationHandler (" ELF" , new MipsElfRelocationHandler ());
38013824
38023825 // Register the architectures with the binary format parsers so that they know when to use
38033826 // these architectures for disassembling an executable file
0 commit comments