From 8aefcb9c1ef1ff92b50e8c484ef6e8bf448670a9 Mon Sep 17 00:00:00 2001 From: Isaac Woods Date: Fri, 3 Mar 2023 00:08:46 +0000 Subject: [PATCH] Add hack to get `aml` compiling on 32-bit platforms This is a, hopefully very temporary, hack to get `aml` to compile on 32-bit platforms. The issue is with `bitvec`, which seems to be unable to operate on 64-bit values on 32-bit systems, which I don't quite understand atm. In the long term, we should sit down and understand how to use `bitvec` properly, or replace it with a simple implementation without this limitation. --- aml/src/value.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/aml/src/value.rs b/aml/src/value.rs index 538e3647..81971ba7 100644 --- a/aml/src/value.rs +++ b/aml/src/value.rs @@ -516,14 +516,29 @@ impl AmlValue { let bitslice = inner_data.view_bits::(); let bits = &bitslice[offset..(offset + length)]; + if length > 64 { let mut bitvec = bits.to_bitvec(); bitvec.set_uninitialized(false); Ok(AmlValue::Buffer(Arc::new(spinning_top::Spinlock::new(bitvec.into_vec())))) + } else if length > 32 { + /* + * TODO: this is a pretty gross hack to work around a weird limitation with the `bitvec` crate on + * 32-bit platforms. For reasons beyond me right now, it can't operate on a `u64` on a 32-bit + * platform, so we manually extract two `u32`s and stick them together. In the future, we should + * definitely have a closer look at what `bitvec` is doing and see if we can fix this code, or + * replace it with a different crate. This should hold everything vaguely together until we have + * time to do that. + */ + let mut upper = 0u32; + let mut lower = 0u32; + lower.view_bits_mut::()[0..32].clone_from_bitslice(bits); + upper.view_bits_mut::()[0..(length - 32)].clone_from_bitslice(&bits[32..]); + Ok(AmlValue::Integer((upper as u64) << 32 + (lower as u64))) } else { - let mut value = 0u64; + let mut value = 0u32; value.view_bits_mut::()[0..length].clone_from_bitslice(bits); - Ok(AmlValue::Integer(value)) + Ok(AmlValue::Integer(value as u64)) } } else { Err(AmlError::IncompatibleValueConversion { current: self.type_of(), target: AmlType::BufferField })