/ src / Ryujinx.Cpu / Jit / JitCpuContext.cs
JitCpuContext.cs
 1  using ARMeilleure.Memory;
 2  using ARMeilleure.Translation;
 3  using Ryujinx.Cpu.Signal;
 4  using Ryujinx.Memory;
 5  
 6  namespace Ryujinx.Cpu.Jit
 7  {
 8      class JitCpuContext : ICpuContext
 9      {
10          private readonly ITickSource _tickSource;
11          private readonly Translator _translator;
12  
13          public JitCpuContext(ITickSource tickSource, IMemoryManager memory, bool for64Bit)
14          {
15              _tickSource = tickSource;
16              _translator = new Translator(new JitMemoryAllocator(forJit: true), memory, for64Bit);
17  
18              if (memory.Type.IsHostMappedOrTracked())
19              {
20                  NativeSignalHandler.InitializeSignalHandler();
21              }
22  
23              memory.UnmapEvent += UnmapHandler;
24          }
25  
26          private void UnmapHandler(ulong address, ulong size)
27          {
28              _translator.InvalidateJitCacheRegion(address, size);
29          }
30  
31          /// <inheritdoc/>
32          public IExecutionContext CreateExecutionContext(ExceptionCallbacks exceptionCallbacks)
33          {
34              return new JitExecutionContext(new JitMemoryAllocator(), _tickSource, exceptionCallbacks);
35          }
36  
37          /// <inheritdoc/>
38          public void Execute(IExecutionContext context, ulong address)
39          {
40              _translator.Execute(((JitExecutionContext)context).Impl, address);
41          }
42  
43          /// <inheritdoc/>
44          public void InvalidateCacheRegion(ulong address, ulong size)
45          {
46              _translator.InvalidateJitCacheRegion(address, size);
47          }
48  
49          /// <inheritdoc/>
50          public IDiskCacheLoadState LoadDiskCache(string titleIdText, string displayVersion, bool enabled)
51          {
52              return new JitDiskCacheLoadState(_translator.LoadDiskCache(titleIdText, displayVersion, enabled));
53          }
54  
55          /// <inheritdoc/>
56          public void PrepareCodeRange(ulong address, ulong size)
57          {
58              _translator.PrepareCodeRange(address, size);
59          }
60  
61          public void Dispose()
62          {
63          }
64      }
65  }