Skip to content

Commit bb3107a

Browse files
committed
aml: make InvalidOperationOnObject error more useful
1 parent 5ef7860 commit bb3107a

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

aml/src/lib.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

aml/src/object.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{AmlError, op_region::OpRegion};
1+
use crate::{AmlError, Handle, Operation, op_region::OpRegion};
22
use alloc::{borrow::Cow, string::String, sync::Arc, vec::Vec};
33
use bit_field::BitField;
44

@@ -92,7 +92,7 @@ impl Object {
9292
_ => panic!(),
9393
},
9494
Object::String(value) => Ok(value.as_bytes().to_vec()),
95-
_ => Err(AmlError::InvalidOperationOnObject),
95+
_ => Err(AmlError::InvalidOperationOnObject { op: Operation::ConvertToBuffer, typ: self.typ() }),
9696
}
9797
}
9898

@@ -107,7 +107,7 @@ impl Object {
107107
copy_bits(buffer, *offset, dst, 0, *length);
108108
Ok(())
109109
} else {
110-
Err(AmlError::InvalidOperationOnObject)
110+
Err(AmlError::InvalidOperationOnObject { op: Operation::ReadBufferField, typ: self.typ() })
111111
}
112112
}
113113

@@ -124,7 +124,7 @@ impl Object {
124124
copy_bits(value, 0, buffer, *offset, *length);
125125
Ok(())
126126
} else {
127-
Err(AmlError::InvalidOperationOnObject)
127+
Err(AmlError::InvalidOperationOnObject { op: Operation::WriteBufferField, typ: self.typ() })
128128
}
129129
}
130130

aml/src/pci_routing.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{
22
AmlError,
33
Handler,
44
Interpreter,
5+
Operation,
56
namespace::AmlName,
67
object::{Object, ReferenceKind},
78
resource::{self, InterruptPolarity, InterruptTrigger, Resource},
@@ -136,13 +137,13 @@ impl PciRoutingTable {
136137
_ => return Err(AmlError::PrtInvalidSource),
137138
}
138139
} else {
139-
return Err(AmlError::InvalidOperationOnObject);
140+
return Err(AmlError::InvalidOperationOnObject { op: Operation::DecodePrt, typ: value.typ() });
140141
}
141142
}
142143

143144
Ok(PciRoutingTable { entries })
144145
} else {
145-
Err(AmlError::InvalidOperationOnObject)
146+
return Err(AmlError::InvalidOperationOnObject { op: Operation::DecodePrt, typ: prt.typ() });
146147
}
147148
}
148149

aml/src/resource.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{AmlError, object::Object};
1+
use crate::{AmlError, Operation, object::Object};
22
use alloc::{sync::Arc, vec::Vec};
33
use bit_field::BitField;
44
use byteorder::{ByteOrder, LittleEndian};
@@ -32,7 +32,7 @@ pub fn resource_descriptor_list(descriptor: Arc<Object>) -> Result<Vec<Resource>
3232

3333
Ok(descriptors)
3434
} else {
35-
Err(AmlError::InvalidOperationOnObject)
35+
Err(AmlError::InvalidOperationOnObject { op: Operation::ParseResource, typ: descriptor.typ() })
3636
}
3737
}
3838

0 commit comments

Comments
 (0)