Skip to content

Commit

Permalink
[RISC-V] Enable R2RDump (#97156)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomeksowi authored Jan 27, 2024
1 parent 2ea4caf commit 08d9819
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/coreclr/tools/r2rdump/CoreDisTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public enum TargetArch
Target_X64,
Target_Thumb,
Target_Arm64,
Target_LoongArch64
Target_LoongArch64,
Target_RiscV64,
};

[DllImport(_dll, CallingConvention = CallingConvention.Cdecl)]
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()
};

Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/tools/r2rdump/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/r2rdump/R2RDump.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputType>Exe</OutputType>
<Platforms>x64;x86;arm64;arm;loongarch64</Platforms>
<Platforms>x64;x86;arm64;arm;loongarch64;riscv64</Platforms>
<AssemblyKey>Open</AssemblyKey>
<IsDotNetFrameworkProductAssembly>true</IsDotNetFrameworkProductAssembly>
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
Expand Down

0 comments on commit 08d9819

Please sign in to comment.