From a40e1f3db0e5e57f390fa3e705a44e5207b975c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Sowi=C5=84ski?= Date: Thu, 18 Jan 2024 14:08:09 +0100 Subject: [PATCH] [RISC-V] Enable R2RDump --- src/coreclr/tools/r2rdump/CoreDisTools.cs | 13 +++++++++++-- src/coreclr/tools/r2rdump/Program.cs | 1 + src/coreclr/tools/r2rdump/R2RDump.csproj | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/coreclr/tools/r2rdump/CoreDisTools.cs b/src/coreclr/tools/r2rdump/CoreDisTools.cs index eda94336b6722..6763c94859a6b 100644 --- a/src/coreclr/tools/r2rdump/CoreDisTools.cs +++ b/src/coreclr/tools/r2rdump/CoreDisTools.cs @@ -22,7 +22,8 @@ public enum TargetArch Target_X64, Target_Thumb, Target_Arm64, - Target_LoongArch64 + Target_LoongArch64, + Target_RiscV64, }; [DllImport(_dll, CallingConvention = CallingConvention.Cdecl)] @@ -77,6 +78,9 @@ public static IntPtr GetDisasm(Machine machine) case Machine.LoongArch64: target = TargetArch.Target_LoongArch64; break; + case Machine.RiscV64: + target = TargetArch.Target_RiscV64; + break; default: Program.WriteWarning($"{machine} not supported on CoreDisTools"); return IntPtr.Zero; @@ -191,6 +195,10 @@ private void SetIndentations() // Instructions are dumped as 4-byte hexadecimal integers Machine.LoongArch64 => 4 * 2 + 1, + // Instructions are dumped as 4-byte hexadecimal integers + // TODO: update once RISC-V runtime supports "C" extension (compressed instructions) + Machine.RiscV64 => 4 * 2 + 1, + _ => throw new NotImplementedException() }; @@ -260,7 +268,8 @@ public int GetInstruction(RuntimeFunction rtf, int imageOffset, int rtfOffset, o } else { - if ((_reader.Machine == Machine.Arm64) || (_reader.Machine == Machine.LoongArch64)) + // TODO: update once RISC-V runtime supports "C" extension (compressed instructions) + if (_reader.Machine is Machine.Arm64 or Machine.LoongArch64 or Machine.RiscV64) { // Replace " hh hh hh hh " byte dump with " hhhhhhhh ". // CoreDisTools should be fixed to dump bytes this way for ARM64. diff --git a/src/coreclr/tools/r2rdump/Program.cs b/src/coreclr/tools/r2rdump/Program.cs index 54f430745343e..831570fe2ea5a 100644 --- a/src/coreclr/tools/r2rdump/Program.cs +++ b/src/coreclr/tools/r2rdump/Program.cs @@ -210,6 +210,7 @@ public void Dump(ReadyToRunReader r2r) Machine.ArmThumb2 => TargetArchitecture.ARM, Machine.Arm64 => TargetArchitecture.ARM64, Machine.LoongArch64 => TargetArchitecture.LoongArch64, + Machine.RiscV64 => TargetArchitecture.RiscV64, _ => throw new NotImplementedException(r2r.Machine.ToString()), }; TargetOS os = r2r.OperatingSystem switch diff --git a/src/coreclr/tools/r2rdump/R2RDump.csproj b/src/coreclr/tools/r2rdump/R2RDump.csproj index f0a60be4274e4..103d8160d0b53 100644 --- a/src/coreclr/tools/r2rdump/R2RDump.csproj +++ b/src/coreclr/tools/r2rdump/R2RDump.csproj @@ -4,7 +4,7 @@ 1.0.0.0 true Exe - x64;x86;arm64;arm;loongarch64 + x64;x86;arm64;arm;loongarch64;riscv64 Open true $(NetCoreAppToolCurrent)