Skip to content

Commit

Permalink
Tidy
Browse files Browse the repository at this point in the history
Signed-off-by: Graham MacDonald <[email protected]>
  • Loading branch information
gmacd committed Sep 17, 2023
1 parent a8e29d4 commit 0c6c07c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 74 deletions.
75 changes: 1 addition & 74 deletions aarch64/src/registers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ bitstruct! {
}
}

#[allow(dead_code)]
impl EsrEl1IssInstructionAbort {
pub fn from_esr_el1(r: EsrEl1) -> Option<EsrEl1IssInstructionAbort> {
r.exception_class_enum()
Expand Down Expand Up @@ -235,36 +236,6 @@ pub enum InstructionFaultStatusCode {
UnsupportedAtomicHardwareUpdateFault = 49,
}

bitstruct! {
#[derive(Copy, Clone)]
pub struct Vaddr4K4K(pub u64) {
offset: u16 = 0..12;
l4idx: u16 = 12..21;
l3idx: u16 = 21..30;
l2idx: u16 = 30..39;
l1idx: u16 = 39..48;
}
}

bitstruct! {
#[derive(Copy, Clone)]
pub struct Vaddr4K2M(pub u64) {
offset: u32 = 0..21;
l3idx: u16 = 21..30;
l2idx: u16 = 30..39;
l1idx: u16 = 39..48;
}
}

bitstruct! {
#[derive(Copy, Clone)]
pub struct Vaddr4K1G(pub u64) {
offset: u32 = 0..30;
l2idx: u16 = 30..39;
l1idx: u16 = 39..48;
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -289,48 +260,4 @@ mod tests {
InstructionFaultStatusCode::TranslationFaultLevel0
);
}

#[test]
fn breakdown_vadder() {
let va = Vaddr4K4K(0xffff_8000_0000_0000);
assert_eq!(va.l1idx(), 256);
assert_eq!(va.l2idx(), 0);
assert_eq!(va.l3idx(), 0);
assert_eq!(va.l4idx(), 0);
assert_eq!(va.offset(), 0);

let va = Vaddr4K4K(0x0000_0000_0008_00a8);
assert_eq!(va.l1idx(), 0);
assert_eq!(va.l2idx(), 0);
assert_eq!(va.l3idx(), 0);
assert_eq!(va.l4idx(), 128);
assert_eq!(va.offset(), 168);

let va = Vaddr4K2M(0xffff_8000_3f00_0000);
assert_eq!(va.l1idx(), 256);
assert_eq!(va.l2idx(), 0);
assert_eq!(va.l3idx(), 504);
assert_eq!(va.offset(), 0);

let va = Vaddr4K2M(0xffff_8000_fe00_0000);
assert_eq!(va.l1idx(), 256);
assert_eq!(va.l2idx(), 3);
assert_eq!(va.l3idx(), 496);
assert_eq!(va.offset(), 0);

let va = Vaddr4K1G(0xffff_8000_0000_0000);
assert_eq!(va.l1idx(), 256);
assert_eq!(va.l2idx(), 0);
assert_eq!(va.offset(), 0);

let va = Vaddr4K1G(0x0000_0000_0008_00a8);
assert_eq!(va.l1idx(), 0);
assert_eq!(va.l2idx(), 0);
assert_eq!(va.offset(), 524456);

let va = Vaddr4K1G(0xffff_8000_0010_00c8);
assert_eq!(va.l1idx(), 256);
assert_eq!(va.l2idx(), 0);
assert_eq!(va.offset(), 0x1000c8);
}
}
2 changes: 2 additions & 0 deletions aarch64/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub const PAGE_SIZE_4K: usize = 4 * 1024;
pub const PAGE_SIZE_2M: usize = 2 * 1024 * 1024;
pub const PAGE_SIZE_1G: usize = 1 * 1024 * 1024 * 1024;

#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
pub enum PageSize {
Page4K,
Expand Down Expand Up @@ -271,6 +272,7 @@ impl Table {
Some(unsafe { &*(raw_ptr as *const Table) })
}

#[allow(dead_code)]
fn next(&self, level: Level, va: usize) -> Option<&Table> {
let index = Self::index(level, va);
let entry = self.entries[index];
Expand Down

0 comments on commit 0c6c07c

Please sign in to comment.