ff53dcf560
* dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0052 warnings * Address or silence dotnet format IDE1006 warnings * Address or silence dotnet format CA2208 warnings * Address dotnet format CA1822 warnings * Address or silence dotnet format CA1069 warnings * Silence CA1806 and CA1834 issues * Address dotnet format CA1401 warnings * Fix new dotnet-format issues after rebase * Address review comments * Address dotnet format CA2208 warnings properly * Fix formatting for switch expressions * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Add previously silenced warnings back I have no clue how these disappeared * Revert formatting changes for OpCodeTable.cs * Enable formatting for a few cases again * Format if-blocks correctly * Enable formatting for a few more cases again * Fix inline comment alignment * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Disable 'prefer switch expression' rule * Add comments to disabled warnings * Remove a few unused parameters * Adjust namespaces * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Start working on disabled warnings * Fix and silence a few dotnet-format warnings again * Address IDE0251 warnings * Address a few disabled IDE0060 warnings * Silence IDE0060 in .editorconfig * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Remove unnecessary formatting exclusion * Add unsafe dotnet format changes * Change visibility of JitSupportDarwin to internal
79 lines
3.3 KiB
C#
79 lines
3.3 KiB
C#
using ARMeilleure.Memory;
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace ARMeilleure.Translation.Cache
|
|
{
|
|
class JitCacheInvalidation
|
|
{
|
|
private static readonly int[] _invalidationCode = new int[]
|
|
{
|
|
unchecked((int)0xd53b0022), // mrs x2, ctr_el0
|
|
unchecked((int)0xd3504c44), // ubfx x4, x2, #16, #4
|
|
unchecked((int)0x52800083), // mov w3, #0x4
|
|
unchecked((int)0x12000c45), // and w5, w2, #0xf
|
|
unchecked((int)0x1ac42064), // lsl w4, w3, w4
|
|
unchecked((int)0x51000482), // sub w2, w4, #0x1
|
|
unchecked((int)0x8a220002), // bic x2, x0, x2
|
|
unchecked((int)0x1ac52063), // lsl w3, w3, w5
|
|
unchecked((int)0xeb01005f), // cmp x2, x1
|
|
unchecked((int)0x93407c84), // sxtw x4, w4
|
|
unchecked((int)0x540000a2), // b.cs 3c <do_ic_clear>
|
|
unchecked((int)0xd50b7b22), // dc cvau, x2
|
|
unchecked((int)0x8b040042), // add x2, x2, x4
|
|
unchecked((int)0xeb02003f), // cmp x1, x2
|
|
unchecked((int)0x54ffffa8), // b.hi 2c <dc_clear_loop>
|
|
unchecked((int)0xd5033b9f), // dsb ish
|
|
unchecked((int)0x51000462), // sub w2, w3, #0x1
|
|
unchecked((int)0x93407c63), // sxtw x3, w3
|
|
unchecked((int)0x8a220000), // bic x0, x0, x2
|
|
unchecked((int)0xeb00003f), // cmp x1, x0
|
|
unchecked((int)0x540000a9), // b.ls 64 <exit>
|
|
unchecked((int)0xd50b7520), // ic ivau, x0
|
|
unchecked((int)0x8b030000), // add x0, x0, x3
|
|
unchecked((int)0xeb00003f), // cmp x1, x0
|
|
unchecked((int)0x54ffffa8), // b.hi 54 <ic_clear_loop>
|
|
unchecked((int)0xd5033b9f), // dsb ish
|
|
unchecked((int)0xd5033fdf), // isb
|
|
unchecked((int)0xd65f03c0), // ret
|
|
};
|
|
|
|
private delegate void InvalidateCache(ulong start, ulong end);
|
|
|
|
private readonly InvalidateCache _invalidateCache;
|
|
private readonly ReservedRegion _invalidateCacheCodeRegion;
|
|
|
|
private readonly bool _needsInvalidation;
|
|
|
|
public JitCacheInvalidation(IJitMemoryAllocator allocator)
|
|
{
|
|
// On macOS and Windows, a different path is used to write to the JIT cache, which does the invalidation.
|
|
if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
|
|
{
|
|
ulong size = (ulong)_invalidationCode.Length * sizeof(int);
|
|
ulong mask = (ulong)ReservedRegion.DefaultGranularity - 1;
|
|
|
|
size = (size + mask) & ~mask;
|
|
|
|
_invalidateCacheCodeRegion = new ReservedRegion(allocator, size);
|
|
_invalidateCacheCodeRegion.ExpandIfNeeded(size);
|
|
|
|
Marshal.Copy(_invalidationCode, 0, _invalidateCacheCodeRegion.Pointer, _invalidationCode.Length);
|
|
|
|
_invalidateCacheCodeRegion.Block.MapAsRx(0, size);
|
|
|
|
_invalidateCache = Marshal.GetDelegateForFunctionPointer<InvalidateCache>(_invalidateCacheCodeRegion.Pointer);
|
|
|
|
_needsInvalidation = true;
|
|
}
|
|
}
|
|
|
|
public void Invalidate(IntPtr basePointer, ulong size)
|
|
{
|
|
if (_needsInvalidation)
|
|
{
|
|
_invalidateCache((ulong)basePointer, (ulong)basePointer + size);
|
|
}
|
|
}
|
|
}
|
|
}
|