Skip to content

Implement Index and Bank fields#274

Open
martin-hughes wants to merge 2 commits intorust-osdev:mainfrom
martin-hughes:issue-212-no-tests
Open

Implement Index and Bank fields#274
martin-hughes wants to merge 2 commits intorust-osdev:mainfrom
martin-hughes:issue-212-no-tests

Conversation

@martin-hughes
Copy link
Contributor

Add support for Index and Bank fields.

I've written a selection of tests using the framework in #269, those are not included here (you can see my branch if you want to see them. If the testing stuff gets merged at some point, then I'll make a PR for the tests themselves.

I tried to test on live hardware, but my motherboard has some AML this crate doesn't currently support, so the only testing has been virtual.

If merged, would close #212.

// behaviour we allow is probably OK.
//
// But warn the user, just in case.
warn!("Data field access width is smaller than normal field width at {:?}", start_pc);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered whether to just panic!, but this weird case runs in ACPICA, it just gives odd results. Since the supposed "reference implementation" supports it acpi ought to as well, but it's weird and unlikely enough it's I felt it worth a warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supports permits

let aligned_offset = object::align_down(field.bit_index + i * access_width_bits, access_width_bits);
// Advance the read pointer. For Index fields, this also means updating the Index
// register.
let aligned_offset = match field.kind {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block isn't ideal - but the alternatives didn't seem great so I stuck with this slightly awkward code.

I considered:

  • Separating do_field_read (or do_field_write) into specialised normal and index-field variants, but that would be a nuisance to maintain - it'd be easy to fix bugs in one variant and forget to do the other
  • Perhaps the "advance the read pointer" could have been a closure provided by the previous match block? I thought it just made the code that bit less readable.

Ultimately I don't think these functions are going to be extended much in future, so there was no need to go for a gold-plated solution.

@martin-hughes martin-hughes marked this pull request as ready for review March 11, 2026 20:29
@martin-hughes
Copy link
Contributor Author

The branch name is now out of date - sorry Isaac! I've rebased on top of the now-merged test infra and added the test files to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AML: IndexField is not implemented

1 participant