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-04 16:52:39 -08:00
|
|
|
public KernelResult AddRange(ulong Address, ulong PagesCount)
|
2018-11-28 14:18:09 -08:00
|
|
|
{
|
2018-12-04 16:52:39 -08:00
|
|
|
if (PagesCount != 0)
|
2018-11-28 14:18:09 -08:00
|
|
|
{
|
|
|
|
if (Nodes.Last != null)
|
|
|
|
{
|
2018-12-04 16:52:39 -08:00
|
|
|
KPageNode LastNode = Nodes.Last.Value;
|
2018-11-28 14:18:09 -08:00
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
if (LastNode.Address + LastNode.PagesCount * KMemoryManager.PageSize == Address)
|
2018-11-28 14:18:09 -08:00
|
|
|
{
|
2018-12-04 16:52:39 -08:00
|
|
|
Address = LastNode.Address;
|
|
|
|
PagesCount += LastNode.PagesCount;
|
2018-11-28 14:18:09 -08:00
|
|
|
|
|
|
|
Nodes.RemoveLast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
Nodes.AddLast(new KPageNode(Address, PagesCount));
|
2018-11-28 14:18:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return KernelResult.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ulong GetPagesCount()
|
|
|
|
{
|
2018-12-04 16:52:39 -08:00
|
|
|
ulong Sum = 0;
|
2018-11-28 14:18:09 -08:00
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
foreach (KPageNode Node in Nodes)
|
2018-11-28 14:18:09 -08:00
|
|
|
{
|
2018-12-04 16:52:39 -08:00
|
|
|
Sum += Node.PagesCount;
|
2018-11-28 14:18:09 -08:00
|
|
|
}
|
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
return Sum;
|
2018-11-28 14:18:09 -08:00
|
|
|
}
|
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
public bool IsEqual(KPageList Other)
|
2018-11-28 14:18:09 -08:00
|
|
|
{
|
2018-12-04 16:52:39 -08:00
|
|
|
LinkedListNode<KPageNode> ThisNode = Nodes.First;
|
|
|
|
LinkedListNode<KPageNode> OtherNode = Other.Nodes.First;
|
2018-11-28 14:18:09 -08:00
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
while (ThisNode != null && OtherNode != null)
|
2018-11-28 14:18:09 -08:00
|
|
|
{
|
2018-12-04 16:52:39 -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-04 16:52:39 -08:00
|
|
|
ThisNode = ThisNode.Next;
|
|
|
|
OtherNode = OtherNode.Next;
|
2018-11-28 14:18:09 -08:00
|
|
|
}
|
|
|
|
|
2018-12-04 16:52:39 -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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|