Skip to content

Commit 14c6c67

Browse files
committed
aml: initial support for DefObjectType and test it
This doesn't do everything yet (particularly it doesn't handle object references), but it should get most of the way there.
1 parent 2bac9f3 commit 14c6c67

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

aml/src/expression.rs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{
2-
name_object::{name_string, super_name, target},
2+
misc::debug_obj,
3+
name_object::{name_string, simple_name, super_name, target},
34
opcode::{self, opcode},
45
parser::{choice, comment_scope, n_of, take, take_to_end_of_pkglength, try_with_context, Parser, Propagate},
56
pkg_length::pkg_length,
@@ -50,6 +51,7 @@ where
5051
def_l_not_equal(),
5152
def_l_or(),
5253
def_mid(),
54+
def_object_type(),
5355
def_package(),
5456
def_shift_left(),
5557
def_shift_right(),
@@ -501,6 +503,77 @@ where
501503
.map(|((), result)| Ok(result))
502504
}
503505

506+
pub fn def_object_type<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
507+
where
508+
'c: 'a,
509+
{
510+
/*
511+
* DefObjectType := 0x8e <SimpleName | DebugObj | DefRefOf | DefDerefOf | DefIndex>
512+
*
513+
* Returns an integer representing the type of an AML object. If executed on an object that is a reference to a
514+
* value (e.g. produced by `Alias`, `RefOf`, or `Index`), the type of the base object is returned. For typeless
515+
* objects, such as scopes, a type of `0 - Uninitialized` is returned.
516+
*
517+
* 0 = Uninitialized
518+
* 1 = Integer
519+
* 2 = String
520+
* 3 = Buffer
521+
* 4 = Package
522+
* 5 = Field Unit
523+
* 6 = Device
524+
* 7 = Event
525+
* 8 = Method
526+
* 9 = Mutex
527+
* 10 = Operation Region
528+
* 11 = Power Resource
529+
* 12 = Processor
530+
* 13 = Thermal Zone
531+
* 14 = Buffer Field
532+
* 15 = Reserved
533+
* 16 = Debug Object
534+
* >16 = *Reserved*
535+
*/
536+
// TODO: this doesn't correctly handle taking the type of a namespace node (e.g. `\_SB`), but I'm not sure any
537+
// other implementations do either?
538+
opcode(opcode::DEF_OBJECT_TYPE_OP)
539+
.then(comment_scope(
540+
DebugVerbosity::AllScopes,
541+
"DefObjectType",
542+
choice!(
543+
simple_name().map_with_context(|target, context| {
544+
let value = try_with_context!(context, context.read_target(&target));
545+
let typ = match value.type_of() {
546+
AmlType::Uninitialized => 0,
547+
AmlType::Integer => 1,
548+
AmlType::String => 2,
549+
AmlType::Buffer => 3,
550+
AmlType::RawDataBuffer => 3, // TODO: not sure if this is correct
551+
AmlType::Package => 4,
552+
AmlType::FieldUnit => 5,
553+
AmlType::Device => 6,
554+
AmlType::Event => 7,
555+
AmlType::Method => 8,
556+
AmlType::Mutex => 9,
557+
AmlType::OpRegion => 10,
558+
AmlType::PowerResource => 11,
559+
AmlType::Processor => 12,
560+
AmlType::ThermalZone => 13,
561+
AmlType::BufferField => 14,
562+
AmlType::DebugObject => 16,
563+
564+
// TODO: what to do with this?
565+
AmlType::DdbHandle => 0,
566+
AmlType::ObjReference => todo!(),
567+
};
568+
569+
(Ok(AmlValue::Integer(typ)), context)
570+
}),
571+
debug_obj().map(|()| Ok(AmlValue::Integer(16)))
572+
),
573+
))
574+
.map(|((), result)| Ok(result))
575+
}
576+
504577
pub fn def_package<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
505578
where
506579
'c: 'a,

aml/src/opcode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub const DEF_SHIFT_LEFT: u8 = 0x79;
6666
pub const DEF_SHIFT_RIGHT: u8 = 0x7a;
6767
pub const DEF_AND_OP: u8 = 0x7b;
6868
pub const DEF_CONCAT_RES_OP: u8 = 0x84;
69+
pub const DEF_OBJECT_TYPE_OP: u8 = 0x8e;
6970
pub const DEF_L_OR_OP: u8 = 0x91;
7071
pub const DEF_L_NOT_OP: u8 = 0x92;
7172
pub const DEF_L_EQUAL_OP: u8 = 0x93;

tests/object_type.asl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
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
6+
7+
Device(TYPS) {
8+
// This is just so it compiles
9+
Name (_HID, EisaId ("PNP0A03"))
10+
11+
Name(INT, 0) // Should be `1`
12+
Name(STR, 0) // Should be `2`
13+
Name(BUFF, 0) // Should be `3`
14+
15+
INT = ObjectType(\INT)
16+
STR = ObjectType(\STR)
17+
BUFF = ObjectType(\BUFF)
18+
}
19+
}

0 commit comments

Comments
 (0)