aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/DeviceMemory.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-05-03 19:54:50 -0300
committerGitHub <noreply@github.com>2020-05-04 08:54:50 +1000
commitf77694e4f774c9391aad5344e70a7c8721cfedc6 (patch)
tree36bccaeb153bd5d921c751966b8a734a7b4b6ae1 /Ryujinx.HLE/DeviceMemory.cs
parent1758424208335d1f4ff7c27c554e517c81bf72f6 (diff)
Implement a new physical memory manager and replace DeviceMemory (#856)
* Implement a new physical memory manager and replace DeviceMemory * Proper generic constraints * Fix debug build * Add memory tests * New CPU memory manager and general code cleanup * Remove host memory management from CPU project, use Ryujinx.Memory instead * Fix tests * Document exceptions on MemoryBlock * Fix leak on unix memory allocation * Proper disposal of some objects on tests * Fix JitCache not being set as initialized * GetRef without checks for 8-bits and 16-bits CAS * Add MemoryBlock destructor * Throw in separate method to improve codegen * Address PR feedback * QueryModified improvements * Fix memory write tracking not marking all pages as modified in some cases * Simplify MarkRegionAsModified * Remove XML doc for ghost param * Add back optimization to avoid useless buffer updates * Add Ryujinx.Cpu project, move MemoryManager there and remove MemoryBlockWrapper * Some nits * Do not perform address translation when size is 0 * Address PR feedback and format NativeInterface class * Remove ghost parameter description * Update Ryujinx.Cpu to .NET Core 3.1 * Address PR feedback * Fix build * Return a well defined value for GetPhysicalAddress with invalid VA, and do not return unmapped ranges as modified * Typo
Diffstat (limited to 'Ryujinx.HLE/DeviceMemory.cs')
-rw-r--r--Ryujinx.HLE/DeviceMemory.cs200
1 files changed, 0 insertions, 200 deletions
diff --git a/Ryujinx.HLE/DeviceMemory.cs b/Ryujinx.HLE/DeviceMemory.cs
deleted file mode 100644
index 22945b83..00000000
--- a/Ryujinx.HLE/DeviceMemory.cs
+++ /dev/null
@@ -1,200 +0,0 @@
-using ARMeilleure.Memory;
-using System;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-
-namespace Ryujinx.HLE
-{
- class DeviceMemory : IDisposable
- {
- public const long RamSize = 4L * 1024 * 1024 * 1024;
-
- public IntPtr RamPointer { get; }
-
- private unsafe byte* _ramPtr;
-
- public unsafe DeviceMemory()
- {
- RamPointer = MemoryManagement.AllocateWriteTracked(RamSize);
-
- _ramPtr = (byte*)RamPointer;
- }
-
- public sbyte ReadSByte(long position)
- {
- return (sbyte)ReadByte(position);
- }
-
- public short ReadInt16(long position)
- {
- return (short)ReadUInt16(position);
- }
-
- public int ReadInt32(long position)
- {
- return (int)ReadUInt32(position);
- }
-
- public long ReadInt64(long position)
- {
- return (long)ReadUInt64(position);
- }
-
- public unsafe byte ReadByte(long position)
- {
- return *(_ramPtr + position);
- }
-
- public unsafe ushort ReadUInt16(long position)
- {
- return *((ushort*)(_ramPtr + position));
- }
-
- public unsafe uint ReadUInt32(long position)
- {
- return *((uint*)(_ramPtr + position));
- }
-
- public unsafe ulong ReadUInt64(long position)
- {
- return *((ulong*)(_ramPtr + position));
- }
-
- public unsafe T ReadStruct<T>(long position)
- {
- return Marshal.PtrToStructure<T>((IntPtr)(_ramPtr + position));
- }
-
- public unsafe ref T GetStructRef<T>(long position)
- {
- return ref Unsafe.AsRef<T>((void*)(IntPtr)(_ramPtr + position));
- }
-
- public void WriteSByte(long position, sbyte value)
- {
- WriteByte(position, (byte)value);
- }
-
- public void WriteInt16(long position, short value)
- {
- WriteUInt16(position, (ushort)value);
- }
-
- public void WriteInt32(long position, int value)
- {
- WriteUInt32(position, (uint)value);
- }
-
- public void WriteInt64(long position, long value)
- {
- WriteUInt64(position, (ulong)value);
- }
-
- public unsafe void WriteByte(long position, byte value)
- {
- *(_ramPtr + position) = value;
- }
-
- public unsafe void WriteUInt16(long position, ushort value)
- {
- *((ushort*)(_ramPtr + position)) = value;
- }
-
- public unsafe void WriteUInt32(long position, uint value)
- {
- *((uint*)(_ramPtr + position)) = value;
- }
-
- public unsafe void WriteUInt64(long position, ulong value)
- {
- *((ulong*)(_ramPtr + position)) = value;
- }
-
- public unsafe void WriteStruct<T>(long position, T value)
- {
- Marshal.StructureToPtr(value, (IntPtr)(_ramPtr + position), false);
- }
-
- public void FillWithZeros(long position, int size)
- {
- int size8 = size & ~(8 - 1);
-
- for (int offs = 0; offs < size8; offs += 8)
- {
- WriteInt64(position + offs, 0);
- }
-
- for (int offs = size8; offs < (size - size8); offs++)
- {
- WriteByte(position + offs, 0);
- }
- }
-
- public void Set(ulong address, byte value, ulong size)
- {
- if (address + size < address)
- {
- throw new ArgumentOutOfRangeException(nameof(size));
- }
-
- if (address + size > RamSize)
- {
- throw new ArgumentOutOfRangeException(nameof(address));
- }
-
- ulong size8 = size & ~7UL;
-
- ulong valueRep = (ulong)value * 0x0101010101010101;
-
- for (ulong offs = 0; offs < size8; offs += 8)
- {
- WriteUInt64((long)(address + offs), valueRep);
- }
-
- for (ulong offs = size8; offs < (size - size8); offs++)
- {
- WriteByte((long)(address + offs), value);
- }
- }
-
- public void Copy(ulong dst, ulong src, ulong size)
- {
- if (dst + size < dst || src + size < src)
- {
- throw new ArgumentOutOfRangeException(nameof(size));
- }
-
- if (dst + size > RamSize)
- {
- throw new ArgumentOutOfRangeException(nameof(dst));
- }
-
- if (src + size > RamSize)
- {
- throw new ArgumentOutOfRangeException(nameof(src));
- }
-
- ulong size8 = size & ~7UL;
-
- for (ulong offs = 0; offs < size8; offs += 8)
- {
- WriteUInt64((long)(dst + offs), ReadUInt64((long)(src + offs)));
- }
-
- for (ulong offs = size8; offs < (size - size8); offs++)
- {
- WriteByte((long)(dst + offs), ReadByte((long)(src + offs)));
- }
- }
-
- public void Dispose()
- {
- Dispose(true);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- MemoryManagement.Free(RamPointer);
- }
- }
-}