Skip to content

Add registers::debug #286

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

Merged
merged 12 commits into from
Jun 23, 2022
Merged

Add registers::debug #286

merged 12 commits into from
Jun 23, 2022

Conversation

mkroening
Copy link
Member

@mkroening mkroening commented Jul 26, 2021

Fixes #284.

This adds registers::debug.

  • Dr0-Dr3 implement DebugAddressRegister.
  • Dr6Flags can be read from Dr6.

For Dr7 I added Dr7Value which contain Dr7Flags but has functions to modify the bits corresponding to the condition and size fields. Via Dr7Value::flags_mut, you can modify flags in place.

@mkroening mkroening force-pushed the debug-registers branch 7 times, most recently from 1961e1e to 805333e Compare July 29, 2021 09:56
@mkroening mkroening force-pushed the debug-registers branch 2 times, most recently from af0e41e to d2fe1cb Compare August 26, 2021 16:37
@mkroening mkroening marked this pull request as ready for review August 26, 2021 16:38
@mkroening
Copy link
Member Author

I added docs to everything and properly integrated the assembly.

Could you enable the CI for this PR and review it? :)

@josephlr
Copy link
Contributor

@mkroening The basic structure here looks reasonable, I'll see if I have time for a full review this weekend.

@josephlr josephlr self-assigned this Aug 26, 2021
@josephlr josephlr added the waiting-for-review Waiting for a review from the maintainers. label Aug 26, 2021
///
/// This can be used to modify the flags of this value in-place.
#[inline]
pub fn flags_mut(&mut self) -> &mut Dr7Flags {
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not completely happy with this function, as it could be misused.

I added it to have a way of modifying the Dr7Flags bits inside the Dr7Value. Doing so via this mutable reference causes unintended side effects to the fields in Dr7Value. Perhaps it would be better to manually implement all operations for adding/removing flags from the value instead of transmuting self to the flags. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

If additional bits are allowed for Dr7Flags, can't we make use Dr7Flags for the inner value directly (instead of u64)?

Alternatively, we could also merge the Dr7Value type into the Dr7Flags type by defining the additional methods in an impl Dr7Flags block. To get the same behavior for from_bits_truncate, we could define an addional bitflag const for all the additional value, i.e. const CONDITIONS_AND_SIZE = (1 << 32) - (1 << 16);.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, yes. We could use Dr7Flags for the inner value.

It would expose the same (problematic?) behavior as defining methods on Dr7Flags or the current behavior: When you have a valid Dr7Value, there are values which are no bitflags (HwBreakpointCondition and HwBreakpointSize). If those values are set to some non-zero value, the behavior of BitAnd and similar traits are not behaving as one might expect.

So I think to cleanly solve this problem, we would have to remove flags_mut and implement BitAnd<Flags> for Value and similar traits manually. We could additionally make use of Dr7Flags for the inner value, but I am not sure yet if that would be beneficial. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

All right. I went ahead and removed this method and any unsafe code handling this type in 0eff064.

I forbid any use of extra bits in the representation of Dr7Flags and added the explicit *_flags methods for manipulating Dr7Value. What do you think?

@mkroening
Copy link
Member Author

Rebased on latest master.

Copy link
Member

@phil-opp phil-opp left a comment

Choose a reason for hiding this comment

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

Looks very good, thanks a lot! I left a few comments, otherwise this seems ready to be merged.

Sorry for the delay from our side. Thanks for keeping the PR up-to-date!

///
/// This can be used to modify the flags of this value in-place.
#[inline]
pub fn flags_mut(&mut self) -> &mut Dr7Flags {
Copy link
Member

Choose a reason for hiding this comment

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

If additional bits are allowed for Dr7Flags, can't we make use Dr7Flags for the inner value directly (instead of u64)?

Alternatively, we could also merge the Dr7Value type into the Dr7Flags type by defining the additional methods in an impl Dr7Flags block. To get the same behavior for from_bits_truncate, we could define an addional bitflag const for all the additional value, i.e. const CONDITIONS_AND_SIZE = (1 << 32) - (1 << 16);.

@phil-opp phil-opp added waiting-on-author Waiting for the author to act on review feedback. and removed waiting-for-review Waiting for a review from the maintainers. labels Nov 6, 2021
@mkroening
Copy link
Member Author

Thanks a lot for the review! I addressed all small issues and have added my thoughts on the big remaining one.

@Freax13 Freax13 added waiting-for-review Waiting for a review from the maintainers. and removed waiting-on-author Waiting for the author to act on review feedback. labels Feb 5, 2022
@mkroening
Copy link
Member Author

Thanks a lot for your reviews and sorry for the wait! I addressed all comments and would appreciate another round of reviews. :)

@Freax13 Freax13 added waiting-for-review Waiting for a review from the maintainers. and removed waiting-on-author Waiting for the author to act on review feedback. labels Jun 22, 2022
Copy link
Member

@Freax13 Freax13 left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@josephlr Do you also want to do another round of review?

Copy link
Contributor

@josephlr josephlr left a comment

Choose a reason for hiding this comment

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

LGTM, the only thing we might want to change is the fact that we have really long names starting with Debug, given that the module is also called debug. So it might make sense to shorten the names to remove the Debug prefix.

@Freax13 your thoughts?

@Freax13
Copy link
Member

Freax13 commented Jun 23, 2022

LGTM, the only thing we might want to change is the fact that we have really long names starting with Debug, given that the module is also called debug. So it might make sense to shorten the names to remove the Debug prefix.

@Freax13 your thoughts?

I think we should keep the prefix, this only affects two types and the names might sound a bit too generic without the Debug prefix (AddressRegister, AddressRegisterNumber). I'd rather we strip the Hw prefix from HwBreakpointCondition and HwBreakpointSize, it's a bit unidiomatic to use abbreviations in type names and it should be pretty clear that those types are meant for hardware breakpoints anyways.

@mkroening
Copy link
Member Author

I renamed them to BreakpointCondition and BreakpointSize respectively. 👍

@josephlr josephlr merged commit 3a8f380 into rust-osdev:master Jun 23, 2022
@Freax13
Copy link
Member

Freax13 commented Jun 23, 2022

Thank you for your contribution! 🥳

@mkroening mkroening deleted the debug-registers branch June 23, 2022 20:23
@mkroening
Copy link
Member Author

🥳 Thanks for your help!

@mkroening
Copy link
Member Author

Would it be possible to have a 0.14.10 release containing these additions? It would help us out a lot. :)

@phil-opp
Copy link
Member

I created a release PR at #386.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-review Waiting for a review from the maintainers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Abstractions over debug registers (DR0-DR7)
5 participants