Skip to content

Commit d5def73

Browse files
committed
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.
1 parent 9fd1120 commit d5def73

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

aml/src/value.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -516,14 +516,29 @@ impl AmlValue {
516516

517517
let bitslice = inner_data.view_bits::<bitvec::order::Lsb0>();
518518
let bits = &bitslice[offset..(offset + length)];
519+
519520
if length > 64 {
520521
let mut bitvec = bits.to_bitvec();
521522
bitvec.set_uninitialized(false);
522523
Ok(AmlValue::Buffer(Arc::new(spinning_top::Spinlock::new(bitvec.into_vec()))))
524+
} else if length > 32 {
525+
/*
526+
* TODO: this is a pretty gross hack to work around a weird limitation with the `bitvec` crate on
527+
* 32-bit platforms. For reasons beyond me right now, it can't operate on a `u64` on a 32-bit
528+
* platform, so we manually extract two `u32`s and stick them together. In the future, we should
529+
* definitely have a closer look at what `bitvec` is doing and see if we can fix this code, or
530+
* replace it with a different crate. This should hold everything vaguely together until we have
531+
* time to do that.
532+
*/
533+
let mut upper = 0u32;
534+
let mut lower = 0u32;
535+
lower.view_bits_mut::<bitvec::order::Lsb0>()[0..32].clone_from_bitslice(bits);
536+
upper.view_bits_mut::<bitvec::order::Lsb0>()[0..(length - 32)].clone_from_bitslice(&bits[32..]);
537+
Ok(AmlValue::Integer((upper as u64) << 32 + (lower as u64)))
523538
} else {
524-
let mut value = 0u64;
539+
let mut value = 0u32;
525540
value.view_bits_mut::<bitvec::order::Lsb0>()[0..length].clone_from_bitslice(bits);
526-
Ok(AmlValue::Integer(value))
541+
Ok(AmlValue::Integer(value as u64))
527542
}
528543
} else {
529544
Err(AmlError::IncompatibleValueConversion { current: self.type_of(), target: AmlType::BufferField })

0 commit comments

Comments
 (0)