Add memory::pageAlignUp/Down functions
This commit is contained in:
parent
9ce71e5596
commit
93b11307fa
2 changed files with 31 additions and 0 deletions
|
|
@ -41,4 +41,11 @@ MemoryManager::initializeGDT()
|
||||||
kstd::printFormat("GDT loaded\n");
|
kstd::printFormat("GDT loaded\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace memory {
|
||||||
|
|
||||||
|
const u32 pageSize = 4096;
|
||||||
|
const u32 pageMask = pageSize - 1;
|
||||||
|
|
||||||
|
} /* namespace memory */
|
||||||
|
|
||||||
} /* namespace kernel */
|
} /* namespace kernel */
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,30 @@ private:
|
||||||
void initializeGDT();
|
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 */
|
} /* namespace kernel */
|
||||||
|
|
||||||
#endif /* __MEMORY_MEMORY_HH__ */
|
#endif /* __MEMORY_MEMORY_HH__ */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue