SimpleKernel 1.17.0
Loading...
Searching...
No Matches
cpu_io::virtual_memory Namespace Reference

Functions

auto GetUserPagePermissions (bool readable=true, bool writable=false, bool executable=false, bool global=false) -> uint64_t
 
auto GetKernelPagePermissions (bool readable=true, bool writable=false, bool executable=false, bool global=false) -> uint64_t
 
void SetPageDirectory (uint64_t pd)
 
auto GetPageDirectory () -> uint64_t
 
void EnablePage ()
 
void FlushTLBAll ()
 
auto GetTableEntryPermissions () -> uint64_t
 
auto GetVirtualPageNumber (uint64_t virtual_addr, size_t level) -> uint64_t
 
auto PageAlign (uint64_t addr) -> uint64_t
 
auto PageAlignUp (uint64_t addr) -> uint64_t
 
auto IsPageAligned (uint64_t addr) -> bool
 
auto IsPageTableEntryValid (uint64_t pte) -> bool
 
auto PageTableEntryToPhysical (uint64_t pte) -> uint64_t
 
auto PhysicalToPageTableEntry (uint64_t physical_addr, uint64_t flags) -> uint64_t
 

Variables

static constexpr size_t kPageSize = 4096
 
static constexpr size_t kPteAttributeBits = 12
 
static constexpr size_t kPageOffsetBits = 12
 
static constexpr size_t kVpnBits = 9
 
static constexpr size_t kVpnMask = 0x1FF
 
static constexpr size_t kPageTableLevels = 4
 
static constexpr uint64_t kValid = 0x1
 
static constexpr uint64_t kWrite = 0x2
 
static constexpr uint64_t kUser = 0x4
 
static constexpr uint64_t kRead = 0x200
 
static constexpr uint64_t kExec = 0x400
 
static constexpr uint64_t kGlobal = 0x100
 

Function Documentation

◆ EnablePage()

void cpu_io::virtual_memory::EnablePage ( )
inline

Definition at line 134 of file cpu_io.h.

134 {
136 assert(env && "TestEnvironmentState not set for current thread");
137 auto& core = env->GetCurrentCoreEnv();
138 core.paging_enabled = true;
139}
static auto GetCurrentThreadEnvironment() -> TestEnvironmentState *
获取当前线程的环境实例指针(供 Mock 层调用)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FlushTLBAll()

void cpu_io::virtual_memory::FlushTLBAll ( )
inline

Definition at line 141 of file cpu_io.h.

141 {
142 // 在测试环境中不需要实际操作
143}
Here is the caller graph for this function:

◆ GetKernelPagePermissions()

auto cpu_io::virtual_memory::GetKernelPagePermissions ( bool  readable = true,
bool  writable = false,
bool  executable = false,
bool  global = false 
) -> uint64_t
inline

Definition at line 99 of file cpu_io.h.

102 {
103 uint64_t flags = kValid; // Kernel pages don't need kUser
104 if (readable) {
105 flags |= kRead;
106 }
107 if (writable) {
108 flags |= kWrite;
109 }
110 if (executable) {
111 flags |= kExec;
112 }
113 if (global) {
114 flags |= kGlobal;
115 }
116 return flags;
117}
static constexpr uint64_t kValid
Definition cpu_io.h:71
static constexpr uint64_t kGlobal
Definition cpu_io.h:76
static constexpr uint64_t kRead
Definition cpu_io.h:74

◆ GetPageDirectory()

auto cpu_io::virtual_memory::GetPageDirectory ( ) -> uint64_t
inline

Definition at line 127 of file cpu_io.h.

127 {
129 assert(env && "TestEnvironmentState not set for current thread");
130 auto& core = env->GetCurrentCoreEnv();
131 return core.page_directory;
132}
Here is the call graph for this function:

◆ GetTableEntryPermissions()

auto cpu_io::virtual_memory::GetTableEntryPermissions ( ) -> uint64_t
inline

Definition at line 146 of file cpu_io.h.

146 {
147 return kValid | kWrite | kUser | kRead | kExec;
148}
static constexpr uint64_t kUser
Definition cpu_io.h:73
static constexpr uint64_t kWrite
Definition cpu_io.h:72
static constexpr uint64_t kExec
Definition cpu_io.h:75
Here is the caller graph for this function:

◆ GetUserPagePermissions()

auto cpu_io::virtual_memory::GetUserPagePermissions ( bool  readable = true,
bool  writable = false,
bool  executable = false,
bool  global = false 
) -> uint64_t
inline

Definition at line 79 of file cpu_io.h.

81 {
82 uint64_t flags = kValid | kUser;
83 if (readable) {
84 flags |= kRead;
85 }
86 if (writable) {
87 flags |= kWrite;
88 }
89 if (executable) {
90 flags |= kExec;
91 }
92 if (global) {
93 flags |= kGlobal;
94 }
95 return flags;
96}
Here is the caller graph for this function:

◆ GetVirtualPageNumber()

auto cpu_io::virtual_memory::GetVirtualPageNumber ( uint64_t  virtual_addr,
size_t  level 
) -> uint64_t
inline

Definition at line 151 of file cpu_io.h.

152 {
153 return (virtual_addr >> (kPageOffsetBits + level * kVpnBits)) & kVpnMask;
154}
static constexpr size_t kVpnMask
Definition cpu_io.h:67
Here is the caller graph for this function:

◆ IsPageAligned()

auto cpu_io::virtual_memory::IsPageAligned ( uint64_t  addr) -> bool
inline

Definition at line 165 of file cpu_io.h.

165 {
166 return (addr & (kPageSize - 1)) == 0;
167}

◆ IsPageTableEntryValid()

auto cpu_io::virtual_memory::IsPageTableEntryValid ( uint64_t  pte) -> bool
inline

Definition at line 170 of file cpu_io.h.

170 {
171 return (pte & kValid) != 0;
172}
Here is the caller graph for this function:

◆ PageAlign()

auto cpu_io::virtual_memory::PageAlign ( uint64_t  addr) -> uint64_t
inline

Definition at line 157 of file cpu_io.h.

157 {
158 return addr & ~(kPageSize - 1);
159}
static constexpr size_t kPageSize
Definition cpu_io.h:63
Here is the caller graph for this function:

◆ PageAlignUp()

auto cpu_io::virtual_memory::PageAlignUp ( uint64_t  addr) -> uint64_t
inline

Definition at line 161 of file cpu_io.h.

161 {
162 return (addr + kPageSize - 1) & ~(kPageSize - 1);
163}
Here is the caller graph for this function:

◆ PageTableEntryToPhysical()

auto cpu_io::virtual_memory::PageTableEntryToPhysical ( uint64_t  pte) -> uint64_t
inline

Definition at line 174 of file cpu_io.h.

174 {
175 return pte & 0x000FFFFFFFFFF000ULL;
176}
Here is the caller graph for this function:

◆ PhysicalToPageTableEntry()

auto cpu_io::virtual_memory::PhysicalToPageTableEntry ( uint64_t  physical_addr,
uint64_t  flags 
) -> uint64_t
inline

Definition at line 178 of file cpu_io.h.

179 {
180 return (physical_addr & 0x000FFFFFFFFFF000ULL) | (flags & 0xFFF) |
181 (flags & (1ULL << 63));
182}
Here is the caller graph for this function:

◆ SetPageDirectory()

void cpu_io::virtual_memory::SetPageDirectory ( uint64_t  pd)
inline

Definition at line 120 of file cpu_io.h.

120 {
122 assert(env && "TestEnvironmentState not set for current thread");
123 auto& core = env->GetCurrentCoreEnv();
124 core.page_directory = pd;
125}
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ kExec

constexpr uint64_t cpu_io::virtual_memory::kExec = 0x400
staticconstexpr

Definition at line 75 of file cpu_io.h.

◆ kGlobal

constexpr uint64_t cpu_io::virtual_memory::kGlobal = 0x100
staticconstexpr

Definition at line 76 of file cpu_io.h.

◆ kPageOffsetBits

constexpr size_t cpu_io::virtual_memory::kPageOffsetBits = 12
staticconstexpr

Definition at line 65 of file cpu_io.h.

◆ kPageSize

constexpr size_t cpu_io::virtual_memory::kPageSize = 4096
staticconstexpr

Definition at line 63 of file cpu_io.h.

◆ kPageTableLevels

constexpr size_t cpu_io::virtual_memory::kPageTableLevels = 4
staticconstexpr

Definition at line 68 of file cpu_io.h.

◆ kPteAttributeBits

constexpr size_t cpu_io::virtual_memory::kPteAttributeBits = 12
staticconstexpr

Definition at line 64 of file cpu_io.h.

◆ kRead

constexpr uint64_t cpu_io::virtual_memory::kRead = 0x200
staticconstexpr

Definition at line 74 of file cpu_io.h.

◆ kUser

constexpr uint64_t cpu_io::virtual_memory::kUser = 0x4
staticconstexpr

Definition at line 73 of file cpu_io.h.

◆ kValid

constexpr uint64_t cpu_io::virtual_memory::kValid = 0x1
staticconstexpr

Definition at line 71 of file cpu_io.h.

◆ kVpnBits

constexpr size_t cpu_io::virtual_memory::kVpnBits = 9
staticconstexpr

Definition at line 66 of file cpu_io.h.

◆ kVpnMask

constexpr size_t cpu_io::virtual_memory::kVpnMask = 0x1FF
staticconstexpr

Definition at line 67 of file cpu_io.h.

◆ kWrite

constexpr uint64_t cpu_io::virtual_memory::kWrite = 0x2
staticconstexpr

Definition at line 72 of file cpu_io.h.