-
-
Notifications
You must be signed in to change notification settings - Fork 79
Support multiple tables per test in aml_tester
#284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
martin-hughes
wants to merge
1
commit into
rust-osdev:main
Choose a base branch
from
martin-hughes:i275-aml-tester-multi-table
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* This file is a test for `aml_tester` rather than of the parser itself. | ||
| * Can `aml_tester` cope with multiple tables? | ||
| */ | ||
| DefinitionBlock("", "DSDT", 1, "RSACPI", "BUFFLD", 1) { | ||
| OperationRegion(MEM, SystemMemory, 0x40000, 0x1000) | ||
| Field(MEM, ByteAcc, NoLock, Preserve) { | ||
| A, 8 | ||
| } | ||
| } | ||
| DefinitionBlock("", "SSDT", 1, "RSACPI", "BUFFLD", 1) { | ||
| OperationRegion(MEMB, SystemMemory, 0x50000, 0x1000) | ||
| Field(MEMB, ByteAcc, NoLock, Preserve) { | ||
| B, 8 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| //! A basic interpreter to extract ACPI tables from byte-slices. | ||
|
|
||
| use acpi::sdt::SdtHeader; | ||
| use std::mem::transmute; | ||
|
|
||
| const AML_TABLE_HEADER_LENGTH: usize = 36; | ||
|
|
||
| /// An ACPI table separated into header and content. | ||
| /// | ||
| /// This is not provided in the main crate as it is unnecessary - but it is useful for testing. | ||
| pub struct TestAcpiTable { | ||
| header: SdtHeader, | ||
| content: Vec<u8>, | ||
| } | ||
|
|
||
| impl TryFrom<&[u8]> for TestAcpiTable { | ||
| type Error = &'static str; | ||
|
|
||
| fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> { | ||
| if bytes.len() < AML_TABLE_HEADER_LENGTH { | ||
| return Err("Buffer shorter than table header"); | ||
| } | ||
|
|
||
| let mut header_bytes: [u8; AML_TABLE_HEADER_LENGTH] = [0; AML_TABLE_HEADER_LENGTH]; | ||
| header_bytes.copy_from_slice(&bytes[..AML_TABLE_HEADER_LENGTH]); | ||
| let header: SdtHeader = unsafe { transmute(header_bytes) }; | ||
|
|
||
| if header.length < AML_TABLE_HEADER_LENGTH as u32 { | ||
| return Err("AML table header reported length too short"); | ||
| } | ||
|
|
||
| let content = bytes[AML_TABLE_HEADER_LENGTH..header.length as usize].to_vec(); | ||
|
|
||
| Ok(Self { header, content }) | ||
| } | ||
| } | ||
|
|
||
| /// Provide accessor functions for the two fields - don't provide write access so that `content` | ||
| /// and `header` can't get out of sync with each other. | ||
| impl TestAcpiTable { | ||
| pub fn content(&self) -> &[u8] { | ||
| &self.content | ||
| } | ||
|
|
||
| pub fn header(&self) -> &SdtHeader { | ||
| &self.header | ||
| } | ||
| } | ||
|
|
||
| /// Construct a Vec of AML tables from a slice of bytes. | ||
| pub fn bytes_to_tables(bytes: &[u8]) -> Result<Vec<TestAcpiTable>, &'static str> { | ||
| let mut tables = Vec::new(); | ||
| let mut offset = 0; | ||
|
|
||
| while offset < bytes.len() { | ||
| let table = TestAcpiTable::try_from(&bytes[offset..])?; | ||
| offset += table.header.length as usize; | ||
| tables.push(table); | ||
| } | ||
|
|
||
| Ok(tables) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not aware of any big-endian archs with ACPI support, but the spec does specify all values are little-endian on all machines. If we do want to tackle this / care about it, we likely need a better abstraction and would need to make a pretty substantial number of changes to tables + potentially the interpreter. Does this need to be handled for this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah no, not in this PR - this was a bit of a lazy comment from me, sorry!
I was aiming to just have a reminder that additional work is needed for big-endian support, since I think it's not explicity documented anywhere. I plopped it in whilst thinking about how to load table headers from byte-slices -
transmuteis obviously useful on little-endian machines, but not so good on big-endian ones.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(as you say though - big-endian machines running ACPI don't seem to be especially common outside of weird qemu testing setups)