diff --git a/src/sdt.rs b/src/sdt.rs index 409fa1a..0da4a22 100644 --- a/src/sdt.rs +++ b/src/sdt.rs @@ -25,7 +25,7 @@ impl GenericAddress { address_space_id: 1, register_bit_width: 8 * core::mem::size_of::() as u8, register_bit_offset: 0, - access_size: core::mem::size_of::() as u8, + access_size: core::mem::size_of::().trailing_zeros() as u8 + 1, address: u64::from(address), } } @@ -34,7 +34,7 @@ impl GenericAddress { address_space_id: 0, register_bit_width: 8 * core::mem::size_of::() as u8, register_bit_offset: 0, - access_size: core::mem::size_of::() as u8, + access_size: core::mem::size_of::().trailing_zeros() as u8 + 1, address, } } @@ -151,7 +151,7 @@ impl Aml for Sdt { #[cfg(test)] mod tests { - use super::Sdt; + use super::{GenericAddress, Sdt}; #[test] fn test_sdt() { @@ -168,4 +168,16 @@ mod tests { .fold(0u8, |acc, x| acc.wrapping_add(*x)); assert_eq!(sum, 0); } + + #[test] + fn test_generic_address_access_size() { + let byte_mmio = GenericAddress::mmio_address::(0x1000); + assert_eq!(byte_mmio.access_size, 1); + let word_mmio = GenericAddress::mmio_address::(0x1000); + assert_eq!(word_mmio.access_size, 2); + let dword_mmio = GenericAddress::mmio_address::(0x1000); + assert_eq!(dword_mmio.access_size, 3); + let qword_mmio = GenericAddress::mmio_address::(0x1000); + assert_eq!(qword_mmio.access_size, 4); + } }