2022-10-01 10:13:38 +00:00
|
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2022-10-13 15:17:28 +00:00
|
|
|
#ifndef PAGE_SIZE
|
|
|
|
#define PAGE_SIZE 4096
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern "C" uint64_t asm_get_rflags();
|
|
|
|
|
2022-10-01 10:13:38 +00:00
|
|
|
namespace Utilities
|
|
|
|
{
|
2022-10-13 15:17:28 +00:00
|
|
|
inline uint64_t get_blocks_from_size(uint64_t blocksize, uint64_t size)
|
|
|
|
{
|
|
|
|
return (size + (blocksize - 1)) / blocksize;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint64_t get_rflags()
|
|
|
|
{
|
|
|
|
return asm_get_rflags();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint64_t get_top_of_stack(uint64_t bottom, uint64_t stack_pages)
|
|
|
|
{
|
|
|
|
return bottom + (stack_pages * PAGE_SIZE) - sizeof(uintptr_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint64_t round_down_to_nearest_page(uint64_t addr)
|
|
|
|
{
|
|
|
|
return addr - (addr % PAGE_SIZE);
|
|
|
|
}
|
2022-10-12 10:56:55 +00:00
|
|
|
|
2022-10-13 15:17:28 +00:00
|
|
|
inline uint64_t round_up_to_nearest_page(uint64_t addr)
|
|
|
|
{
|
|
|
|
if (addr % PAGE_SIZE) return addr + (PAGE_SIZE - (addr % PAGE_SIZE));
|
|
|
|
return addr;
|
|
|
|
}
|
2022-10-01 10:13:38 +00:00
|
|
|
}
|