aboutsummaryrefslogtreecommitdiff
path: root/i686/paging.h
blob: f9c04a8a3f3ee6f830e8fc04022f25790e6c5ce5 (plain)
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
#pragma once

// DirectoryEntry
// |31|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |11|  | 9| 8| 7| 6| 5| 4| 3| 2| 1| 0|
// |   page table 4-kb aligned address                         | avail  | G| S|  | A| C| W| U| R| P|
struct __attribute__((packed)) DirectoryEntry {
  unsigned present : 1;      // 0: if set, the page is actually in physical memory
  unsigned writeable : 1;    // 1: if set, the page is read/write; otherwise the page is read-only
  unsigned user : 1;         // 2: if set, then page can be access by all; otherwise only the supervisor can access it
  unsigned writethrough : 1; // 3: if set, write-through caching is enabled; otherwise write-back is enabled instead
  unsigned cachedisable : 1; // 4: if set, the page will not be cached
  unsigned accessed : 1;     // 5: set by the CPU when the page is read from or written to
  unsigned dirty : 1;        // 6: used to determine whether a page has been written to
  unsigned pagesize : 1;     // 7: page size == 0
  unsigned global : 1;
  unsigned int __available__ : 3; // available to the OS
  unsigned int address : 20;
};
_Static_assert(sizeof(struct DirectoryEntry) == 4, "DirectoryEntry size");

// DirectoryEntry4MB
// |31|  |  |  |  |  |  |  |  |22|21|20|  |  |  |  |  |  |13|12|11|  | 9| 8| 7| 6| 5| 4| 3| 2| 1| 0|
// |   bits 31-22 of address     |RS|   bits 39-22 of       |AT| avail  | G|PS| D| A|CD|WT|US|RW| P|
// |                             |VD|   address
struct __attribute__((packed)) DirectoryEntry4MB {
  unsigned present : 1;      // 0: if set, the page is actually in physical memory
  unsigned writeable : 1;    // 1: if set, the page is read/write; otherwise the page is read-only
  unsigned useraccess : 1;   // 2: if set, then page can be access by all; otherwise only the supervisor can access it
  unsigned writethrough : 1; // 3: if set, write-through caching is enabled; otherwise write-back is enabled instead
  unsigned cachedisable : 1; // 4: if set, the page will not be cached
  unsigned accessed : 1;     // 5: set by the CPU when the page is read from or written to
  unsigned dirty : 1;        // 6: used to determine whether a page has been written to
  unsigned pagesize : 1;     // 7: page size == 1
  unsigned global : 1;       // 8:
  unsigned __available__ : 3; // 11..9 available to the OS
  unsigned pat : 1;           // 12: page attribute table
  unsigned int address_high : 8;
  unsigned rsvd : 1; // 21
  unsigned int address_low : 10;
};
_Static_assert(sizeof(struct DirectoryEntry4MB) == 4, "DirectoryEntry4M size");

// TableEntry
// |31|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |11|  | 9| 8| 7| 6| 5| 4| 3| 2| 1| 0|
// |   page table 4-kb aligned address                         | avail  | G|  | D| A| C| W|US|RW| P|
struct __attribute__((packed)) TableEntry {
  unsigned present : 1;      // if set, the page is actually in physical memory
  unsigned writeable : 1;    // if set, the page is read/write; otherwise the page is read-only
  unsigned user : 1;         // if set, then page can be access by all; otherwise only the supervisor can access it
  unsigned writethrough : 1; // if set, write-through caching is enabled; otherwise write-back is enabled instead
  unsigned cachedisable : 1; // if set, the page will not be cached
  unsigned accessed : 1;     // set by the CPU when the page is read from or written to
  unsigned dirty : 1;        // used to determine whether a page has been written to
  unsigned pat : 1;          // page attribute table?
  unsigned global : 1;
  unsigned int __available__ : 3; // available to the OS
  unsigned int address : 20;
};
_Static_assert(sizeof(struct TableEntry) == 4, "TableEntry size");