diff --git a/Ryujinx.HLE/HOS/ProgramLoader.cs b/Ryujinx.HLE/HOS/ProgramLoader.cs index efe196b7a4..b60e086efb 100644 --- a/Ryujinx.HLE/HOS/ProgramLoader.cs +++ b/Ryujinx.HLE/HOS/ProgramLoader.cs @@ -31,7 +31,7 @@ namespace Ryujinx.HLE.HOS 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; @@ -44,27 +44,27 @@ namespace Ryujinx.HLE.HOS mmuFlags |= 0x20; } - if (kip.Addr39Bits) + if ((kip.Header.Flags & 0x10) != 0) { mmuFlags |= (int)AddressSpaceType.Addr39Bits << 1; } - if (kip.Is64Bits) + if ((kip.Header.Flags & 0x08) != 0) { mmuFlags |= 1; } ProcessCreationInfo creationInfo = new ProcessCreationInfo( - kip.Name, - kip.ProcessCategory, - kip.TitleId, + kip.Header.Name, + kip.Header.ProcessCategory, + kip.Header.TitleId, codeAddress, codePagesCount, mmuFlags, 0, 0); - MemoryRegion memoryRegion = kip.IsService + MemoryRegion memoryRegion = (kip.Header.Flags & 0x20) != 0 ? MemoryRegion.Service : MemoryRegion.Application; @@ -104,9 +104,9 @@ namespace Ryujinx.HLE.HOS 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) { diff --git a/Ryujinx.HLE/Loaders/Executables/KernelInitialProcess.cs b/Ryujinx.HLE/Loaders/Executables/KernelInitialProcess.cs index 0e60472b0e..f93d6f0c7f 100644 --- a/Ryujinx.HLE/Loaders/Executables/KernelInitialProcess.cs +++ b/Ryujinx.HLE/Loaders/Executables/KernelInitialProcess.cs @@ -5,70 +5,34 @@ using LibHac.Fs; 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[] Ro { get; private set; } public byte[] Data { get; private set; } - public int TextOffset => kip.Header.Sections[0].OutOffset; - public int RoOffset => kip.Header.Sections[1].OutOffset; - public int DataOffset => kip.Header.Sections[2].OutOffset; - public int BssOffset => kip.Header.Sections[3].OutOffset; - public int BssSize => kip.Header.Sections[3].DecompressedSize; + public int TextOffset => Header.Sections[0].OutOffset; + public int RoOffset => Header.Sections[1].OutOffset; + public int DataOffset => Header.Sections[2].OutOffset; + public int BssOffset => Header.Sections[3].OutOffset; + public int BssSize => Header.Sections[3].DecompressedSize; - public int MainThreadStackSize => kip.Header.Sections[1].Attribute; 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]; 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); - Ro = kip.DecompressSection(1); - Data = kip.DecompressSection(2); + Text = DecompressSection(0); + Ro = DecompressSection(1); + Data = DecompressSection(2); } } diff --git a/Ryujinx.HLE/Loaders/Executables/NxStaticObject.cs b/Ryujinx.HLE/Loaders/Executables/NxStaticObject.cs index 0e4da6bcaf..6996fbb9fc 100644 --- a/Ryujinx.HLE/Loaders/Executables/NxStaticObject.cs +++ b/Ryujinx.HLE/Loaders/Executables/NxStaticObject.cs @@ -6,37 +6,25 @@ using LibHac; namespace Ryujinx.HLE.Loaders.Executables { - class NxStaticObject : IExecutable + class NxStaticObject : Nso, IExecutable { - Nso nso; public byte[] Text { get; private set; } public byte[] Ro { get; private set; } public byte[] Data { get; private set; } - public int TextOffset => (int)nso.Sections[0].MemoryOffset; - public int RoOffset => (int)nso.Sections[1].MemoryOffset; - public int DataOffset => (int)nso.Sections[2].MemoryOffset; + public int TextOffset => (int)Sections[0].MemoryOffset; + public int RoOffset => (int)Sections[1].MemoryOffset; + public int DataOffset => (int)Sections[2].MemoryOffset; public int BssOffset => DataOffset + Data.Length; - public int BssSize => (int)nso.BssSize; - [Flags] - private enum NsoFlags - { - IsTextCompressed = 1 << 0, - IsRoCompressed = 1 << 1, - IsDataCompressed = 1 << 2, - HasTextHash = 1 << 3, - HasRoHash = 1 << 4, - HasDataHash = 1 << 5 - } + public new int BssSize => (int)base.BssSize; - public NxStaticObject(IStorage inStorage) + public NxStaticObject(IStorage inStorage) : base(inStorage) { - nso = new Nso(inStorage); - Text = nso.Sections[0].DecompressSection(); - Ro = nso.Sections[1].DecompressSection(); - Data = nso.Sections[2].DecompressSection(); + Text = Sections[0].DecompressSection(); + Ro = Sections[1].DecompressSection(); + Data = Sections[2].DecompressSection(); } }