Skip to content

Commit

Permalink
feat(vmm): vmm working for riscv64
Browse files Browse the repository at this point in the history
Signed-off-by: Zone.N <[email protected]>
  • Loading branch information
MRNIU committed Oct 14, 2024
1 parent 77d443e commit 79ff6e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
8 changes: 6 additions & 2 deletions src/kernel/arch/riscv64/include/cpu/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,17 @@ inline void DisablePage() {
* @return true 成功
* @return false 失败
*/
inline void SetPageDirectory(uint64_t pgd) { kAllCsr.satp.ppn.Write(pgd); }
inline void SetPageDirectory(uint64_t pgd) {
kAllCsr.satp.ppn.Write(pgd >> register_info::csr::SatpInfo::kPpnOffset);
}

/**
* @brief 获取页目录
* @return uint64_t 页目录值
*/
inline uint64_t GetPageDirectory() { return kAllCsr.satp.ppn.Get(); }
inline uint64_t GetPageDirectory() {
return kAllCsr.satp.ppn.Get() << register_info::csr::SatpInfo::kPpnOffset;
}

inline void FlushPage(uint64_t addr) {
(void)addr;
Expand Down
33 changes: 2 additions & 31 deletions src/kernel/arch/riscv64/include/cpu/regs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,6 @@
*/
namespace cpu {

// namespace vmm_info {
// /// 有效位
// static constexpr const uint8_t VMM_PAGE_VALID = CPU::pte_t::VALID;
// /// 可读位
// static constexpr const uint8_t VMM_PAGE_READABLE = CPU::pte_t::READ;
// /// 可写位s
// static constexpr const uint8_t VMM_PAGE_WRITABLE = CPU::pte_t::WRITE;
// /// 可执行位
// static constexpr const uint8_t VMM_PAGE_EXECUTABLE = CPU::pte_t::EXEC;
// /// 用户位
// static constexpr const uint8_t VMM_PAGE_USER = CPU::pte_t::USER;
// /// 全局位,我们不会使用
// static constexpr const uint8_t VMM_PAGE_GLOBAL = CPU::pte_t::GLOBAL;
// /// 已使用位,用于替换算法
// static constexpr const uint8_t VMM_PAGE_ACCESSED = CPU::pte_t::ACCESSED;
// /// 已修改位,用于替换算法
// static constexpr const uint8_t VMM_PAGE_DIRTY = CPU::pte_t::DIRTY;
// /// 内核虚拟地址相对物理地址的偏移
// static constexpr const size_t KERNEL_OFFSET = 0x0;
// /// PTE 属性位数
// static constexpr const size_t VMM_PTE_PROP_BITS = 10;
// /// PTE 页内偏移位数
// static constexpr const size_t VMM_PAGE_OFF_BITS = 12;
// /// VPN 位数
// static constexpr const size_t VMM_VPN_BITS = 9;
// /// VPN 位数掩码,9 位 VPN
// static constexpr const size_t VMM_VPN_BITS_MASK = 0x1FF;
// /// riscv64 使用了三级页表
// static constexpr const size_t VMM_PT_LEVEL = 3;
// }; // namespace vmm_info

// 第一部分:寄存器定义
namespace register_info {

Expand Down Expand Up @@ -378,6 +347,8 @@ struct SatpInfo : public RegInfoBase {
"Reserved", "Reserved", "SV39", "SV48", "SV57", "SV64",
};

static constexpr const uint64_t kPpnOffset = 12;

struct Ppn {
using DataType = uint64_t;
static constexpr uint64_t kBitOffset = 0;
Expand Down

0 comments on commit 79ff6e9

Please sign in to comment.