Kernel: Make Utilities be inline
This commit is contained in:
parent
531b2848ac
commit
9f2c9fb190
@ -1,13 +1,37 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef PAGE_SIZE
|
||||
#define PAGE_SIZE 4096
|
||||
#endif
|
||||
|
||||
extern "C" uint64_t asm_get_rflags();
|
||||
|
||||
namespace Utilities
|
||||
{
|
||||
uint64_t get_blocks_from_size(uint64_t blocksize,
|
||||
uint64_t size); // Returns how many blocks of size blocksize does size occupy.
|
||||
inline uint64_t get_blocks_from_size(uint64_t blocksize, uint64_t size)
|
||||
{
|
||||
return (size + (blocksize - 1)) / blocksize;
|
||||
}
|
||||
|
||||
uint64_t get_rflags();
|
||||
uint64_t get_top_of_stack(uint64_t bottom, uint64_t stack_pages);
|
||||
uint64_t round_down_to_nearest_page(uint64_t addr);
|
||||
uint64_t round_up_to_nearest_page(uint64_t addr);
|
||||
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);
|
||||
}
|
||||
|
||||
inline uint64_t round_up_to_nearest_page(uint64_t addr)
|
||||
{
|
||||
if (addr % PAGE_SIZE) return addr + (PAGE_SIZE - (addr % PAGE_SIZE));
|
||||
return addr;
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
#include "misc/utils.h"
|
||||
|
||||
#ifndef PAGE_SIZE
|
||||
#define PAGE_SIZE 4096
|
||||
#endif
|
||||
|
||||
uint64_t Utilities::get_blocks_from_size(uint64_t blocksize, uint64_t size)
|
||||
{
|
||||
return (size + (blocksize - 1)) / blocksize;
|
||||
}
|
||||
|
||||
extern "C" uint64_t asm_get_rflags();
|
||||
uint64_t Utilities::get_rflags()
|
||||
{
|
||||
return asm_get_rflags();
|
||||
}
|
||||
|
||||
uint64_t Utilities::get_top_of_stack(uint64_t bottom, uint64_t stack_pages)
|
||||
{
|
||||
return bottom + (stack_pages * PAGE_SIZE) - sizeof(uintptr_t);
|
||||
}
|
||||
|
||||
uint64_t Utilities::round_down_to_nearest_page(uint64_t addr)
|
||||
{
|
||||
return addr - (addr % PAGE_SIZE);
|
||||
}
|
||||
|
||||
uint64_t Utilities::round_up_to_nearest_page(uint64_t addr)
|
||||
{
|
||||
if (addr % PAGE_SIZE) return addr + (PAGE_SIZE - (addr % PAGE_SIZE));
|
||||
return addr;
|
||||
}
|
Loading…
Reference in New Issue
Block a user