Kernel: Make Utilities be inline

This commit is contained in:
apio 2022-10-13 17:17:28 +02:00
parent 531b2848ac
commit 9f2c9fb190
2 changed files with 30 additions and 38 deletions

View File

@ -1,13 +1,37 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif
extern "C" uint64_t asm_get_rflags();
namespace Utilities namespace Utilities
{ {
uint64_t get_blocks_from_size(uint64_t blocksize, inline uint64_t get_blocks_from_size(uint64_t blocksize, uint64_t size)
uint64_t size); // Returns how many blocks of size blocksize does size occupy. {
return (size + (blocksize - 1)) / blocksize;
}
uint64_t get_rflags(); inline 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); return asm_get_rflags();
uint64_t round_up_to_nearest_page(uint64_t addr); }
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;
}
} }

View File

@ -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;
}