Skip to content

Commit c1b0eb7

Browse files
jonathanzetierfuzyll
authored andcommitted
Add little-endian octeon mips arch
1 parent 40172b3 commit c1b0eb7

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

arch/mips/arch_mips.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

platform/linux/platform_linux.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,35 +545,40 @@ extern "C"
545545
Ref<Architecture> mips3eb = Architecture::GetByName("mips3");
546546
Ref<Architecture> mips64eb = Architecture::GetByName("mips64");
547547
Ref<Architecture> cnmips64eb = Architecture::GetByName("cavium-mips64");
548-
if (mipsel && mipseb && mips64eb && cnmips64eb && mips3el && mips3eb)
548+
Ref<Architecture> cnmips64el = Architecture::GetByName("cavium-mipsel64");
549+
if (mipsel && mipseb && mips64eb && cnmips64eb && cnmips64el && mips3el && mips3eb)
549550
{
550-
Ref<Platform> platformLE, platformBE, platformBE64, platformBE64cn, platform3LE, platform3BE;
551+
Ref<Platform> platformLE, platformBE, platformBE64, platformBE64cn, platformLE64cn, platform3LE, platform3BE;
551552

552553
platformLE = new LinuxMipsPlatform(mipsel, "linux-mipsel");
553554
platformBE = new LinuxMipsPlatform(mipseb, "linux-mips");
554555
platform3LE = new LinuxMipsPlatform(mips3el, "linux-mipsel3");
555556
platform3BE = new LinuxMipsPlatform(mips3eb, "linux-mips3");
556557
platformBE64 = new LinuxMips64Platform(mips64eb, "linux-mips64");
557558
platformBE64cn = new LinuxMips64Platform(cnmips64eb, "linux-cnmips64");
559+
platformLE64cn = new LinuxMips64Platform(cnmips64el, "linux-cnmipsel64");
558560
Platform::Register("linux", platformLE);
559561
Platform::Register("linux", platformBE);
560562
Platform::Register("linux", platform3LE);
561563
Platform::Register("linux", platform3BE);
562564
Platform::Register("linux", platformBE64);
563565
Platform::Register("linux", platformBE64cn);
566+
Platform::Register("linux", platformLE64cn);
564567
// Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one
565568
BinaryViewType::RegisterPlatform("ELF", 0, platformLE);
566569
BinaryViewType::RegisterPlatform("ELF", 0, platformBE);
567570
BinaryViewType::RegisterPlatform("ELF", 0, platform3LE);
568571
BinaryViewType::RegisterPlatform("ELF", 0, platform3BE);
569572
BinaryViewType::RegisterPlatform("ELF", 0, platformBE64);
570573
BinaryViewType::RegisterPlatform("ELF", 0, platformBE64cn);
574+
BinaryViewType::RegisterPlatform("ELF", 0, platformLE64cn);
571575
BinaryViewType::RegisterPlatform("ELF", 3, platformLE);
572576
BinaryViewType::RegisterPlatform("ELF", 3, platformBE);
573577
BinaryViewType::RegisterPlatform("ELF", 3, platform3LE);
574578
BinaryViewType::RegisterPlatform("ELF", 3, platform3BE);
575579
BinaryViewType::RegisterPlatform("ELF", 3, platformBE64);
576580
BinaryViewType::RegisterPlatform("ELF", 3, platformBE64cn);
581+
BinaryViewType::RegisterPlatform("ELF", 3, platformLE64cn);
577582
}
578583

579584
Ref<Architecture> rv32 = Architecture::GetByName("rv32gc");

0 commit comments

Comments
 (0)