Refactor KIP and NSO executables for libhac
This commit is contained in:
parent
2c417d83d2
commit
d94bd25b1e
3 changed files with 29 additions and 77 deletions
|
@ -31,7 +31,7 @@ namespace Ryujinx.HLE.HOS
|
||||||
|
|
||||||
int codePagesCount = codeSize / KMemoryManager.PageSize;
|
int codePagesCount = codeSize / KMemoryManager.PageSize;
|
||||||
|
|
||||||
ulong codeBaseAddress = kip.Addr39Bits ? 0x8000000UL : 0x200000UL;
|
ulong codeBaseAddress = (kip.Header.Flags & 0x10) != 0 ? 0x8000000UL : 0x200000UL;
|
||||||
|
|
||||||
ulong codeAddress = codeBaseAddress + (ulong)kip.TextOffset;
|
ulong codeAddress = codeBaseAddress + (ulong)kip.TextOffset;
|
||||||
|
|
||||||
|
@ -44,27 +44,27 @@ namespace Ryujinx.HLE.HOS
|
||||||
mmuFlags |= 0x20;
|
mmuFlags |= 0x20;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kip.Addr39Bits)
|
if ((kip.Header.Flags & 0x10) != 0)
|
||||||
{
|
{
|
||||||
mmuFlags |= (int)AddressSpaceType.Addr39Bits << 1;
|
mmuFlags |= (int)AddressSpaceType.Addr39Bits << 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kip.Is64Bits)
|
if ((kip.Header.Flags & 0x08) != 0)
|
||||||
{
|
{
|
||||||
mmuFlags |= 1;
|
mmuFlags |= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessCreationInfo creationInfo = new ProcessCreationInfo(
|
ProcessCreationInfo creationInfo = new ProcessCreationInfo(
|
||||||
kip.Name,
|
kip.Header.Name,
|
||||||
kip.ProcessCategory,
|
kip.Header.ProcessCategory,
|
||||||
kip.TitleId,
|
kip.Header.TitleId,
|
||||||
codeAddress,
|
codeAddress,
|
||||||
codePagesCount,
|
codePagesCount,
|
||||||
mmuFlags,
|
mmuFlags,
|
||||||
0,
|
0,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
MemoryRegion memoryRegion = kip.IsService
|
MemoryRegion memoryRegion = (kip.Header.Flags & 0x20) != 0
|
||||||
? MemoryRegion.Service
|
? MemoryRegion.Service
|
||||||
: MemoryRegion.Application;
|
: MemoryRegion.Application;
|
||||||
|
|
||||||
|
@ -104,9 +104,9 @@ namespace Ryujinx.HLE.HOS
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
process.DefaultCpuCore = kip.DefaultProcessorId;
|
process.DefaultCpuCore = kip.Header.DefaultCore;
|
||||||
|
|
||||||
result = process.Start(kip.MainThreadPriority, (ulong)kip.MainThreadStackSize);
|
result = process.Start(kip.Header.MainThreadPriority, (ulong)kip.Header.Sections[1].Attribute);
|
||||||
|
|
||||||
if (result != KernelResult.Success)
|
if (result != KernelResult.Success)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,70 +5,34 @@ using LibHac.Fs;
|
||||||
|
|
||||||
namespace Ryujinx.HLE.Loaders.Executables
|
namespace Ryujinx.HLE.Loaders.Executables
|
||||||
{
|
{
|
||||||
class KernelInitialProcess : IExecutable
|
class KernelInitialProcess : Kip, IExecutable
|
||||||
{
|
{
|
||||||
Kip kip;
|
|
||||||
public string Name => kip.Header.Name;
|
|
||||||
|
|
||||||
public ulong TitleId => kip.Header.TitleId;
|
|
||||||
|
|
||||||
public int ProcessCategory => kip.Header.ProcessCategory;
|
|
||||||
|
|
||||||
public byte MainThreadPriority => kip.Header.MainThreadPriority;
|
|
||||||
public byte DefaultProcessorId => kip.Header.DefaultCore;
|
|
||||||
|
|
||||||
public bool Is64Bits => (kip.Header.Flags & 0x08) != 0;
|
|
||||||
public bool Addr39Bits => (kip.Header.Flags & 0x10) != 0;
|
|
||||||
public bool IsService => (kip.Header.Flags & 0x20) != 0;
|
|
||||||
|
|
||||||
|
|
||||||
public byte[] Text { get; private set; }
|
public byte[] Text { get; private set; }
|
||||||
public byte[] Ro { get; private set; }
|
public byte[] Ro { get; private set; }
|
||||||
public byte[] Data { get; private set; }
|
public byte[] Data { get; private set; }
|
||||||
|
|
||||||
public int TextOffset => kip.Header.Sections[0].OutOffset;
|
public int TextOffset => Header.Sections[0].OutOffset;
|
||||||
public int RoOffset => kip.Header.Sections[1].OutOffset;
|
public int RoOffset => Header.Sections[1].OutOffset;
|
||||||
public int DataOffset => kip.Header.Sections[2].OutOffset;
|
public int DataOffset => Header.Sections[2].OutOffset;
|
||||||
public int BssOffset => kip.Header.Sections[3].OutOffset;
|
public int BssOffset => Header.Sections[3].OutOffset;
|
||||||
public int BssSize => kip.Header.Sections[3].DecompressedSize;
|
public int BssSize => Header.Sections[3].DecompressedSize;
|
||||||
|
|
||||||
public int MainThreadStackSize => kip.Header.Sections[1].Attribute;
|
|
||||||
public int[] Capabilities { get; set; }
|
public int[] Capabilities { get; set; }
|
||||||
|
|
||||||
private struct SegmentHeader
|
public KernelInitialProcess(IStorage inStorage) : base(inStorage)
|
||||||
{
|
{
|
||||||
public int Offset { get; private set; }
|
|
||||||
public int DecompressedSize { get; private set; }
|
|
||||||
public int CompressedSize { get; private set; }
|
|
||||||
public int Attribute { get; private set; }
|
|
||||||
|
|
||||||
public SegmentHeader(
|
|
||||||
int offset,
|
|
||||||
int decompressedSize,
|
|
||||||
int compressedSize,
|
|
||||||
int attribute)
|
|
||||||
{
|
|
||||||
Offset = offset;
|
|
||||||
DecompressedSize = decompressedSize;
|
|
||||||
CompressedSize = compressedSize;
|
|
||||||
Attribute = attribute;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public KernelInitialProcess(IStorage inStorage)
|
|
||||||
{
|
|
||||||
kip = new Kip(inStorage);
|
|
||||||
Capabilities = new int[32];
|
Capabilities = new int[32];
|
||||||
|
|
||||||
for (int index = 0; index < Capabilities.Length; index++)
|
for (int index = 0; index < Capabilities.Length; index++)
|
||||||
{
|
{
|
||||||
Capabilities[index] = System.BitConverter.ToInt32(kip.Header.Capabilities, index * 4);
|
Capabilities[index] = System.BitConverter.ToInt32(Header.Capabilities, index * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Text = kip.DecompressSection(0);
|
Text = DecompressSection(0);
|
||||||
Ro = kip.DecompressSection(1);
|
Ro = DecompressSection(1);
|
||||||
Data = kip.DecompressSection(2);
|
Data = DecompressSection(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,37 +6,25 @@ using LibHac;
|
||||||
|
|
||||||
namespace Ryujinx.HLE.Loaders.Executables
|
namespace Ryujinx.HLE.Loaders.Executables
|
||||||
{
|
{
|
||||||
class NxStaticObject : IExecutable
|
class NxStaticObject : Nso, IExecutable
|
||||||
{
|
{
|
||||||
Nso nso;
|
|
||||||
|
|
||||||
public byte[] Text { get; private set; }
|
public byte[] Text { get; private set; }
|
||||||
public byte[] Ro { get; private set; }
|
public byte[] Ro { get; private set; }
|
||||||
public byte[] Data { get; private set; }
|
public byte[] Data { get; private set; }
|
||||||
|
|
||||||
public int TextOffset => (int)nso.Sections[0].MemoryOffset;
|
public int TextOffset => (int)Sections[0].MemoryOffset;
|
||||||
public int RoOffset => (int)nso.Sections[1].MemoryOffset;
|
public int RoOffset => (int)Sections[1].MemoryOffset;
|
||||||
public int DataOffset => (int)nso.Sections[2].MemoryOffset;
|
public int DataOffset => (int)Sections[2].MemoryOffset;
|
||||||
public int BssOffset => DataOffset + Data.Length;
|
public int BssOffset => DataOffset + Data.Length;
|
||||||
public int BssSize => (int)nso.BssSize;
|
|
||||||
|
|
||||||
[Flags]
|
public new int BssSize => (int)base.BssSize;
|
||||||
private enum NsoFlags
|
|
||||||
|
public NxStaticObject(IStorage inStorage) : base(inStorage)
|
||||||
{
|
{
|
||||||
IsTextCompressed = 1 << 0,
|
Text = Sections[0].DecompressSection();
|
||||||
IsRoCompressed = 1 << 1,
|
Ro = Sections[1].DecompressSection();
|
||||||
IsDataCompressed = 1 << 2,
|
Data = Sections[2].DecompressSection();
|
||||||
HasTextHash = 1 << 3,
|
|
||||||
HasRoHash = 1 << 4,
|
|
||||||
HasDataHash = 1 << 5
|
|
||||||
}
|
|
||||||
|
|
||||||
public NxStaticObject(IStorage inStorage)
|
|
||||||
{
|
|
||||||
nso = new Nso(inStorage);
|
|
||||||
Text = nso.Sections[0].DecompressSection();
|
|
||||||
Ro = nso.Sections[1].DecompressSection();
|
|
||||||
Data = nso.Sections[2].DecompressSection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue