Skip to content

Commit 7c9931b

Browse files
committed
aml: support creation of buffer field objects
Still need to do a bunch of bit fiddling stuff to facilitate actually reading and storing to them.
1 parent a1bcccc commit 7c9931b

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
lines changed

aml/src/lib.rs

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,59 @@ impl Interpreter {
190190
}
191191
}
192192
}
193+
opcode @ Opcode::CreateBitField
194+
| opcode @ Opcode::CreateByteField
195+
| opcode @ Opcode::CreateWordField
196+
| opcode @ Opcode::CreateDWordField
197+
| opcode @ Opcode::CreateQWordField => {
198+
let [Argument::Object(buffer), Argument::Object(index)] = &op.arguments[..] else {
199+
panic!()
200+
};
201+
let name = context.namestring()?;
202+
let Object::Integer(index) = **index else { panic!() };
203+
println!(
204+
"CreateBitField(or adjacent). buffer = {:?}, bit/byte_index={:?}, name={:?}",
205+
buffer, index, name
206+
);
207+
let (offset, length) = match opcode {
208+
Opcode::CreateBitField => (index, 1),
209+
Opcode::CreateByteField => (index * 8, 8),
210+
Opcode::CreateWordField => (index * 8, 16),
211+
Opcode::CreateDWordField => (index * 8, 32),
212+
Opcode::CreateQWordField => (index * 8, 64),
213+
_ => unreachable!(),
214+
};
215+
self.namespace.lock().insert(
216+
name.resolve(&context.current_scope)?,
217+
Arc::new(Object::BufferField {
218+
buffer: buffer.clone(),
219+
offset: offset as usize,
220+
length,
221+
}),
222+
)?;
223+
}
224+
Opcode::CreateField => {
225+
let [Argument::Object(buffer), Argument::Object(bit_index), Argument::Object(num_bits)] =
226+
&op.arguments[..]
227+
else {
228+
panic!()
229+
};
230+
let name = context.namestring()?;
231+
let Object::Integer(bit_index) = **bit_index else { panic!() };
232+
let Object::Integer(num_bits) = **num_bits else { panic!() };
233+
println!(
234+
"CreateBitField(or adjacent). buffer = {:?}, bit/byte_index={:?}, num_bits={:?}, name={:?}",
235+
buffer, bit_index, num_bits, name
236+
);
237+
self.namespace.lock().insert(
238+
name.resolve(&context.current_scope)?,
239+
Arc::new(Object::BufferField {
240+
buffer: buffer.clone(),
241+
offset: bit_index as usize,
242+
length: num_bits as usize,
243+
}),
244+
)?;
245+
}
193246
Opcode::InternalMethodCall => {
194247
let Argument::Object(method) = &op.arguments[0] else { panic!() };
195248

@@ -403,7 +456,6 @@ impl Interpreter {
403456
Opcode::Mutex => todo!(),
404457
Opcode::Event => todo!(),
405458
Opcode::CondRefOf => todo!(),
406-
Opcode::CreateField => todo!(),
407459
Opcode::LoadTable => todo!(),
408460
Opcode::Load => todo!(),
409461
Opcode::Stall => todo!(),
@@ -564,10 +616,13 @@ impl Interpreter {
564616
Opcode::SizeOf => todo!(),
565617
Opcode::Index => todo!(),
566618
Opcode::Match => todo!(),
567-
Opcode::CreateDWordField => todo!(),
568-
Opcode::CreateWordField => todo!(),
569-
Opcode::CreateByteField => todo!(),
570-
Opcode::CreateBitField => todo!(),
619+
620+
Opcode::CreateBitField
621+
| Opcode::CreateByteField
622+
| Opcode::CreateWordField
623+
| Opcode::CreateDWordField
624+
| Opcode::CreateQWordField => context.start_in_flight_op(OpInFlight::new(opcode, 2)),
625+
Opcode::CreateField => context.start_in_flight_op(OpInFlight::new(Opcode::CreateField, 3)),
571626
Opcode::ObjectType => todo!(),
572627
Opcode::CreateQWordField => todo!(),
573628
Opcode::LAnd => todo!(),

aml/src/object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use bit_field::BitField;
66
pub enum Object {
77
Uninitialized,
88
Buffer(Vec<u8>),
9-
BufferField,
9+
BufferField { buffer: Arc<Object>, offset: usize, length: usize },
1010
Device,
1111
Event,
1212
FieldUnit,

0 commit comments

Comments
 (0)