summaryrefslogtreecommitdiff
path: root/platform/linux
diff options
context:
space:
mode:
authorRusty Wagner <rusty.wagner@gmail.com>2023-12-19 22:39:33 -0700
committerRusty Wagner <rusty.wagner@gmail.com>2024-01-04 12:42:11 -0700
commita9cfac7ff14d93ff22092366f99eb2dd3213ea7e (patch)
treeb61163e052a1827846b0c3b8330b0289aac8cabf /platform/linux
parenta82a2105fd1b1a99bddb835ed1d9dbf2e2a5c56f (diff)
Add RISC-V architecture plugin
Diffstat (limited to 'platform/linux')
-rw-r--r--platform/linux/platform_linux.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/platform/linux/platform_linux.cpp b/platform/linux/platform_linux.cpp
index 1a4c9d93..107ce892 100644
--- a/platform/linux/platform_linux.cpp
+++ b/platform/linux/platform_linux.cpp
@@ -162,6 +162,29 @@ public:
};
+class LinuxRiscVPlatform : public Platform
+{
+public:
+ LinuxRiscVPlatform(Architecture* arch, const std::string& name) : Platform(arch, name)
+ {
+ Ref<CallingConvention> cc;
+
+ cc = arch->GetCallingConventionByName("default");
+ if (cc)
+ {
+ RegisterDefaultCallingConvention(cc);
+ RegisterCdeclCallingConvention(cc);
+ RegisterFastcallCallingConvention(cc);
+ RegisterStdcallCallingConvention(cc);
+ }
+
+ cc = arch->GetCallingConventionByName("syscall");
+ if (cc)
+ SetSystemCallConvention(cc);
+ }
+};
+
+
extern "C"
{
BN_DECLARE_CORE_ABI_VERSION
@@ -174,6 +197,7 @@ extern "C"
AddOptionalPluginDependency("arch_arm64");
AddOptionalPluginDependency("arch_mips");
AddOptionalPluginDependency("arch_ppc");
+ AddOptionalPluginDependency("arch_riscv");
AddOptionalPluginDependency("view_elf");
}
#endif
@@ -300,6 +324,30 @@ extern "C"
BinaryViewType::RegisterPlatform("ELF", 3, mipseb, platformBE);
}
+ Ref<Architecture> rv32 = Architecture::GetByName("rv32gc");
+ if (rv32)
+ {
+ Ref<Platform> platform;
+
+ platform = new LinuxRiscVPlatform(rv32, "linux-rv32gc");
+ Platform::Register("linux", platform);
+ // Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one
+ BinaryViewType::RegisterPlatform("ELF", 0, rv32, platform);
+ BinaryViewType::RegisterPlatform("ELF", 3, rv32, platform);
+ }
+
+ Ref<Architecture> rv64 = Architecture::GetByName("rv64gc");
+ if (rv64)
+ {
+ Ref<Platform> platform;
+
+ platform = new LinuxRiscVPlatform(rv64, "linux-rv64gc");
+ Platform::Register("linux", platform);
+ // Linux binaries sometimes have an OS identifier of zero, even though 3 is the correct one
+ BinaryViewType::RegisterPlatform("ELF", 0, rv64, platform);
+ BinaryViewType::RegisterPlatform("ELF", 3, rv64, platform);
+ }
+
return true;
}
}