aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/memory/paging.h
blob: ac0dbfaa095d2a2dd2679a6625925095a7947271 (plain) (blame)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef MELVIX_PAGING_H
#define MELVIX_PAGING_H

#include <stdint.h>

#define PAGE_SIZE 0x1000
#define PAGE_COUNT 1024
#define SHIFT(address) ((address) >> 12)
#define UNSHIFT(address) ((address) << 12)

int paging_enabled;

struct page_table_entry {
	u32 present : 1;
	u32 writable : 1;
	u32 user : 1;
	u32 write_through : 1;
	u32 cache_disable : 1;
	u32 accessed : 1;
	u32 dirty : 1;
	u32 attribute : 1;
	u32 global : 1;
	u32 available : 3;
	u32 address : 20;
} __attribute__((packed));

struct page_table {
	struct page_table_entry entries[PAGE_COUNT];
};

struct page_dir_entry {
	u32 present : 1;
	u32 writable : 1;
	u32 user : 1;
	u32 write_through : 1;
	u32 cache_disable : 1;
	u32 accessed : 1;
	u32 reserved : 1;
	u32 page_size : 1;
	u32 global : 1;
	u32 available : 3;
	u32 address : 20;
} __attribute__((packed));

struct page_dir {
	struct page_dir_entry entries[PAGE_COUNT];
};

void paging_install();
void paging_enable();
void paging_disable();
void paging_switch_directory(u32 dir);

struct page_table_entry *paging_get_page(u32 address, struct page_dir *page_dir);
void paging_frame_alloc(struct page_table_entry *page);
void paging_frame_free(struct page_table_entry *page);
struct page_dir *paging_make_dir();
void paging_free_dir();

#endif