Iros
 
Loading...
Searching...
No Matches
page_structure.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/bit/prelude.h"
5
7using namespace di::bit;
8
9// The format of the amd64 paging structures in long mode is described
10// in the AMD64 Programmer's Manual; Volume 2; Figure 5-18, 5-19, 5-20, and 5-21.
11struct Present : BitFlag<0> {};
12struct Writable : BitFlag<1> {};
13struct User : BitFlag<2> {};
14
15// This bit is obsolete in the amd64 architecture. See Table 7-4 from the amd manual.
16struct WriteThrough : BitFlag<3> {};
17
18// This bit allows disabling the cache when reading and writing to memory. This
19// may be necessary on real-hardware when dealing with memory-mapped IO registers.
20struct CacheDisable : BitFlag<4> {};
21
22// This bit is set by the CPU when a corresponding section of memory is accessed.
23// This can be used to collect memory usage decisions to effect swap and disk cache
24// behavior.
25struct Accessed : BitFlag<5> {};
26
27// This bit is set by the CPU when a write has been made to an individual page.
28// This can be used to know whether pages need to be flushed to disk when using
29// memory-mapped file IO.
30struct Dirty : BitFlag<6> {};
31
32// This bit enables either 2 MiB paging or 1 GiB paging, depending on which tier
33// entry is being used.
34struct HugePage : BitFlag<7> {};
35
36// This bit prevents TLB flushed (reloading cr3) from effecting these pages.
37// This is ideally used to kernel pages, which are present in all address spaces.
38// However, some mitigations for spectre and meltdown may restrict its usage.
39struct Global : BitFlag<8> {};
40
41// This is the structure which stores the actual physical address which the
42// CPU accesses. It must be page-aligned, and the lowest 12 bits must be dropped.
43struct PhysicalAddress : BitField<12, 40> {};
44
45struct NotExecutable : BitFlag<63> {};
46
49
51
52// The translation of virtual addresses to physical addresses is defined illustrated
53// in Figure 5-17 of the AMD64 Programmer's Manual; Volume 2.
54struct Pml4Offset : BitField<39, 9> {};
55struct PdpOffset : BitField<30, 9> {};
56struct PdOffset : BitField<21, 9> {};
57struct PtOffset : BitField<12, 9> {};
58struct PhysicalOffset : BitField<0, 12> {};
59
61}
Definition bit_struct.h:11
Definition bit_proxy_reference.h:5
Definition page_structure.h:6
di::Array< StructureEntry, 512 > PageStructureTable
Definition page_structure.h:50
BitStruct< 8, Pml4Offset, PdpOffset, PdOffset, PtOffset, PhysicalOffset > VirtualAddressStructure
Definition page_structure.h:60
BitStruct< 8, Present, Writable, User, WriteThrough, CacheDisable, Accessed, Dirty, HugePage, Global, PhysicalAddress, NotExecutable > StructureEntry
Definition page_structure.h:47
constexpr BitField(Value value)
Definition bit_field.h:28
constexpr BitFlag(bool value)
Definition bit_flag.h:19
Definition span_fixed_size.h:37
Definition page_structure.h:25
Definition page_structure.h:30
Definition page_structure.h:39
Definition page_structure.h:34
Definition page_structure.h:56
Definition page_structure.h:55
Definition page_structure.h:54
Definition page_structure.h:11
Definition page_structure.h:57
Definition page_structure.h:13
Definition page_structure.h:12