aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/paging/paging.h
blob: 681b84e80ccdc3e1343ad0bd40d1e7cf591461c1 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef MELVIX_PAGING_H
#define MELVIX_PAGING_H

#include <stdint.h>
#include "../interrupts/interrupts.h"

typedef struct page {
    uint32_t present    : 1;   // Page present in memory
    uint32_t rw         : 1;   // Read-only if clear, readwrite if set
    uint32_t user       : 1;   // Supervisor level only if clear
    uint32_t accessed   : 1;   // Has the page been accessed since last refresh?
    uint32_t dirty      : 1;   // Has the page been written to since last refresh?
    uint32_t unused     : 7;   // Amalgamation of unused and reserved bits
    uint32_t 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];
    uint32_t tablesPhysical[1024];
    uint32_t physicalAddr;
} page_directory_t;

/**
 * Initialize the environment and enable paging
 */
void initialise_paging();

/**
 * Enable paging bit in CR0 (without initializing)
 */
void enable_paging();

/**
 * Disable paging bit in CR0
 */
void disable_paging();

/**
 * Load the page directory into the CR3 register
 * @param new The page directory
 */
void switch_page_directory(page_directory_t *new);

/**
 * Get a specific page pointer
 * @param address The page address
 * @param make If 1 create the page first
 * @param dir The page directory
 * @return The page pointer
 */
page_t *get_page(uint32_t address, int make, page_directory_t *dir);

/**
 * Page fault handler
 * @param r The IRQ registers
 */
void page_fault(struct regs *r);

void alloc_frame(page_t *page, int is_kernel, int is_writeable);

void free_frame(page_t *page);

/**
 * Copy/clone a page directory
 * @param src The page directory
 * @return A new page directory pointer
 */
page_directory_t *clone_directory(page_directory_t *src);

#endif