From 133001e59d3f56056d371954eb52a79ee5a2b377 Mon Sep 17 00:00:00 2001 From: Isaac Woods Date: Wed, 13 Sep 2023 02:24:03 +0100 Subject: [PATCH] aml: add support for the `DefStall` opcode --- aml/src/lib.rs | 5 +++++ aml/src/opcode.rs | 5 +++-- aml/src/statement.rs | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/aml/src/lib.rs b/aml/src/lib.rs index 3a1ecc3..de604f4 100644 --- a/aml/src/lib.rs +++ b/aml/src/lib.rs @@ -689,6 +689,11 @@ pub trait Handler: Send + Sync { fn write_pci_u16(&self, segment: u16, bus: u8, device: u8, function: u8, offset: u16, value: u16); fn write_pci_u32(&self, segment: u16, bus: u8, device: u8, function: u8, offset: u16, value: u32); + /// Stall for at least the given number of **microseconds**. An implementation should not relinquish control of + /// the processor during the stall, and for this reason, firmwares should not stall for periods of more than + /// 100 microseconds. + fn stall(&self, microseconds: u64); + fn handle_fatal_error(&self, fatal_type: u8, fatal_code: u32, fatal_arg: u64) { panic!("Fatal error while executing AML (encountered DefFatal op). fatal_type = {:?}, fatal_code = {:?}, fatal_arg = {:?}", fatal_type, fatal_code, fatal_arg); } diff --git a/aml/src/opcode.rs b/aml/src/opcode.rs index 6d7c0fa..fe32a83 100644 --- a/aml/src/opcode.rs +++ b/aml/src/opcode.rs @@ -45,7 +45,7 @@ pub const EXT_DEF_POWER_RES_OP: u8 = 0x84; pub const EXT_DEF_THERMAL_ZONE_OP: u8 = 0x85; /* - * Type 1 opcodes + * Statement opcodes */ pub const DEF_CONTINUE_OP: u8 = 0x9f; pub const DEF_IF_ELSE_OP: u8 = 0xa0; @@ -55,9 +55,10 @@ pub const DEF_NOOP_OP: u8 = 0xa3; pub const DEF_RETURN_OP: u8 = 0xa4; pub const DEF_BREAK_OP: u8 = 0xa5; pub const DEF_BREAKPOINT_OP: u8 = 0xcc; +pub const EXT_DEF_STALL_OP: u8 = 0x21; /* - * Type 2 opcodes + * Expression opcodes */ pub const DEF_STORE_OP: u8 = 0x70; pub const DEF_ADD_OP: u8 = 0x72; diff --git a/aml/src/statement.rs b/aml/src/statement.rs index 4368b94..9d0a926 100644 --- a/aml/src/statement.rs +++ b/aml/src/statement.rs @@ -39,6 +39,7 @@ where def_if_else(), def_noop(), def_return(), + def_stall(), def_while() ), ) @@ -209,6 +210,27 @@ where .discard_result() } +fn def_stall<'a, 'c>() -> impl Parser<'a, 'c, ()> +where + 'c: 'a, +{ + /* + * DefStall := ExtOpPrefix 0x21 USecTime + * USecTime := TermArg => Integer + */ + ext_opcode(opcode::EXT_DEF_STALL_OP) + .then(comment_scope( + DebugVerbosity::Scopes, + "DefStall", + term_arg().map_with_context(|microseconds, context| { + let microseconds = try_with_context!(context, microseconds.as_integer(&context)); + context.handler.stall(microseconds); + (Ok(()), context) + }), + )) + .discard_result() +} + fn def_while<'a, 'c>() -> impl Parser<'a, 'c, ()> where 'c: 'a,