Skip to content
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

implement RegId for x86/x86_64 #34

Merged
merged 2 commits into from
Oct 29, 2020
Merged

Conversation

keiichiw
Copy link
Contributor

This is one of action items in issue #29.

#[non_exhaustive]
pub enum X86_64CoreRegId {
/// General purpose registers: RAX, RBX, RCX, RDX, RSI, RDI, RBP, RSP, r8-r15
Gpr(u8),
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 also considered to have Rax, Rbx, etc as different enum variants but chose this design to align with the design of X86_64CoreRegs for now.
Which design do you prefer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The order of general purpose registers seems not to be well defined.
It looks inconsistent even in the Intel SDM. For example, RSI comes before RDI in some paragraphs, but it sometimes comes after RDI in other parts:(
That's why I had considered to have different variants for these registers. Actually, X86CoreRegs does so. (crosvm also does so.)

But, it's probably a different topic. The current design is also reasonable, as it simply follows the order defined in the GDB's XML file and the order is documented well. So, let me leave this design as is.

Copy link
Owner

Choose a reason for hiding this comment

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

Ahh, classic x86...

Personally, I'm now leaning towards breaking out RAX, RBX, ..., RSP into their own variants (and now that I think about it, the Segment registers as well). That said, I think it's fine if we leave the design as-is, as it matches the existing x86[_64]CoreRegs structure.

I'll probably open a tracking issue to break-up the GPRs + SRs into their own struct fields / variants, though that should be something I can take care of myself at some point closer to the release of 0.5

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good!
The register names are really confusing. Actually, when I was implementing the GDB feature for crosvm, I mistakenly swapped the order of RBP and RSP, and wasted a whole day to debug it😓
So, I'm really supportive of breaking GPRs + SRs into their own variants.

Copy link
Owner

Choose a reason for hiding this comment

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

I've gone ahead and opened the tracking issue at #35

If you're bored, feel free to open a PR for it yourself, otherwise, I'll try to get around to it at some arbitrary point in the future 😄

@keiichiw
Copy link
Contributor Author

@daniel5151 Please take a look.
FYI, I'm working to use this crate in crosvm. (Yeah, I know you worked on crosvm before!)

Copy link
Owner

@daniel5151 daniel5151 left a comment

Choose a reason for hiding this comment

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

Thank you for the PR!

I have a couple of comments, but all in all, this LGTM 👍


I won't lie, I'm pretty excited to see that my library might be integrated into crosvm!
I had a blast working on crosvm as an intern, and I'm glad to be able to contribute back to it again (albeit indirectly 😉)

src/arch/x86/reg/id.rs Outdated Show resolved Hide resolved
src/arch/x86/reg/id.rs Outdated Show resolved Hide resolved
src/arch/x86/reg/id.rs Outdated Show resolved Hide resolved
src/arch/x86/reg/id.rs Outdated Show resolved Hide resolved
src/arch/x86/mod.rs Outdated Show resolved Hide resolved
src/arch/x86/reg/id.rs Outdated Show resolved Hide resolved
@keiichiw
Copy link
Contributor Author

Please take a look again. I addressed your comments. Also, I added tests.

@keiichiw keiichiw changed the title implement RegId for x86_64 implement RegId for x86/x86_64 Oct 28, 2020
Copy link
Owner

@daniel5151 daniel5151 left a comment

Choose a reason for hiding this comment

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

Awesome!

Thanks again for implementing the x86 register ids as well, I really appreciate it!

I've just got a few more nits and comments, but after those are addressed, this should be ready to merge 🚢

Cargo.toml Outdated Show resolved Hide resolved
#[non_exhaustive]
pub enum X86_64CoreRegId {
/// General purpose registers: RAX, RBX, RCX, RDX, RSI, RDI, RBP, RSP, r8-r15
Gpr(u8),
Copy link
Owner

Choose a reason for hiding this comment

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

Ahh, classic x86...

Personally, I'm now leaning towards breaking out RAX, RBX, ..., RSP into their own variants (and now that I think about it, the Segment registers as well). That said, I think it's fine if we leave the design as-is, as it matches the existing x86[_64]CoreRegs structure.

I'll probably open a tracking issue to break-up the GPRs + SRs into their own struct fields / variants, though that should be something I can take care of myself at some point closer to the release of 0.5

src/arch/x86/reg/id.rs Outdated Show resolved Hide resolved
src/arch/x86/reg/id.rs Outdated Show resolved Hide resolved
src/arch/x86/reg/id.rs Show resolved Hide resolved
@keiichiw
Copy link
Contributor Author

Thanks for the comments and suggestions! I addressed them 😄

Copy link
Owner

@daniel5151 daniel5151 left a comment

Choose a reason for hiding this comment

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

I'll go ahead and push out a minor version sometime today that includes your two PRs.

Fantastic work, thanks again!

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.

2 participants