ICpuContext.cs 3.1 KB

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