-
Notifications
You must be signed in to change notification settings - Fork 0
/
paging.h
54 lines (42 loc) · 1.64 KB
/
paging.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
// paging.h
// Enables paging management for the kernel (x86 arch).
// Based on JamesM's kernel tutorial.
#ifndef PAGING_H
#define PAGING_H
#include "common.h"
#include "isr.h"
typedef struct page
{
u32int present : 1; // Page present in memory.
u32int rw : 1; // Read-only if clear, readwrite if set.
u32int user : 1; // Supervisor level only if clear.
u32int accessed : 1; // Has the page been accessed since last refresh?
u32int dirty : 1; // Has the page been written to since last refresh?
u32int unused : 7; // Amalgamation of unused and reserved bits.
u32int frame : 20; // Frame address (shifted right 12 bits).
} page_t;
typedef struct page_table
{
page_t pages[1024];
} page_table_t;
typedef struct page_directory
{
page_table_t *tables[1024]; // Array of pointers to pagetables.
u32int tablesPhysical[1024]; // Array of pointers to physical location.
u32int physicalAddr; // The physical address ot tablesPhysical.
} page_directory_t;
// Sets up the environment, page directoruies etc and enables paging.
void initialise_paging(void);
// Causes the specified page directory to be loaded into the CR3 register.
void switch_page_directory(page_directory_t *new_pd);
/**
Retrieves a pointer tot he page required.
If make == 1, if the page table in which this page should
reside isn't created, create it!
**/
page_t *get_page(u32int address, int make, page_directory_t *dir);
// Handler for page faults.
void page_fault(registers_t regs);
void alloc_frame(page_t *page, int is_kernel, int is_writtable);
void free_frame(page_t *page);
#endif