summaryrefslogtreecommitdiff
path: root/src/include/mm/paging.h
blob: 7ff9e7a6cbe2dbc8ad340bac5e5da2f3a89d6c3d (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef PAGING_H
#define PAGING_H

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

/*
 * Virtual address bits meaning
 *
 * [	    31-22	|      21-12	 |	  11-00	      ]
 * [ Page directory Idx | Page table Idx | Offset within page ]
 *
 *
 */
#define PAGING_DIRECTORY_BITS	(22)
#define PAGING_TABLE_BITS	(12)
#define PAGING_TABLE_MASK	(0x3ff)
#define PAGING_PAGE_OFFSET_MASK	(0xfff)

/* Page directory control bits */
#define PAGING_CACHE_DISABLED	(1 << 4)
#define PAGING_WRITE_THROUGH	(1 << 3)
#define PAGING_USER_ACCESS	(1 << 2)
#define PAGING_IS_WRITABLE	(1 << 1)
#define PAGING_IS_PRESENT	(1 << 0)

#define PAGING_ENTRIES_PER_TABLE	1024

struct page_directory
{
	uint32_t	*directory;
};

struct page_directory * paging_new_directory(uint8_t flags);
uint32_t * paging_get_directory(struct page_directory *pd);
void paging_switch(struct page_directory *directory);

void enable_paging();

bool paging_is_aligned(void *addr);
int paging_map_vaddr(struct page_directory *directory,
		     void *vaddr,
		     void *paddr,
		     uint32_t val);

#endif /* PAGING_H */