Selaa lähdekoodia

Implement zero-extension in stores to buffer fields

Isaac Woods 3 vuotta sitten
vanhempi
commit
b7afb442b6
2 muutettua tiedostoa jossa 9 lisäystä ja 5 poistoa
  1. 4 2
      aml/src/value.rs
  2. 5 3
      tests/buffer_fields.asl

+ 4 - 2
aml/src/value.rs

@@ -521,7 +521,8 @@ impl AmlValue {
                     let bits_to_copy = cmp::min(length, 64);
                     bitslice[offset..(offset + bits_to_copy)]
                         .copy_from_bitslice(&value.to_le_bytes().view_bits()[..(bits_to_copy as usize)]);
-                    // TODO: zero extend the field if needed
+                    // Zero extend to the end of the buffer field
+                    bitslice[(offset + bits_to_copy)..(offset + length)].set_all(false);
                     Ok(())
                 }
                 AmlValue::Boolean(value) => {
@@ -540,7 +541,8 @@ impl AmlValue {
                     let bits_to_copy = cmp::min(length, value_data.len() * 8);
                     bitslice[offset..(offset + bits_to_copy)]
                         .copy_from_bitslice(&value_data.view_bits()[..(bits_to_copy as usize)]);
-                    // TODO: zero extend if needed
+                    // Zero extend to the end of the buffer field
+                    bitslice[(offset + bits_to_copy)..(offset + length)].set_all(false);
                     Ok(())
                 }
                 _ => Err(AmlError::TypeCannotBeWrittenToBufferField(value.type_of())),

+ 5 - 3
tests/buffer_fields.asl

@@ -1,5 +1,5 @@
 DefinitionBlock("buffer_fields.aml", "DSDT", 1, "RSACPI", "BUFFLD", 1) {
-	Name(X, Buffer (16) { 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })
+	Name(X, Buffer (16) { 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff })
 	CreateBitField(X, 3, BIT3)
 	CreateField(X, 0, 3, BITS)
 	CreateByteField(X, 1, BYTE)
@@ -7,11 +7,13 @@ DefinitionBlock("buffer_fields.aml", "DSDT", 1, "RSACPI", "BUFFLD", 1) {
 	CreateDWordField(X, 4, DWRD)
 	CreateQWordField(X, 8, QWRD)
 
-	// `X` should end up as [0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
+	// `X` should end up as [0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x00, 0x00]
 	BIT3 = 1
 	BITS = 7
 	BYTE = 0x01
 	WORD = 0x0302
 	DWRD = 0x07060504
-	QWRD = Buffer() { 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }
+	// Last two bytes should be cleared because of zero-extension of this store
+	// We do this as a buffer store a) to test them b) because `iasl` doesn't support 64-bit integer constants...
+	QWRD = Buffer() { 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d }
 }