diff --git a/kernel/include/misc/utils.h b/kernel/include/misc/utils.h index 510200eb..7bb36f17 100644 --- a/kernel/include/misc/utils.h +++ b/kernel/include/misc/utils.h @@ -1,13 +1,37 @@ #pragma once #include +#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; + } } \ No newline at end of file diff --git a/kernel/src/misc/utils.cpp b/kernel/src/misc/utils.cpp deleted file mode 100644 index 6607f9fe..00000000 --- a/kernel/src/misc/utils.cpp +++ /dev/null @@ -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; -} \ No newline at end of file