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