aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Memory/PageTable.cs
diff options
context:
space:
mode:
authorTSR Berry <20988865+TSRBerry@users.noreply.github.com>2023-04-08 01:22:00 +0200
committerMary <thog@protonmail.com>2023-04-27 23:51:14 +0200
commitcee712105850ac3385cd0091a923438167433f9f (patch)
tree4a5274b21d8b7f938c0d0ce18736d3f2993b11b1 /Ryujinx.Memory/PageTable.cs
parentcd124bda587ef09668a971fa1cac1c3f0cfc9f21 (diff)
Move solution and projects to src
Diffstat (limited to 'Ryujinx.Memory/PageTable.cs')
-rw-r--r--Ryujinx.Memory/PageTable.cs141
1 files changed, 0 insertions, 141 deletions
diff --git a/Ryujinx.Memory/PageTable.cs b/Ryujinx.Memory/PageTable.cs
deleted file mode 100644
index 8fdedd4f..00000000
--- a/Ryujinx.Memory/PageTable.cs
+++ /dev/null
@@ -1,141 +0,0 @@
-namespace Ryujinx.Memory
-{
- public class PageTable<T> where T : unmanaged
- {
- public const int PageBits = 12;
- public const int PageSize = 1 << PageBits;
- public const int PageMask = PageSize - 1;
-
- private const int PtLevelBits = 9; // 9 * 4 + 12 = 48 (max address space size)
- private const int PtLevelSize = 1 << PtLevelBits;
- private const int PtLevelMask = PtLevelSize - 1;
-
- private readonly T[][][][] _pageTable;
-
- public PageTable()
- {
- _pageTable = new T[PtLevelSize][][][];
- }
-
- public T Read(ulong va)
- {
- int l3 = (int)(va >> PageBits) & PtLevelMask;
- int l2 = (int)(va >> (PageBits + PtLevelBits)) & PtLevelMask;
- int l1 = (int)(va >> (PageBits + PtLevelBits * 2)) & PtLevelMask;
- int l0 = (int)(va >> (PageBits + PtLevelBits * 3)) & PtLevelMask;
-
- if (_pageTable[l0] == null)
- {
- return default;
- }
-
- if (_pageTable[l0][l1] == null)
- {
- return default;
- }
-
- if (_pageTable[l0][l1][l2] == null)
- {
- return default;
- }
-
- return _pageTable[l0][l1][l2][l3];
- }
-
- public void Map(ulong va, T value)
- {
- int l3 = (int)(va >> PageBits) & PtLevelMask;
- int l2 = (int)(va >> (PageBits + PtLevelBits)) & PtLevelMask;
- int l1 = (int)(va >> (PageBits + PtLevelBits * 2)) & PtLevelMask;
- int l0 = (int)(va >> (PageBits + PtLevelBits * 3)) & PtLevelMask;
-
- if (_pageTable[l0] == null)
- {
- _pageTable[l0] = new T[PtLevelSize][][];
- }
-
- if (_pageTable[l0][l1] == null)
- {
- _pageTable[l0][l1] = new T[PtLevelSize][];
- }
-
- if (_pageTable[l0][l1][l2] == null)
- {
- _pageTable[l0][l1][l2] = new T[PtLevelSize];
- }
-
- _pageTable[l0][l1][l2][l3] = value;
- }
-
- public void Unmap(ulong va)
- {
- int l3 = (int)(va >> PageBits) & PtLevelMask;
- int l2 = (int)(va >> (PageBits + PtLevelBits)) & PtLevelMask;
- int l1 = (int)(va >> (PageBits + PtLevelBits * 2)) & PtLevelMask;
- int l0 = (int)(va >> (PageBits + PtLevelBits * 3)) & PtLevelMask;
-
- if (_pageTable[l0] == null)
- {
- return;
- }
-
- if (_pageTable[l0][l1] == null)
- {
- return;
- }
-
- if (_pageTable[l0][l1][l2] == null)
- {
- return;
- }
-
- _pageTable[l0][l1][l2][l3] = default;
-
- bool empty = true;
-
- for (int i = 0; i < _pageTable[l0][l1][l2].Length; i++)
- {
- empty &= _pageTable[l0][l1][l2][i].Equals(default);
- }
-
- if (empty)
- {
- _pageTable[l0][l1][l2] = null;
-
- RemoveIfAllNull(l0, l1);
- }
- }
-
- private void RemoveIfAllNull(int l0, int l1)
- {
- bool empty = true;
-
- for (int i = 0; i < _pageTable[l0][l1].Length; i++)
- {
- empty &= (_pageTable[l0][l1][i] == null);
- }
-
- if (empty)
- {
- _pageTable[l0][l1] = null;
-
- RemoveIfAllNull(l0);
- }
- }
-
- private void RemoveIfAllNull(int l0)
- {
- bool empty = true;
-
- for (int i = 0; i < _pageTable[l0].Length; i++)
- {
- empty &= (_pageTable[l0][i] == null);
- }
-
- if (empty)
- {
- _pageTable[l0] = null;
- }
- }
- }
-}