-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvm.c
More file actions
45 lines (36 loc) · 1.33 KB
/
Copy pathvm.c
File metadata and controls
45 lines (36 loc) · 1.33 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* SPDX-License-Identifier: MIT */
#include <pmm.h>
#include <balloc.h>
#include <mmu.h>
extern int __code_start;
extern int __end;
extern void vmm_init_preheap(void);
extern x86_mmu_status_t x86_mmu_query(vaddr_t vaddr, paddr_t *paddr,
uint32_t *flags);
static void mark_pages_in_use(vaddr_t va, size_t len)
{
va = ROUND_DOWN(va, PAGE_SIZE);
len = PAGE_ALIGN(len + (va & (PAGE_SIZE - 1)));
for (size_t offset = 0; offset < len; offset += PAGE_SIZE) {
uint32_t flags;
paddr_t pa;
/* look up the physical address for the virtual address */
x86_mmu_status_t status = x86_mmu_query(va, &pa, NULL);
if (status == MMU_NO_ERROR) {
/* once we have the physical address we need to allocate pages for
the physical address to set those pages as non free. */
pmm_alloc_range(pa, 1, NULL);
}
}
}
void vm_init_preheap(void)
{
vmm_init_preheap();
/* mark all the kernel pages in use */
mark_pages_in_use((uintptr_t)&__code_start,
((uintptr_t)&__end - (uintptr_t)&__code_start));
/* mark all the pages used by the boot time allocator as used */
if (boot_alloc_start != boot_alloc_end) {
mark_pages_in_use(boot_alloc_start, boot_alloc_end - boot_alloc_start);
}
}