Skip to content

Commit a56959e

Browse files
committed
aml: support DefObjectType
1 parent 33b41f6 commit a56959e

File tree

4 files changed

+94
-17
lines changed

4 files changed

+94
-17
lines changed

aml/src/lib.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use alloc::{boxed::Box, sync::Arc, vec, vec::Vec};
1414
use bit_field::BitField;
1515
use core::{mem, str};
1616
use namespace::{AmlName, Namespace, NamespaceLevelKind};
17-
use object::{MethodFlags, Object};
17+
use object::{MethodFlags, Object, ObjectType};
1818
use op_region::{OpRegion, RegionSpace};
1919
use spinning_top::Spinlock;
2020

@@ -290,6 +290,38 @@ impl Interpreter {
290290
}
291291
}
292292
}
293+
Opcode::ObjectType => {
294+
let [Argument::Object(object)] = &op.arguments[..] else { panic!() };
295+
// TODO: this should technically support scopes as well - this is less easy
296+
// (they should return `0`)
297+
// TODO: calling this on the debug object should should return `16`
298+
let typ = match object.typ() {
299+
ObjectType::Uninitialized => 0,
300+
ObjectType::Integer => 1,
301+
ObjectType::String => 2,
302+
ObjectType::Buffer => 3,
303+
ObjectType::Package => 4,
304+
ObjectType::FieldUnit => 5,
305+
ObjectType::Device => 6,
306+
ObjectType::Event => 7,
307+
ObjectType::Method => 8,
308+
ObjectType::Mutex => 9,
309+
ObjectType::OpRegion => 10,
310+
ObjectType::PowerResource => 11,
311+
ObjectType::Processor => 12,
312+
ObjectType::ThermalZone => 13,
313+
ObjectType::BufferField => 14,
314+
// XXX: 15 is reserved
315+
ObjectType::Reference => panic!(),
316+
ObjectType::RawDataBuffer => todo!(),
317+
};
318+
319+
if let Some(prev_op) = context.in_flight.last_mut() {
320+
if prev_op.arguments.len() < prev_op.expected_arguments {
321+
prev_op.arguments.push(Argument::Object(Arc::new(Object::Integer(typ))));
322+
}
323+
}
324+
}
293325
_ => panic!("Unexpected operation has created in-flight op!"),
294326
}
295327
}
@@ -673,7 +705,7 @@ impl Interpreter {
673705
| Opcode::ToInteger
674706
| Opcode::ToString => context.start_in_flight_op(OpInFlight::new(opcode, 2)),
675707

676-
Opcode::ObjectType => todo!(),
708+
Opcode::ObjectType => context.start_in_flight_op(OpInFlight::new(opcode, 1)),
677709
Opcode::CopyObject => todo!(),
678710
Opcode::Mid => context.start_in_flight_op(OpInFlight::new(Opcode::Mid, 4)),
679711
Opcode::Continue => todo!(),

aml/src/object.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,30 @@ impl Object {
4242
&mut *(self as *const Self as *mut Self)
4343
}
4444
}
45+
46+
/// Returns the `ObjectType` of this object. Returns the type of the referenced object in the
47+
/// case of `Object::Reference`.
48+
pub fn typ(&self) -> ObjectType {
49+
match self {
50+
Object::Uninitialized => ObjectType::Uninitialized,
51+
Object::Buffer(_) => ObjectType::Buffer,
52+
Object::BufferField { .. } => ObjectType::BufferField,
53+
Object::Device => ObjectType::Device,
54+
Object::Event => ObjectType::Event,
55+
Object::FieldUnit(_) => ObjectType::FieldUnit,
56+
Object::Integer(_) => ObjectType::Integer,
57+
Object::Method { .. } => ObjectType::Method,
58+
Object::Mutex => ObjectType::Mutex,
59+
Object::Reference(object) => object.typ(),
60+
Object::OpRegion(_) => ObjectType::OpRegion,
61+
Object::Package(_) => ObjectType::Package,
62+
Object::PowerResource => ObjectType::PowerResource,
63+
Object::Processor => ObjectType::Processor,
64+
Object::RawDataBuffer => ObjectType::RawDataBuffer,
65+
Object::String(_) => ObjectType::String,
66+
Object::ThermalZone => ObjectType::ThermalZone,
67+
}
68+
}
4569
}
4670

4771
#[derive(Debug)]
@@ -67,3 +91,24 @@ impl MethodFlags {
6791
self.0.get_bits(4..8)
6892
}
6993
}
94+
95+
#[derive(Clone, Copy, PartialEq, Debug)]
96+
pub enum ObjectType {
97+
Uninitialized,
98+
Buffer,
99+
BufferField,
100+
Device,
101+
Event,
102+
FieldUnit,
103+
Integer,
104+
Method,
105+
Mutex,
106+
Reference,
107+
OpRegion,
108+
Package,
109+
PowerResource,
110+
Processor,
111+
RawDataBuffer,
112+
String,
113+
ThermalZone,
114+
}

tests/object_type.asl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
DefinitionBlock("object_type.aml", "DSDT", 1, "RSACPI", "OBJTYP", 1) {
2-
Name(INT, 723)
3-
Name(STR, "Hello, World!")
4-
Name(BUFF, Buffer { 7, 2, 3, 5, 92, 6 })
5-
// TODO: more types
2+
Name(INT, 723)
3+
Name(STR, "Hello, World!")
4+
Name(BUFF, Buffer { 7, 2, 3, 5, 92, 6 })
5+
// TODO: more types
66

7-
Device(TYPS) {
8-
// This is just so it compiles
9-
Name (_HID, EisaId ("PNP0A03"))
7+
Device(TYPS) {
8+
// This is just so it compiles
9+
Name (_HID, EisaId ("PNP0A03"))
1010

11-
Name(INT, 0) // Should be `1`
12-
Name(STR, 0) // Should be `2`
13-
Name(BUFF, 0) // Should be `3`
11+
Name(INT, 0) // Should be `1`
12+
Name(STR, 0) // Should be `2`
13+
Name(BUFF, 0) // Should be `3`
1414

15-
INT = ObjectType(\INT)
16-
STR = ObjectType(\STR)
17-
BUFF = ObjectType(\BUFF)
18-
}
15+
INT = ObjectType(\INT)
16+
STR = ObjectType(\STR)
17+
BUFF = ObjectType(\BUFF)
18+
}
1919
}

tests/pc-bios_acpi-dsdt.asl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1896,4 +1896,4 @@
18961896
}
18971897
}
18981898

1899-
1899+

0 commit comments

Comments
 (0)