SyscallHandler.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Ryujinx.Cpu;
  2. using Ryujinx.HLE.HOS.Kernel.Threading;
  3. using System;
  4. namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
  5. {
  6. partial class SyscallHandler
  7. {
  8. private readonly KernelContext _context;
  9. private readonly Syscall32 _syscall32;
  10. private readonly Syscall64 _syscall64;
  11. public SyscallHandler(KernelContext context)
  12. {
  13. _context = context;
  14. _syscall32 = new Syscall32(context.Syscall);
  15. _syscall64 = new Syscall64(context.Syscall);
  16. }
  17. public void SvcCall(IExecutionContext context, ulong address, int id)
  18. {
  19. KThread currentThread = KernelStatic.GetCurrentThread();
  20. if (currentThread.Owner != null &&
  21. currentThread.GetUserDisableCount() != 0 &&
  22. currentThread.Owner.PinnedThreads[currentThread.CurrentCore] == null)
  23. {
  24. _context.CriticalSection.Enter();
  25. currentThread.Owner.PinThread(currentThread);
  26. currentThread.SetUserInterruptFlag();
  27. _context.CriticalSection.Leave();
  28. }
  29. if (context.IsAarch32)
  30. {
  31. var svcFunc = SyscallTable.SvcTable32[id];
  32. if (svcFunc == null)
  33. {
  34. throw new NotImplementedException($"SVC 0x{id:X4} is not implemented.");
  35. }
  36. svcFunc(_syscall32, context);
  37. }
  38. else
  39. {
  40. var svcFunc = SyscallTable.SvcTable64[id];
  41. if (svcFunc == null)
  42. {
  43. throw new NotImplementedException($"SVC 0x{id:X4} is not implemented.");
  44. }
  45. svcFunc(_syscall64, context);
  46. }
  47. currentThread.HandlePostSyscall();
  48. }
  49. }
  50. }