Modestus Moon OS  R4
CS 450 project
paging.h
Go to the documentation of this file.
1 #ifndef _PAGING_H
2 #define _PAGING_H
3 
4 #include <system.h>
5 
6 #define PAGE_SIZE 0x1000
7 
8 /*
9  Page entry structure
10  Describes a single page in memory
11 */
12 typedef struct {
13  u32int present : 1;
14  u32int writeable : 1;
15  u32int usermode : 1;
16  u32int accessed : 1;
17  u32int dirty : 1;
19  u32int frameaddr : 20;
20 } page_entry;
21 
22 /*
23  Page table structure
24  Contains 1024 pages/frames
25 */
26 typedef struct {
27  page_entry pages[1024];
28 } page_table;
29 
30 /*
31  Page directory structure
32  Limited to 1024 tables for now
33 */
34 typedef struct {
35  page_table *tables[1024];
36  u32int tables_phys[1024];
37 } page_dir;
38 
39 /*
40  Procedure..: set_bit
41  Description..: Marks a page frame bit as in use (1).
42 */
43 void set_bit(u32int addr);
44 
45 /*
46  Procedure..: clear_bit
47  Description..: Marks a page frame bit as free (0).
48 */
49 void clear_bit(u32int addr);
50 
51 /*
52  Procedure..: get_bit
53  Description..: Checks if page frame is in use.
54 */
55 u32int get_bit(u32int addr);
56 
57 /*
58  Procedure..: first_free
59  Description..: Finds the first free page frame.
60 */
62 
63 /*
64  Procedure..: init_paging
65  Description..: Initializes the kernel page directory and
66  initial kernel heap area. Performs identity mapping of
67  the kernel frames such that the virtual addresses are
68  equivalent to the physical addresses.
69 */
70 void init_paging();
71 
72 /*
73  Procedure..: load_page_dir
74  Description..: Sets a page directory as the current
75  directory and enables paging via the cr0 register.
76  The cr3 register enables address translation from
77  linear to physical addresses.
78  http://en.wikipedia.org/wiki/Control_register#Control_registers_in_x86_series
79 */
80 void load_page_dir(page_dir *new_page_dir);
81 
82 /*
83  Procedure..: get_page
84  Description..: Finds and returns a page, allocating a new
85  page table if necessary.
86 */
87 page_entry* get_page(u32int addr, page_dir *dir, int make_table);
88 
89 /*
90  Procedure..: new_frame
91  Description..: Marks a frame as in use in the frame bitmap,
92  sets up the page, and saves the frame index in the page.
93 */
94 void new_frame(page_entry* page);
95 
96 #endif
u32int get_bit(u32int addr)
Definition: paging.c:56
Definition: paging.h:12
void init_paging()
Definition: paging.c:111
void set_bit(u32int addr)
Definition: paging.c:32
void load_page_dir(page_dir *new_page_dir)
Definition: paging.c:158
void new_frame(page_entry *page)
Definition: paging.c:173
unsigned long u32int
Definition: system.h:27
page_entry * get_page(u32int addr, page_dir *dir, int make_table)
Definition: paging.c:85
void clear_bit(u32int addr)
Definition: paging.c:44
void reserved()
u32int first_free()