freezer.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2019 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <atomic>
  6. #include <mutex>
  7. #include <optional>
  8. #include <vector>
  9. #include "common/common_types.h"
  10. namespace Core::Timing {
  11. class CoreTiming;
  12. struct EventType;
  13. } // namespace Core::Timing
  14. namespace Tools {
  15. // A class that will effectively freeze memory values.
  16. class Freezer {
  17. public:
  18. struct Entry {
  19. VAddr address;
  20. u32 width;
  21. u64 value;
  22. };
  23. explicit Freezer(Core::Timing::CoreTiming& core_timing);
  24. ~Freezer();
  25. // Enables or disables the entire memory freezer.
  26. void SetActive(bool active);
  27. // Returns whether or not the freezer is active.
  28. bool IsActive() const;
  29. // Removes all entries from the freezer.
  30. void Clear();
  31. // Freezes a value to its current memory address. The value the memory is kept at will be the
  32. // value that is read during this function. Width can be 1, 2, 4, or 8 (in bytes).
  33. u64 Freeze(VAddr address, u32 width);
  34. // Unfreezes the memory value at address. If the address isn't frozen, this is a no-op.
  35. void Unfreeze(VAddr address);
  36. // Returns whether or not the address is frozen.
  37. bool IsFrozen(VAddr address) const;
  38. // Sets the value that address should be frozen to. This doesn't change the width set by using
  39. // Freeze(). If the value isn't frozen, this will not freeze it and is thus a no-op.
  40. void SetFrozenValue(VAddr address, u64 value);
  41. // Returns the entry corresponding to the address if the address is frozen, otherwise
  42. // std::nullopt.
  43. std::optional<Entry> GetEntry(VAddr address) const;
  44. // Returns all the entries in the freezer, an empty vector means nothing is frozen.
  45. std::vector<Entry> GetEntries() const;
  46. private:
  47. void FrameCallback(u64 userdata, s64 cycles_late);
  48. void FillEntryReads();
  49. std::atomic_bool active{false};
  50. mutable std::mutex entries_mutex;
  51. std::vector<Entry> entries;
  52. Core::Timing::EventType* event;
  53. Core::Timing::CoreTiming& core_timing;
  54. };
  55. } // namespace Tools