2
0

dirty.h 995 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef DIRTY_H
  2. #define DIRTY_H
  3. #include "compiler.h"
  4. #include "ioregs.h"
  5. #define DIRTY_PAGE_BITS 12
  6. #define DIRTY_PAGE_SIZE (1U << DIRTY_PAGE_BITS)
  7. #define DIRTY_PAGES (1U << (SDRAM_BITS - DIRTY_PAGE_BITS))
  8. #define DIRTY_PAGE_MASK (DIRTY_PAGES - 1)
  9. static inline size_t dirty_page_num(const void *addr)
  10. {
  11. return ((size_t)addr - SDRAM_ADDR) >> DIRTY_PAGE_BITS;
  12. }
  13. static inline volatile bool *dirty_page_reg(size_t page)
  14. {
  15. return (volatile bool *)(&DIRTY_PAGE_REG + page);
  16. }
  17. static inline bool is_dirty_page(size_t page)
  18. {
  19. volatile bool *dreg = dirty_page_reg(page);
  20. return *dreg;
  21. }
  22. static inline bool mem_dirty(const void *addr)
  23. {
  24. return is_dirty_page(dirty_page_num(addr));
  25. }
  26. static inline bool is_dirty_page_clear(size_t page)
  27. {
  28. volatile bool *dreg = dirty_page_reg(page);
  29. bool d = *dreg;
  30. *dreg = d;
  31. return d;
  32. }
  33. static inline bool mem_dirty_clear(const void *addr)
  34. {
  35. return is_dirty_page_clear(dirty_page_num(addr));
  36. }
  37. #endif /* DIRTY_H */