aboutsummaryrefslogtreecommitdiff
path: root/i686/paging.h
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-10-29 11:26:44 +0300
committeraqua <aqua@iserlohn-fortress.net>2022-10-29 11:26:44 +0300
commitc4fcc92183c55db868d0d6ae53e6009fb2e53ee5 (patch)
treead5ef50aa07465e11f779c4482e20e6071182e9c /i686/paging.h
parentmakefile: add libk target (diff)
downloadkernel-c4fcc92183c55db868d0d6ae53e6009fb2e53ee5.tar.xz
makefile: add i686/arch.a target
Diffstat (limited to 'i686/paging.h')
-rw-r--r--i686/paging.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/i686/paging.h b/i686/paging.h
new file mode 100644
index 0000000..cff0506
--- /dev/null
+++ b/i686/paging.h
@@ -0,0 +1,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);
+
+// 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);
+
+// 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);