From 9878fc2d3cf4c64f56c44c2a5de013acb6bcbade Mon Sep 17 00:00:00 2001 From: gdkchan Date: Thu, 30 Jul 2020 11:29:28 -0300 Subject: Implement inline memory load/store exclusive and ordered (#1413) * Implement inline memory load/store exclusive * Fix missing REX prefix on 8-bits CMPXCHG * Increment PTC version due to bugfix * Remove redundant memory checks * Address PR feedback * Increment PPTC version --- ARMeilleure/Memory/IMemoryManager.cs | 3 +- ARMeilleure/Memory/InvalidAccessException.cs | 23 +++++++++ ARMeilleure/Memory/MemoryManagerPal.cs | 76 ---------------------------- 3 files changed, 25 insertions(+), 77 deletions(-) create mode 100644 ARMeilleure/Memory/InvalidAccessException.cs delete mode 100644 ARMeilleure/Memory/MemoryManagerPal.cs (limited to 'ARMeilleure/Memory') diff --git a/ARMeilleure/Memory/IMemoryManager.cs b/ARMeilleure/Memory/IMemoryManager.cs index ce1f5848..f4e26886 100644 --- a/ARMeilleure/Memory/IMemoryManager.cs +++ b/ARMeilleure/Memory/IMemoryManager.cs @@ -12,8 +12,9 @@ namespace ARMeilleure.Memory void Write(ulong va, T value) where T : unmanaged; ref T GetRef(ulong va) where T : unmanaged; - ref T GetRefNoChecks(ulong va) where T : unmanaged; bool IsMapped(ulong va); + + void MarkRegionAsModified(ulong va, ulong size); } } \ No newline at end of file diff --git a/ARMeilleure/Memory/InvalidAccessException.cs b/ARMeilleure/Memory/InvalidAccessException.cs new file mode 100644 index 00000000..ad540719 --- /dev/null +++ b/ARMeilleure/Memory/InvalidAccessException.cs @@ -0,0 +1,23 @@ +using System; + +namespace ARMeilleure.Memory +{ + class InvalidAccessException : Exception + { + public InvalidAccessException() + { + } + + public InvalidAccessException(ulong address) : base($"Invalid memory access at virtual address 0x{address:X16}.") + { + } + + public InvalidAccessException(string message) : base(message) + { + } + + public InvalidAccessException(string message, Exception innerException) : base(message, innerException) + { + } + } +} diff --git a/ARMeilleure/Memory/MemoryManagerPal.cs b/ARMeilleure/Memory/MemoryManagerPal.cs deleted file mode 100644 index 0dc83959..00000000 --- a/ARMeilleure/Memory/MemoryManagerPal.cs +++ /dev/null @@ -1,76 +0,0 @@ -using ARMeilleure.IntermediateRepresentation; -using ARMeilleure.State; -using ARMeilleure.Translation; - -namespace ARMeilleure.Memory -{ - static class MemoryManagerPal - { - private delegate V128 CompareExchange128(ref V128 location, V128 expected, V128 desired); - - private static CompareExchange128 _compareExchange128; - - private static object _lock; - - static MemoryManagerPal() - { - _lock = new object(); - } - - public static V128 AtomicLoad128(ref V128 location) - { - return GetCompareAndSwap128()(ref location, V128.Zero, V128.Zero); - } - - public static V128 CompareAndSwap128(ref V128 location, V128 expected, V128 desired) - { - return GetCompareAndSwap128()(ref location, expected, desired); - } - - private static CompareExchange128 GetCompareAndSwap128() - { - if (_compareExchange128 == null) - { - GenerateCompareAndSwap128(); - } - - return _compareExchange128; - } - - private static void GenerateCompareAndSwap128() - { - lock (_lock) - { - if (_compareExchange128 != null) - { - return; - } - - EmitterContext context = new EmitterContext(); - - Operand address = context.LoadArgument(OperandType.I64, 0); - Operand expected = context.LoadArgument(OperandType.V128, 1); - Operand desired = context.LoadArgument(OperandType.V128, 2); - - Operand result = context.CompareAndSwap(address, expected, desired); - - context.Return(result); - - ControlFlowGraph cfg = context.GetControlFlowGraph(); - - OperandType[] argTypes = new OperandType[] - { - OperandType.I64, - OperandType.V128, - OperandType.V128 - }; - - _compareExchange128 = Compiler.Compile( - cfg, - argTypes, - OperandType.V128, - CompilerOptions.HighCq); - } - } - } -} \ No newline at end of file -- cgit v1.2.3