2018-12-18 06:33:36 +01:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
2018-11-28 23:18:09 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2018-12-18 06:33:36 +01:00
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Memory
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
|
|
|
class KPageList : IEnumerable<KPageNode>
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
public LinkedList<KPageNode> Nodes { get; private set; }
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
public KPageList()
|
|
|
|
{
|
|
|
|
Nodes = new LinkedList<KPageNode>();
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public KernelResult AddRange(ulong address, ulong pagesCount)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (pagesCount != 0)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
|
|
|
if (Nodes.Last != null)
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
KPageNode lastNode = Nodes.Last.Value;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (lastNode.Address + lastNode.PagesCount * KMemoryManager.PageSize == address)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
address = lastNode.Address;
|
|
|
|
pagesCount += lastNode.PagesCount;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
Nodes.RemoveLast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
Nodes.AddLast(new KPageNode(address, pagesCount));
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return KernelResult.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ulong GetPagesCount()
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
ulong sum = 0;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
foreach (KPageNode node in Nodes)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
sum += node.PagesCount;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return sum;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public bool IsEqual(KPageList other)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
LinkedListNode<KPageNode> thisNode = Nodes.First;
|
|
|
|
LinkedListNode<KPageNode> otherNode = other.Nodes.First;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
while (thisNode != null && otherNode != null)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (thisNode.Value.Address != otherNode.Value.Address ||
|
|
|
|
thisNode.Value.PagesCount != otherNode.Value.PagesCount)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
thisNode = thisNode.Next;
|
|
|
|
otherNode = otherNode.Next;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return thisNode == null && otherNode == null;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerator<KPageNode> GetEnumerator()
|
|
|
|
{
|
|
|
|
return Nodes.GetEnumerator();
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
{
|
|
|
|
return GetEnumerator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|