aboutsummaryrefslogtreecommitdiff
path: root/arch/i686/include/paging.h
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-03-28 20:03:38 +0300
committeraqua <aqua@iserlohn-fortress.net>2022-08-12 10:13:59 +0300
commitedf9e71e2a7b6b89775c29cf28c19c6b89992c25 (patch)
tree3adbf944d9e47a743063487c4facb7eed1fbdee0 /arch/i686/include/paging.h
downloadkernel-edf9e71e2a7b6b89775c29cf28c19c6b89992c25.tar.xz
Initial commit
x86 kernel that prints a hello world message to com1
Diffstat (limited to 'arch/i686/include/paging.h')
-rw-r--r--arch/i686/include/paging.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/arch/i686/include/paging.h b/arch/i686/include/paging.h
new file mode 100644
index 0000000..cff0506
--- /dev/null
+++ b/arch/i686/include/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);