ICpuContext.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. namespace Ryujinx.Cpu
  3. {
  4. /// <summary>
  5. /// CPU context interface.
  6. /// </summary>
  7. public interface ICpuContext : IDisposable
  8. {
  9. /// <summary>
  10. /// Creates a new execution context that will store thread CPU register state when executing guest code.
  11. /// </summary>
  12. /// <param name="exceptionCallbacks">Optional functions to be called when the CPU receives an interrupt</param>
  13. /// <returns>Execution context</returns>
  14. IExecutionContext CreateExecutionContext(ExceptionCallbacks exceptionCallbacks);
  15. /// <summary>
  16. /// Starts executing code at a specified entry point address.
  17. /// </summary>
  18. /// <remarks>
  19. /// This function only returns when the execution is stopped, by calling <see cref="IExecutionContext.StopRunning"/>.
  20. /// </remarks>
  21. /// <param name="context">Execution context to be used for this run</param>
  22. /// <param name="address">Entry point address</param>
  23. void Execute(IExecutionContext context, ulong address);
  24. /// <summary>
  25. /// Invalidates the instruction cache for a given memory region.
  26. /// </summary>
  27. /// <remarks>
  28. /// This should be called if code is modified to make the CPU emulator aware of the modifications,
  29. /// otherwise it might run stale code which will lead to errors and crashes.
  30. /// Calling this function is not necessary if the code memory was modified by guest code,
  31. /// as the expectation is that it will do it on its own using the appropriate cache invalidation instructions,
  32. /// except on Arm32 where those instructions can't be used in unprivileged mode.
  33. /// </remarks>
  34. /// <param name="address">Address of the region to be invalidated</param>
  35. /// <param name="size">Size of the region to be invalidated</param>
  36. void InvalidateCacheRegion(ulong address, ulong size);
  37. /// <summary>
  38. /// Loads cached code from disk for a given application.
  39. /// </summary>
  40. /// <remarks>
  41. /// If the execution engine is recompiling guest code, this can be used to load cached code from disk.
  42. /// </remarks>
  43. /// <param name="titleIdText">Title ID of the application in padded hex form</param>
  44. /// <param name="displayVersion">Version of the application</param>
  45. /// <param name="enabled">True if the cache should be loaded from disk if it exists, false otherwise</param>
  46. /// <returns>Disk cache load progress reporter and manager</returns>
  47. IDiskCacheLoadState LoadDiskCache(string titleIdText, string displayVersion, bool enabled);
  48. /// <summary>
  49. /// Indicates that code has been loaded into guest memory, and that it might be executed in the future.
  50. /// </summary>
  51. /// <remarks>
  52. /// Some execution engines might use this information to cache recompiled code on disk or to ensure it can be executed.
  53. /// </remarks>
  54. /// <param name="address">CPU virtual address where the code starts</param>
  55. /// <param name="size">Size of the code range in bytes</param>
  56. void PrepareCodeRange(ulong address, ulong size);
  57. }
  58. }