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

riscv: define mcause using CSR macros #233

Merged
merged 1 commit into from
Oct 27, 2024

Conversation

rmsyn
Copy link
Contributor

@rmsyn rmsyn commented Oct 21, 2024

Uses CSR helper macros to define the mcause register.

Related: #229

@rmsyn rmsyn requested a review from a team as a code owner October 21, 2024 00:20
@rmsyn rmsyn added this to the riscv 0.13.0 milestone Oct 21, 2024
Copy link
Contributor

@romancardenas romancardenas left a comment

Choose a reason for hiding this comment

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

Can't we use a target-dependent const INTERRUPT_BIT set to 31 or 63 and forget about all these #[cfg(target_arch=...)]? I guess that to support that we would need to tweak the macros once again...

(This suggestion is not a strong one, if you feel that it is not necessary, I'm OK with the current approach)

@rmsyn
Copy link
Contributor Author

rmsyn commented Oct 23, 2024

Can't we use a target-dependent const INTERRUPT_BIT set to 31 or 63 and forget about all these #[cfg(target_arch=...)]?

So, the problem I ran into here is that the macro helpers currently use literals for bitfield indexes (single, repeated-range, and field-range).

I attempted to use the tt fragment specifier, but it causes matching issues with the branch arms. It is too generic, and ends up matching with delimiting characters.

Using tt seems to work for the invocations in mcountinhibit, but fails with the test cases in riscv/src/register/tests/*.

The expr fragment specifier also doesn't work, because of the $bit_start ..= $bit_end and [$bit_start : $bit_end] syntax.

Using item is too exclusive, because it leaves out literal.

That leaves us with using literal, and the somewhat awkward implementation syntax you pointed out.

If you know some other macro-fu to resolve the issue, I am happy to refactor.

(This suggestion is not a strong one, if you feel that it is not necessary, I'm OK with the current approach)

I would also prefer more flexibility, but it seems this would require doubling the existing macro arms to include those that use tt, and those that use literal. This would be for each arm in the *csr_field macros.

Edit: even this looks like it wouldn't work, and we'd probably need to move to procedural macros instead of declarative.

romancardenas
romancardenas previously approved these changes Oct 23, 2024
Copy link
Contributor

@romancardenas romancardenas left a comment

Choose a reason for hiding this comment

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

Let's leave it as is

Uses CSR helper macros to define the `mcause` register.
@romancardenas romancardenas added this pull request to the merge queue Oct 27, 2024
Merged via the queue into rust-embedded:master with commit b60a5a7 Oct 27, 2024
101 checks passed
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