diff --git a/kernel/include/paging.hpp b/kernel/include/paging.hpp index 237f06cf..87afd055 100644 --- a/kernel/include/paging.hpp +++ b/kernel/include/paging.hpp @@ -12,7 +12,7 @@ namespace paging { -const int PAGE_SIZE = 4096; +constexpr const int PAGE_SIZE = 4096; void* physical_address(void* virt); bool page_present(void* virt); diff --git a/kernel/include/utils.hpp b/kernel/include/utils.hpp index 023484c8..07698fb7 100644 --- a/kernel/include/utils.hpp +++ b/kernel/include/utils.hpp @@ -10,6 +10,26 @@ #include "types.hpp" +namespace std { + +template +void fill(ForwardIterator it, ForwardIterator end, const T& value){ + while(it != end){ + *it = value; + ++it; + } +} + +template +void fill_n(ForwardIterator it, size_t n, const T& value){ + while(n--){ + *it = value; + ++it; + } +} + +} //end of namespace std + template struct basic_string; typedef basic_string string; @@ -20,7 +40,6 @@ uint64_t parse(const string& str); uint64_t str_len(const char* a); -void memset(void * ptr, uint8_t value, size_t num); int memcmp(const void* s1, const void* s2, size_t n); void memcopy(void* destination, const void* source, size_t n); diff --git a/kernel/src/paging.cpp b/kernel/src/paging.cpp index f46f1040..123fe9ba 100644 --- a/kernel/src/paging.cpp +++ b/kernel/src/paging.cpp @@ -19,17 +19,18 @@ typedef pt_t* pdt_t; typedef pdt_t* pdpt_t; typedef pdpt_t* pml4t_t; -constexpr int PRESENT = 0x1; -constexpr int WRITEABLE = 0x2; -constexpr int USER = 0x4; +constexpr const int PRESENT = 0x1; +constexpr const int WRITEABLE = 0x2; +constexpr const int USER = 0x4; //Memory from 0x70000 can be used for pages uintptr_t last_page = 0x73000; uintptr_t init_new_page(){ auto new_page = last_page + paging::PAGE_SIZE; + auto it = reinterpret_cast(new_page); - memset(reinterpret_cast(new_page), 0, paging::PAGE_SIZE); + std::fill(it, it + paging::PAGE_SIZE / sizeof(size_t), 0); last_page = new_page; diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp index d1f76ec4..a92fd4cd 100644 --- a/kernel/src/shell.cpp +++ b/kernel/src/shell.cpp @@ -25,9 +25,9 @@ namespace { #ifdef CONFIG_HISTORY -static constexpr bool History = true; +static constexpr const bool History = true; #else -static constexpr bool History = false; +static constexpr const bool History = false; #endif vector history; diff --git a/kernel/src/utils.cpp b/kernel/src/utils.cpp index c5dfb204..5f0aa8e6 100644 --- a/kernel/src/utils.cpp +++ b/kernel/src/utils.cpp @@ -8,16 +8,6 @@ #include "utils.hpp" #include "string.hpp" -void memset(void* ptr, unsigned char value, size_t num){ - auto p = static_cast(ptr); - - --p; - - while(num--){ - *++p = value; - } -} - int memcmp(const void* s1, const void* s2, size_t n){ auto p1 = static_cast(s1); auto p2 = static_cast(s2);