Skip to content

Commit 514e55d

Browse files
committed
Parse DefFatal and report to the user
1 parent 1eedc2a commit 514e55d

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

aml/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,10 @@ pub trait Handler: Send + Sync {
674674
fn write_pci_u8(&self, segment: u16, bus: u8, device: u8, function: u8, offset: u16, value: u8);
675675
fn write_pci_u16(&self, segment: u16, bus: u8, device: u8, function: u8, offset: u16, value: u16);
676676
fn write_pci_u32(&self, segment: u16, bus: u8, device: u8, function: u8, offset: u16, value: u32);
677+
678+
fn handle_fatal_error(&self, fatal_type: u8, fatal_code: u32, fatal_arg: u64) {
679+
panic!("Fatal error while executing AML (encountered DefFatal op). fatal_type = {:?}, fatal_code = {:?}, fatal_arg = {:?}", fatal_type, fatal_code, fatal_arg);
680+
}
677681
}
678682

679683
#[derive(Clone, PartialEq, Eq, Debug)]
@@ -699,6 +703,8 @@ pub enum AmlError {
699703
/// that parser (e.g. the wrong opcode starts the stream). This is handled specially by some
700704
/// parsers such as `or` and `choice!`.
701705
WrongParser,
706+
/// Returned when a `DefFatal` op is encountered. This is separately reported using [`Handler::handle_fatal_error`].
707+
FatalError,
702708

703709
/*
704710
* Errors produced manipulating AML names.

aml/src/opcode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub const DEF_CREATE_QWORD_FIELD_OP: u8 = 0x8f;
3434
pub const EXT_DEF_MUTEX_OP: u8 = 0x01;
3535
pub const EXT_DEF_CREATE_FIELD_OP: u8 = 0x13;
3636
pub const EXT_REVISION_OP: u8 = 0x30;
37+
pub const EXT_DEF_FATAL_OP: u8 = 0x32;
3738
pub const EXT_DEF_OP_REGION_OP: u8 = 0x80;
3839
pub const EXT_DEF_FIELD_OP: u8 = 0x81;
3940
pub const EXT_DEF_DEVICE_OP: u8 = 0x82;

aml/src/type1.rs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
use crate::{
2-
opcode::{self, opcode},
3-
parser::{choice, comment_scope, id, take_to_end_of_pkglength, ParseResult, Parser, Propagate},
2+
opcode::{self, ext_opcode, opcode},
3+
parser::{
4+
choice,
5+
comment_scope,
6+
id,
7+
take,
8+
take_to_end_of_pkglength,
9+
take_u32,
10+
try_with_context,
11+
ParseResult,
12+
Parser,
13+
Propagate,
14+
},
415
pkg_length::{pkg_length, PkgLength},
516
term_object::{term_arg, term_list},
17+
AmlContext,
18+
AmlError,
619
DebugVerbosity,
720
};
821

@@ -19,7 +32,7 @@ where
1932
comment_scope(
2033
DebugVerbosity::AllScopes,
2134
"Type1Opcode",
22-
choice!(def_breakpoint(), def_if_else(), def_noop(), def_return()),
35+
choice!(def_breakpoint(), def_fatal(), def_if_else(), def_noop(), def_return()),
2336
)
2437
}
2538

@@ -37,6 +50,31 @@ where
3750
.discard_result()
3851
}
3952

53+
fn def_fatal<'a, 'c>() -> impl Parser<'a, 'c, ()>
54+
where
55+
'c: 'a,
56+
{
57+
/*
58+
* DefFatal := ExtOpPrefix 0x32 FatalType FatalCode FatalArg
59+
* FatalType := ByteData
60+
* FatalCode := DWordData
61+
* FatalArg := TermArg => Integer
62+
*/
63+
ext_opcode(opcode::EXT_DEF_FATAL_OP)
64+
.then(comment_scope(
65+
DebugVerbosity::Scopes,
66+
"DefFatal",
67+
take().then(take_u32()).then(term_arg()).map_with_context(
68+
|((fatal_type, fatal_code), fatal_arg), context| -> (Result<(), Propagate>, &'c mut AmlContext) {
69+
let fatal_arg = try_with_context!(context, fatal_arg.as_integer(context));
70+
context.handler.handle_fatal_error(fatal_type, fatal_code, fatal_arg);
71+
(Err(Propagate::Err(AmlError::FatalError)), context)
72+
},
73+
),
74+
))
75+
.discard_result()
76+
}
77+
4078
fn def_if_else<'a, 'c>() -> impl Parser<'a, 'c, ()>
4179
where
4280
'c: 'a,

0 commit comments

Comments
 (0)