5#ifndef SIMPLEKERNEL_TESTS_UNIT_TEST_MOCKS_CPU_IO_H_
6#define SIMPLEKERNEL_TESTS_UNIT_TEST_MOCKS_CPU_IO_H_
14#include <unordered_map>
22 std::this_thread::yield();
29 "TestEnvironmentState not set for current thread. "
30 "Did you forget to call SetCurrentThreadEnvironment()?");
31 return env->GetCoreIdForThread(std::this_thread::get_id());
36 assert(env &&
"TestEnvironmentState not set for current thread");
37 auto& core = env->GetCurrentCoreEnv();
38 core.interrupt_enabled =
true;
43 assert(env &&
"TestEnvironmentState not set for current thread");
44 auto& core = env->GetCurrentCoreEnv();
45 core.interrupt_enabled =
false;
50 assert(env &&
"TestEnvironmentState not set for current thread");
51 auto& core = env->GetCurrentCoreEnv();
52 return core.interrupt_enabled;
60namespace virtual_memory {
71static constexpr uint64_t
kValid = 0x1;
72static constexpr uint64_t
kWrite = 0x2;
73static constexpr uint64_t
kUser = 0x4;
74static constexpr uint64_t
kRead = 0x200;
75static constexpr uint64_t
kExec = 0x400;
80 bool executable =
false,
bool global =
false)
100 bool writable =
false,
101 bool executable =
false,
102 bool global =
false) -> uint64_t {
122 assert(env &&
"TestEnvironmentState not set for current thread");
123 auto& core = env->GetCurrentCoreEnv();
124 core.page_directory = pd;
129 assert(env &&
"TestEnvironmentState not set for current thread");
130 auto& core = env->GetCurrentCoreEnv();
131 return core.page_directory;
136 assert(env &&
"TestEnvironmentState not set for current thread");
137 auto& core = env->GetCurrentCoreEnv();
138 core.paging_enabled =
true;
171 return (pte &
kValid) != 0;
175 return pte & 0x000FFFFFFFFFF000ULL;
180 return (physical_addr & 0x000FFFFFFFFFF000ULL) | (flags & 0xFFF) |
181 (flags & (1ULL << 63));
static auto GetCurrentThreadEnvironment() -> TestEnvironmentState *
获取当前线程的环境实例指针(供 Mock 层调用)
static constexpr uint64_t kValid
static constexpr size_t kVpnMask
static constexpr size_t kPageSize
static constexpr uint64_t kGlobal
void SetPageDirectory(uint64_t pd)
static constexpr size_t kPteAttributeBits
auto IsPageAligned(uint64_t addr) -> bool
auto GetVirtualPageNumber(uint64_t virtual_addr, size_t level) -> uint64_t
auto PageTableEntryToPhysical(uint64_t pte) -> uint64_t
static constexpr uint64_t kUser
static constexpr uint64_t kRead
auto PageAlign(uint64_t addr) -> uint64_t
auto IsPageTableEntryValid(uint64_t pte) -> bool
auto GetTableEntryPermissions() -> uint64_t
static constexpr uint64_t kWrite
static constexpr size_t kPageTableLevels
static constexpr size_t kPageOffsetBits
auto GetKernelPagePermissions(bool readable=true, bool writable=false, bool executable=false, bool global=false) -> uint64_t
auto GetPageDirectory() -> uint64_t
static constexpr uint64_t kExec
static constexpr size_t kVpnBits
auto GetUserPagePermissions(bool readable=true, bool writable=false, bool executable=false, bool global=false) -> uint64_t
auto PhysicalToPageTableEntry(uint64_t physical_addr, uint64_t flags) -> uint64_t
auto PageAlignUp(uint64_t addr) -> uint64_t
auto GetCurrentCoreId() -> size_t
bool GetInterruptStatus()
__always_inline uint64_t & EntryFunction()
__always_inline uint64_t & EntryArgument()
__always_inline uint64_t & ReturnAddress()
__always_inline uint64_t & StackPointer()
__always_inline uint64_t & ReturnValue()
__always_inline uint64_t & ThreadPointer()
__always_inline uint64_t & UserStackPointer()