Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generic extract_bits and PTE traits methods #14

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
.devenv

# Vim swap files
*.swp
26 changes: 18 additions & 8 deletions src/architecture/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ use super::generic::{CPURegister as CPURegisterTrait, PageTableEntry as PageTabl
use anyhow::Result;
use serde::{Deserialize, Serialize};

/// Extracts bits from a 64-bit entry in little-endian order.
fn extract_bits(entry: u64, pos: u64, n: u64) -> u64 {
(entry >> pos) & ((1 << n) - 1)
}

/// Represents a RISC-V CPU register associated with a value.
#[derive(Debug, Clone, Serialize, Deserialize, Default, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct CPURegister {
Expand Down Expand Up @@ -33,43 +38,48 @@ pub struct PageTableEntry {
pub flags: u64,
}



impl PageTableEntry {
pub fn new(address: u64, flags: u64) -> Self {
Self { address, flags }
}

pub fn is_supervisor(&self) -> bool {
todo!()
extract_bits(self.flags, 4, 1) == 0
}

pub fn extract_addr(entry: u64) -> u64 {
extract_bits(entry, 10, 21) << 12
}
}

impl PageTableEntryTrait for PageTableEntry {
type Address = u64;
type Flags = u64;

// FIXME: Implement the following methods
fn is_dirty(&self) -> bool {
todo!()
extract_bits(self.flags, 7, 1) != 0
}

fn is_accessed(&self) -> bool {
todo!()
extract_bits(self.flags, 6, 1) != 0
}

fn is_global(&self) -> bool {
todo!()
extract_bits(self.flags, 5, 1) != 0
}

fn is_readable(&self) -> bool {
todo!()
extract_bits(self.flags, 1, 1) != 0
}

fn is_writable(&self) -> bool {
todo!()
extract_bits(self.flags, 2, 1) != 0
}

fn is_executable(&self) -> bool {
todo!()
extract_bits(self.flags, 3, 1) != 0
}
}

Expand Down
Loading