Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement DefAdd
  • Loading branch information
IsaacWoods committed Jan 10, 2021
1 parent e4b49be commit 2fec65a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions aml/src/opcode.rs
Expand Up @@ -45,6 +45,7 @@ pub const DEF_BREAKPOINT_OP: u8 = 0xcc;
* Type 2 opcodes
*/
pub const DEF_STORE_OP: u8 = 0x70;
pub const DEF_ADD_OP: u8 = 0x72;
pub const DEF_SHIFT_LEFT: u8 = 0x79;
pub const DEF_SHIFT_RIGHT: u8 = 0x7a;
pub const DEF_AND_OP: u8 = 0x7b;
Expand Down
27 changes: 27 additions & 0 deletions aml/src/type2.rs
Expand Up @@ -40,6 +40,7 @@ where
DebugVerbosity::AllScopes,
"Type2Opcode",
choice!(
def_add(),
def_and(),
def_buffer(),
def_l_equal(),
Expand All @@ -58,6 +59,32 @@ where
))
}

pub fn def_add<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
where
'c: 'a,
{
/*
* DefAdd := 0x72 Operand Operand Target
* Operand := TermArg => Integer
*/
opcode(opcode::DEF_ADD_OP)
.then(comment_scope(
DebugVerbosity::AllScopes,
"DefAdd",
term_arg().then(term_arg()).then(target()).map_with_context(
|((left_arg, right_arg), target), context| {
let left = try_with_context!(context, left_arg.as_integer(context));
let right = try_with_context!(context, right_arg.as_integer(context));
let result = AmlValue::Integer(left.wrapping_add(right));

try_with_context!(context, context.store(target, result.clone()));
(Ok(result), context)
},
),
))
.map(|((), result)| Ok(result))
}

pub fn def_and<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
where
'c: 'a,
Expand Down

0 comments on commit 2fec65a

Please sign in to comment.