Browse Source

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.
Isaac Woods 2 years ago
parent
commit
d5def73b37
1 changed files with 17 additions and 2 deletions
  1. 17 2
      aml/src/value.rs

+ 17 - 2
aml/src/value.rs

@@ -516,14 +516,29 @@ impl AmlValue {
 
             let bitslice = inner_data.view_bits::<bitvec::order::Lsb0>();
             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::<bitvec::order::Lsb0>()[0..32].clone_from_bitslice(bits);
+                upper.view_bits_mut::<bitvec::order::Lsb0>()[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::<bitvec::order::Lsb0>()[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 })