Skip to content

Commit 2fec65a

Browse files
committed
Implement DefAdd
1 parent e4b49be commit 2fec65a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

aml/src/opcode.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub const DEF_BREAKPOINT_OP: u8 = 0xcc;
4545
* Type 2 opcodes
4646
*/
4747
pub const DEF_STORE_OP: u8 = 0x70;
48+
pub const DEF_ADD_OP: u8 = 0x72;
4849
pub const DEF_SHIFT_LEFT: u8 = 0x79;
4950
pub const DEF_SHIFT_RIGHT: u8 = 0x7a;
5051
pub const DEF_AND_OP: u8 = 0x7b;

aml/src/type2.rs

+27
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ where
4040
DebugVerbosity::AllScopes,
4141
"Type2Opcode",
4242
choice!(
43+
def_add(),
4344
def_and(),
4445
def_buffer(),
4546
def_l_equal(),
@@ -58,6 +59,32 @@ where
5859
))
5960
}
6061

62+
pub fn def_add<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
63+
where
64+
'c: 'a,
65+
{
66+
/*
67+
* DefAdd := 0x72 Operand Operand Target
68+
* Operand := TermArg => Integer
69+
*/
70+
opcode(opcode::DEF_ADD_OP)
71+
.then(comment_scope(
72+
DebugVerbosity::AllScopes,
73+
"DefAdd",
74+
term_arg().then(term_arg()).then(target()).map_with_context(
75+
|((left_arg, right_arg), target), context| {
76+
let left = try_with_context!(context, left_arg.as_integer(context));
77+
let right = try_with_context!(context, right_arg.as_integer(context));
78+
let result = AmlValue::Integer(left.wrapping_add(right));
79+
80+
try_with_context!(context, context.store(target, result.clone()));
81+
(Ok(result), context)
82+
},
83+
),
84+
))
85+
.map(|((), result)| Ok(result))
86+
}
87+
6188
pub fn def_and<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
6289
where
6390
'c: 'a,

0 commit comments

Comments
 (0)