Add memory::pageAlignUp/Down functions

This commit is contained in:
Eryn Wells 2016-04-13 00:21:28 -04:00
parent 9ce71e5596
commit 93b11307fa
2 changed files with 31 additions and 0 deletions

View file

@ -41,4 +41,11 @@ MemoryManager::initializeGDT()
kstd::printFormat("GDT loaded\n");
}
namespace memory {
const u32 pageSize = 4096;
const u32 pageMask = pageSize - 1;
} /* namespace memory */
} /* namespace kernel */

View file

@ -30,6 +30,30 @@ private:
void initializeGDT();
};
namespace memory {
extern const u32 pageSize;
extern const u32 pageMask;
/** Align to the nearest page boundary below `addr`. */
inline u32
pageAlignDown(u32 addr)
{
return addr & ~pageMask;
}
/** Align to the nearest page boundary above `addr`. */
inline u32
pageAlignUp(u32 addr)
{
if (pageAlignDown(addr) == addr) {
return addr;
}
return (addr + pageSize) & ~pageMask;
}
} /* namespace memory */
} /* namespace kernel */
#endif /* __MEMORY_MEMORY_HH__ */