@@ -1120,13 +1120,14 @@ where
11201120 } ;
11211121
11221122 let result = Arc :: new ( Object :: Integer ( result) ) ;
1123+ // TODO: use result for arg
11231124 self . do_store ( context, target, result. clone ( ) ) ?;
11241125 context. contribute_arg ( Argument :: Object ( result) ) ;
11251126 Ok ( ( ) )
11261127 }
11271128
11281129 fn do_unary_maths( & self , context: & mut MethodContext , op: OpInFlight ) -> Result <( ) , AmlError > {
1129- let [ Argument :: Object ( operand) ] = & op. arguments [ ..] else { Err ( AmlError :: InvalidOperationOnObject ) ? } ;
1130+ let [ Argument :: Object ( operand) ] = & op. arguments [ ..] else { panic ! ( ) } ;
11301131 let operand = operand. clone ( ) . unwrap_transparent_reference ( ) . as_integer ( ) ?;
11311132
11321133 let result = match op. op {
@@ -1137,6 +1138,7 @@ where
11371138 /*
11381139 * TODO: this is a particular instance where not respecting integers being
11391140 * 32-bit on revision 1 tables does cause properly incorrect behaviour...
1141+ * TODO: we can fix this now we have the DSDT revision
11401142 */
11411143 ( operand. leading_zeros ( ) + 1 ) as u64
11421144 }
@@ -1164,7 +1166,7 @@ where
11641166
11651167 fn do_logical_op( & self , context: & mut MethodContext , op: OpInFlight ) -> Result <( ) , AmlError > {
11661168 if op. op == Opcode :: LNot {
1167- let [ Argument :: Object ( operand) ] = & op. arguments [ ..] else { Err ( AmlError :: InvalidOperationOnObject ) ? } ;
1169+ let [ Argument :: Object ( operand) ] = & op. arguments [ ..] else { panic ! ( ) } ;
11681170 let operand = operand. clone ( ) . unwrap_transparent_reference ( ) . as_integer ( ) ?;
11691171 let result = if operand == 0 { u64:: MAX } else { 0 } ;
11701172
@@ -1177,9 +1179,7 @@ where
11771179 return Ok ( ( ) ) ;
11781180 }
11791181
1180- let [ Argument :: Object ( left) , Argument :: Object ( right) ] = & op. arguments [ ..] else {
1181- Err ( AmlError :: InvalidOperationOnObject ) ?
1182- } ;
1182+ let [ Argument :: Object ( left) , Argument :: Object ( right) ] = & op. arguments [ ..] else { panic ! ( ) } ;
11831183
11841184 /*
11851185 * Some of these operations allow strings and buffers to be used as operands. Apparently
@@ -1220,7 +1220,7 @@ where
12201220 } ;
12211221 ( left, right)
12221222 }
1223- _ => panic ! ( ) ,
1223+ _ => Err ( AmlError :: InvalidOperationOnObject { op : Operation :: LogicalOp , typ : left . typ ( ) } ) ? ,
12241224 } ;
12251225
12261226 let result = match op. op {
@@ -1268,7 +1268,7 @@ where
12681268 Object :: Buffer ( bytes. to_vec ( ) )
12691269 }
12701270 }
1271- _ => Err ( AmlError :: InvalidOperationOnObject ) ?,
1271+ _ => Err ( AmlError :: InvalidOperationOnObject { op : Operation :: Mid , typ : source . typ ( ) } ) ?,
12721272 } ) ;
12731273
12741274 self . do_store ( context, target, result. clone ( ) ) ?;
@@ -1334,7 +1334,7 @@ where
13341334 }
13351335
13361336 fn do_from_bcd( & self , context: & mut MethodContext , op: OpInFlight ) -> Result <( ) , AmlError > {
1337- let [ Argument :: Object ( value) ] = & op. arguments [ ..] else { Err ( AmlError :: InvalidOperationOnObject ) ? } ;
1337+ let [ Argument :: Object ( value) ] = & op. arguments [ ..] else { panic ! ( ) } ;
13381338 let mut value = value. clone ( ) . unwrap_transparent_reference ( ) . as_integer ( ) ?;
13391339
13401340 let mut result = 0 ;
@@ -1350,7 +1350,7 @@ where
13501350 }
13511351
13521352 fn do_to_bcd( & self , context: & mut MethodContext , op: OpInFlight ) -> Result <( ) , AmlError > {
1353- let [ Argument :: Object ( value) ] = & op. arguments [ ..] else { Err ( AmlError :: InvalidOperationOnObject ) ? } ;
1353+ let [ Argument :: Object ( value) ] = & op. arguments [ ..] else { panic ! ( ) } ;
13541354 let mut value = value. clone ( ) . unwrap_transparent_reference ( ) . as_integer ( ) ?;
13551355
13561356 let mut result = 0 ;
@@ -1366,14 +1366,14 @@ where
13661366 }
13671367
13681368 fn do_size_of( & self , context: & mut MethodContext , op: OpInFlight ) -> Result <( ) , AmlError > {
1369- let [ Argument :: Object ( object) ] = & op. arguments [ ..] else { Err ( AmlError :: InvalidOperationOnObject ) ? } ;
1369+ let [ Argument :: Object ( object) ] = & op. arguments [ ..] else { panic ! ( ) } ;
13701370 let object = object. clone ( ) . unwrap_reference ( ) ;
13711371
13721372 let result = match * object {
13731373 Object :: Buffer ( ref buffer) => buffer. len ( ) ,
13741374 Object :: String ( ref str) => str. len ( ) ,
13751375 Object :: Package ( ref package) => package. len ( ) ,
1376- _ => Err ( AmlError :: InvalidOperationOnObject ) ?,
1376+ _ => Err ( AmlError :: InvalidOperationOnObject { op : Operation :: SizeOf , typ : object . typ ( ) } ) ?,
13771377 } ;
13781378
13791379 context. contribute_arg ( Argument :: Object ( Arc :: new ( Object :: Integer ( result as u64 ) ) ) ) ;
@@ -2171,6 +2171,21 @@ enum Opcode {
21712171 InternalMethodCall ,
21722172}
21732173
2174+ #[ derive( Clone , Copy , PartialEq , Debug ) ]
2175+ pub enum Operation {
2176+ Mid ,
2177+ SizeOf ,
2178+ Acquire ,
2179+ Release ,
2180+ ConvertToBuffer ,
2181+
2182+ ReadBufferField ,
2183+ WriteBufferField ,
2184+ LogicalOp ,
2185+ DecodePrt ,
2186+ ParseResource ,
2187+ }
2188+
21742189/*
21752190 * TODO: not sure if we should use a better error reporting system or just keep a giant enum?
21762191 */
@@ -2197,7 +2212,7 @@ pub enum AmlError {
21972212
21982213 MethodArgCountIncorrect ,
21992214
2200- InvalidOperationOnObject ,
2215+ InvalidOperationOnObject { op : Operation , typ : ObjectType } ,
22012216 IndexOutOfBounds ,
22022217 ObjectNotOfExpectedType { expected : ObjectType , got : ObjectType } ,
22032218
0 commit comments