|
1 | 1 | use crate::{
|
2 |
| - name_object::{name_string, super_name, target}, |
| 2 | + misc::debug_obj, |
| 3 | + name_object::{name_string, simple_name, super_name, target}, |
3 | 4 | opcode::{self, opcode},
|
4 | 5 | parser::{choice, comment_scope, n_of, take, take_to_end_of_pkglength, try_with_context, Parser, Propagate},
|
5 | 6 | pkg_length::pkg_length,
|
|
50 | 51 | def_l_not_equal(),
|
51 | 52 | def_l_or(),
|
52 | 53 | def_mid(),
|
| 54 | + def_object_type(), |
53 | 55 | def_package(),
|
54 | 56 | def_shift_left(),
|
55 | 57 | def_shift_right(),
|
@@ -501,6 +503,77 @@ where
|
501 | 503 | .map(|((), result)| Ok(result))
|
502 | 504 | }
|
503 | 505 |
|
| 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 | + |
504 | 577 | pub fn def_package<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
|
505 | 578 | where
|
506 | 579 | 'c: 'a,
|
|
0 commit comments