-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.h
65 lines (53 loc) · 1.4 KB
/
page.h
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
61
62
63
64
65
#ifndef PAGE_H
#define PAGE_H
/*
// Page directory entry
typedef struct {
unsigned int present : 1;
unsigned int r_w : 1; // Read/write
unsigned int u_s : 1; // User/supervisor
unsigned int accessed: 1;
unsigned int unused : 8;
unsigned int phyaddr : 20; // Physical address
}__attribute__((packed)) dir_t;
*/
// Page table entry
struct page {
unsigned int present : 1;
unsigned int r_w : 1; // Read/write
unsigned int u_s : 1; // User/supervisor
unsigned int unused1 : 2;
unsigned int accessed: 1;
unsigned int dirty : 1;
unsigned int unused : 4;
unsigned int pinned : 1; // Can it be swapped out?
unsigned int frame : 20; // Physical address
}__attribute__((packed));
typedef struct page page_t;
// A Page table
struct page_table {
page_t pages[1024];
};
typedef struct page_table page_table_t;
// A Directory
struct page_dir {
uint dirs[1024]; // the array of directory entries
page_table_t *pagetables[1024];
};
typedef struct page_dir page_dir_t;
page_dir_t *kernel_dir;
// Control register
#define CR0_PG 0x80000000 // Paging Enable
#define CR0_WP 0x00010000 // Write protect
#define CR4_PAE 0x00000020
// Memory offsets
// +---------+---------+----------+
// | Dir | Page | Offset |
// +---------+---------+----------+
// 10 10 12
#define DIR_L 0x400
#define PAGE_L 0x400
#define OFFSET_L 0x1000
// Some addresses
#define KSTART_A 0x00100000
#endif