From 00579927e43bf55ee06ae02933c1e755fb4120eb Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 28 Nov 2018 20:18:09 -0200 Subject: Better process implementation (#491) * Initial implementation of KProcess * Some improvements to the memory manager, implement back guest stack trace printing * Better GetInfo implementation, improve checking in some places with information from process capabilities * Allow the cpu to read/write from the correct memory locations for accesses crossing a page boundary * Change long -> ulong for address/size on memory related methods to avoid unnecessary casts * Attempt at implementing ldr:ro with new KProcess * Allow BSS with size 0 on ldr:ro * Add checking for memory block slab heap usage, return errors if full, exit gracefully * Use KMemoryBlockSize const from KMemoryManager * Allow all methods to read from non-contiguous locations * Fix for TransactParcelAuto * Address PR feedback, additionally fix some small issues related to the KIP loader and implement SVCs GetProcessId, GetProcessList, GetSystemInfo, CreatePort and ManageNamedPort * Fix wrong check for source pages count from page list on MapPhysicalMemory * Fix some issues with UnloadNro on ldr:ro --- Ryujinx.HLE/Loaders/Compression/BackwardsLz.cs | 105 +++++++++++ Ryujinx.HLE/Loaders/Elf/ElfDynamic.cs | 15 ++ Ryujinx.HLE/Loaders/Elf/ElfDynamicTag.cs | 72 ++++++++ Ryujinx.HLE/Loaders/Elf/ElfSymbol.cs | 40 ++++ Ryujinx.HLE/Loaders/Elf/ElfSymbolBinding.cs | 9 + Ryujinx.HLE/Loaders/Elf/ElfSymbolType.cs | 13 ++ Ryujinx.HLE/Loaders/Elf/ElfSymbolVisibility.cs | 10 + Ryujinx.HLE/Loaders/ElfDyn.cs | 15 -- Ryujinx.HLE/Loaders/ElfDynTag.cs | 72 -------- Ryujinx.HLE/Loaders/ElfRel.cs | 19 -- Ryujinx.HLE/Loaders/ElfRelType.cs | 128 ------------- Ryujinx.HLE/Loaders/ElfSym.cs | 40 ---- Ryujinx.HLE/Loaders/ElfSymBinding.cs | 9 - Ryujinx.HLE/Loaders/ElfSymType.cs | 13 -- Ryujinx.HLE/Loaders/ElfSymVisibility.cs | 10 - Ryujinx.HLE/Loaders/Executable.cs | 205 --------------------- Ryujinx.HLE/Loaders/Executables/IExecutable.cs | 9 +- .../Loaders/Executables/KernelInitialProcess.cs | 149 +++++++++++++++ Ryujinx.HLE/Loaders/Executables/Nro.cs | 65 ------- Ryujinx.HLE/Loaders/Executables/Nso.cs | 127 ------------- .../Loaders/Executables/NxRelocatableObject.cs | 64 +++++++ Ryujinx.HLE/Loaders/Executables/NxStaticObject.cs | 109 +++++++++++ Ryujinx.HLE/Loaders/Npdm/ApplicationType.cs | 9 - Ryujinx.HLE/Loaders/Npdm/FsPermissionBool.cs | 33 ---- Ryujinx.HLE/Loaders/Npdm/FsPermissionRw.cs | 45 ----- Ryujinx.HLE/Loaders/Npdm/KernelAccessControl.cs | 162 +--------------- Ryujinx.HLE/Loaders/Npdm/KernelAccessControlIrq.cs | 14 -- .../Loaders/Npdm/KernelAccessControlMmio.cs | 22 --- Ryujinx.HLE/Loaders/Npdm/KernelAccessItem.cs | 33 ---- Ryujinx.HLE/Loaders/Npdm/Npdm.cs | 36 ++-- Ryujinx.HLE/Loaders/Npdm/ServiceAccessControl.cs | 4 +- Ryujinx.HLE/Loaders/Npdm/SvcName.cs | 134 -------------- 32 files changed, 611 insertions(+), 1179 deletions(-) create mode 100644 Ryujinx.HLE/Loaders/Compression/BackwardsLz.cs create mode 100644 Ryujinx.HLE/Loaders/Elf/ElfDynamic.cs create mode 100644 Ryujinx.HLE/Loaders/Elf/ElfDynamicTag.cs create mode 100644 Ryujinx.HLE/Loaders/Elf/ElfSymbol.cs create mode 100644 Ryujinx.HLE/Loaders/Elf/ElfSymbolBinding.cs create mode 100644 Ryujinx.HLE/Loaders/Elf/ElfSymbolType.cs create mode 100644 Ryujinx.HLE/Loaders/Elf/ElfSymbolVisibility.cs delete mode 100644 Ryujinx.HLE/Loaders/ElfDyn.cs delete mode 100644 Ryujinx.HLE/Loaders/ElfDynTag.cs delete mode 100644 Ryujinx.HLE/Loaders/ElfRel.cs delete mode 100644 Ryujinx.HLE/Loaders/ElfRelType.cs delete mode 100644 Ryujinx.HLE/Loaders/ElfSym.cs delete mode 100644 Ryujinx.HLE/Loaders/ElfSymBinding.cs delete mode 100644 Ryujinx.HLE/Loaders/ElfSymType.cs delete mode 100644 Ryujinx.HLE/Loaders/ElfSymVisibility.cs delete mode 100644 Ryujinx.HLE/Loaders/Executable.cs create mode 100644 Ryujinx.HLE/Loaders/Executables/KernelInitialProcess.cs delete mode 100644 Ryujinx.HLE/Loaders/Executables/Nro.cs delete mode 100644 Ryujinx.HLE/Loaders/Executables/Nso.cs create mode 100644 Ryujinx.HLE/Loaders/Executables/NxRelocatableObject.cs create mode 100644 Ryujinx.HLE/Loaders/Executables/NxStaticObject.cs delete mode 100644 Ryujinx.HLE/Loaders/Npdm/ApplicationType.cs delete mode 100644 Ryujinx.HLE/Loaders/Npdm/FsPermissionBool.cs delete mode 100644 Ryujinx.HLE/Loaders/Npdm/FsPermissionRw.cs delete mode 100644 Ryujinx.HLE/Loaders/Npdm/KernelAccessControlIrq.cs delete mode 100644 Ryujinx.HLE/Loaders/Npdm/KernelAccessControlMmio.cs delete mode 100644 Ryujinx.HLE/Loaders/Npdm/KernelAccessItem.cs delete mode 100644 Ryujinx.HLE/Loaders/Npdm/SvcName.cs (limited to 'Ryujinx.HLE/Loaders') diff --git a/Ryujinx.HLE/Loaders/Compression/BackwardsLz.cs b/Ryujinx.HLE/Loaders/Compression/BackwardsLz.cs new file mode 100644 index 00000000..43cc601f --- /dev/null +++ b/Ryujinx.HLE/Loaders/Compression/BackwardsLz.cs @@ -0,0 +1,105 @@ +using System; +using System.IO; + +namespace Ryujinx.HLE.Loaders.Compression +{ + static class BackwardsLz + { + private class BackwardsReader + { + private Stream BaseStream; + + public BackwardsReader(Stream BaseStream) + { + this.BaseStream = BaseStream; + } + + public byte ReadByte() + { + BaseStream.Seek(-1, SeekOrigin.Current); + + byte Value = (byte)BaseStream.ReadByte(); + + BaseStream.Seek(-1, SeekOrigin.Current); + + return Value; + } + + public short ReadInt16() + { + return (short)((ReadByte() << 8) | (ReadByte() << 0)); + } + + public int ReadInt32() + { + return ((ReadByte() << 24) | + (ReadByte() << 16) | + (ReadByte() << 8) | + (ReadByte() << 0)); + } + } + + public static byte[] Decompress(Stream Input, int DecompressedLength) + { + long End = Input.Position; + + BackwardsReader Reader = new BackwardsReader(Input); + + int AdditionalDecLength = Reader.ReadInt32(); + int StartOffset = Reader.ReadInt32(); + int CompressedLength = Reader.ReadInt32(); + + Input.Seek(12 - StartOffset, SeekOrigin.Current); + + byte[] Dec = new byte[DecompressedLength]; + + int DecompressedLengthUnpadded = CompressedLength + AdditionalDecLength; + + int DecompressionStart = DecompressedLength - DecompressedLengthUnpadded; + + int DecPos = Dec.Length; + + byte Mask = 0; + byte Header = 0; + + while (DecPos > DecompressionStart) + { + if ((Mask >>= 1) == 0) + { + Header = Reader.ReadByte(); + Mask = 0x80; + } + + if ((Header & Mask) == 0) + { + Dec[--DecPos] = Reader.ReadByte(); + } + else + { + ushort Pair = (ushort)Reader.ReadInt16(); + + int Length = (Pair >> 12) + 3; + int Position = (Pair & 0xfff) + 3; + + DecPos -= Length; + + if (Length <= Position) + { + int SrcPos = DecPos + Position; + + Buffer.BlockCopy(Dec, SrcPos, Dec, DecPos, Length); + } + else + { + for (int Offset = 0; Offset < Length; Offset++) + { + Dec[DecPos + Offset] = Dec[DecPos + Position + Offset]; + } + } + } + } + + return Dec; + } + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Elf/ElfDynamic.cs b/Ryujinx.HLE/Loaders/Elf/ElfDynamic.cs new file mode 100644 index 00000000..fb0ea53e --- /dev/null +++ b/Ryujinx.HLE/Loaders/Elf/ElfDynamic.cs @@ -0,0 +1,15 @@ +namespace Ryujinx.HLE.Loaders.Elf +{ + struct ElfDynamic + { + public ElfDynamicTag Tag { get; private set; } + + public long Value { get; private set; } + + public ElfDynamic(ElfDynamicTag Tag, long Value) + { + this.Tag = Tag; + this.Value = Value; + } + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Elf/ElfDynamicTag.cs b/Ryujinx.HLE/Loaders/Elf/ElfDynamicTag.cs new file mode 100644 index 00000000..9d7ad72e --- /dev/null +++ b/Ryujinx.HLE/Loaders/Elf/ElfDynamicTag.cs @@ -0,0 +1,72 @@ +namespace Ryujinx.HLE.Loaders.Elf +{ + enum ElfDynamicTag + { + DT_NULL = 0, + DT_NEEDED = 1, + DT_PLTRELSZ = 2, + DT_PLTGOT = 3, + DT_HASH = 4, + DT_STRTAB = 5, + DT_SYMTAB = 6, + DT_RELA = 7, + DT_RELASZ = 8, + DT_RELAENT = 9, + DT_STRSZ = 10, + DT_SYMENT = 11, + DT_INIT = 12, + DT_FINI = 13, + DT_SONAME = 14, + DT_RPATH = 15, + DT_SYMBOLIC = 16, + DT_REL = 17, + DT_RELSZ = 18, + DT_RELENT = 19, + DT_PLTREL = 20, + DT_DEBUG = 21, + DT_TEXTREL = 22, + DT_JMPREL = 23, + DT_BIND_NOW = 24, + DT_INIT_ARRAY = 25, + DT_FINI_ARRAY = 26, + DT_INIT_ARRAYSZ = 27, + DT_FINI_ARRAYSZ = 28, + DT_RUNPATH = 29, + DT_FLAGS = 30, + DT_ENCODING = 32, + DT_PREINIT_ARRAY = 32, + DT_PREINIT_ARRAYSZ = 33, + DT_GNU_PRELINKED = 0x6ffffdf5, + DT_GNU_CONFLICTSZ = 0x6ffffdf6, + DT_GNU_LIBLISTSZ = 0x6ffffdf7, + DT_CHECKSUM = 0x6ffffdf8, + DT_PLTPADSZ = 0x6ffffdf9, + DT_MOVEENT = 0x6ffffdfa, + DT_MOVESZ = 0x6ffffdfb, + DT_FEATURE_1 = 0x6ffffdfc, + DT_POSFLAG_1 = 0x6ffffdfd, + DT_SYMINSZ = 0x6ffffdfe, + DT_SYMINENT = 0x6ffffdff, + DT_GNU_HASH = 0x6ffffef5, + DT_TLSDESC_PLT = 0x6ffffef6, + DT_TLSDESC_GOT = 0x6ffffef7, + DT_GNU_CONFLICT = 0x6ffffef8, + DT_GNU_LIBLIST = 0x6ffffef9, + DT_CONFIG = 0x6ffffefa, + DT_DEPAUDIT = 0x6ffffefb, + DT_AUDIT = 0x6ffffefc, + DT_PLTPAD = 0x6ffffefd, + DT_MOVETAB = 0x6ffffefe, + DT_SYMINFO = 0x6ffffeff, + DT_VERSYM = 0x6ffffff0, + DT_RELACOUNT = 0x6ffffff9, + DT_RELCOUNT = 0x6ffffffa, + DT_FLAGS_1 = 0x6ffffffb, + DT_VERDEF = 0x6ffffffc, + DT_VERDEFNUM = 0x6ffffffd, + DT_VERNEED = 0x6ffffffe, + DT_VERNEEDNUM = 0x6fffffff, + DT_AUXILIARY = 0x7ffffffd, + DT_FILTER = 0x7fffffff + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Elf/ElfSymbol.cs b/Ryujinx.HLE/Loaders/Elf/ElfSymbol.cs new file mode 100644 index 00000000..3f3a2a79 --- /dev/null +++ b/Ryujinx.HLE/Loaders/Elf/ElfSymbol.cs @@ -0,0 +1,40 @@ +namespace Ryujinx.HLE.Loaders.Elf +{ + struct ElfSymbol + { + public string Name { get; private set; } + + public ElfSymbolType Type { get; private set; } + public ElfSymbolBinding Binding { get; private set; } + public ElfSymbolVisibility Visibility { get; private set; } + + public bool IsFuncOrObject => + Type == ElfSymbolType.STT_FUNC || + Type == ElfSymbolType.STT_OBJECT; + + public bool IsGlobalOrWeak => + Binding == ElfSymbolBinding.STB_GLOBAL || + Binding == ElfSymbolBinding.STB_WEAK; + + public int SHIdx { get; private set; } + public long Value { get; private set; } + public long Size { get; private set; } + + public ElfSymbol( + string Name, + int Info, + int Other, + int SHIdx, + long Value, + long Size) + { + this.Name = Name; + this.Type = (ElfSymbolType)(Info & 0xf); + this.Binding = (ElfSymbolBinding)(Info >> 4); + this.Visibility = (ElfSymbolVisibility)Other; + this.SHIdx = SHIdx; + this.Value = Value; + this.Size = Size; + } + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Elf/ElfSymbolBinding.cs b/Ryujinx.HLE/Loaders/Elf/ElfSymbolBinding.cs new file mode 100644 index 00000000..3c915311 --- /dev/null +++ b/Ryujinx.HLE/Loaders/Elf/ElfSymbolBinding.cs @@ -0,0 +1,9 @@ +namespace Ryujinx.HLE.Loaders.Elf +{ + enum ElfSymbolBinding + { + STB_LOCAL = 0, + STB_GLOBAL = 1, + STB_WEAK = 2 + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Elf/ElfSymbolType.cs b/Ryujinx.HLE/Loaders/Elf/ElfSymbolType.cs new file mode 100644 index 00000000..f22e6c45 --- /dev/null +++ b/Ryujinx.HLE/Loaders/Elf/ElfSymbolType.cs @@ -0,0 +1,13 @@ +namespace Ryujinx.HLE.Loaders.Elf +{ + enum ElfSymbolType + { + STT_NOTYPE = 0, + STT_OBJECT = 1, + STT_FUNC = 2, + STT_SECTION = 3, + STT_FILE = 4, + STT_COMMON = 5, + STT_TLS = 6 + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Elf/ElfSymbolVisibility.cs b/Ryujinx.HLE/Loaders/Elf/ElfSymbolVisibility.cs new file mode 100644 index 00000000..4bec50a3 --- /dev/null +++ b/Ryujinx.HLE/Loaders/Elf/ElfSymbolVisibility.cs @@ -0,0 +1,10 @@ +namespace Ryujinx.HLE.Loaders.Elf +{ + enum ElfSymbolVisibility + { + STV_DEFAULT = 0, + STV_INTERNAL = 1, + STV_HIDDEN = 2, + STV_PROTECTED = 3 + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/ElfDyn.cs b/Ryujinx.HLE/Loaders/ElfDyn.cs deleted file mode 100644 index 3508e6e4..00000000 --- a/Ryujinx.HLE/Loaders/ElfDyn.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Ryujinx.HLE.Loaders -{ - struct ElfDyn - { - public ElfDynTag Tag { get; private set; } - - public long Value { get; private set; } - - public ElfDyn(ElfDynTag Tag, long Value) - { - this.Tag = Tag; - this.Value = Value; - } - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/ElfDynTag.cs b/Ryujinx.HLE/Loaders/ElfDynTag.cs deleted file mode 100644 index 5915d4d1..00000000 --- a/Ryujinx.HLE/Loaders/ElfDynTag.cs +++ /dev/null @@ -1,72 +0,0 @@ -namespace Ryujinx.HLE.Loaders -{ - enum ElfDynTag - { - DT_NULL = 0, - DT_NEEDED = 1, - DT_PLTRELSZ = 2, - DT_PLTGOT = 3, - DT_HASH = 4, - DT_STRTAB = 5, - DT_SYMTAB = 6, - DT_RELA = 7, - DT_RELASZ = 8, - DT_RELAENT = 9, - DT_STRSZ = 10, - DT_SYMENT = 11, - DT_INIT = 12, - DT_FINI = 13, - DT_SONAME = 14, - DT_RPATH = 15, - DT_SYMBOLIC = 16, - DT_REL = 17, - DT_RELSZ = 18, - DT_RELENT = 19, - DT_PLTREL = 20, - DT_DEBUG = 21, - DT_TEXTREL = 22, - DT_JMPREL = 23, - DT_BIND_NOW = 24, - DT_INIT_ARRAY = 25, - DT_FINI_ARRAY = 26, - DT_INIT_ARRAYSZ = 27, - DT_FINI_ARRAYSZ = 28, - DT_RUNPATH = 29, - DT_FLAGS = 30, - DT_ENCODING = 32, - DT_PREINIT_ARRAY = 32, - DT_PREINIT_ARRAYSZ = 33, - DT_GNU_PRELINKED = 0x6ffffdf5, - DT_GNU_CONFLICTSZ = 0x6ffffdf6, - DT_GNU_LIBLISTSZ = 0x6ffffdf7, - DT_CHECKSUM = 0x6ffffdf8, - DT_PLTPADSZ = 0x6ffffdf9, - DT_MOVEENT = 0x6ffffdfa, - DT_MOVESZ = 0x6ffffdfb, - DT_FEATURE_1 = 0x6ffffdfc, - DT_POSFLAG_1 = 0x6ffffdfd, - DT_SYMINSZ = 0x6ffffdfe, - DT_SYMINENT = 0x6ffffdff, - DT_GNU_HASH = 0x6ffffef5, - DT_TLSDESC_PLT = 0x6ffffef6, - DT_TLSDESC_GOT = 0x6ffffef7, - DT_GNU_CONFLICT = 0x6ffffef8, - DT_GNU_LIBLIST = 0x6ffffef9, - DT_CONFIG = 0x6ffffefa, - DT_DEPAUDIT = 0x6ffffefb, - DT_AUDIT = 0x6ffffefc, - DT_PLTPAD = 0x6ffffefd, - DT_MOVETAB = 0x6ffffefe, - DT_SYMINFO = 0x6ffffeff, - DT_VERSYM = 0x6ffffff0, - DT_RELACOUNT = 0x6ffffff9, - DT_RELCOUNT = 0x6ffffffa, - DT_FLAGS_1 = 0x6ffffffb, - DT_VERDEF = 0x6ffffffc, - DT_VERDEFNUM = 0x6ffffffd, - DT_VERNEED = 0x6ffffffe, - DT_VERNEEDNUM = 0x6fffffff, - DT_AUXILIARY = 0x7ffffffd, - DT_FILTER = 0x7fffffff - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/ElfRel.cs b/Ryujinx.HLE/Loaders/ElfRel.cs deleted file mode 100644 index cfc31d89..00000000 --- a/Ryujinx.HLE/Loaders/ElfRel.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Ryujinx.HLE.Loaders -{ - struct ElfRel - { - public long Offset { get; private set; } - public long Addend { get; private set; } - - public ElfSym Symbol { get; private set; } - public ElfRelType Type { get; private set; } - - public ElfRel(long Offset, long Addend, ElfSym Symbol, ElfRelType Type) - { - this.Offset = Offset; - this.Addend = Addend; - this.Symbol = Symbol; - this.Type = Type; - } - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/ElfRelType.cs b/Ryujinx.HLE/Loaders/ElfRelType.cs deleted file mode 100644 index 7da5eec3..00000000 --- a/Ryujinx.HLE/Loaders/ElfRelType.cs +++ /dev/null @@ -1,128 +0,0 @@ -namespace Ryujinx.HLE.Loaders -{ - enum ElfRelType - { - R_AARCH64_NONE = 0, - R_AARCH64_ABS64 = 257, - R_AARCH64_ABS32 = 258, - R_AARCH64_ABS16 = 259, - R_AARCH64_PREL64 = 260, - R_AARCH64_PREL32 = 261, - R_AARCH64_PREL16 = 262, - R_AARCH64_MOVW_UABS_G0 = 263, - R_AARCH64_MOVW_UABS_G0_NC = 264, - R_AARCH64_MOVW_UABS_G1 = 265, - R_AARCH64_MOVW_UABS_G1_NC = 266, - R_AARCH64_MOVW_UABS_G2 = 267, - R_AARCH64_MOVW_UABS_G2_NC = 268, - R_AARCH64_MOVW_UABS_G3 = 269, - R_AARCH64_MOVW_SABS_G0 = 270, - R_AARCH64_MOVW_SABS_G1 = 271, - R_AARCH64_MOVW_SABS_G2 = 272, - R_AARCH64_LD_PREL_LO19 = 273, - R_AARCH64_ADR_PREL_LO21 = 274, - R_AARCH64_ADR_PREL_PG_HI21 = 275, - R_AARCH64_ADR_PREL_PG_HI21_NC = 276, - R_AARCH64_ADD_ABS_LO12_NC = 277, - R_AARCH64_LDST8_ABS_LO12_NC = 278, - R_AARCH64_TSTBR14 = 279, - R_AARCH64_CONDBR19 = 280, - R_AARCH64_JUMP26 = 282, - R_AARCH64_CALL26 = 283, - R_AARCH64_LDST16_ABS_LO12_NC = 284, - R_AARCH64_LDST32_ABS_LO12_NC = 285, - R_AARCH64_LDST64_ABS_LO12_NC = 286, - R_AARCH64_MOVW_PREL_G0 = 287, - R_AARCH64_MOVW_PREL_G0_NC = 288, - R_AARCH64_MOVW_PREL_G1 = 289, - R_AARCH64_MOVW_PREL_G1_NC = 290, - R_AARCH64_MOVW_PREL_G2 = 291, - R_AARCH64_MOVW_PREL_G2_NC = 292, - R_AARCH64_MOVW_PREL_G3 = 293, - R_AARCH64_LDST128_ABS_LO12_NC = 299, - R_AARCH64_MOVW_GOTOFF_G0 = 300, - R_AARCH64_MOVW_GOTOFF_G0_NC = 301, - R_AARCH64_MOVW_GOTOFF_G1 = 302, - R_AARCH64_MOVW_GOTOFF_G1_NC = 303, - R_AARCH64_MOVW_GOTOFF_G2 = 304, - R_AARCH64_MOVW_GOTOFF_G2_NC = 305, - R_AARCH64_MOVW_GOTOFF_G3 = 306, - R_AARCH64_GOTREL64 = 307, - R_AARCH64_GOTREL32 = 308, - R_AARCH64_GOT_LD_PREL19 = 309, - R_AARCH64_LD64_GOTOFF_LO15 = 310, - R_AARCH64_ADR_GOT_PAGE = 311, - R_AARCH64_LD64_GOT_LO12_NC = 312, - R_AARCH64_LD64_GOTPAGE_LO15 = 313, - R_AARCH64_TLSGD_ADR_PREL21 = 512, - R_AARCH64_TLSGD_ADR_PAGE21 = 513, - R_AARCH64_TLSGD_ADD_LO12_NC = 514, - R_AARCH64_TLSGD_MOVW_G1 = 515, - R_AARCH64_TLSGD_MOVW_G0_NC = 516, - R_AARCH64_TLSLD_ADR_PREL21 = 517, - R_AARCH64_TLSLD_ADR_PAGE21 = 518, - R_AARCH64_TLSLD_ADD_LO12_NC = 519, - R_AARCH64_TLSLD_MOVW_G1 = 520, - R_AARCH64_TLSLD_MOVW_G0_NC = 521, - R_AARCH64_TLSLD_LD_PREL19 = 522, - R_AARCH64_TLSLD_MOVW_DTPREL_G2 = 523, - R_AARCH64_TLSLD_MOVW_DTPREL_G1 = 524, - R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC = 525, - R_AARCH64_TLSLD_MOVW_DTPREL_G0 = 526, - R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC = 527, - R_AARCH64_TLSLD_ADD_DTPREL_HI12 = 528, - R_AARCH64_TLSLD_ADD_DTPREL_LO12 = 529, - R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC = 530, - R_AARCH64_TLSLD_LDST8_DTPREL_LO12 = 531, - R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC = 532, - R_AARCH64_TLSLD_LDST16_DTPREL_LO12 = 533, - R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC = 534, - R_AARCH64_TLSLD_LDST32_DTPREL_LO12 = 535, - R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC = 536, - R_AARCH64_TLSLD_LDST64_DTPREL_LO12 = 537, - R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC = 538, - R_AARCH64_TLSIE_MOVW_GOTTPREL_G1 = 539, - R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC = 540, - R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 = 541, - R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC = 542, - R_AARCH64_TLSIE_LD_GOTTPREL_PREL19 = 543, - R_AARCH64_TLSLE_MOVW_TPREL_G2 = 544, - R_AARCH64_TLSLE_MOVW_TPREL_G1 = 545, - R_AARCH64_TLSLE_MOVW_TPREL_G1_NC = 546, - R_AARCH64_TLSLE_MOVW_TPREL_G0 = 547, - R_AARCH64_TLSLE_MOVW_TPREL_G0_NC = 548, - R_AARCH64_TLSLE_ADD_TPREL_HI12 = 549, - R_AARCH64_TLSLE_ADD_TPREL_LO12 = 550, - R_AARCH64_TLSLE_ADD_TPREL_LO12_NC = 551, - R_AARCH64_TLSLE_LDST8_TPREL_LO12 = 552, - R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC = 553, - R_AARCH64_TLSLE_LDST16_TPREL_LO12 = 554, - R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC = 555, - R_AARCH64_TLSLE_LDST32_TPREL_LO12 = 556, - R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC = 557, - R_AARCH64_TLSLE_LDST64_TPREL_LO12 = 558, - R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC = 559, - R_AARCH64_TLSDESC_LD_PREL19 = 560, - R_AARCH64_TLSDESC_ADR_PREL21 = 561, - R_AARCH64_TLSDESC_ADR_PAGE21 = 562, - R_AARCH64_TLSDESC_LD64_LO12 = 563, - R_AARCH64_TLSDESC_ADD_LO12 = 564, - R_AARCH64_TLSDESC_OFF_G1 = 565, - R_AARCH64_TLSDESC_OFF_G0_NC = 566, - R_AARCH64_TLSDESC_LDR = 567, - R_AARCH64_TLSDESC_ADD = 568, - R_AARCH64_TLSDESC_CALL = 569, - R_AARCH64_TLSLE_LDST128_TPREL_LO12 = 570, - R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC = 571, - R_AARCH64_TLSLD_LDST128_DTPREL_LO12 = 572, - R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC = 573, - R_AARCH64_COPY = 1024, - R_AARCH64_GLOB_DAT = 1025, - R_AARCH64_JUMP_SLOT = 1026, - R_AARCH64_RELATIVE = 1027, - R_AARCH64_TLS_DTPMOD64 = 1028, - R_AARCH64_TLS_DTPREL64 = 1029, - R_AARCH64_TLS_TPREL64 = 1030, - R_AARCH64_TLSDESC = 1031 - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/ElfSym.cs b/Ryujinx.HLE/Loaders/ElfSym.cs deleted file mode 100644 index 869938d3..00000000 --- a/Ryujinx.HLE/Loaders/ElfSym.cs +++ /dev/null @@ -1,40 +0,0 @@ -namespace Ryujinx.HLE.Loaders -{ - struct ElfSym - { - public string Name { get; private set; } - - public ElfSymType Type { get; private set; } - public ElfSymBinding Binding { get; private set; } - public ElfSymVisibility Visibility { get; private set; } - - public bool IsFuncOrObject => - Type == ElfSymType.STT_FUNC || - Type == ElfSymType.STT_OBJECT; - - public bool IsGlobalOrWeak => - Binding == ElfSymBinding.STB_GLOBAL || - Binding == ElfSymBinding.STB_WEAK; - - public int SHIdx { get; private set; } - public long Value { get; private set; } - public long Size { get; private set; } - - public ElfSym( - string Name, - int Info, - int Other, - int SHIdx, - long Value, - long Size) - { - this.Name = Name; - this.Type = (ElfSymType)(Info & 0xf); - this.Binding = (ElfSymBinding)(Info >> 4); - this.Visibility = (ElfSymVisibility)Other; - this.SHIdx = SHIdx; - this.Value = Value; - this.Size = Size; - } - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/ElfSymBinding.cs b/Ryujinx.HLE/Loaders/ElfSymBinding.cs deleted file mode 100644 index f1d249ec..00000000 --- a/Ryujinx.HLE/Loaders/ElfSymBinding.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Ryujinx.HLE.Loaders -{ - enum ElfSymBinding - { - STB_LOCAL = 0, - STB_GLOBAL = 1, - STB_WEAK = 2 - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/ElfSymType.cs b/Ryujinx.HLE/Loaders/ElfSymType.cs deleted file mode 100644 index 478064bc..00000000 --- a/Ryujinx.HLE/Loaders/ElfSymType.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Ryujinx.HLE.Loaders -{ - enum ElfSymType - { - STT_NOTYPE = 0, - STT_OBJECT = 1, - STT_FUNC = 2, - STT_SECTION = 3, - STT_FILE = 4, - STT_COMMON = 5, - STT_TLS = 6 - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/ElfSymVisibility.cs b/Ryujinx.HLE/Loaders/ElfSymVisibility.cs deleted file mode 100644 index fe7243a7..00000000 --- a/Ryujinx.HLE/Loaders/ElfSymVisibility.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Ryujinx.HLE.Loaders -{ - enum ElfSymVisibility - { - STV_DEFAULT = 0, - STV_INTERNAL = 1, - STV_HIDDEN = 2, - STV_PROTECTED = 3 - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Executable.cs b/Ryujinx.HLE/Loaders/Executable.cs deleted file mode 100644 index d4d79073..00000000 --- a/Ryujinx.HLE/Loaders/Executable.cs +++ /dev/null @@ -1,205 +0,0 @@ -using ChocolArm64.Memory; -using Ryujinx.HLE.HOS; -using Ryujinx.HLE.HOS.Kernel; -using Ryujinx.HLE.Loaders.Executables; -using Ryujinx.HLE.Utilities; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.IO; -using System.Linq; - -namespace Ryujinx.HLE.Loaders -{ - class Executable - { - private MemoryManager Memory; - - private List Dynamic; - - public ReadOnlyCollection SymbolTable; - - public string Name { get; private set; } - - public string FilePath { get; private set; } - - public long ImageBase { get; private set; } - public long ImageEnd { get; private set; } - - private KMemoryManager MemoryManager; - - public Executable(IExecutable Exe, KMemoryManager MemoryManager, MemoryManager Memory, long ImageBase) - { - Dynamic = new List(); - - FilePath = Exe.FilePath; - - if (FilePath != null) - { - Name = Path.GetFileNameWithoutExtension(FilePath.Replace(Homebrew.TemporaryNroSuffix, "")); - } - - this.Memory = Memory; - this.MemoryManager = MemoryManager; - this.ImageBase = ImageBase; - this.ImageEnd = ImageBase; - - long TextPosition = ImageBase + (uint)Exe.TextOffset; - long ROPosition = ImageBase + (uint)Exe.ROOffset; - long DataPosition = ImageBase + (uint)Exe.DataOffset; - - long TextSize = (uint)IntUtils.AlignUp(Exe.Text.Length, KMemoryManager.PageSize); - long ROSize = (uint)IntUtils.AlignUp(Exe.RO.Length, KMemoryManager.PageSize); - long DataSize = (uint)IntUtils.AlignUp(Exe.Data.Length, KMemoryManager.PageSize); - long BssSize = (uint)IntUtils.AlignUp(Exe.BssSize, KMemoryManager.PageSize); - - long DataAndBssSize = BssSize + DataSize; - - ImageEnd = DataPosition + DataAndBssSize; - - if (Exe.SourceAddress == 0) - { - MemoryManager.HleMapProcessCode(TextPosition, TextSize + ROSize + DataAndBssSize); - - MemoryManager.SetProcessMemoryPermission(ROPosition, ROSize, MemoryPermission.Read); - MemoryManager.SetProcessMemoryPermission(DataPosition, DataAndBssSize, MemoryPermission.ReadAndWrite); - - Memory.WriteBytes(TextPosition, Exe.Text); - Memory.WriteBytes(ROPosition, Exe.RO); - Memory.WriteBytes(DataPosition, Exe.Data); - } - else - { - long Result = MemoryManager.MapProcessCodeMemory(TextPosition, Exe.SourceAddress, TextSize + ROSize + DataSize); - - if (Result != 0) - { - throw new InvalidOperationException(); - } - - MemoryManager.SetProcessMemoryPermission(ROPosition, ROSize, MemoryPermission.Read); - MemoryManager.SetProcessMemoryPermission(DataPosition, DataSize, MemoryPermission.ReadAndWrite); - - if (Exe.BssAddress != 0 && Exe.BssSize != 0) - { - Result = MemoryManager.MapProcessCodeMemory(DataPosition + DataSize, Exe.BssAddress, BssSize); - - if (Result != 0) - { - throw new InvalidOperationException(); - } - - MemoryManager.SetProcessMemoryPermission(DataPosition + DataSize, BssSize, MemoryPermission.ReadAndWrite); - } - } - - if (Exe.Mod0Offset == 0) - { - return; - } - - long Mod0Offset = ImageBase + Exe.Mod0Offset; - - int Mod0Magic = Memory.ReadInt32(Mod0Offset + 0x0); - long DynamicOffset = Memory.ReadInt32(Mod0Offset + 0x4) + Mod0Offset; - long BssStartOffset = Memory.ReadInt32(Mod0Offset + 0x8) + Mod0Offset; - long BssEndOffset = Memory.ReadInt32(Mod0Offset + 0xc) + Mod0Offset; - long EhHdrStartOffset = Memory.ReadInt32(Mod0Offset + 0x10) + Mod0Offset; - long EhHdrEndOffset = Memory.ReadInt32(Mod0Offset + 0x14) + Mod0Offset; - long ModObjOffset = Memory.ReadInt32(Mod0Offset + 0x18) + Mod0Offset; - - while (true) - { - long TagVal = Memory.ReadInt64(DynamicOffset + 0); - long Value = Memory.ReadInt64(DynamicOffset + 8); - - DynamicOffset += 0x10; - - ElfDynTag Tag = (ElfDynTag)TagVal; - - if (Tag == ElfDynTag.DT_NULL) - { - break; - } - - Dynamic.Add(new ElfDyn(Tag, Value)); - } - - long StrTblAddr = ImageBase + GetFirstValue(ElfDynTag.DT_STRTAB); - long SymTblAddr = ImageBase + GetFirstValue(ElfDynTag.DT_SYMTAB); - - long SymEntSize = GetFirstValue(ElfDynTag.DT_SYMENT); - - List Symbols = new List(); - - while ((ulong)SymTblAddr < (ulong)StrTblAddr) - { - ElfSym Sym = GetSymbol(SymTblAddr, StrTblAddr); - - Symbols.Add(Sym); - - SymTblAddr += SymEntSize; - } - - SymbolTable = Array.AsReadOnly(Symbols.OrderBy(x => x.Value).ToArray()); - } - - private ElfRel GetRelocation(long Position) - { - long Offset = Memory.ReadInt64(Position + 0); - long Info = Memory.ReadInt64(Position + 8); - long Addend = Memory.ReadInt64(Position + 16); - - int RelType = (int)(Info >> 0); - int SymIdx = (int)(Info >> 32); - - ElfSym Symbol = GetSymbol(SymIdx); - - return new ElfRel(Offset, Addend, Symbol, (ElfRelType)RelType); - } - - private ElfSym GetSymbol(int Index) - { - long StrTblAddr = ImageBase + GetFirstValue(ElfDynTag.DT_STRTAB); - long SymTblAddr = ImageBase + GetFirstValue(ElfDynTag.DT_SYMTAB); - - long SymEntSize = GetFirstValue(ElfDynTag.DT_SYMENT); - - long Position = SymTblAddr + Index * SymEntSize; - - return GetSymbol(Position, StrTblAddr); - } - - private ElfSym GetSymbol(long Position, long StrTblAddr) - { - int NameIndex = Memory.ReadInt32(Position + 0); - int Info = Memory.ReadByte(Position + 4); - int Other = Memory.ReadByte(Position + 5); - int SHIdx = Memory.ReadInt16(Position + 6); - long Value = Memory.ReadInt64(Position + 8); - long Size = Memory.ReadInt64(Position + 16); - - string Name = string.Empty; - - for (int Chr; (Chr = Memory.ReadByte(StrTblAddr + NameIndex++)) != 0;) - { - Name += (char)Chr; - } - - return new ElfSym(Name, Info, Other, SHIdx, Value, Size); - } - - private long GetFirstValue(ElfDynTag Tag) - { - foreach (ElfDyn Entry in Dynamic) - { - if (Entry.Tag == Tag) - { - return Entry.Value; - } - } - - return 0; - } - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Executables/IExecutable.cs b/Ryujinx.HLE/Loaders/Executables/IExecutable.cs index 6f0952ab..d3eefde6 100644 --- a/Ryujinx.HLE/Loaders/Executables/IExecutable.cs +++ b/Ryujinx.HLE/Loaders/Executables/IExecutable.cs @@ -1,20 +1,15 @@ namespace Ryujinx.HLE.Loaders.Executables { - public interface IExecutable + interface IExecutable { - string FilePath { get; } - byte[] Text { get; } byte[] RO { get; } byte[] Data { get; } - long SourceAddress { get; } - long BssAddress { get; } - - int Mod0Offset { get; } int TextOffset { get; } int ROOffset { get; } int DataOffset { get; } + int BssOffset { get; } int BssSize { get; } } } \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Executables/KernelInitialProcess.cs b/Ryujinx.HLE/Loaders/Executables/KernelInitialProcess.cs new file mode 100644 index 00000000..1395d56f --- /dev/null +++ b/Ryujinx.HLE/Loaders/Executables/KernelInitialProcess.cs @@ -0,0 +1,149 @@ +using Ryujinx.HLE.Loaders.Compression; +using System.IO; + +namespace Ryujinx.HLE.Loaders.Executables +{ + class KernelInitialProcess : IExecutable + { + public string Name { get; private set; } + + public long TitleId { get; private set; } + + public int ProcessCategory { get; private set; } + + public byte MainThreadPriority { get; private set; } + public byte DefaultProcessorId { get; private set; } + + public bool Is64Bits { get; private set; } + public bool Addr39Bits { get; private set; } + public bool IsService { get; private set; } + + public byte[] Text { get; private set; } + public byte[] RO { get; private set; } + public byte[] Data { get; private set; } + + public int TextOffset { get; private set; } + public int ROOffset { get; private set; } + public int DataOffset { get; private set; } + public int BssOffset { get; private set; } + public int BssSize { get; private set; } + + public int MainThreadStackSize { get; private set; } + + public int[] Capabilities { get; private set; } + + private struct SegmentHeader + { + 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) + { + this.Offset = Offset; + this.DecompressedSize = DecompressedSize; + this.CompressedSize = CompressedSize; + this.Attribute = Attribute; + } + } + + public KernelInitialProcess(Stream Input) + { + BinaryReader Reader = new BinaryReader(Input); + + string Magic = ReadString(Reader, 4); + + if (Magic != "KIP1") + { + + } + + Name = ReadString(Reader, 12); + + TitleId = Reader.ReadInt64(); + + ProcessCategory = Reader.ReadInt32(); + + MainThreadPriority = Reader.ReadByte(); + DefaultProcessorId = Reader.ReadByte(); + + byte Reserved = Reader.ReadByte(); + byte Flags = Reader.ReadByte(); + + Is64Bits = (Flags & 0x08) != 0; + Addr39Bits = (Flags & 0x10) != 0; + IsService = (Flags & 0x20) != 0; + + SegmentHeader[] Segments = new SegmentHeader[6]; + + for (int Index = 0; Index < Segments.Length; Index++) + { + Segments[Index] = new SegmentHeader( + Reader.ReadInt32(), + Reader.ReadInt32(), + Reader.ReadInt32(), + Reader.ReadInt32()); + } + + TextOffset = Segments[0].Offset; + ROOffset = Segments[1].Offset; + DataOffset = Segments[2].Offset; + BssOffset = Segments[3].Offset; + BssSize = Segments[3].DecompressedSize; + + MainThreadStackSize = Segments[1].Attribute; + + Capabilities = new int[8]; + + for (int Index = 0; Index < Capabilities.Length; Index++) + { + Capabilities[Index] = Reader.ReadInt32(); + } + + Input.Seek(0x100, SeekOrigin.Begin); + + Text = ReadSegment(Segments[0], Input); + RO = ReadSegment(Segments[1], Input); + Data = ReadSegment(Segments[2], Input); + } + + private byte[] ReadSegment(SegmentHeader Header, Stream Input) + { + long End = Input.Position + Header.CompressedSize; + + Input.Seek(End, SeekOrigin.Begin); + + byte[] Data = BackwardsLz.Decompress(Input, Header.DecompressedSize); + + Input.Seek(End, SeekOrigin.Begin); + + return Data; + } + + private static string ReadString(BinaryReader Reader, int MaxSize) + { + string Value = string.Empty; + + for (int Index = 0; Index < MaxSize; Index++) + { + char Chr = (char)Reader.ReadByte(); + + if (Chr == '\0') + { + Reader.BaseStream.Seek(MaxSize - Index - 1, SeekOrigin.Current); + + break; + } + + Value += Chr; + } + + return Value; + } + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Executables/Nro.cs b/Ryujinx.HLE/Loaders/Executables/Nro.cs deleted file mode 100644 index 6015da21..00000000 --- a/Ryujinx.HLE/Loaders/Executables/Nro.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.IO; - -namespace Ryujinx.HLE.Loaders.Executables -{ - class Nro : IExecutable - { - public string FilePath { get; private set; } - - public byte[] Text { get; private set; } - public byte[] RO { get; private set; } - public byte[] Data { get; private set; } - - public int Mod0Offset { get; private set; } - public int TextOffset { get; private set; } - public int ROOffset { get; private set; } - public int DataOffset { get; private set; } - public int BssSize { get; private set; } - - public long SourceAddress { get; private set; } - public long BssAddress { get; private set; } - - public Nro(Stream Input, string FilePath, long SourceAddress = 0, long BssAddress = 0) - { - this.FilePath = FilePath; - this.SourceAddress = SourceAddress; - this.BssAddress = BssAddress; - - BinaryReader Reader = new BinaryReader(Input); - - Input.Seek(4, SeekOrigin.Begin); - - int Mod0Offset = Reader.ReadInt32(); - int Padding8 = Reader.ReadInt32(); - int Paddingc = Reader.ReadInt32(); - int NroMagic = Reader.ReadInt32(); - int Unknown14 = Reader.ReadInt32(); - int FileSize = Reader.ReadInt32(); - int Unknown1c = Reader.ReadInt32(); - int TextOffset = Reader.ReadInt32(); - int TextSize = Reader.ReadInt32(); - int ROOffset = Reader.ReadInt32(); - int ROSize = Reader.ReadInt32(); - int DataOffset = Reader.ReadInt32(); - int DataSize = Reader.ReadInt32(); - int BssSize = Reader.ReadInt32(); - - this.Mod0Offset = Mod0Offset; - this.TextOffset = TextOffset; - this.ROOffset = ROOffset; - this.DataOffset = DataOffset; - this.BssSize = BssSize; - - byte[] Read(long Position, int Size) - { - Input.Seek(Position, SeekOrigin.Begin); - - return Reader.ReadBytes(Size); - } - - Text = Read(TextOffset, TextSize); - RO = Read(ROOffset, ROSize); - Data = Read(DataOffset, DataSize); - } - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Executables/Nso.cs b/Ryujinx.HLE/Loaders/Executables/Nso.cs deleted file mode 100644 index c7b48a5f..00000000 --- a/Ryujinx.HLE/Loaders/Executables/Nso.cs +++ /dev/null @@ -1,127 +0,0 @@ -using Ryujinx.HLE.Loaders.Compression; -using System; -using System.IO; - -namespace Ryujinx.HLE.Loaders.Executables -{ - class Nso : IExecutable - { - public string FilePath { get; private set; } - - public byte[] Text { get; private set; } - public byte[] RO { get; private set; } - public byte[] Data { get; private set; } - - public int Mod0Offset { get; private set; } - public int TextOffset { get; private set; } - public int ROOffset { get; private set; } - public int DataOffset { get; private set; } - public int BssSize { get; private set; } - - public long SourceAddress { get; private set; } - public long BssAddress { get; private set; } - - [Flags] - private enum NsoFlags - { - IsTextCompressed = 1 << 0, - IsROCompressed = 1 << 1, - IsDataCompressed = 1 << 2, - HasTextHash = 1 << 3, - HasROHash = 1 << 4, - HasDataHash = 1 << 5 - } - - public Nso(Stream Input, string FilePath) - { - this.FilePath = FilePath; - - SourceAddress = 0; - BssAddress = 0; - - BinaryReader Reader = new BinaryReader(Input); - - Input.Seek(0, SeekOrigin.Begin); - - int NsoMagic = Reader.ReadInt32(); - int Version = Reader.ReadInt32(); - int Reserved = Reader.ReadInt32(); - int FlagsMsk = Reader.ReadInt32(); - int TextOffset = Reader.ReadInt32(); - int TextMemOffset = Reader.ReadInt32(); - int TextDecSize = Reader.ReadInt32(); - int ModNameOffset = Reader.ReadInt32(); - int ROOffset = Reader.ReadInt32(); - int ROMemOffset = Reader.ReadInt32(); - int RODecSize = Reader.ReadInt32(); - int ModNameSize = Reader.ReadInt32(); - int DataOffset = Reader.ReadInt32(); - int DataMemOffset = Reader.ReadInt32(); - int DataDecSize = Reader.ReadInt32(); - int BssSize = Reader.ReadInt32(); - - byte[] BuildId = Reader.ReadBytes(0x20); - - int TextSize = Reader.ReadInt32(); - int ROSize = Reader.ReadInt32(); - int DataSize = Reader.ReadInt32(); - - Input.Seek(0x24, SeekOrigin.Current); - - int DynStrOffset = Reader.ReadInt32(); - int DynStrSize = Reader.ReadInt32(); - int DynSymOffset = Reader.ReadInt32(); - int DynSymSize = Reader.ReadInt32(); - - byte[] TextHash = Reader.ReadBytes(0x20); - byte[] ROHash = Reader.ReadBytes(0x20); - byte[] DataHash = Reader.ReadBytes(0x20); - - NsoFlags Flags = (NsoFlags)FlagsMsk; - - this.TextOffset = TextMemOffset; - this.ROOffset = ROMemOffset; - this.DataOffset = DataMemOffset; - this.BssSize = BssSize; - - //Text segment - Input.Seek(TextOffset, SeekOrigin.Begin); - - Text = Reader.ReadBytes(TextSize); - - if (Flags.HasFlag(NsoFlags.IsTextCompressed) || true) - { - Text = Lz4.Decompress(Text, TextDecSize); - } - - //Read-only data segment - Input.Seek(ROOffset, SeekOrigin.Begin); - - RO = Reader.ReadBytes(ROSize); - - if (Flags.HasFlag(NsoFlags.IsROCompressed) || true) - { - RO = Lz4.Decompress(RO, RODecSize); - } - - //Data segment - Input.Seek(DataOffset, SeekOrigin.Begin); - - Data = Reader.ReadBytes(DataSize); - - if (Flags.HasFlag(NsoFlags.IsDataCompressed) || true) - { - Data = Lz4.Decompress(Data, DataDecSize); - } - - using (MemoryStream TextMS = new MemoryStream(Text)) - { - BinaryReader TextReader = new BinaryReader(TextMS); - - TextMS.Seek(4, SeekOrigin.Begin); - - Mod0Offset = TextReader.ReadInt32(); - } - } - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Executables/NxRelocatableObject.cs b/Ryujinx.HLE/Loaders/Executables/NxRelocatableObject.cs new file mode 100644 index 00000000..20de5b5d --- /dev/null +++ b/Ryujinx.HLE/Loaders/Executables/NxRelocatableObject.cs @@ -0,0 +1,64 @@ +using System.IO; + +namespace Ryujinx.HLE.Loaders.Executables +{ + class NxRelocatableObject : IExecutable + { + public byte[] Text { get; private set; } + public byte[] RO { get; private set; } + public byte[] Data { get; private set; } + + public int Mod0Offset { get; private set; } + public int TextOffset { get; private set; } + public int ROOffset { get; private set; } + public int DataOffset { get; private set; } + public int BssSize { get; private set; } + + public int BssOffset => DataOffset + Data.Length; + + public ulong SourceAddress { get; private set; } + public ulong BssAddress { get; private set; } + + public NxRelocatableObject(Stream Input, ulong SourceAddress = 0, ulong BssAddress = 0) + { + this.SourceAddress = SourceAddress; + this.BssAddress = BssAddress; + + BinaryReader Reader = new BinaryReader(Input); + + Input.Seek(4, SeekOrigin.Begin); + + int Mod0Offset = Reader.ReadInt32(); + int Padding8 = Reader.ReadInt32(); + int Paddingc = Reader.ReadInt32(); + int NroMagic = Reader.ReadInt32(); + int Unknown14 = Reader.ReadInt32(); + int FileSize = Reader.ReadInt32(); + int Unknown1c = Reader.ReadInt32(); + int TextOffset = Reader.ReadInt32(); + int TextSize = Reader.ReadInt32(); + int ROOffset = Reader.ReadInt32(); + int ROSize = Reader.ReadInt32(); + int DataOffset = Reader.ReadInt32(); + int DataSize = Reader.ReadInt32(); + int BssSize = Reader.ReadInt32(); + + this.Mod0Offset = Mod0Offset; + this.TextOffset = TextOffset; + this.ROOffset = ROOffset; + this.DataOffset = DataOffset; + this.BssSize = BssSize; + + byte[] Read(long Position, int Size) + { + Input.Seek(Position, SeekOrigin.Begin); + + return Reader.ReadBytes(Size); + } + + Text = Read(TextOffset, TextSize); + RO = Read(ROOffset, ROSize); + Data = Read(DataOffset, DataSize); + } + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Executables/NxStaticObject.cs b/Ryujinx.HLE/Loaders/Executables/NxStaticObject.cs new file mode 100644 index 00000000..9fecb650 --- /dev/null +++ b/Ryujinx.HLE/Loaders/Executables/NxStaticObject.cs @@ -0,0 +1,109 @@ +using Ryujinx.HLE.Loaders.Compression; +using System; +using System.IO; + +namespace Ryujinx.HLE.Loaders.Executables +{ + class NxStaticObject : IExecutable + { + public byte[] Text { get; private set; } + public byte[] RO { get; private set; } + public byte[] Data { get; private set; } + + public int TextOffset { get; private set; } + public int ROOffset { get; private set; } + public int DataOffset { get; private set; } + public int BssSize { get; private set; } + + public int BssOffset => DataOffset + Data.Length; + + [Flags] + private enum NsoFlags + { + IsTextCompressed = 1 << 0, + IsROCompressed = 1 << 1, + IsDataCompressed = 1 << 2, + HasTextHash = 1 << 3, + HasROHash = 1 << 4, + HasDataHash = 1 << 5 + } + + public NxStaticObject(Stream Input) + { + BinaryReader Reader = new BinaryReader(Input); + + Input.Seek(0, SeekOrigin.Begin); + + int NsoMagic = Reader.ReadInt32(); + int Version = Reader.ReadInt32(); + int Reserved = Reader.ReadInt32(); + int FlagsMsk = Reader.ReadInt32(); + int TextOffset = Reader.ReadInt32(); + int TextMemOffset = Reader.ReadInt32(); + int TextDecSize = Reader.ReadInt32(); + int ModNameOffset = Reader.ReadInt32(); + int ROOffset = Reader.ReadInt32(); + int ROMemOffset = Reader.ReadInt32(); + int RODecSize = Reader.ReadInt32(); + int ModNameSize = Reader.ReadInt32(); + int DataOffset = Reader.ReadInt32(); + int DataMemOffset = Reader.ReadInt32(); + int DataDecSize = Reader.ReadInt32(); + int BssSize = Reader.ReadInt32(); + + byte[] BuildId = Reader.ReadBytes(0x20); + + int TextSize = Reader.ReadInt32(); + int ROSize = Reader.ReadInt32(); + int DataSize = Reader.ReadInt32(); + + Input.Seek(0x24, SeekOrigin.Current); + + int DynStrOffset = Reader.ReadInt32(); + int DynStrSize = Reader.ReadInt32(); + int DynSymOffset = Reader.ReadInt32(); + int DynSymSize = Reader.ReadInt32(); + + byte[] TextHash = Reader.ReadBytes(0x20); + byte[] ROHash = Reader.ReadBytes(0x20); + byte[] DataHash = Reader.ReadBytes(0x20); + + NsoFlags Flags = (NsoFlags)FlagsMsk; + + this.TextOffset = TextMemOffset; + this.ROOffset = ROMemOffset; + this.DataOffset = DataMemOffset; + this.BssSize = BssSize; + + //Text segment + Input.Seek(TextOffset, SeekOrigin.Begin); + + Text = Reader.ReadBytes(TextSize); + + if (Flags.HasFlag(NsoFlags.IsTextCompressed)) + { + Text = Lz4.Decompress(Text, TextDecSize); + } + + //Read-only data segment + Input.Seek(ROOffset, SeekOrigin.Begin); + + RO = Reader.ReadBytes(ROSize); + + if (Flags.HasFlag(NsoFlags.IsROCompressed)) + { + RO = Lz4.Decompress(RO, RODecSize); + } + + //Data segment + Input.Seek(DataOffset, SeekOrigin.Begin); + + Data = Reader.ReadBytes(DataSize); + + if (Flags.HasFlag(NsoFlags.IsDataCompressed)) + { + Data = Lz4.Decompress(Data, DataDecSize); + } + } + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Npdm/ApplicationType.cs b/Ryujinx.HLE/Loaders/Npdm/ApplicationType.cs deleted file mode 100644 index ad279032..00000000 --- a/Ryujinx.HLE/Loaders/Npdm/ApplicationType.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Ryujinx.HLE.Loaders.Npdm -{ - enum ApplicationType - { - SystemModule, - Application, - Applet - } -} diff --git a/Ryujinx.HLE/Loaders/Npdm/FsPermissionBool.cs b/Ryujinx.HLE/Loaders/Npdm/FsPermissionBool.cs deleted file mode 100644 index 571b7b5a..00000000 --- a/Ryujinx.HLE/Loaders/Npdm/FsPermissionBool.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace Ryujinx.HLE.Loaders.Npdm -{ - enum FsPermissionBool : ulong - { - BisCache = 0x8000000000000080, - EraseMmc = 0x8000000000000080, - GameCardCertificate = 0x8000000000000010, - GameCardIdSet = 0x8000000000000010, - GameCardDriver = 0x8000000000000200, - GameCardAsic = 0x8000000000000200, - SaveDataCreate = 0x8000000000002020, - SaveDataDelete0 = 0x8000000000000060, - SystemSaveDataCreate0 = 0x8000000000000028, - SystemSaveDataCreate1 = 0x8000000000000020, - SaveDataDelete1 = 0x8000000000004028, - SaveDataIterators0 = 0x8000000000000060, - SaveDataIterators1 = 0x8000000000004020, - SaveThumbnails = 0x8000000000020000, - PosixTime = 0x8000000000000400, - SaveDataExtraData = 0x8000000000004060, - GlobalMode = 0x8000000000080000, - SpeedEmulation = 0x8000000000080000, - NULL = 0, - PaddingFiles = 0xC000000000800000, - SaveData_Debug = 0xC000000001000000, - SaveData_SystemManagement = 0xC000000002000000, - Unknown0x16 = 0x8000000004000000, - Unknown0x17 = 0x8000000008000000, - Unknown0x18 = 0x8000000010000000, - Unknown0x19 = 0x8000000000000800, - Unknown0x1A = 0x8000000000004020 - } -} diff --git a/Ryujinx.HLE/Loaders/Npdm/FsPermissionRw.cs b/Ryujinx.HLE/Loaders/Npdm/FsPermissionRw.cs deleted file mode 100644 index ca21279b..00000000 --- a/Ryujinx.HLE/Loaders/Npdm/FsPermissionRw.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace Ryujinx.HLE.Loaders.Npdm -{ - enum FsPermissionRw : ulong - { - MountContentType2 = 0x8000000000000801, - MountContentType5 = 0x8000000000000801, - MountContentType3 = 0x8000000000000801, - MountContentType4 = 0x8000000000000801, - MountContentType6 = 0x8000000000000801, - MountContentType7 = 0x8000000000000801, - Unknown0x6 = 0x8000000000000000, - ContentStorageAccess = 0x8000000000000800, - ImageDirectoryAccess = 0x8000000000001000, - MountBisType28 = 0x8000000000000084, - MountBisType29 = 0x8000000000000080, - MountBisType30 = 0x8000000000008080, - MountBisType31 = 0x8000000000008080, - Unknown0xD = 0x8000000000000080, - SdCardAccess = 0xC000000000200000, - GameCardUser = 0x8000000000000010, - SaveDataAccess0 = 0x8000000000040020, - SystemSaveDataAccess0 = 0x8000000000000028, - SaveDataAccess1 = 0x8000000000000020, - SystemSaveDataAccess1 = 0x8000000000000020, - BisPartition0 = 0x8000000000010082, - BisPartition10 = 0x8000000000010080, - BisPartition20 = 0x8000000000010080, - BisPartition21 = 0x8000000000010080, - BisPartition22 = 0x8000000000010080, - BisPartition23 = 0x8000000000010080, - BisPartition24 = 0x8000000000010080, - BisPartition25 = 0x8000000000010080, - BisPartition26 = 0x8000000000000080, - BisPartition27 = 0x8000000000000084, - BisPartition28 = 0x8000000000000084, - BisPartition29 = 0x8000000000000080, - BisPartition30 = 0x8000000000000080, - BisPartition31 = 0x8000000000000080, - BisPartition32 = 0x8000000000000080, - Unknown0x23 = 0xC000000000200000, - GameCard_System = 0x8000000000000100, - MountContent_System = 0x8000000000100008, - HostAccess = 0xC000000000400000 - } -} diff --git a/Ryujinx.HLE/Loaders/Npdm/KernelAccessControl.cs b/Ryujinx.HLE/Loaders/Npdm/KernelAccessControl.cs index 0b45ebfb..cd3d3252 100644 --- a/Ryujinx.HLE/Loaders/Npdm/KernelAccessControl.cs +++ b/Ryujinx.HLE/Loaders/Npdm/KernelAccessControl.cs @@ -1,173 +1,23 @@ -using Ryujinx.HLE.Exceptions; -using System; -using System.Collections.ObjectModel; -using System.IO; +using System.IO; namespace Ryujinx.HLE.Loaders.Npdm { class KernelAccessControl { - public ReadOnlyCollection Items; + public int[] Capabilities { get; private set; } public KernelAccessControl(Stream Stream, int Offset, int Size) { Stream.Seek(Offset, SeekOrigin.Begin); - BinaryReader Reader = new BinaryReader(Stream); + Capabilities = new int[Size / 4]; - KernelAccessControlItem[] Items = new KernelAccessControlItem[Size / 4]; + BinaryReader Reader = new BinaryReader(Stream); - for (int Index = 0; Index < Size / 4; Index++) + for (int Index = 0; Index < Capabilities.Length; Index++) { - uint Descriptor = Reader.ReadUInt32(); - - //Ignore the descriptor. - if (Descriptor == 0xffffffff) - { - continue; - } - - Items[Index] = new KernelAccessControlItem(); - - int LowBits = 0; - - while ((Descriptor & 1) != 0) - { - Descriptor >>= 1; - - LowBits++; - } - - Descriptor >>= 1; - - switch (LowBits) - { - //Kernel flags. - case 3: - { - Items[Index].HasKernelFlags = true; - - Items[Index].HighestThreadPriority = (Descriptor >> 0) & 0x3f; - Items[Index].LowestThreadPriority = (Descriptor >> 6) & 0x3f; - Items[Index].LowestCpuId = (Descriptor >> 12) & 0xff; - Items[Index].HighestCpuId = (Descriptor >> 20) & 0xff; - - break; - } - - //Syscall mask. - case 4: - { - Items[Index].HasSvcFlags = true; - - Items[Index].AllowedSvcs = new bool[0x80]; - - int SysCallBase = (int)(Descriptor >> 24) * 0x18; - - for (int SysCall = 0; SysCall < 0x18 && SysCallBase + SysCall < 0x80; SysCall++) - { - Items[Index].AllowedSvcs[SysCallBase + SysCall] = (Descriptor & 1) != 0; - - Descriptor >>= 1; - } - - break; - } - - //Map IO/Normal. - case 6: - { - ulong Address = (Descriptor & 0xffffff) << 12; - bool IsRo = (Descriptor >> 24) != 0; - - if (Index == Size / 4 - 1) - { - throw new InvalidNpdmException("Invalid Kernel Access Control Descriptors!"); - } - - Descriptor = Reader.ReadUInt32(); - - if ((Descriptor & 0x7f) != 0x3f) - { - throw new InvalidNpdmException("Invalid Kernel Access Control Descriptors!"); - } - - Descriptor >>= 7; - - ulong MmioSize = (Descriptor & 0xffffff) << 12; - bool IsNormal = (Descriptor >> 24) != 0; - - Items[Index].NormalMmio.Add(new KernelAccessControlMmio(Address, MmioSize, IsRo, IsNormal)); - - Index++; - - break; - } - - //Map Normal Page. - case 7: - { - ulong Address = Descriptor << 12; - - Items[Index].PageMmio.Add(new KernelAccessControlMmio(Address, 0x1000, false, false)); - - break; - } - - //IRQ Pair. - case 11: - { - Items[Index].Irq.Add(new KernelAccessControlIrq( - (Descriptor >> 0) & 0x3ff, - (Descriptor >> 10) & 0x3ff)); - - break; - } - - //Application Type. - case 13: - { - Items[Index].HasApplicationType = true; - - Items[Index].ApplicationType = (int)Descriptor & 7; - - break; - } - - //Kernel Release Version. - case 14: - { - Items[Index].HasKernelVersion = true; - - Items[Index].KernelVersionRelease = (int)Descriptor; - - break; - } - - //Handle Table Size. - case 15: - { - Items[Index].HasHandleTableSize = true; - - Items[Index].HandleTableSize = (int)Descriptor; - - break; - } - - //Debug Flags. - case 16: - { - Items[Index].HasDebugFlags = true; - - Items[Index].AllowDebug = ((Descriptor >> 0) & 1) != 0; - Items[Index].ForceDebug = ((Descriptor >> 1) & 1) != 0; - - break; - } - } + Capabilities[Index] = Reader.ReadInt32(); } - - this.Items = Array.AsReadOnly(Items); } } } diff --git a/Ryujinx.HLE/Loaders/Npdm/KernelAccessControlIrq.cs b/Ryujinx.HLE/Loaders/Npdm/KernelAccessControlIrq.cs deleted file mode 100644 index 63671331..00000000 --- a/Ryujinx.HLE/Loaders/Npdm/KernelAccessControlIrq.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Ryujinx.HLE.Loaders.Npdm -{ - struct KernelAccessControlIrq - { - public uint Irq0 { get; private set; } - public uint Irq1 { get; private set; } - - public KernelAccessControlIrq(uint Irq0, uint Irq1) - { - this.Irq0 = Irq0; - this.Irq1 = Irq1; - } - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Npdm/KernelAccessControlMmio.cs b/Ryujinx.HLE/Loaders/Npdm/KernelAccessControlMmio.cs deleted file mode 100644 index 1ec79c88..00000000 --- a/Ryujinx.HLE/Loaders/Npdm/KernelAccessControlMmio.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace Ryujinx.HLE.Loaders.Npdm -{ - struct KernelAccessControlMmio - { - public ulong Address { get; private set; } - public ulong Size { get; private set; } - public bool IsRo { get; private set; } - public bool IsNormal { get; private set; } - - public KernelAccessControlMmio( - ulong Address, - ulong Size, - bool IsRo, - bool IsNormal) - { - this.Address = Address; - this.Size = Size; - this.IsRo = IsRo; - this.IsNormal = IsNormal; - } - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Npdm/KernelAccessItem.cs b/Ryujinx.HLE/Loaders/Npdm/KernelAccessItem.cs deleted file mode 100644 index 42015c3e..00000000 --- a/Ryujinx.HLE/Loaders/Npdm/KernelAccessItem.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Collections.Generic; - -namespace Ryujinx.HLE.Loaders.Npdm -{ - struct KernelAccessControlItem - { - public bool HasKernelFlags { get; set; } - public uint LowestThreadPriority { get; set; } - public uint HighestThreadPriority { get; set; } - public uint LowestCpuId { get; set; } - public uint HighestCpuId { get; set; } - - public bool HasSvcFlags { get; set; } - public bool[] AllowedSvcs { get; set; } - - public List NormalMmio { get; set; } - public List PageMmio { get; set; } - public List Irq { get; set; } - - public bool HasApplicationType { get; set; } - public int ApplicationType { get; set; } - - public bool HasKernelVersion { get; set; } - public int KernelVersionRelease { get; set; } - - public bool HasHandleTableSize { get; set; } - public int HandleTableSize { get; set; } - - public bool HasDebugFlags { get; set; } - public bool AllowDebug { get; set; } - public bool ForceDebug { get; set; } - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Npdm/Npdm.cs b/Ryujinx.HLE/Loaders/Npdm/Npdm.cs index 8aacfd99..9c2fdb38 100644 --- a/Ryujinx.HLE/Loaders/Npdm/Npdm.cs +++ b/Ryujinx.HLE/Loaders/Npdm/Npdm.cs @@ -1,5 +1,4 @@ using Ryujinx.HLE.Exceptions; -using Ryujinx.HLE.Utilities; using System.IO; using System.Text; @@ -12,15 +11,15 @@ namespace Ryujinx.HLE.Loaders.Npdm { private const int MetaMagic = 'M' << 0 | 'E' << 8 | 'T' << 16 | 'A' << 24; - public bool Is64Bits { get; private set; } - public int AddressSpaceWidth { get; private set; } - public byte MainThreadPriority { get; private set; } - public byte DefaultCpuId { get; private set; } - public int SystemResourceSize { get; private set; } - public int ProcessCategory { get; private set; } - public int MainEntrypointStackSize { get; private set; } - public string TitleName { get; private set; } - public byte[] ProductCode { get; private set; } + public byte MmuFlags { get; private set; } + public bool Is64Bits { get; private set; } + public byte MainThreadPriority { get; private set; } + public byte DefaultCpuId { get; private set; } + public int PersonalMmHeapSize { get; private set; } + public int ProcessCategory { get; private set; } + public int MainThreadStackSize { get; private set; } + public string TitleName { get; private set; } + public byte[] ProductCode { get; private set; } public ACI0 ACI0 { get; private set; } public ACID ACID { get; private set; } @@ -36,27 +35,22 @@ namespace Ryujinx.HLE.Loaders.Npdm Reader.ReadInt64(); - //MmuFlags, bit0: 64-bit instructions, bits1-3: address space width (1=64-bit, 2=32-bit). Needs to be <= 0xF. - byte MmuFlags = Reader.ReadByte(); + MmuFlags = Reader.ReadByte(); - Is64Bits = (MmuFlags & 1) != 0; - AddressSpaceWidth = (MmuFlags >> 1) & 7; + Is64Bits = (MmuFlags & 1) != 0; Reader.ReadByte(); - MainThreadPriority = Reader.ReadByte(); //(0-63). + MainThreadPriority = Reader.ReadByte(); DefaultCpuId = Reader.ReadByte(); Reader.ReadInt32(); - //System resource size (max size as of 5.x: 534773760). - SystemResourceSize = EndianSwap.Swap32(Reader.ReadInt32()); + PersonalMmHeapSize = Reader.ReadInt32(); - //ProcessCategory (0: regular title, 1: kernel built-in). Should be 0 here. - ProcessCategory = EndianSwap.Swap32(Reader.ReadInt32()); + ProcessCategory = Reader.ReadInt32(); - //Main entrypoint stack size. - MainEntrypointStackSize = Reader.ReadInt32(); + MainThreadStackSize = Reader.ReadInt32(); byte[] TempTitleName = Reader.ReadBytes(0x10); diff --git a/Ryujinx.HLE/Loaders/Npdm/ServiceAccessControl.cs b/Ryujinx.HLE/Loaders/Npdm/ServiceAccessControl.cs index 910eacb3..b18538e5 100644 --- a/Ryujinx.HLE/Loaders/Npdm/ServiceAccessControl.cs +++ b/Ryujinx.HLE/Loaders/Npdm/ServiceAccessControl.cs @@ -28,8 +28,8 @@ namespace Ryujinx.HLE.Loaders.Npdm break; } - int Length = ((ControlByte & 0x07)) + 1; - bool RegisterAllowed = ((ControlByte & 0x80) != 0); + int Length = (ControlByte & 0x07) + 1; + bool RegisterAllowed = (ControlByte & 0x80) != 0; Services.Add(Encoding.ASCII.GetString(Reader.ReadBytes(Length), 0, Length), RegisterAllowed); diff --git a/Ryujinx.HLE/Loaders/Npdm/SvcName.cs b/Ryujinx.HLE/Loaders/Npdm/SvcName.cs deleted file mode 100644 index e519e05e..00000000 --- a/Ryujinx.HLE/Loaders/Npdm/SvcName.cs +++ /dev/null @@ -1,134 +0,0 @@ -namespace Ryujinx.HLE.Loaders.Npdm -{ - enum SvcName - { - Reserved0, - SetHeapSize, - SetMemoryPermission, - SetMemoryAttribute, - MapMemory, - UnmapMemory, - QueryMemory, - ExitProcess, - CreateThread, - StartThread, - ExitThread, - SleepThread, - GetThreadPriority, - SetThreadPriority, - GetThreadCoreMask, - SetThreadCoreMask, - GetCurrentProcessorNumber, - SignalEvent, - ClearEvent, - MapSharedMemory, - UnmapSharedMemory, - CreateTransferMemory, - CloseHandle, - ResetSignal, - WaitSynchronization, - CancelSynchronization, - ArbitrateLock, - ArbitrateUnlock, - WaitProcessWideKeyAtomic, - SignalProcessWideKey, - GetSystemTick, - ConnectToNamedPort, - SendSyncRequestLight, - SendSyncRequest, - SendSyncRequestWithUserBuffer, - SendAsyncRequestWithUserBuffer, - GetProcessId, - GetThreadId, - Break, - OutputDebugString, - ReturnFromException, - GetInfo, - FlushEntireDataCache, - FlushDataCache, - MapPhysicalMemory, - UnmapPhysicalMemory, - GetFutureThreadInfo, - GetLastThreadInfo, - GetResourceLimitLimitValue, - GetResourceLimitCurrentValue, - SetThreadActivity, - GetThreadContext3, - WaitForAddress, - SignalToAddress, - Reserved1, - Reserved2, - Reserved3, - Reserved4, - Reserved5, - Reserved6, - DumpInfo, - DumpInfoNew, - Reserved7, - Reserved8, - CreateSession, - AcceptSession, - ReplyAndReceiveLight, - ReplyAndReceive, - ReplyAndReceiveWithUserBuffer, - CreateEvent, - Reserved9, - Reserved10, - MapPhysicalMemoryUnsafe, - UnmapPhysicalMemoryUnsafe, - SetUnsafeLimit, - CreateCodeMemory, - ControlCodeMemory, - SleepSystem, - ReadWriteRegister, - SetProcessActivity, - CreateSharedMemory, - MapTransferMemory, - UnmapTransferMemory, - CreateInterruptEvent, - QueryPhysicalAddress, - QueryIoMapping, - CreateDeviceAddressSpace, - AttachDeviceAddressSpace, - DetachDeviceAddressSpace, - MapDeviceAddressSpaceByForce, - MapDeviceAddressSpaceAligned, - MapDeviceAddressSpace, - UnmapDeviceAddressSpace, - InvalidateProcessDataCache, - StoreProcessDataCache, - FlushProcessDataCache, - DebugActiveProcess, - BreakDebugProcess, - TerminateDebugProcess, - GetDebugEvent, - ContinueDebugEvent, - GetProcessList, - GetThreadList, - GetDebugThreadContext, - SetDebugThreadContext, - QueryDebugProcessMemory, - ReadDebugProcessMemory, - WriteDebugProcessMemory, - SetHardwareBreakPoint, - GetDebugThreadParam, - Reserved11, - GetSystemInfo, - CreatePort, - ManageNamedPort, - ConnectToPort, - SetProcessMemoryPermission, - MapProcessMemory, - UnmapProcessMemory, - QueryProcessMemory, - MapProcessCodeMemory, - UnmapProcessCodeMemory, - CreateProcess, - StartProcess, - TerminateProcess, - GetProcessInfo, - CreateResourceLimit, - SetResourceLimitLimitValue, - CallSecureMonitor - } -} -- cgit v1.2.3