page_table.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 <vector>
  6. #include <boost/icl/interval_map.hpp>
  7. #include "common/common_types.h"
  8. #include "common/memory_hook.h"
  9. #include "common/virtual_buffer.h"
  10. namespace Common {
  11. enum class PageType : u8 {
  12. /// Page is unmapped and should cause an access error.
  13. Unmapped,
  14. /// Page is mapped to regular memory. This is the only type you can get pointers to.
  15. Memory,
  16. /// Page is mapped to regular memory, but also needs to check for rasterizer cache flushing and
  17. /// invalidation
  18. RasterizerCachedMemory,
  19. /// Page is mapped to a I/O region. Writing and reading to this page is handled by functions.
  20. Special,
  21. /// Page is allocated for use.
  22. Allocated,
  23. };
  24. struct SpecialRegion {
  25. enum class Type {
  26. DebugHook,
  27. IODevice,
  28. } type;
  29. MemoryHookPointer handler;
  30. bool operator<(const SpecialRegion& other) const {
  31. return std::tie(type, handler) < std::tie(other.type, other.handler);
  32. }
  33. bool operator==(const SpecialRegion& other) const {
  34. return std::tie(type, handler) == std::tie(other.type, other.handler);
  35. }
  36. };
  37. /**
  38. * A (reasonably) fast way of allowing switchable and remappable process address spaces. It loosely
  39. * mimics the way a real CPU page table works.
  40. */
  41. struct PageTable {
  42. PageTable();
  43. ~PageTable();
  44. /**
  45. * Resizes the page table to be able to accomodate enough pages within
  46. * a given address space.
  47. *
  48. * @param address_space_width_in_bits The address size width in bits.
  49. */
  50. void Resize(std::size_t address_space_width_in_bits, std::size_t page_size_in_bits,
  51. bool has_attribute);
  52. /**
  53. * Vector of memory pointers backing each page. An entry can only be non-null if the
  54. * corresponding entry in the `attributes` vector is of type `Memory`.
  55. */
  56. VirtualBuffer<u8*> pointers;
  57. VirtualBuffer<u64> backing_addr;
  58. VirtualBuffer<PageType> attributes;
  59. };
  60. } // namespace Common