My Kernel v0.1.0
mmu.h
Go to the documentation of this file.
1
26#ifndef KERNEL_MMU_H
27#define KERNEL_MMU_H
28
29#include <kernel/error.h>
30#include <kernel/types.h>
31
32#include <stdbool.h>
33
38typedef enum mmu_prot {
39 PROT_NONE = 0x0,
40 PROT_EXEC = 0x1,
41 PROT_READ = 0x2,
42 // TODO: NX bit for PROT_EXEC
43 PROT_WRITE = 0x4,
45} mmu_prot;
46
59bool mmu_init(void);
60
64paddr_t mmu_new(void);
65
70void mmu_destroy(paddr_t mmu);
71
73void mmu_clone(paddr_t destination);
74
76error_t mmu_copy_on_write(vaddr_t);
77
82void mmu_load(paddr_t mmu);
83
94bool mmu_map(vaddr_t virt, paddr_t physical, int prot);
95
107bool mmu_map_range(vaddr_t virt, paddr_t physical, size_t size, int prot);
108
119paddr_t mmu_unmap(vaddr_t virt);
120
126void mmu_unmap_range(vaddr_t start, vaddr_t end);
127
141void mmu_identity_map(paddr_t start, paddr_t end, int prot);
142
146paddr_t mmu_find_physical(vaddr_t);
147
149static inline bool mmu_is_mapped(vaddr_t addr)
150{
151 return !IS_ERR(mmu_find_physical(addr));
152}
153
154#endif /* KERNEL_MMU_H */
#define IS_ERR(_x)
Check if an integer can be interpreted as an error.
Definition: error.h:83
paddr_t mmu_find_physical(vaddr_t)
Find the physical mapping of a virtual address.
Definition: mmu.c:427
void mmu_clone(paddr_t destination)
Clone the current MMU inside another one.
Definition: mmu.c:232
mmu_prot
Protection flags passed to the mmu's functions.
Definition: mmu.h:38
bool mmu_map(vaddr_t virt, paddr_t physical, int prot)
Map a virtual address to a physical one.
Definition: mmu.c:272
void mmu_unmap_range(vaddr_t start, vaddr_t end)
Unmap a range of virtual addresses.
Definition: mmu.c:409
void mmu_destroy(paddr_t mmu)
Release the MMU's page_directory.
Definition: mmu.c:224
paddr_t mmu_unmap(vaddr_t virt)
Unmap a virtual address.
Definition: mmu.c:375
error_t mmu_copy_on_write(vaddr_t)
Try to remap a potential copy-on-write mapping.
Definition: mmu.c:441
void mmu_identity_map(paddr_t start, paddr_t end, int prot)
Perform identity mapping inside a given virtual address range.
Definition: mmu.c:422
paddr_t mmu_new(void)
Allocate and initialize a new page directory.
Definition: mmu.c:198
bool mmu_init(void)
Initialize the MMU's paging system.
Definition: mmu.c:511
bool mmu_map_range(vaddr_t virt, paddr_t physical, size_t size, int prot)
Map a range of virtual addresses to physical ones.
Definition: mmu.c:331
static bool mmu_is_mapped(vaddr_t addr)
Definition: mmu.h:149
void mmu_load(paddr_t mmu)
Replace the current page directory.
Definition: mmu.c:180
@ PROT_READ
Definition: mmu.h:41
@ PROT_WRITE
Definition: mmu.h:43
@ PROT_EXEC
Definition: mmu.h:40
@ PROT_NONE
Definition: mmu.h:39
@ PROT_KERNEL
Definition: mmu.h:44