lib.rs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #![no_std]
  2. #![feature(decl_macro)]
  3. extern crate alloc;
  4. #[cfg(test)]
  5. extern crate std;
  6. #[cfg(test)]
  7. mod test_utils;
  8. pub(crate) mod name_object;
  9. pub(crate) mod opcode;
  10. pub(crate) mod parser;
  11. pub(crate) mod pkg_length;
  12. pub(crate) mod term_object;
  13. pub mod value;
  14. pub use crate::value::AmlValue;
  15. use alloc::{collections::BTreeMap, string::String};
  16. use log::{error, trace};
  17. use parser::Parser;
  18. use pkg_length::PkgLength;
  19. /// AML has a `RevisionOp` operator that returns the "AML interpreter revision". It's not clear
  20. /// what this is actually used for, but this is ours.
  21. pub const AML_INTERPRETER_REVISION: u64 = 0;
  22. #[derive(Clone, Copy, Debug, PartialEq, Eq)]
  23. pub enum AmlError {
  24. UnexpectedEndOfStream,
  25. UnexpectedByte(u8),
  26. InvalidNameSeg([u8; 4]),
  27. }
  28. pub struct AmlNamespace {
  29. namespace: BTreeMap<String, AmlValue>,
  30. }
  31. impl AmlNamespace {
  32. pub fn new() -> AmlNamespace {
  33. AmlNamespace { namespace: BTreeMap::new() }
  34. }
  35. pub fn parse_table(&mut self, stream: &[u8]) -> Result<(), AmlError> {
  36. if stream.len() == 0 {
  37. return Err(AmlError::UnexpectedEndOfStream);
  38. }
  39. match term_object::term_list(
  40. PkgLength::from_raw_length(stream, stream.len() as u32) as PkgLength
  41. )
  42. .parse(stream)
  43. {
  44. Ok(_) => Ok(()),
  45. Err((remaining, err)) => {
  46. error!("Failed to parse AML stream. Err = {:?}", err);
  47. trace!("Remaining AML: {:02x?}", remaining);
  48. Err(err)
  49. }
  50. }
  51. }
  52. }