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

Fix observing CHERI execution mode code #506

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

James-Williams
Copy link
Contributor

The example for observing the CHERI execution mode for privilege modes other than debug incorrectly uses gctag instead of gcmode.

Copy link
Collaborator

@jrtc27 jrtc27 left a comment

Choose a reason for hiding this comment

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

Existing code is correct, if confusing. New code is not.

@@ -109,7 +109,7 @@ for {cheri_cap_mode_name} and {INT_MODE_VALUE} for

```
auipc c1, 0
gctag x1, c1
gcmode x1, c1
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is wrong though. AUIPC in integer mode gives you an integer not a capability. Hence the use of GCTAG to determine whether you got an integer or a capability.

Of course, the elephant in the room is that you've had to tell your assembler what mode you're in in order to assemble it in the first place, and if you lie to your assembler then generally speaking all bets are off (e.g. with RVC enabled it'll compress some instructions to encodings that mean different things between RV32 and RV64). Generally speaking you should never do this, and you'll always know what mode you're in anyway based on your execution environment. However, just as the privileged spec mentions how to probe XLEN (which has exactly the same, if not more, dodginess when it comes to running code assembled for one base ISA on another), I guess it's ok to have something here. But this may be worth (a) a disclaimer reminding people this is bad practice and dangerous (b) explaining why it's GCTAG (and that AUIPC is the integer form in integer mode).

Copy link
Collaborator

Choose a reason for hiding this comment

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

yep - this needs gctag instead. I guess this needs some words somewhere in the spec to clarify (I remember this came up recently - maybe it's just in an issue)

@tariqkurd-repo tariqkurd-repo marked this pull request as draft January 14, 2025 10:17
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.

3 participants