diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index f5300f3..0391d73 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -30,4 +30,7 @@ void *memset(void *s, int c, size_t n); void *memmove(void *dest, const void *src, size_t n); int memcmp(const void *s1, const void *s2, size_t n); size_t strlen(const char *s); + +void pmm_free(uintptr_t page); +uintptr_t pmm_alloc(); #endif diff --git a/src/kernel/memory/pmm.c b/src/kernel/memory/pmm.c index e0df00b..5f1c679 100644 --- a/src/kernel/memory/pmm.c +++ b/src/kernel/memory/pmm.c @@ -1,18 +1,18 @@ #include -uintptr_t *first = 0; +uintptr_t first = 0; -void pmm_free(void *c) +void pmm_free(uintptr_t page) { - c = (void *)P2V(c); - *(uintptr_t **)c = first; - first = c; + page = (uintptr_t)P2V(page); + *(uintptr_t *)page = first; + first = page; } -void *pmm_alloc() +uintptr_t pmm_alloc() { - void *c = first; - first = c?*(uintptr_t **)c:0; - c = (void *)V2P(c); - return c; + uintptr_t page = first; + first = page?*(uintptr_t *)page:0; + page = (uintptr_t)V2P(page); + return page; } diff --git a/src/kernel/memory/pmm.tt b/src/kernel/memory/pmm.tt index 71732d6..cb9b8e1 100644 --- a/src/kernel/memory/pmm.tt +++ b/src/kernel/memory/pmm.tt @@ -14,44 +14,44 @@ struct { TEST(alloc_returns_freed_page) { - pmm_free(&mem[0]); - void *a = pmm_alloc(); + pmm_free((uintptr_t)&mem[0]); + uintptr_t a = pmm_alloc(); ASSERT_EQ_PTR(a, &mem[0]); } TEST(alloc_returns_0_if_no_free_pages) { - void *a = pmm_alloc(); + uintptr_t a = pmm_alloc(); ASSERT_EQ_PTR(a, 0); } TEST(alloc_zero_after_all_free_pages) { - pmm_free(&mem[0]); + pmm_free((uintptr_t)&mem[0]); pmm_alloc(); - void *a = pmm_alloc(); + uintptr_t a = pmm_alloc(); ASSERT_EQ_PTR(a, 0); } TEST(alloc_two_pages___first_page_is_not_zero) { - pmm_free(&mem[0]); - pmm_free(&mem[1]); - void *a = pmm_alloc(); + pmm_free((uintptr_t)&mem[0]); + pmm_free((uintptr_t)&mem[1]); + uintptr_t a = pmm_alloc(); pmm_alloc(); ASSERT_NEQ_PTR(a, 0); } TEST(alloc_two_pages___second_page_is_not_zero) { - pmm_free(&mem[0]); - pmm_free(&mem[1]); + pmm_free((uintptr_t)&mem[0]); + pmm_free((uintptr_t)&mem[1]); pmm_alloc(); - void *a = pmm_alloc(); + uintptr_t a = pmm_alloc(); ASSERT_NEQ_PTR(a, 0); } TEST(alloc_two_pages___doesnt_return_same_page_twice) { - pmm_free(&mem[0]); - pmm_free(&mem[1]); - void *a = pmm_alloc(); - void *b = pmm_alloc(); + pmm_free((uintptr_t)&mem[0]); + pmm_free((uintptr_t)&mem[1]); + uintptr_t a = pmm_alloc(); + uintptr_t b = pmm_alloc(); ASSERT_NEQ_PTR(a, b); }