Merge pull request #8 from gdkchan/master

Working...
This commit is contained in:
Dr.Hacknik 2018-02-10 12:36:14 -05:00 committed by GitHub
commit 8e3ef9a5b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
101 changed files with 1144 additions and 795 deletions

View file

@ -2,10 +2,10 @@
Logging_Enable_Info = true
#Enabled print trace logs
Logging_Enable_Trace = true
Logging_Enable_Trace = false
#Enabled print debug logs
Logging_Enable_Debug = true
Logging_Enable_Debug = false
#Enabled print warning logs
Logging_Enable_Warn = true

View file

@ -32,6 +32,7 @@ namespace ChocolArm64
Set("100101xxxxxxxxxxxxxxxxxxxxxxxxxx", AInstEmit.Bl, typeof(AOpCodeBImmAl));
Set("11010110001xxxxx000000xxxxxxxxxx", AInstEmit.Blr, typeof(AOpCodeBReg));
Set("11010110000xxxxx000000xxxxxxxxxx", AInstEmit.Br, typeof(AOpCodeBReg));
Set("11010100001xxxxxxxxxxxxxxxx00000", AInstEmit.Brk, typeof(AOpCodeException));
Set("x0110101xxxxxxxxxxxxxxxxxxxxxxxx", AInstEmit.Cbnz, typeof(AOpCodeBImmCmp));
Set("x0110100xxxxxxxxxxxxxxxxxxxxxxxx", AInstEmit.Cbz, typeof(AOpCodeBImmCmp));
Set("x0111010010xxxxxxxxx10xxxxxxxxxx", AInstEmit.Ccmn, typeof(AOpCodeCcmpImm));

View file

@ -150,7 +150,8 @@ namespace ChocolArm64.Decoder
private static bool IsException(AOpCode OpCode)
{
return OpCode.Emitter == AInstEmit.Svc ||
return OpCode.Emitter == AInstEmit.Brk ||
OpCode.Emitter == AInstEmit.Svc ||
OpCode.Emitter == AInstEmit.Und;
}
@ -160,7 +161,7 @@ namespace ChocolArm64.Decoder
AInst Inst = AOpCodeTable.GetInst(OpCode);
AOpCode DecodedOpCode = new AOpCode(AInst.Undefined, Position);
AOpCode DecodedOpCode = new AOpCode(AInst.Undefined, Position, OpCode);
if (Inst.Type != null)
{

View file

@ -7,13 +7,15 @@ namespace ChocolArm64.Decoder
class AOpCode : IAOpCode
{
public long Position { get; private set; }
public int RawOpCode { get; private set; }
public AInstEmitter Emitter { get; protected set; }
public ARegisterSize RegisterSize { get; protected set; }
public AOpCode(AInst Inst, long Position)
public AOpCode(AInst Inst, long Position, int OpCode)
{
this.Position = Position;
this.RawOpCode = OpCode;
RegisterSize = ARegisterSize.Int64;

View file

@ -7,7 +7,7 @@ namespace ChocolArm64.Decoder
public int Rd { get; private set; }
public long Imm { get; private set; }
public AOpCodeAdr(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeAdr(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
Rd = OpCode & 0x1f;

View file

@ -10,7 +10,7 @@ namespace ChocolArm64.Decoder
public ADataOp DataOp { get; private set; }
public AOpCodeAlu(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeAlu(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
Rd = (OpCode >> 0) & 0x1f;
Rn = (OpCode >> 5) & 0x1f;

View file

@ -6,6 +6,6 @@ namespace ChocolArm64.Decoder
{
public long Imm { get; protected set; }
public AOpCodeBImm(AInst Inst, long Position) : base(Inst, Position) { }
public AOpCodeBImm(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode) { }
}
}

View file

@ -4,7 +4,7 @@ namespace ChocolArm64.Decoder
{
class AOpCodeBImmAl : AOpCodeBImm
{
public AOpCodeBImmAl(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeBImmAl(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
Imm = Position + ADecoderHelper.DecodeImm26_2(OpCode);
}

View file

@ -6,7 +6,7 @@ namespace ChocolArm64.Decoder
{
public int Rt { get; private set; }
public AOpCodeBImmCmp(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeBImmCmp(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
Rt = OpCode & 0x1f;

View file

@ -6,7 +6,7 @@ namespace ChocolArm64.Decoder
{
public ACond Cond { get; private set; }
public AOpCodeBImmCond(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeBImmCond(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
int O0 = (OpCode >> 4) & 1;

View file

@ -7,7 +7,7 @@ namespace ChocolArm64.Decoder
public int Rt { get; private set; }
public int Pos { get; private set; }
public AOpCodeBImmTest(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeBImmTest(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
Rt = OpCode & 0x1f;

View file

@ -6,7 +6,7 @@ namespace ChocolArm64.Decoder
{
public int Rn { get; private set; }
public AOpCodeBReg(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeBReg(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
int Op4 = (OpCode >> 0) & 0x1f;
int Op2 = (OpCode >> 16) & 0x1f;

View file

@ -6,9 +6,9 @@ namespace ChocolArm64.Decoder
{
public int Id { get; private set; }
public AOpCodeException(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeException(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
Id = (OpCode >> 5) & 0xfff;
Id = (OpCode >> 5) & 0xffff;
}
}
}

View file

@ -9,7 +9,7 @@ namespace ChocolArm64.Decoder
public int Size { get; protected set; }
public bool Extend64 { get; protected set; }
public AOpCodeMem(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeMem(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
Rt = (OpCode >> 0) & 0x1f;
Rn = (OpCode >> 5) & 0x1f;

View file

@ -10,7 +10,7 @@ namespace ChocolArm64.Decoder
public bool Signed { get; private set; }
public bool Prefetch { get; private set; }
public AOpCodeMemLit(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeMemLit(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
Rt = OpCode & 0x1f;

View file

@ -9,7 +9,7 @@ namespace ChocolArm64.Decoder
public long Imm { get; private set; }
public int Pos { get; private set; }
public AOpCodeMov(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeMov(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
int P1 = (OpCode >> 22) & 1;
int SF = (OpCode >> 31) & 1;

View file

@ -12,7 +12,7 @@ namespace ChocolArm64.Decoder
public int SizeF => Size & 1;
public AOpCodeSimd(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeSimd(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
Rd = (OpCode >> 0) & 0x1f;
Rn = (OpCode >> 5) & 0x1f;

View file

@ -8,7 +8,7 @@ namespace ChocolArm64.Decoder
public long Imm { get; private set; }
public int Size { get; private set; }
public AOpCodeSimdFmov(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeSimdFmov(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
int Imm5 = (OpCode >> 5) & 0x1f;
int Type = (OpCode >> 22) & 0x3;

View file

@ -9,7 +9,7 @@ namespace ChocolArm64.Decoder
public long Imm { get; private set; }
public int Size { get; private set; }
public AOpCodeSimdImm(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeSimdImm(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
Rd = OpCode & 0x1f;

View file

@ -10,7 +10,7 @@ namespace ChocolArm64.Decoder
public bool Signed => false;
public bool Prefetch => false;
public AOpCodeSimdMemLit(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeSimdMemLit(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
int Opc = (OpCode >> 30) & 3;

View file

@ -14,7 +14,7 @@ namespace ChocolArm64.Decoder
public int Elems { get; private set; }
public bool WBack { get; private set; }
public AOpCodeSimdMemMs(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeSimdMemMs(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
switch ((OpCode >> 12) & 0xf)
{

View file

@ -14,7 +14,7 @@ namespace ChocolArm64.Decoder
public bool Replicate { get; private set; }
public bool WBack { get; private set; }
public AOpCodeSimdMemSs(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeSimdMemSs(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
int Size = (OpCode >> 10) & 3;
int S = (OpCode >> 12) & 1;

View file

@ -11,7 +11,7 @@ namespace ChocolArm64.Decoder
public int Op1 { get; private set; }
public int Op0 { get; private set; }
public AOpCodeSystem(AInst Inst, long Position, int OpCode) : base(Inst, Position)
public AOpCodeSystem(AInst Inst, long Position, int OpCode) : base(Inst, Position, OpCode)
{
Rt = (OpCode >> 0) & 0x1f;
Op2 = (OpCode >> 5) & 0x7;

View file

@ -5,7 +5,7 @@ namespace ChocolArm64.Exceptions
{
public class VmmAccessViolationException : Exception
{
private const string ExMsg = "Value at address 0x{0:x16} could not be \"{1}\"!";
private const string ExMsg = "Address 0x{0:x16} does not have \"{1}\" permission!";
public VmmAccessViolationException() { }

View file

@ -7,7 +7,17 @@ namespace ChocolArm64.Instruction
{
static partial class AInstEmit
{
public static void Brk(AILEmitterCtx Context)
{
EmitExceptionCall(Context, nameof(ARegisters.OnBreak));
}
public static void Svc(AILEmitterCtx Context)
{
EmitExceptionCall(Context, nameof(ARegisters.OnSvcCall));
}
private static void EmitExceptionCall(AILEmitterCtx Context, string MthdName)
{
AOpCodeException Op = (AOpCodeException)Context.CurrOp;
@ -17,7 +27,7 @@ namespace ChocolArm64.Instruction
Context.EmitLdc_I4(Op.Id);
Context.EmitCall(typeof(ARegisters), nameof(ARegisters.OnSvcCall));
Context.EmitCall(typeof(ARegisters), MthdName);
if (Context.CurrBlock.Next != null)
{
@ -27,7 +37,21 @@ namespace ChocolArm64.Instruction
public static void Und(AILEmitterCtx Context)
{
throw new NotImplementedException($"Undefined instruction at {Context.CurrOp.Position:x16}");
AOpCode Op = Context.CurrOp;
Context.EmitStoreState();
Context.EmitLdarg(ATranslatedSub.RegistersArgIdx);
Context.EmitLdc_I8(Op.Position);
Context.EmitLdc_I4(Op.RawOpCode);
Context.EmitCall(typeof(ARegisters), nameof(ARegisters.OnUndefined));
if (Context.CurrBlock.Next != null)
{
Context.EmitLoadState(Context.CurrBlock.Next);
}
}
}
}

View file

@ -5,14 +5,16 @@ namespace ChocolArm64.Memory
public long Position { get; private set; }
public long Size { get; private set; }
public int Type { get; private set; }
public int Attr { get; private set; }
public AMemoryPerm Perm { get; private set; }
public AMemoryMapInfo(long Position, long Size, int Type, AMemoryPerm Perm)
public AMemoryMapInfo(long Position, long Size, int Type, int Attr, AMemoryPerm Perm)
{
this.Position = Position;
this.Size = Size;
this.Type = Type;
this.Attr = Attr;
this.Perm = Perm;
}
}

View file

@ -1,5 +1,3 @@
using System.Runtime.CompilerServices;
namespace ChocolArm64.Memory
{
public class AMemoryMgr
@ -27,24 +25,23 @@ namespace ChocolArm64.Memory
private enum PTMap
{
Unmapped,
Physical,
Mirror
Mapped
}
private struct PTEntry
{
public long Position;
public int Type;
public PTMap Map;
public AMemoryPerm Perm;
public PTEntry(long Position, int Type, PTMap Map, AMemoryPerm Perm)
public int Type;
public int Attr;
public PTEntry(PTMap Map, AMemoryPerm Perm, int Type, int Attr)
{
this.Position = Position;
this.Type = Type;
this.Map = Map;
this.Perm = Perm;
this.Type = Type;
this.Attr = Attr;
}
}
@ -53,7 +50,7 @@ namespace ChocolArm64.Memory
private bool IsHeapInitialized;
public long HeapAddr { get; private set; }
public int HeapSize { get; private set; }
public long HeapSize { get; private set; }
public AMemoryMgr(AMemoryAlloc Allocator)
{
@ -101,10 +98,10 @@ namespace ChocolArm64.Memory
return false;
}
public void SetHeapSize(int Size, int Type)
public void SetHeapSize(long Size, int Type)
{
//TODO: Return error when theres no enough space to allocate heap.
Size = (int)AMemoryHelper.PageRoundUp(Size);
Size = AMemoryHelper.PageRoundUp(Size);
long Position = HeapAddr;
@ -132,40 +129,13 @@ namespace ChocolArm64.Memory
HeapSize = Size;
}
public bool MapPhys(long Src, long Dst, long Size, int Type, AMemoryPerm Perm)
{
Src = AMemoryHelper.PageRoundDown(Src);
Dst = AMemoryHelper.PageRoundDown(Dst);
Size = AMemoryHelper.PageRoundUp(Size);
if (Dst < 0 || Dst + Size >= RamSize)
{
return false;
}
long PagesCount = Size / PageSize;
while (PagesCount-- > 0)
{
SetPTEntry(Src, new PTEntry(Dst, Type, PTMap.Physical, Perm));
Src += PageSize;
Dst += PageSize;
}
return true;
}
public void MapPhys(long Position, long Size, int Type, AMemoryPerm Perm)
{
while (Size > 0)
{
if (!IsMapped(Position))
{
long PhysPos = Allocator.Alloc(PageSize);
SetPTEntry(Position, new PTEntry(PhysPos, Type, PTMap.Physical, Perm));
SetPTEntry(Position, new PTEntry(PTMap.Mapped, Perm, Type, 0));
}
long CPgSize = PageSize - (Position & PageMask);
@ -186,13 +156,19 @@ namespace ChocolArm64.Memory
while (PagesCount-- > 0)
{
PTEntry Entry = GetPTEntry(Src);
PTEntry SrcEntry = GetPTEntry(Src);
PTEntry DstEntry = GetPTEntry(Dst);
Entry.Type = Type;
Entry.Map = PTMap.Mirror;
Entry.Position = Dst;
DstEntry.Map = PTMap.Mapped;
DstEntry.Type = Type;
DstEntry.Perm = SrcEntry.Perm;
SetPTEntry(Src, Entry);
SrcEntry.Perm = AMemoryPerm.None;
SrcEntry.Attr |= 1;
SetPTEntry(Src, SrcEntry);
SetPTEntry(Dst, DstEntry);
Src += PageSize;
Dst += PageSize;
@ -229,9 +205,10 @@ namespace ChocolArm64.Memory
{
PTEntry Entry = GetPTEntry(Pos);
return Entry.Type == BaseEntry.Type &&
Entry.Map == BaseEntry.Map &&
Entry.Perm == BaseEntry.Perm;
return Entry.Map == BaseEntry.Map &&
Entry.Perm == BaseEntry.Perm &&
Entry.Type == BaseEntry.Type &&
Entry.Attr == BaseEntry.Attr;
}
long Start = Position;
@ -249,7 +226,12 @@ namespace ChocolArm64.Memory
long Size = End - Start;
return new AMemoryMapInfo(Start, Size, BaseEntry.Type, BaseEntry.Perm);
return new AMemoryMapInfo(
Start,
Size,
BaseEntry.Type,
BaseEntry.Attr,
BaseEntry.Perm);
}
public bool HasPermission(long Position, AMemoryPerm Perm)
@ -257,7 +239,6 @@ namespace ChocolArm64.Memory
return GetPTEntry(Position).Perm.HasFlag(Perm);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsMapped(long Position)
{
if (Position >> PTLvl0Bits + PTLvl1Bits + PTPageBits != 0)
@ -276,7 +257,6 @@ namespace ChocolArm64.Memory
return PageTable[L0][L1].Map != PTMap.Unmapped;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private PTEntry GetPTEntry(long Position)
{
long L0 = (Position >> PTLvl0Bit) & PTLvl0Mask;
@ -290,7 +270,6 @@ namespace ChocolArm64.Memory
return PageTable[L0][L1];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetPTEntry(long Position, PTEntry Entry)
{
long L0 = (Position >> PTLvl0Bit) & PTLvl0Mask;

View file

@ -2,11 +2,11 @@ using System;
namespace ChocolArm64.State
{
public class SvcEventArgs : EventArgs
public class AInstExceptEventArgs : EventArgs
{
public int Id { get; private set; }
public SvcEventArgs(int Id)
public AInstExceptEventArgs(int Id)
{
this.Id = Id;
}

View file

@ -0,0 +1,16 @@
using System;
namespace ChocolArm64.State
{
public class AInstUndEventArgs : EventArgs
{
public long Position { get; private set; }
public int RawOpCode { get; private set; }
public AInstUndEventArgs(long Position, int RawOpCode)
{
this.Position = Position;
this.RawOpCode = RawOpCode;
}
}
}

View file

@ -42,17 +42,23 @@ namespace ChocolArm64.State
public long CntpctEl0 => Environment.TickCount * TicksPerMS;
public event EventHandler<SvcEventArgs> SvcCall;
public event EventHandler<EventArgs> Undefined;
public event EventHandler<AInstExceptEventArgs> Break;
public event EventHandler<AInstExceptEventArgs> SvcCall;
public event EventHandler<AInstUndEventArgs> Undefined;
public void OnBreak(int Imm)
{
Break?.Invoke(this, new AInstExceptEventArgs(Imm));
}
public void OnSvcCall(int Imm)
{
SvcCall?.Invoke(this, new SvcEventArgs(Imm));
SvcCall?.Invoke(this, new AInstExceptEventArgs(Imm));
}
public void OnUndefined()
public void OnUndefined(long Position, int RawOpCode)
{
Undefined?.Invoke(this, EventArgs.Empty);
Undefined?.Invoke(this, new AInstUndEventArgs(Position, RawOpCode));
}
}
}

View file

@ -1,5 +1,3 @@
using System.Runtime.CompilerServices;
namespace Ryujinx.Gpu
{
class NsGpuMemoryMgr
@ -107,6 +105,11 @@ namespace Ryujinx.Gpu
long Position = 0;
long FreeSize = 0;
if (Align < 1)
{
Align = 1;
}
Align = (Align + PageMask) & ~PageMask;
while (Position + FreeSize < AddrSize)
@ -149,7 +152,6 @@ namespace Ryujinx.Gpu
return BasePos + (Position & PageMask);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool HasPTAddr(long Position)
{
if (Position >> PTLvl0Bits + PTLvl1Bits + PTPageBits != 0)
@ -168,7 +170,6 @@ namespace Ryujinx.Gpu
return PageTable[L0][L1] != PteUnmapped;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private long GetPTAddr(long Position)
{
long L0 = (Position >> PTLvl0Bit) & PTLvl0Mask;
@ -182,7 +183,6 @@ namespace Ryujinx.Gpu
return PageTable[L0][L1];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetPTAddr(long Position, long TgtAddr)
{
long L0 = (Position >> PTLvl0Bit) & PTLvl0Mask;

View file

@ -0,0 +1,11 @@
using System;
namespace Ryujinx.OsHle.Exceptions
{
public class GuestBrokeExecutionException : Exception
{
private const string ExMsg = "The guest program broke execution!";
public GuestBrokeExecutionException() : base(ExMsg) { }
}
}

View file

@ -0,0 +1,13 @@
using System;
namespace Ryujinx.OsHle.Exceptions
{
public class UndefinedInstructionException : Exception
{
private const string ExMsg = "The instruction at 0x{0:x16} (opcode 0x{1:x8}) is undefined!";
public UndefinedInstructionException() : base() { }
public UndefinedInstructionException(long Position, int OpCode) : base(string.Format(ExMsg, Position, OpCode)) { }
}
}

View file

@ -10,8 +10,6 @@ namespace Ryujinx.OsHle.Ipc
{
static class IpcHandler
{
private delegate long ServiceProcessRequest(ServiceCtx Context);
private static Dictionary<(string, int), ServiceProcessRequest> ServiceCmds =
new Dictionary<(string, int), ServiceProcessRequest>()
{
@ -71,122 +69,10 @@ namespace Ryujinx.OsHle.Ipc
{ ( "vi:m", 2), Service.ViGetDisplayService },
};
private static Dictionary<(Type, int), ServiceProcessRequest> ObjectCmds =
new Dictionary<(Type, int), ServiceProcessRequest>()
{
//IManagerForApplication
{ (typeof(AccIManagerForApplication), 0), AccIManagerForApplication.CheckAvailability },
{ (typeof(AccIManagerForApplication), 1), AccIManagerForApplication.GetAccountId },
//IProfile
{ (typeof(AccIProfile), 1), AccIProfile.GetBase },
//IApplicationFunctions
{ (typeof(AmIApplicationFunctions), 1), AmIApplicationFunctions.PopLaunchParameter },
{ (typeof(AmIApplicationFunctions), 20), AmIApplicationFunctions.EnsureSaveData },
{ (typeof(AmIApplicationFunctions), 21), AmIApplicationFunctions.GetDesiredLanguage },
{ (typeof(AmIApplicationFunctions), 40), AmIApplicationFunctions.NotifyRunning },
//IApplicationProxy
{ (typeof(AmIApplicationProxy), 0), AmIApplicationProxy.GetCommonStateGetter },
{ (typeof(AmIApplicationProxy), 1), AmIApplicationProxy.GetSelfController },
{ (typeof(AmIApplicationProxy), 2), AmIApplicationProxy.GetWindowController },
{ (typeof(AmIApplicationProxy), 3), AmIApplicationProxy.GetAudioController },
{ (typeof(AmIApplicationProxy), 4), AmIApplicationProxy.GetDisplayController },
{ (typeof(AmIApplicationProxy), 11), AmIApplicationProxy.GetLibraryAppletCreator },
{ (typeof(AmIApplicationProxy), 20), AmIApplicationProxy.GetApplicationFunctions },
{ (typeof(AmIApplicationProxy), 1000), AmIApplicationProxy.GetDebugFunctions },
//ICommonStateGetter
{ (typeof(AmICommonStateGetter), 0), AmICommonStateGetter.GetEventHandle },
{ (typeof(AmICommonStateGetter), 1), AmICommonStateGetter.ReceiveMessage },
{ (typeof(AmICommonStateGetter), 5), AmICommonStateGetter.GetOperationMode },
{ (typeof(AmICommonStateGetter), 6), AmICommonStateGetter.GetPerformanceMode },
{ (typeof(AmICommonStateGetter), 9), AmICommonStateGetter.GetCurrentFocusState },
//ISelfController
{ (typeof(AmISelfController), 11), AmISelfController.SetOperationModeChangedNotification },
{ (typeof(AmISelfController), 12), AmISelfController.SetPerformanceModeChangedNotification },
{ (typeof(AmISelfController), 13), AmISelfController.SetFocusHandlingMode },
{ (typeof(AmISelfController), 16), AmISelfController.SetOutOfFocusSuspendingEnabled },
//IStorage
{ (typeof(AmIStorage), 0), AmIStorage.Open },
//IStorageAccessor
{ (typeof(AmIStorageAccessor), 0), AmIStorageAccessor.GetSize },
{ (typeof(AmIStorageAccessor), 11), AmIStorageAccessor.Read },
//IWindowController
{ (typeof(AmIWindowController), 1), AmIWindowController.GetAppletResourceUserId },
{ (typeof(AmIWindowController), 10), AmIWindowController.AcquireForegroundRights },
//ISession
{ (typeof(ApmISession), 0), ApmISession.SetPerformanceConfiguration },
//IAudioRenderer
{ (typeof(AudIAudioRenderer), 4), AudIAudioRenderer.RequestUpdateAudioRenderer },
{ (typeof(AudIAudioRenderer), 5), AudIAudioRenderer.StartAudioRenderer },
{ (typeof(AudIAudioRenderer), 6), AudIAudioRenderer.StopAudioRenderer },
{ (typeof(AudIAudioRenderer), 7), AudIAudioRenderer.QuerySystemEvent },
//IAudioOut
{ (typeof(AudIAudioOut), 0), AudIAudioOut.GetAudioOutState },
{ (typeof(AudIAudioOut), 1), AudIAudioOut.StartAudioOut },
{ (typeof(AudIAudioOut), 2), AudIAudioOut.StopAudioOut },
{ (typeof(AudIAudioOut), 3), AudIAudioOut.AppendAudioOutBuffer },
{ (typeof(AudIAudioOut), 4), AudIAudioOut.RegisterBufferEvent },
{ (typeof(AudIAudioOut), 5), AudIAudioOut.GetReleasedAudioOutBuffer },
{ (typeof(AudIAudioOut), 6), AudIAudioOut.ContainsAudioOutBuffer },
{ (typeof(AudIAudioOut), 7), AudIAudioOut.AppendAudioOutBuffer_ex },
{ (typeof(AudIAudioOut), 8), AudIAudioOut.GetReleasedAudioOutBuffer_ex },
//IFile
{ (typeof(FspSrvIFile), 0), FspSrvIFile.Read },
{ (typeof(FspSrvIFile), 1), FspSrvIFile.Write },
//IFileSystem
{ (typeof(FspSrvIFileSystem), 7), FspSrvIFileSystem.GetEntryType },
{ (typeof(FspSrvIFileSystem), 8), FspSrvIFileSystem.OpenFile },
{ (typeof(FspSrvIFileSystem), 10), FspSrvIFileSystem.Commit },
//IStorage
{ (typeof(FspSrvIStorage), 0), FspSrvIStorage.Read },
//IAppletResource
{ (typeof(HidIAppletResource), 0), HidIAppletResource.GetSharedMemoryHandle },
//ISystemClock
{ (typeof(TimeISystemClock), 0), TimeISystemClock.GetCurrentTime },
//IApplicationDisplayService
{ (typeof(ViIApplicationDisplayService), 100), ViIApplicationDisplayService.GetRelayService },
{ (typeof(ViIApplicationDisplayService), 101), ViIApplicationDisplayService.GetSystemDisplayService },
{ (typeof(ViIApplicationDisplayService), 102), ViIApplicationDisplayService.GetManagerDisplayService },
{ (typeof(ViIApplicationDisplayService), 103), ViIApplicationDisplayService.GetIndirectDisplayTransactionService },
{ (typeof(ViIApplicationDisplayService), 1010), ViIApplicationDisplayService.OpenDisplay },
{ (typeof(ViIApplicationDisplayService), 2020), ViIApplicationDisplayService.OpenLayer },
{ (typeof(ViIApplicationDisplayService), 2030), ViIApplicationDisplayService.CreateStrayLayer },
{ (typeof(ViIApplicationDisplayService), 2101), ViIApplicationDisplayService.SetLayerScalingMode },
{ (typeof(ViIApplicationDisplayService), 5202), ViIApplicationDisplayService.GetDisplayVSyncEvent },
//IHOSBinderDriver
{ (typeof(ViIHOSBinderDriver), 0), ViIHOSBinderDriver.TransactParcel },
{ (typeof(ViIHOSBinderDriver), 1), ViIHOSBinderDriver.AdjustRefcount },
{ (typeof(ViIHOSBinderDriver), 2), ViIHOSBinderDriver.GetNativeHandle },
//IManagerDisplayService
{ (typeof(ViIManagerDisplayService), 2010), ViIManagerDisplayService.CreateManagedLayer },
{ (typeof(ViIManagerDisplayService), 6000), ViIManagerDisplayService.AddToLayerStack },
//ISystemDisplayService
{ (typeof(ViISystemDisplayService), 2205), ViISystemDisplayService.SetLayerZ },
};
private const long SfciMagic = 'S' << 0 | 'F' << 8 | 'C' << 16 | 'I' << 24;
private const long SfcoMagic = 'S' << 0 | 'F' << 8 | 'C' << 16 | 'O' << 24;
public static void ProcessRequest(
public static void IpcCall(
Switch Ns,
AMemory Memory,
HSession Session,
@ -221,15 +107,15 @@ namespace Ryujinx.OsHle.Ipc
if (Obj is HDomain)
{
DbgServiceName = $"{ServiceName} {CmdId}";
ServiceCmds.TryGetValue((ServiceName, CmdId), out ProcReq);
DbgServiceName = $"{ServiceName} {ProcReq?.Method.Name ?? CmdId.ToString()}";
}
else if (Obj != null)
{
DbgServiceName = $"{ServiceName} {Obj.GetType().Name} {CmdId}";
((IIpcInterface)Obj).Commands.TryGetValue(CmdId, out ProcReq);
ObjectCmds.TryGetValue((Obj.GetType(), CmdId), out ProcReq);
DbgServiceName = $"{ServiceName} {Obj.GetType().Name} {ProcReq?.Method.Name ?? CmdId.ToString()}";
}
}
else if (Request.DomCmd == IpcDomCmd.DeleteObj)
@ -250,15 +136,15 @@ namespace Ryujinx.OsHle.Ipc
{
object Obj = ((HSessionObj)Session).Obj;
DbgServiceName = $"{ServiceName} {Obj.GetType().Name} {CmdId}";
((IIpcInterface)Obj).Commands.TryGetValue(CmdId, out ProcReq);
ObjectCmds.TryGetValue((Obj.GetType(), CmdId), out ProcReq);
DbgServiceName = $"{ServiceName} {Obj.GetType().Name} {ProcReq?.Method.Name ?? CmdId.ToString()}";
}
else
{
DbgServiceName = $"{ServiceName} {CmdId}";
ServiceCmds.TryGetValue((ServiceName, CmdId), out ProcReq);
DbgServiceName = $"{ServiceName} {ProcReq?.Method.Name ?? CmdId.ToString()}";
}
}

View file

@ -0,0 +1,4 @@
namespace Ryujinx.OsHle.Ipc
{
delegate long ServiceProcessRequest(ServiceCtx Context);
}

View file

@ -18,7 +18,7 @@ namespace Ryujinx.OsHle
BaseAddress = MapInfo.Position;
Size = MapInfo.Size;
MemType = MapInfo.Type;
MemAttr = 0;
MemAttr = MapInfo.Attr;
MemPerm = (int)MapInfo.Perm;
IpcRefCount = 0;
DeviceRefCount = 0;

View file

@ -0,0 +1,33 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Acc
{
class IManagerForApplication : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public IManagerForApplication()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, CheckAvailability },
{ 1, GetAccountId }
};
}
public long CheckAvailability(ServiceCtx Context)
{
return 0;
}
public long GetAccountId(ServiceCtx Context)
{
Context.ResponseData.Write(0xcafeL);
return 0;
}
}
}

View file

@ -0,0 +1,33 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Acc
{
class IProfile : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public IProfile()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 1, GetBase }
};
}
public long GetBase(ServiceCtx Context)
{
Context.ResponseData.Write(0L);
Context.ResponseData.Write(0L);
Context.ResponseData.Write(0L);
Context.ResponseData.Write(0L);
Context.ResponseData.Write(0L);
Context.ResponseData.Write(0L);
Context.ResponseData.Write(0L);
return 0;
}
}
}

View file

@ -1,17 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class AccIManagerForApplication
{
public static long CheckAvailability(ServiceCtx Context)
{
return 0;
}
public static long GetAccountId(ServiceCtx Context)
{
Context.ResponseData.Write(0xcafeL);
return 0;
}
}
}

View file

@ -1,18 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class AccIProfile
{
public static long GetBase(ServiceCtx Context)
{
Context.ResponseData.Write(0L);
Context.ResponseData.Write(0L);
Context.ResponseData.Write(0L);
Context.ResponseData.Write(0L);
Context.ResponseData.Write(0L);
Context.ResponseData.Write(0L);
Context.ResponseData.Write(0L);
return 0;
}
}
}

View file

@ -1,22 +1,39 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
using System.IO;
using static Ryujinx.OsHle.Objects.ObjHelper;
namespace Ryujinx.OsHle.Objects
namespace Ryujinx.OsHle.Objects.Am
{
class AmIApplicationFunctions
class IApplicationFunctions : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public IApplicationFunctions()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 1, PopLaunchParameter },
{ 20, EnsureSaveData },
{ 21, GetDesiredLanguage },
{ 40, NotifyRunning }
};
}
private const uint LaunchParamsMagic = 0xc79497ca;
public static long PopLaunchParameter(ServiceCtx Context)
public long PopLaunchParameter(ServiceCtx Context)
{
//Only the first 0x18 bytes of the Data seems to be actually used.
MakeObject(Context, new AmIStorage(MakeLaunchParams()));
MakeObject(Context, new IStorage(MakeLaunchParams()));
return 0;
}
public static long EnsureSaveData(ServiceCtx Context)
public long EnsureSaveData(ServiceCtx Context)
{
long UIdLow = Context.RequestData.ReadInt64();
long UIdHigh = Context.RequestData.ReadInt64();
@ -26,7 +43,7 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long GetDesiredLanguage(ServiceCtx Context)
public long GetDesiredLanguage(ServiceCtx Context)
{
//This is an enumerator where each number is a differnet language.
//0 is Japanese and 1 is English, need to figure out the other codes.
@ -35,14 +52,14 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long NotifyRunning(ServiceCtx Context)
public long NotifyRunning(ServiceCtx Context)
{
Context.ResponseData.Write(1);
return 0;
}
private static byte[] MakeLaunchParams()
private byte[] MakeLaunchParams()
{
//Size needs to be at least 0x88 bytes otherwise application errors.
using (MemoryStream MS = new MemoryStream())

View file

@ -0,0 +1,85 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
using static Ryujinx.OsHle.Objects.ObjHelper;
namespace Ryujinx.OsHle.Objects.Am
{
class IApplicationProxy : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public IApplicationProxy()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, GetCommonStateGetter },
{ 1, GetSelfController },
{ 2, GetWindowController },
{ 3, GetAudioController },
{ 4, GetDisplayController },
{ 11, GetLibraryAppletCreator },
{ 20, GetApplicationFunctions },
{ 1000, GetDebugFunctions }
};
}
public long GetCommonStateGetter(ServiceCtx Context)
{
MakeObject(Context, new ICommonStateGetter());
return 0;
}
public long GetSelfController(ServiceCtx Context)
{
MakeObject(Context, new ISelfController());
return 0;
}
public long GetWindowController(ServiceCtx Context)
{
MakeObject(Context, new IWindowController());
return 0;
}
public long GetAudioController(ServiceCtx Context)
{
MakeObject(Context, new IAudioController());
return 0;
}
public long GetDisplayController(ServiceCtx Context)
{
MakeObject(Context, new IDisplayController());
return 0;
}
public long GetLibraryAppletCreator(ServiceCtx Context)
{
MakeObject(Context, new ILibraryAppletCreator());
return 0;
}
public long GetApplicationFunctions(ServiceCtx Context)
{
MakeObject(Context, new IApplicationFunctions());
return 0;
}
public long GetDebugFunctions(ServiceCtx Context)
{
MakeObject(Context, new IDebugFunctions());
return 0;
}
}
}

View file

@ -0,0 +1,20 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Am
{
class IAudioController : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public IAudioController()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
//...
};
}
}
}

View file

@ -0,0 +1,74 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Am
{
class ICommonStateGetter : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public ICommonStateGetter()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, GetEventHandle },
{ 1, ReceiveMessage },
{ 5, GetOperationMode },
{ 6, GetPerformanceMode },
{ 9, GetCurrentFocusState },
};
}
private enum FocusState
{
InFocus = 1,
OutOfFocus = 2
}
private enum OperationMode
{
Handheld = 0,
Docked = 1
}
public long GetEventHandle(ServiceCtx Context)
{
Context.ResponseData.Write(0L);
return 0;
}
public long ReceiveMessage(ServiceCtx Context)
{
//Program expects 0xF at 0x17ae70 on puyo sdk,
//otherwise runs on a infinite loop until it reads said value.
//What it means is still unknown.
Context.ResponseData.Write(0xfL);
return 0; //0x680;
}
public long GetOperationMode(ServiceCtx Context)
{
Context.ResponseData.Write((byte)OperationMode.Handheld);
return 0;
}
public long GetPerformanceMode(ServiceCtx Context)
{
Context.ResponseData.Write((byte)0);
return 0;
}
public long GetCurrentFocusState(ServiceCtx Context)
{
Context.ResponseData.Write((byte)FocusState.InFocus);
return 0;
}
}
}

View file

@ -0,0 +1,20 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Am
{
class IDebugFunctions : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public IDebugFunctions()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
//...
};
}
}
}

View file

@ -0,0 +1,20 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Am
{
class IDisplayController : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public IDisplayController()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
//...
};
}
}
}

View file

@ -0,0 +1,20 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Am
{
class ILibraryAppletCreator : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public ILibraryAppletCreator()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
//...
};
}
}
}

View file

@ -0,0 +1,20 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Am
{
class IParentalControlService : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public IParentalControlService()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
//...
};
}
}
}

View file

@ -0,0 +1,53 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Am
{
class ISelfController : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public ISelfController()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 11, SetOperationModeChangedNotification },
{ 12, SetPerformanceModeChangedNotification },
{ 13, SetFocusHandlingMode },
{ 16, SetOutOfFocusSuspendingEnabled }
};
}
public long SetOperationModeChangedNotification(ServiceCtx Context)
{
bool Enable = Context.RequestData.ReadByte() != 0 ? true : false;
return 0;
}
public long SetPerformanceModeChangedNotification(ServiceCtx Context)
{
bool Enable = Context.RequestData.ReadByte() != 0 ? true : false;
return 0;
}
public long SetFocusHandlingMode(ServiceCtx Context)
{
bool Flag1 = Context.RequestData.ReadByte() != 0 ? true : false;
bool Flag2 = Context.RequestData.ReadByte() != 0 ? true : false;
bool Flag3 = Context.RequestData.ReadByte() != 0 ? true : false;
return 0;
}
public long SetOutOfFocusSuspendingEnabled(ServiceCtx Context)
{
bool Enable = Context.RequestData.ReadByte() != 0 ? true : false;
return 0;
}
}
}

View file

@ -0,0 +1,33 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
using static Ryujinx.OsHle.Objects.ObjHelper;
namespace Ryujinx.OsHle.Objects.Am
{
class IStorage : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public byte[] Data { get; private set; }
public IStorage(byte[] Data)
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, Open }
};
this.Data = Data;
}
public long Open(ServiceCtx Context)
{
MakeObject(Context, new IStorageAccessor(this));
return 0;
}
}
}

View file

@ -1,32 +1,38 @@
using ChocolArm64.Memory;
using Ryujinx.OsHle.Ipc;
using System;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects
namespace Ryujinx.OsHle.Objects.Am
{
class AmIStorageAccessor
class IStorageAccessor : IIpcInterface
{
public AmIStorage Storage { get; private set; }
private Dictionary<int, ServiceProcessRequest> m_Commands;
public AmIStorageAccessor(AmIStorage Storage)
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
private IStorage Storage;
public IStorageAccessor(IStorage Storage)
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, GetSize },
{ 11, Read }
};
this.Storage = Storage;
}
public static long GetSize(ServiceCtx Context)
public long GetSize(ServiceCtx Context)
{
AmIStorageAccessor Accessor = Context.GetObject<AmIStorageAccessor>();
Context.ResponseData.Write((long)Accessor.Storage.Data.Length);
Context.ResponseData.Write((long)Storage.Data.Length);
return 0;
}
public static long Read(ServiceCtx Context)
public long Read(ServiceCtx Context)
{
AmIStorageAccessor Accessor = Context.GetObject<AmIStorageAccessor>();
AmIStorage Storage = Accessor.Storage;
long ReadPosition = Context.RequestData.ReadInt64();
if (Context.Request.RecvListBuff.Count > 0)

View file

@ -0,0 +1,33 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Am
{
class IWindowController : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public IWindowController()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 1, GetAppletResourceUserId },
{ 10, AcquireForegroundRights }
};
}
public long GetAppletResourceUserId(ServiceCtx Context)
{
Context.ResponseData.Write(0L);
return 0;
}
public long AcquireForegroundRights(ServiceCtx Context)
{
return 0;
}
}
}

View file

@ -1,63 +0,0 @@
using static Ryujinx.OsHle.Objects.ObjHelper;
namespace Ryujinx.OsHle.Objects
{
class AmIApplicationProxy
{
public static long GetCommonStateGetter(ServiceCtx Context)
{
MakeObject(Context, new AmICommonStateGetter());
return 0;
}
public static long GetSelfController(ServiceCtx Context)
{
MakeObject(Context, new AmISelfController());
return 0;
}
public static long GetWindowController(ServiceCtx Context)
{
MakeObject(Context, new AmIWindowController());
return 0;
}
public static long GetAudioController(ServiceCtx Context)
{
MakeObject(Context, new AmIAudioController());
return 0;
}
public static long GetDisplayController(ServiceCtx Context)
{
MakeObject(Context, new AmIDisplayController());
return 0;
}
public static long GetLibraryAppletCreator(ServiceCtx Context)
{
MakeObject(Context, new AmILibraryAppletCreator());
return 0;
}
public static long GetApplicationFunctions(ServiceCtx Context)
{
MakeObject(Context, new AmIApplicationFunctions());
return 0;
}
public static long GetDebugFunctions(ServiceCtx Context)
{
MakeObject(Context, new AmIDebugFunctions());
return 0;
}
}
}

View file

@ -1,7 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class AmIAudioController
{
}
}

View file

@ -1,55 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class AmICommonStateGetter
{
private enum FocusState
{
InFocus = 1,
OutOfFocus = 2
}
private enum OperationMode
{
Handheld = 0,
Docked = 1
}
public static long GetEventHandle(ServiceCtx Context)
{
Context.ResponseData.Write(0L);
return 0;
}
public static long ReceiveMessage(ServiceCtx Context)
{
//Program expects 0xF at 0x17ae70 on puyo sdk,
//otherwise runs on a infinite loop until it reads said value.
//What it means is still unknown.
Context.ResponseData.Write(0xfL);
return 0; //0x680;
}
public static long GetOperationMode(ServiceCtx Context)
{
Context.ResponseData.Write((byte)OperationMode.Handheld);
return 0;
}
public static long GetPerformanceMode(ServiceCtx Context)
{
Context.ResponseData.Write((byte)0);
return 0;
}
public static long GetCurrentFocusState(ServiceCtx Context)
{
Context.ResponseData.Write((byte)FocusState.InFocus);
return 0;
}
}
}

View file

@ -1,7 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class AmIDebugFunctions
{
}
}

View file

@ -1,7 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class AmIDisplayController
{
}
}

View file

@ -1,7 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class AmILibraryAppletCreator
{
}
}

View file

@ -1,7 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class AmIParentalControlService
{
}
}

View file

@ -1,35 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class AmISelfController
{
public static long SetOperationModeChangedNotification(ServiceCtx Context)
{
bool Enable = Context.RequestData.ReadByte() != 0 ? true : false;
return 0;
}
public static long SetPerformanceModeChangedNotification(ServiceCtx Context)
{
bool Enable = Context.RequestData.ReadByte() != 0 ? true : false;
return 0;
}
public static long SetFocusHandlingMode(ServiceCtx Context)
{
bool Flag1 = Context.RequestData.ReadByte() != 0 ? true : false;
bool Flag2 = Context.RequestData.ReadByte() != 0 ? true : false;
bool Flag3 = Context.RequestData.ReadByte() != 0 ? true : false;
return 0;
}
public static long SetOutOfFocusSuspendingEnabled(ServiceCtx Context)
{
bool Enable = Context.RequestData.ReadByte() != 0 ? true : false;
return 0;
}
}
}

View file

@ -1,23 +0,0 @@
using static Ryujinx.OsHle.Objects.ObjHelper;
namespace Ryujinx.OsHle.Objects
{
class AmIStorage
{
public byte[] Data { get; private set; }
public AmIStorage(byte[] Data)
{
this.Data = Data;
}
public static long Open(ServiceCtx Context)
{
AmIStorage Storage = Context.GetObject<AmIStorage>();
MakeObject(Context, new AmIStorageAccessor(Storage));
return 0;
}
}
}

View file

@ -1,17 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class AmIWindowController
{
public static long GetAppletResourceUserId(ServiceCtx Context)
{
Context.ResponseData.Write(0L);
return 0;
}
public static long AcquireForegroundRights(ServiceCtx Context)
{
return 0;
}
}
}

View file

@ -0,0 +1,28 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Apm
{
class ISession : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public ISession()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, SetPerformanceConfiguration }
};
}
public long SetPerformanceConfiguration(ServiceCtx Context)
{
int PerfMode = Context.RequestData.ReadInt32();
int PerfConfig = Context.RequestData.ReadInt32();
return 0;
}
}
}

View file

@ -1,13 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class ApmISession
{
public static long SetPerformanceConfiguration(ServiceCtx Context)
{
int PerfMode = Context.RequestData.ReadInt32();
int PerfConfig = Context.RequestData.ReadInt32();
return 0;
}
}
}

View file

@ -1,16 +1,36 @@
using ChocolArm64.Memory;
using OpenTK.Audio;
using OpenTK.Audio.OpenAL;
using Ryujinx.OsHle.Handles;
using Ryujinx.OsHle.Ipc;
using OpenTK.Audio;
using OpenTK.Audio.OpenAL;
using System;
using System.Collections.Generic;
using System.IO;
namespace Ryujinx.OsHle.Objects
namespace Ryujinx.OsHle.Objects.Aud
{
class AudIAudioOut
class IAudioOut : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public IAudioOut()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, GetAudioOutState },
{ 1, StartAudioOut },
{ 2, StopAudioOut },
{ 3, AppendAudioOutBuffer },
{ 4, RegisterBufferEvent },
{ 5, GetReleasedAudioOutBuffer },
{ 6, ContainsAudioOutBuffer },
{ 7, AppendAudioOutBuffer_ex },
{ 8, GetReleasedAudioOutBuffer_ex }
};
}
enum AudioOutState
{
Started,
@ -18,24 +38,24 @@ namespace Ryujinx.OsHle.Objects
};
//IAudioOut
private static AudioOutState State = AudioOutState.Stopped;
private static Queue<long> KeysQueue = new Queue<long>();
private AudioOutState State = AudioOutState.Stopped;
private Queue<long> KeysQueue = new Queue<long>();
//OpenAL
private static bool OpenALInstalled = true;
private static AudioContext AudioCtx;
private static int Source;
private static int Buffer;
private bool OpenALInstalled = true;
private AudioContext AudioCtx;
private int Source;
private int Buffer;
//Return State of IAudioOut
public static long GetAudioOutState(ServiceCtx Context)
public long GetAudioOutState(ServiceCtx Context)
{
Context.ResponseData.Write((int)State);
return 0;
}
public static long StartAudioOut(ServiceCtx Context)
public long StartAudioOut(ServiceCtx Context)
{
if (State == AudioOutState.Stopped)
{
@ -57,7 +77,7 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long StopAudioOut(ServiceCtx Context)
public long StopAudioOut(ServiceCtx Context)
{
if (State == AudioOutState.Started)
{
@ -75,7 +95,7 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long AppendAudioOutBuffer(ServiceCtx Context)
public long AppendAudioOutBuffer(ServiceCtx Context)
{
long BufferId = Context.RequestData.ReadInt64();
@ -109,7 +129,7 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long RegisterBufferEvent(ServiceCtx Context)
public long RegisterBufferEvent(ServiceCtx Context)
{
int Handle = Context.Ns.Os.Handles.GenerateId(new HEvent());
@ -118,7 +138,7 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long GetReleasedAudioOutBuffer(ServiceCtx Context)
public long GetReleasedAudioOutBuffer(ServiceCtx Context)
{
long TempKey = 0;
@ -141,17 +161,17 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long ContainsAudioOutBuffer(ServiceCtx Context)
public long ContainsAudioOutBuffer(ServiceCtx Context)
{
return 0;
}
public static long AppendAudioOutBuffer_ex(ServiceCtx Context)
public long AppendAudioOutBuffer_ex(ServiceCtx Context)
{
return 0;
}
public static long GetReleasedAudioOutBuffer_ex(ServiceCtx Context)
public long GetReleasedAudioOutBuffer_ex(ServiceCtx Context)
{
return 0;
}

View file

@ -1,13 +1,29 @@
using Ryujinx.OsHle.Handles;
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects
namespace Ryujinx.OsHle.Objects.Aud
{
class AudIAudioRenderer
class IAudioRenderer : IIpcInterface
{
public static long RequestUpdateAudioRenderer(ServiceCtx Context)
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public IAudioRenderer()
{
//buffer < unknown, 5, 0 >) -> (buffer < unknown, 6, 0 >, buffer < unknown, 6, 0 >
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 4, RequestUpdateAudioRenderer },
{ 5, StartAudioRenderer },
{ 6, StopAudioRenderer },
{ 7, QuerySystemEvent }
};
}
public long RequestUpdateAudioRenderer(ServiceCtx Context)
{
//(buffer<unknown, 5, 0>) -> (buffer<unknown, 6, 0>, buffer<unknown, 6, 0>)
long Position = Context.Request.ReceiveBuff[0].Position;
@ -28,17 +44,17 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long StartAudioRenderer(ServiceCtx Context)
public long StartAudioRenderer(ServiceCtx Context)
{
return 0;
}
public static long StopAudioRenderer(ServiceCtx Context)
public long StopAudioRenderer(ServiceCtx Context)
{
return 0;
}
public static long QuerySystemEvent(ServiceCtx Context)
public long QuerySystemEvent(ServiceCtx Context)
{
int Handle = Context.Ns.Os.Handles.GenerateId(new HEvent());

View file

@ -0,0 +1,20 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Friend
{
class IFriendService : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public IFriendService()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
//...
};
}
}
}

View file

@ -1,7 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class FriendIFriendService
{
}
}

View file

@ -1,23 +1,32 @@
using ChocolArm64.Memory;
using Ryujinx.OsHle.Ipc;
using System;
using System.Collections.Generic;
using System.IO;
namespace Ryujinx.OsHle.Objects
namespace Ryujinx.OsHle.Objects.FspSrv
{
class FspSrvIFile : IDisposable
class IFile : IIpcInterface, IDisposable
{
public Stream BaseStream { get; private set; }
private Dictionary<int, ServiceProcessRequest> m_Commands;
public FspSrvIFile(Stream BaseStream)
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
private Stream BaseStream;
public IFile(Stream BaseStream)
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, Read },
{ 1, Write }
};
this.BaseStream = BaseStream;
}
public static long Read(ServiceCtx Context)
public long Read(ServiceCtx Context)
{
FspSrvIFile File = Context.GetObject<FspSrvIFile>();
long Position = Context.Request.ReceiveBuff[0].Position;
long Zero = Context.RequestData.ReadInt64();
@ -26,7 +35,7 @@ namespace Ryujinx.OsHle.Objects
byte[] Data = new byte[Size];
int ReadSize = File.BaseStream.Read(Data, 0, (int)Size);
int ReadSize = BaseStream.Read(Data, 0, (int)Size);
AMemoryHelper.WriteBytes(Context.Memory, Position, Data);
@ -38,10 +47,8 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long Write(ServiceCtx Context)
public long Write(ServiceCtx Context)
{
FspSrvIFile File = Context.GetObject<FspSrvIFile>();
long Position = Context.Request.SendBuff[0].Position;
long Zero = Context.RequestData.ReadInt64();
@ -50,8 +57,8 @@ namespace Ryujinx.OsHle.Objects
byte[] Data = AMemoryHelper.ReadBytes(Context.Memory, Position, (int)Size);
File.BaseStream.Seek(Offset, SeekOrigin.Begin);
File.BaseStream.Write(Data, 0, (int)Size);
BaseStream.Seek(Offset, SeekOrigin.Begin);
BaseStream.Write(Data, 0, (int)Size);
return 0;
}

View file

@ -1,28 +1,39 @@
using ChocolArm64.Memory;
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
using System.IO;
using static Ryujinx.OsHle.Objects.ObjHelper;
namespace Ryujinx.OsHle.Objects
namespace Ryujinx.OsHle.Objects.FspSrv
{
class FspSrvIFileSystem
class IFileSystem : IIpcInterface
{
public string FilePath { get; private set; }
private Dictionary<int, ServiceProcessRequest> m_Commands;
public FspSrvIFileSystem(string Path)
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
private string Path;
public IFileSystem(string Path)
{
this.FilePath = Path;
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 7, GetEntryType },
{ 8, OpenFile },
{ 10, Commit }
};
this.Path = Path;
}
public static long GetEntryType(ServiceCtx Context)
public long GetEntryType(ServiceCtx Context)
{
FspSrvIFileSystem FileSystem = Context.GetObject<FspSrvIFileSystem>();
long Position = Context.Request.PtrBuff[0].Position;
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
string FileName = Context.Ns.VFs.GetFullPath(FileSystem.FilePath, Name);
string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
if (FileName == null)
{
@ -37,17 +48,15 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long OpenFile(ServiceCtx Context)
public long OpenFile(ServiceCtx Context)
{
FspSrvIFileSystem FileSystem = Context.GetObject<FspSrvIFileSystem>();
long Position = Context.Request.PtrBuff[0].Position;
int FilterFlags = Context.RequestData.ReadInt32();
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
string FileName = Context.Ns.VFs.GetFullPath(FileSystem.FilePath, Name);
string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
if (FileName == null)
{
@ -57,12 +66,12 @@ namespace Ryujinx.OsHle.Objects
FileStream Stream = new FileStream(FileName, FileMode.OpenOrCreate);
MakeObject(Context, new FspSrvIFile(Stream));
MakeObject(Context, new IFile(Stream));
return 0;
}
public static long Commit(ServiceCtx Context)
public long Commit(ServiceCtx Context)
{
return 0;
}

View file

@ -1,22 +1,30 @@
using ChocolArm64.Memory;
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
using System.IO;
namespace Ryujinx.OsHle.Objects
namespace Ryujinx.OsHle.Objects.FspSrv
{
class FspSrvIStorage
class IStorage : IIpcInterface
{
public Stream BaseStream { get; private set; }
private Dictionary<int, ServiceProcessRequest> m_Commands;
public FspSrvIStorage(Stream BaseStream)
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
private Stream BaseStream;
public IStorage(Stream BaseStream)
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, Read }
};
this.BaseStream = BaseStream;
}
public static long Read(ServiceCtx Context)
public long Read(ServiceCtx Context)
{
FspSrvIStorage Storage = Context.GetObject<FspSrvIStorage>();
long Offset = Context.RequestData.ReadInt64();
long Size = Context.RequestData.ReadInt64();
@ -32,8 +40,8 @@ namespace Ryujinx.OsHle.Objects
byte[] Data = new byte[Size];
Storage.BaseStream.Seek(Offset, SeekOrigin.Begin);
Storage.BaseStream.Read(Data, 0, Data.Length);
BaseStream.Seek(Offset, SeekOrigin.Begin);
BaseStream.Read(Data, 0, Data.Length);
AMemoryHelper.WriteBytes(Context.Memory, BuffDesc.Position, Data);
}

View file

@ -0,0 +1,32 @@
using Ryujinx.OsHle.Handles;
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Hid
{
class IAppletResource : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public HSharedMem Handle;
public IAppletResource(HSharedMem Handle)
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, GetSharedMemoryHandle }
};
this.Handle = Handle;
}
public static long GetSharedMemoryHandle(ServiceCtx Context)
{
Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Context.Ns.Os.HidHandle);
return 0;
}
}
}

View file

@ -1,22 +0,0 @@
using Ryujinx.OsHle.Handles;
using Ryujinx.OsHle.Ipc;
namespace Ryujinx.OsHle.Objects
{
class HidIAppletResource
{
public HSharedMem Handle;
public HidIAppletResource(HSharedMem Handle)
{
this.Handle = Handle;
}
public static long GetSharedMemoryHandle(ServiceCtx Context)
{
Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Context.Ns.Os.HidHandle);
return 0;
}
}
}

View file

@ -0,0 +1,10 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects
{
interface IIpcInterface
{
IReadOnlyDictionary<int, ServiceProcessRequest> Commands { get; }
}
}

View file

@ -0,0 +1,20 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Time
{
class ISteadyClock : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public ISteadyClock()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
//...
};
}
}
}

View file

@ -0,0 +1,30 @@
using Ryujinx.OsHle.Ipc;
using System;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Time
{
class ISystemClock : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
private static DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public ISystemClock()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, GetCurrentTime }
};
}
public long GetCurrentTime(ServiceCtx Context)
{
Context.ResponseData.Write((long)(DateTime.Now - Epoch).TotalSeconds);
return 0;
}
}
}

View file

@ -0,0 +1,20 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Time
{
class ITimeZoneService : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public ITimeZoneService()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
//...
};
}
}
}

View file

@ -1,7 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class TimeISteadyClock
{
}
}

View file

@ -1,16 +0,0 @@
using System;
namespace Ryujinx.OsHle.Objects
{
class TimeISystemClock
{
private static DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public static long GetCurrentTime(ServiceCtx Context)
{
Context.ResponseData.Write((long)(DateTime.Now - Epoch).TotalSeconds);
return 0;
}
}
}

View file

@ -1,7 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class TimeITimeZoneService
{
}
}

View file

@ -1,44 +1,65 @@
using ChocolArm64.Memory;
using Ryujinx.OsHle.Handles;
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
using System.IO;
using static Ryujinx.OsHle.Objects.Android.Parcel;
using static Ryujinx.OsHle.Objects.ObjHelper;
namespace Ryujinx.OsHle.Objects
namespace Ryujinx.OsHle.Objects.Vi
{
class ViIApplicationDisplayService
class IApplicationDisplayService : IIpcInterface
{
public static long GetRelayService(ServiceCtx Context)
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public IApplicationDisplayService()
{
MakeObject(Context, new ViIHOSBinderDriver());
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 100, GetRelayService },
{ 101, GetSystemDisplayService },
{ 102, GetManagerDisplayService },
{ 103, GetIndirectDisplayTransactionService },
{ 1010, OpenDisplay },
{ 2020, OpenLayer },
{ 2030, CreateStrayLayer },
{ 2101, SetLayerScalingMode },
{ 5202, GetDisplayVSyncEvent }
};
}
public long GetRelayService(ServiceCtx Context)
{
MakeObject(Context, new IHOSBinderDriver());
return 0;
}
public static long GetSystemDisplayService(ServiceCtx Context)
public long GetSystemDisplayService(ServiceCtx Context)
{
MakeObject(Context, new ViISystemDisplayService());
MakeObject(Context, new ISystemDisplayService());
return 0;
}
public static long GetManagerDisplayService(ServiceCtx Context)
public long GetManagerDisplayService(ServiceCtx Context)
{
MakeObject(Context, new ViIManagerDisplayService());
MakeObject(Context, new IManagerDisplayService());
return 0;
}
public static long GetIndirectDisplayTransactionService(ServiceCtx Context)
public long GetIndirectDisplayTransactionService(ServiceCtx Context)
{
MakeObject(Context, new ViIHOSBinderDriver());
MakeObject(Context, new IHOSBinderDriver());
return 0;
}
public static long OpenDisplay(ServiceCtx Context)
public long OpenDisplay(ServiceCtx Context)
{
string Name = GetDisplayName(Context);
@ -49,7 +70,7 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long OpenLayer(ServiceCtx Context)
public long OpenLayer(ServiceCtx Context)
{
long LayerId = Context.RequestData.ReadInt64();
long UserId = Context.RequestData.ReadInt64();
@ -65,7 +86,7 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long CreateStrayLayer(ServiceCtx Context)
public long CreateStrayLayer(ServiceCtx Context)
{
long LayerFlags = Context.RequestData.ReadInt64();
long DisplayId = Context.RequestData.ReadInt64();
@ -84,7 +105,7 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long SetLayerScalingMode(ServiceCtx Context)
public long SetLayerScalingMode(ServiceCtx Context)
{
int ScalingMode = Context.RequestData.ReadInt32();
long Unknown = Context.RequestData.ReadInt64();
@ -92,7 +113,7 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long GetDisplayVSyncEvent(ServiceCtx Context)
public long GetDisplayVSyncEvent(ServiceCtx Context)
{
string Name = GetDisplayName(Context);
@ -103,7 +124,7 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
private static byte[] MakeIGraphicsBufferProducer(long BasePtr)
private byte[] MakeIGraphicsBufferProducer(long BasePtr)
{
long Id = 0x20;
long CookiePtr = 0L;
@ -133,7 +154,7 @@ namespace Ryujinx.OsHle.Objects
}
}
private static string GetDisplayName(ServiceCtx Context)
private string GetDisplayName(ServiceCtx Context)
{
string Name = string.Empty;

View file

@ -9,39 +9,51 @@ using System.Text;
using static Ryujinx.OsHle.Objects.Android.Parcel;
namespace Ryujinx.OsHle.Objects
namespace Ryujinx.OsHle.Objects.Vi
{
class ViIHOSBinderDriver
class IHOSBinderDriver : IIpcInterface
{
private delegate long ServiceProcessRequest(ServiceCtx Context, byte[] ParcelData);
private delegate long ServiceProcessParcel(ServiceCtx Context, byte[] ParcelData);
private static Dictionary<(string, int), ServiceProcessRequest> InterfaceMthd =
new Dictionary<(string, int), ServiceProcessRequest>()
{
{ ("android.gui.IGraphicBufferProducer", 0x1), GraphicBufferProducerRequestBuffer },
{ ("android.gui.IGraphicBufferProducer", 0x3), GraphicBufferProducerDequeueBuffer },
{ ("android.gui.IGraphicBufferProducer", 0x7), GraphicBufferProducerQueueBuffer },
//{ ("android.gui.IGraphicBufferProducer", 0x8), GraphicBufferProducerCancelBuffer },
{ ("android.gui.IGraphicBufferProducer", 0x9), GraphicBufferProducerQuery },
{ ("android.gui.IGraphicBufferProducer", 0xa), GraphicBufferProducerConnect },
{ ("android.gui.IGraphicBufferProducer", 0xe), GraphicBufferPreallocateBuffer },
};
private Dictionary<int, ServiceProcessRequest> m_Commands;
private Dictionary<(string, int), ServiceProcessParcel> m_Methods;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
private class BufferObj
{
}
public IdPoolWithObj BufferSlots { get; private set; }
private IdPoolWithObj BufferSlots;
public byte[] Gbfr;
private byte[] Gbfr;
public ViIHOSBinderDriver()
public IHOSBinderDriver()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, TransactParcel },
{ 1, AdjustRefcount },
{ 2, GetNativeHandle }
};
m_Methods = new Dictionary<(string, int), ServiceProcessParcel>()
{
{ ("android.gui.IGraphicBufferProducer", 0x1), GraphicBufferProducerRequestBuffer },
{ ("android.gui.IGraphicBufferProducer", 0x3), GraphicBufferProducerDequeueBuffer },
{ ("android.gui.IGraphicBufferProducer", 0x7), GraphicBufferProducerQueueBuffer },
{ ("android.gui.IGraphicBufferProducer", 0x8), GraphicBufferProducerCancelBuffer },
{ ("android.gui.IGraphicBufferProducer", 0x9), GraphicBufferProducerQuery },
{ ("android.gui.IGraphicBufferProducer", 0xa), GraphicBufferProducerConnect },
{ ("android.gui.IGraphicBufferProducer", 0xe), GraphicBufferPreallocateBuffer }
};
BufferSlots = new IdPoolWithObj();
}
public static long TransactParcel(ServiceCtx Context)
public long TransactParcel(ServiceCtx Context)
{
int Id = Context.RequestData.ReadInt32();
int Code = Context.RequestData.ReadInt32();
@ -63,7 +75,7 @@ namespace Ryujinx.OsHle.Objects
string InterfaceName = Encoding.Unicode.GetString(Data, 8, StrSize * 2);
if (InterfaceMthd.TryGetValue((InterfaceName, Code), out ServiceProcessRequest ProcReq))
if (m_Methods.TryGetValue((InterfaceName, Code), out ServiceProcessParcel ProcReq))
{
return ProcReq(Context, Data);
}
@ -74,43 +86,37 @@ namespace Ryujinx.OsHle.Objects
}
}
private static long GraphicBufferProducerRequestBuffer(ServiceCtx Context, byte[] ParcelData)
private long GraphicBufferProducerRequestBuffer(ServiceCtx Context, byte[] ParcelData)
{
ViIHOSBinderDriver BinderDriver = Context.GetObject<ViIHOSBinderDriver>();
int GbfrSize = BinderDriver.Gbfr?.Length ?? 0;
int GbfrSize = Gbfr?.Length ?? 0;
byte[] Data = new byte[GbfrSize + 4];
if (BinderDriver.Gbfr != null)
if (Gbfr != null)
{
Buffer.BlockCopy(BinderDriver.Gbfr, 0, Data, 0, GbfrSize);
Buffer.BlockCopy(Gbfr, 0, Data, 0, GbfrSize);
}
return MakeReplyParcel(Context, Data);
}
private static long GraphicBufferProducerDequeueBuffer(ServiceCtx Context, byte[] ParcelData)
private long GraphicBufferProducerDequeueBuffer(ServiceCtx Context, byte[] ParcelData)
{
ViIHOSBinderDriver BinderDriver = Context.GetObject<ViIHOSBinderDriver>();
//Note: It seems that the maximum number of slots is 64, because if we return
//a Slot number > 63, it seems to cause a buffer overrun and it reads garbage.
//Note 2: The size of each object associated with the slot is 0x30.
int Slot = BinderDriver.BufferSlots.GenerateId(new BufferObj());
int Slot = BufferSlots.GenerateId(new BufferObj());
return MakeReplyParcel(Context, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
private static long GraphicBufferProducerQueueBuffer(ServiceCtx Context, byte[] ParcelData)
private long GraphicBufferProducerQueueBuffer(ServiceCtx Context, byte[] ParcelData)
{
return MakeReplyParcel(Context, 1280, 720, 0, 0, 0);
}
private static long GraphicBufferProducerCancelBuffer(ServiceCtx Context, byte[] ParcelData)
private long GraphicBufferProducerCancelBuffer(ServiceCtx Context, byte[] ParcelData)
{
ViIHOSBinderDriver BinderDriver = Context.GetObject<ViIHOSBinderDriver>();
using (MemoryStream MS = new MemoryStream(ParcelData))
{
BinaryReader Reader = new BinaryReader(MS);
@ -119,31 +125,29 @@ namespace Ryujinx.OsHle.Objects
int Slot = Reader.ReadInt32();
BinderDriver.BufferSlots.Delete(Slot);
BufferSlots.Delete(Slot);
return MakeReplyParcel(Context, 0);
}
}
private static long GraphicBufferProducerQuery(ServiceCtx Context, byte[] ParcelData)
private long GraphicBufferProducerQuery(ServiceCtx Context, byte[] ParcelData)
{
return MakeReplyParcel(Context, 0, 0);
}
private static long GraphicBufferProducerConnect(ServiceCtx Context, byte[] ParcelData)
private long GraphicBufferProducerConnect(ServiceCtx Context, byte[] ParcelData)
{
return MakeReplyParcel(Context, 1280, 720, 0, 0, 0);
}
private static long GraphicBufferPreallocateBuffer(ServiceCtx Context, byte[] ParcelData)
private long GraphicBufferPreallocateBuffer(ServiceCtx Context, byte[] ParcelData)
{
ViIHOSBinderDriver BinderDriver = Context.GetObject<ViIHOSBinderDriver>();
int GbfrSize = ParcelData.Length - 0x54;
BinderDriver.Gbfr = new byte[GbfrSize];
Gbfr = new byte[GbfrSize];
Buffer.BlockCopy(ParcelData, 0x54, BinderDriver.Gbfr, 0, GbfrSize);
Buffer.BlockCopy(ParcelData, 0x54, Gbfr, 0, GbfrSize);
using (MemoryStream MS = new MemoryStream(ParcelData))
{
@ -161,7 +165,7 @@ namespace Ryujinx.OsHle.Objects
return MakeReplyParcel(Context, 0);
}
private static long MakeReplyParcel(ServiceCtx Context, params int[] Ints)
private long MakeReplyParcel(ServiceCtx Context, params int[] Ints)
{
using (MemoryStream MS = new MemoryStream())
{
@ -176,7 +180,7 @@ namespace Ryujinx.OsHle.Objects
}
}
private static long MakeReplyParcel(ServiceCtx Context, byte[] Data)
private long MakeReplyParcel(ServiceCtx Context, byte[] Data)
{
long ReplyPos = Context.Request.ReceiveBuff[0].Position;
long ReplySize = Context.Request.ReceiveBuff[0].Position;
@ -188,7 +192,7 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long AdjustRefcount(ServiceCtx Context)
public long AdjustRefcount(ServiceCtx Context)
{
int Id = Context.RequestData.ReadInt32();
int AddVal = Context.RequestData.ReadInt32();
@ -197,7 +201,7 @@ namespace Ryujinx.OsHle.Objects
return 0;
}
public static long GetNativeHandle(ServiceCtx Context)
public long GetNativeHandle(ServiceCtx Context)
{
int Id = Context.RequestData.ReadInt32();
uint Unk = Context.RequestData.ReadUInt32();

View file

@ -0,0 +1,33 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Vi
{
class IManagerDisplayService : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public IManagerDisplayService()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 2010, CreateManagedLayer },
{ 6000, AddToLayerStack }
};
}
public static long CreateManagedLayer(ServiceCtx Context)
{
Context.ResponseData.Write(0L); //LayerId
return 0;
}
public static long AddToLayerStack(ServiceCtx Context)
{
return 0;
}
}
}

View file

@ -0,0 +1,25 @@
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
namespace Ryujinx.OsHle.Objects.Vi
{
class ISystemDisplayService : IIpcInterface
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public ISystemDisplayService()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 2205, SetLayerZ }
};
}
public static long SetLayerZ(ServiceCtx Context)
{
return 0;
}
}
}

View file

@ -1,17 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class ViIManagerDisplayService
{
public static long CreateManagedLayer(ServiceCtx Context)
{
Context.ResponseData.Write(0L); //LayerId
return 0;
}
public static long AddToLayerStack(ServiceCtx Context)
{
return 0;
}
}
}

View file

@ -1,10 +0,0 @@
namespace Ryujinx.OsHle.Objects
{
class ViISystemDisplayService
{
public static long SetLayerZ(ServiceCtx Context)
{
return 0;
}
}
}

View file

@ -1,7 +1,9 @@
using ChocolArm64;
using ChocolArm64.Memory;
using ChocolArm64.State;
using Ryujinx.Loaders;
using Ryujinx.Loaders.Executables;
using Ryujinx.OsHle.Exceptions;
using Ryujinx.OsHle.Handles;
using Ryujinx.OsHle.Svc;
using System;
@ -135,7 +137,9 @@ namespace Ryujinx.OsHle
return -1;
}
Thread.Registers.Break += BreakHandler;
Thread.Registers.SvcCall += SvcHandler.SvcCall;
Thread.Registers.Undefined += UndefinedHandler;
Thread.Registers.ProcessId = ProcessId;
Thread.Registers.ThreadId = Ns.Os.IdGen.GenerateId();
Thread.Registers.Tpidr = TlsPageAddr + TlsSlot * TlsSize;
@ -148,6 +152,16 @@ namespace Ryujinx.OsHle
return Handle;
}
private void BreakHandler(object sender, AInstExceptEventArgs e)
{
throw new GuestBrokeExecutionException();
}
private void UndefinedHandler(object sender, AInstUndEventArgs e)
{
throw new UndefinedInstructionException(e.Position, e.RawOpCode);
}
private int GetFreeTlsSlot(AThread Thread)
{
for (int Index = 1; Index < TotalTlsSlots; Index++)

View file

@ -32,21 +32,5 @@ namespace Ryujinx.OsHle
this.RequestData = RequestData;
this.ResponseData = ResponseData;
}
public T GetObject<T>()
{
object Obj = null;
if (Session is HSessionObj SessionObj)
{
Obj = SessionObj.Obj;
}
if (Session is HDomain Dom)
{
Obj = Dom.GetObject(Request.DomObjId);
}
return Obj is T ? (T)Obj : default(T);
}
}
}

View file

@ -1,4 +1,4 @@
using Ryujinx.OsHle.Objects;
using Ryujinx.OsHle.Objects.Acc;
using static Ryujinx.OsHle.Objects.ObjHelper;
@ -13,7 +13,7 @@ namespace Ryujinx.OsHle.Services
public static long AccU0GetProfile(ServiceCtx Context)
{
MakeObject(Context, new AccIProfile());
MakeObject(Context, new IProfile());
return 0;
}
@ -25,7 +25,7 @@ namespace Ryujinx.OsHle.Services
public static long AccU0GetBaasAccountManagerForApplication(ServiceCtx Context)
{
MakeObject(Context, new AccIManagerForApplication());
MakeObject(Context, new IManagerForApplication());
return 0;
}

View file

@ -1,4 +1,4 @@
using Ryujinx.OsHle.Objects;
using Ryujinx.OsHle.Objects.Apm;
using static Ryujinx.OsHle.Objects.ObjHelper;
@ -8,7 +8,7 @@ namespace Ryujinx.OsHle.Services
{
public static long ApmOpenSession(ServiceCtx Context)
{
MakeObject(Context, new ApmISession());
MakeObject(Context, new ISession());
return 0;
}

View file

@ -1,4 +1,4 @@
using Ryujinx.OsHle.Objects;
using Ryujinx.OsHle.Objects.Am;
using static Ryujinx.OsHle.Objects.ObjHelper;
@ -8,7 +8,7 @@ namespace Ryujinx.OsHle.Services
{
public static long AppletOpenApplicationProxy(ServiceCtx Context)
{
MakeObject(Context, new AmIApplicationProxy());
MakeObject(Context, new IApplicationProxy());
return 0;
}

View file

@ -1,5 +1,5 @@
using ChocolArm64.Memory;
using Ryujinx.OsHle.Objects;
using Ryujinx.OsHle.Objects.Aud;
using System.Text;
using static Ryujinx.OsHle.Objects.ObjHelper;
@ -21,7 +21,7 @@ namespace Ryujinx.OsHle.Services
public static long AudOutOpenAudioOut(ServiceCtx Context)
{
MakeObject(Context, new AudIAudioOut());
MakeObject(Context, new IAudioOut());
Context.ResponseData.Write(48000); //Sample Rate
Context.ResponseData.Write(2); //Channel Count
@ -42,7 +42,7 @@ namespace Ryujinx.OsHle.Services
public static long AudRenOpenAudioRenderer(ServiceCtx Context)
{
MakeObject(Context, new AudIAudioRenderer());
MakeObject(Context, new IAudioRenderer());
return 0;
}

View file

@ -1,4 +1,4 @@
using Ryujinx.OsHle.Objects;
using Ryujinx.OsHle.Objects.Friend;
using static Ryujinx.OsHle.Objects.ObjHelper;
@ -8,7 +8,7 @@ namespace Ryujinx.OsHle.Services
{
public static long FriendCreateFriendService(ServiceCtx Context)
{
MakeObject(Context, new FriendIFriendService());
MakeObject(Context, new IFriendService());
return 0;
}

View file

@ -1,4 +1,4 @@
using Ryujinx.OsHle.Objects;
using Ryujinx.OsHle.Objects.FspSrv;
using static Ryujinx.OsHle.Objects.ObjHelper;
@ -13,28 +13,28 @@ namespace Ryujinx.OsHle.Services
public static long FspSrvMountSdCard(ServiceCtx Context)
{
MakeObject(Context, new FspSrvIFileSystem(Context.Ns.VFs.GetSdCardPath()));
MakeObject(Context, new IFileSystem(Context.Ns.VFs.GetSdCardPath()));
return 0;
}
public static long FspSrvMountSaveData(ServiceCtx Context)
{
MakeObject(Context, new FspSrvIFileSystem(Context.Ns.VFs.GetGameSavesPath()));
MakeObject(Context, new IFileSystem(Context.Ns.VFs.GetGameSavesPath()));
return 0;
}
public static long FspSrvOpenDataStorageByCurrentProcess(ServiceCtx Context)
{
MakeObject(Context, new FspSrvIStorage(Context.Ns.VFs.RomFs));
MakeObject(Context, new IStorage(Context.Ns.VFs.RomFs));
return 0;
}
public static long FspSrvOpenRomStorage(ServiceCtx Context)
{
MakeObject(Context, new FspSrvIStorage(Context.Ns.VFs.RomFs));
MakeObject(Context, new IStorage(Context.Ns.VFs.RomFs));
return 0;
}

View file

@ -1,5 +1,5 @@
using Ryujinx.OsHle.Handles;
using Ryujinx.OsHle.Objects;
using Ryujinx.OsHle.Objects.Hid;
using static Ryujinx.OsHle.Objects.ObjHelper;
@ -11,7 +11,7 @@ namespace Ryujinx.OsHle.Services
{
HSharedMem HidHndData = Context.Ns.Os.Handles.GetData<HSharedMem>(Context.Ns.Os.HidHandle);
MakeObject(Context, new HidIAppletResource(HidHndData));
MakeObject(Context, new IAppletResource(HidHndData));
return 0;
}

View file

@ -1,4 +1,4 @@
using Ryujinx.OsHle.Objects;
using Ryujinx.OsHle.Objects.Am;
using static Ryujinx.OsHle.Objects.ObjHelper;
@ -8,7 +8,7 @@ namespace Ryujinx.OsHle.Services
{
public static long PctlCreateService(ServiceCtx Context)
{
MakeObject(Context, new AmIParentalControlService());
MakeObject(Context, new IParentalControlService());
return 0;
}

View file

@ -1,4 +1,4 @@
using Ryujinx.OsHle.Objects;
using Ryujinx.OsHle.Objects.Time;
using static Ryujinx.OsHle.Objects.ObjHelper;
@ -8,28 +8,28 @@ namespace Ryujinx.OsHle.Services
{
public static long TimeGetStandardUserSystemClock(ServiceCtx Context)
{
MakeObject(Context, new TimeISystemClock());
MakeObject(Context, new ISystemClock());
return 0;
}
public static long TimeGetStandardNetworkSystemClock(ServiceCtx Context)
{
MakeObject(Context, new TimeISystemClock());
MakeObject(Context, new ISystemClock());
return 0;
}
public static long TimeGetStandardSteadyClock(ServiceCtx Context)
{
MakeObject(Context, new TimeISteadyClock());
MakeObject(Context, new ISteadyClock());
return 0;
}
public static long TimeGetTimeZoneService(ServiceCtx Context)
{
MakeObject(Context, new TimeITimeZoneService());
MakeObject(Context, new ITimeZoneService());
return 0;
}

View file

@ -1,4 +1,4 @@
using Ryujinx.OsHle.Objects;
using Ryujinx.OsHle.Objects.Vi;
using static Ryujinx.OsHle.Objects.ObjHelper;
@ -10,7 +10,7 @@ namespace Ryujinx.OsHle.Services
{
int Unknown = Context.RequestData.ReadInt32();
MakeObject(Context, new ViIApplicationDisplayService());
MakeObject(Context, new IApplicationDisplayService());
return 0;
}

View file

@ -63,7 +63,7 @@ namespace Ryujinx.OsHle.Svc
Rng = new Random();
}
public void SvcCall(object sender, SvcEventArgs e)
public void SvcCall(object sender, AInstExceptEventArgs e)
{
ARegisters Registers = (ARegisters)sender;
@ -75,7 +75,7 @@ namespace Ryujinx.OsHle.Svc
}
else
{
throw new NotImplementedException(e.Id.ToString("x3"));
throw new NotImplementedException(e.Id.ToString("x4"));
}
}
}

View file

@ -8,7 +8,7 @@ namespace Ryujinx.OsHle.Svc
{
private static void SvcSetHeapSize(Switch Ns, ARegisters Registers, AMemory Memory)
{
int Size = (int)Registers.X1;
uint Size = (uint)Registers.X1;
Memory.Manager.SetHeapSize(Size, (int)MemoryType.Heap);
@ -30,8 +30,8 @@ namespace Ryujinx.OsHle.Svc
private static void SvcMapMemory(Switch Ns, ARegisters Registers, AMemory Memory)
{
long Src = (long)Registers.X0;
long Dst = (long)Registers.X1;
long Dst = (long)Registers.X0;
long Src = (long)Registers.X1;
long Size = (long)Registers.X2;
Memory.Manager.MapMirror(Src, Dst, Size, (int)MemoryType.MappedMemory);
@ -79,12 +79,10 @@ namespace Ryujinx.OsHle.Svc
HndData.VirtPos = Src;
if (Memory.Manager.MapPhys(Src, Dst, Size,
(int)MemoryType.SharedMemory, (AMemoryPerm)Perm))
{
Memory.Manager.MapPhys(Position, Size, (int)MemoryType.SharedMemory, (AMemoryPerm)Perm);
Registers.X0 = (int)SvcResult.Success;
}
}
//TODO: Error codes.
}

Some files were not shown because too many files have changed in this diff Show more