mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
feat: add utils/bin
This commit is contained in:
parent
ea80bd3e8d
commit
c371fd543f
@ -1,5 +1,6 @@
|
||||
use num_traits::ToPrimitive;
|
||||
use utils::size::{GIB, KIB, MIB, TIB};
|
||||
use utils::MASK;
|
||||
use vspace::addr::{AddressOps, PhysAddr, VirtAddr};
|
||||
use vspace::paging::TableLevel;
|
||||
|
||||
@ -8,8 +9,8 @@ pub trait PhysAddrPaging {
|
||||
const PPN_BITS: usize;
|
||||
const PPN_OFFSET: usize;
|
||||
|
||||
const PA_PPN_MASK: usize = ((1 << Self::PPN_BITS) - 1) << Self::PG_OFFSET;
|
||||
const PTE_PPN_MASK: usize = ((1 << Self::PPN_BITS) - 1) << Self::PPN_OFFSET;
|
||||
const PA_PPN_MASK: usize = MASK!(Self::PPN_BITS) << Self::PG_OFFSET;
|
||||
const PTE_PPN_MASK: usize = MASK!(Self::PPN_BITS) << Self::PPN_OFFSET;
|
||||
|
||||
fn to_ppn(&self) -> usize
|
||||
where Self: AddressOps {
|
||||
@ -61,7 +62,7 @@ pub trait VirtAddrPaging {
|
||||
|
||||
fn lower_bits(&self, level: usize) -> usize
|
||||
where Self: AddressOps {
|
||||
self.as_usize() & ((1 << (Self::PG_OFFSET + Self::VPN_BITS * (level + 1))) - 1)
|
||||
self.as_usize() & MASK!(Self::PG_OFFSET + Self::VPN_BITS * (level + 1))
|
||||
}
|
||||
}
|
||||
|
||||
|
6
lib/utils/src/bin.rs
Normal file
6
lib/utils/src/bin.rs
Normal file
@ -0,0 +1,6 @@
|
||||
#[macro_export]
|
||||
macro_rules! MASK {
|
||||
($bits:expr) => {
|
||||
(1 << $bits) - 1
|
||||
};
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
|
||||
pub mod assert;
|
||||
pub mod atomic;
|
||||
pub mod bin;
|
||||
pub mod container_of;
|
||||
pub mod extern_addr;
|
||||
pub mod function_name;
|
||||
|
Loading…
Reference in New Issue
Block a user