12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #ifndef DIRTY_H
- #define DIRTY_H
- #include "compiler.h"
- #include "ioregs.h"
- #define DIRTY_PAGE_BITS 12
- #define DIRTY_PAGE_SIZE (1U << DIRTY_PAGE_BITS)
- #define DIRTY_PAGES (1U << (SDRAM_BITS - DIRTY_PAGE_BITS))
- #define DIRTY_PAGE_MASK (DIRTY_PAGES - 1)
- static inline size_t dirty_page_num(const void *addr)
- {
- return ((size_t)addr - SDRAM_ADDR) >> DIRTY_PAGE_BITS;
- }
- static inline volatile bool *dirty_page_reg(size_t page)
- {
- return (volatile bool *)(&DIRTY_PAGE_REG + page);
- }
- static inline bool is_dirty_page(size_t page)
- {
- volatile bool *dreg = dirty_page_reg(page);
- return *dreg;
- }
- static inline bool mem_dirty(const void *addr)
- {
- return is_dirty_page(dirty_page_num(addr));
- }
- static inline bool is_dirty_page_clear(size_t page)
- {
- volatile bool *dreg = dirty_page_reg(page);
- bool d = *dreg;
- *dreg = d;
- return d;
- }
- static inline bool mem_dirty_clear(const void *addr)
- {
- return is_dirty_page_clear(dirty_page_num(addr));
- }
- #endif /* DIRTY_H */
|