blob: 1fce506a758e54bf705c6ca15bed50f40e9171a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#include <kernel/arch/generic.h>
#include <kernel/mem.h>
#include <stdint.h>
static void *highest_page;
void mem_init(struct kmain_info *info) {
// finds the highest used page, and starts allocating pages above it
void *highest = &_bss_end;
size_t page_mask = PAGE_SIZE - 1;
if (highest < info->init.at + info->init.size)
highest = info->init.at + info->init.size;
// align up to PAGE_SIZE
highest_page = (void*)(((uintptr_t)highest + page_mask) & ~page_mask);
}
void *page_alloc(size_t pages) {
void *bottom = highest_page;
highest_page += pages * PAGE_SIZE;
return bottom;
}
// frees `pages` consecutive pages starting from *first
void page_free(void *first, size_t pages) {
// not implemented
}
|