Skip to content

Commit 3759c63

Browse files
committed
aml: add support for the DefSleep opcode
1 parent 133001e commit 3759c63

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

aml/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,10 @@ pub trait Handler: Send + Sync {
694694
/// 100 microseconds.
695695
fn stall(&self, microseconds: u64);
696696

697+
/// Sleep for at least the given number of **milliseconds**. An implementation may round to the closest sleep time
698+
/// supported, and should relinquish the processor.
699+
fn sleep(&self, milliseconds: u64);
700+
697701
fn handle_fatal_error(&self, fatal_type: u8, fatal_code: u32, fatal_arg: u64) {
698702
panic!("Fatal error while executing AML (encountered DefFatal op). fatal_type = {:?}, fatal_code = {:?}, fatal_arg = {:?}", fatal_type, fatal_code, fatal_arg);
699703
}

aml/src/opcode.rs

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub const DEF_RETURN_OP: u8 = 0xa4;
5656
pub const DEF_BREAK_OP: u8 = 0xa5;
5757
pub const DEF_BREAKPOINT_OP: u8 = 0xcc;
5858
pub const EXT_DEF_STALL_OP: u8 = 0x21;
59+
pub const EXT_DEF_SLEEP_OP: u8 = 0x22;
5960

6061
/*
6162
* Expression opcodes

aml/src/statement.rs

+22
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ where
3939
def_if_else(),
4040
def_noop(),
4141
def_return(),
42+
def_sleep(),
4243
def_stall(),
4344
def_while()
4445
),
@@ -210,6 +211,27 @@ where
210211
.discard_result()
211212
}
212213

214+
fn def_sleep<'a, 'c>() -> impl Parser<'a, 'c, ()>
215+
where
216+
'c: 'a,
217+
{
218+
/*
219+
* DefSleep := ExtOpPrefix 0x22 MSecTime
220+
* MSecTime := TermArg => Integer
221+
*/
222+
ext_opcode(opcode::EXT_DEF_SLEEP_OP)
223+
.then(comment_scope(
224+
DebugVerbosity::Scopes,
225+
"DefSleep",
226+
term_arg().map_with_context(|milliseconds, context| {
227+
let milliseconds = try_with_context!(context, milliseconds.as_integer(&context));
228+
context.handler.sleep(milliseconds);
229+
(Ok(()), context)
230+
}),
231+
))
232+
.discard_result()
233+
}
234+
213235
fn def_stall<'a, 'c>() -> impl Parser<'a, 'c, ()>
214236
where
215237
'c: 'a,

0 commit comments

Comments
 (0)