-
Notifications
You must be signed in to change notification settings - Fork 21
Add an implementation of the proposed CRelocate instruction #62
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
Open
jrtc27
wants to merge
2
commits into
master
Choose a base branch
from
crelocate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -854,6 +854,39 @@ function clause execute (CFromPtr(cd, cs1, rs2)) = { | |
} | ||
} | ||
|
||
union clause ast = CRelocate : (regidx, regidx, regidx) | ||
/*! | ||
* Capability register *cd* is set equal to capability register *cs1*, with the | ||
* **tag** field cleared, and its **base** and **address* replaced with | ||
* *cs1*.**base** $+$ *rs2* and *cs1*.**address** $+$ *rs2* respectively, | ||
* subject to representability. If the resulting capability is not | ||
* representable, the value of *rs2* as used for both calculations is | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find this sentence rather hard to parse |
||
* truncated, and for out-of-bounds capabilities where the **address* is not | ||
* representable with the requested **base** the **address** is further | ||
* adjusted to yield the requested **base**. | ||
* | ||
* ## Notes | ||
* | ||
* This instruction is designed to accelerate relocating capabilities in | ||
* position-independent code at load time which will then be given to | ||
* [CBuildCap]. | ||
* | ||
* Unlike instructions like [CIncOffset] where unrepresentable capabilities | ||
* result in changing the **base** but keeping the **address**, this | ||
* instruction instead keeps the **base** but changes the **address** in order | ||
* to avoid introducing accidental aliasing for invalid requests where *rs2* is | ||
* nevertheless sufficiently aligned. | ||
*/ | ||
function clause execute(CRelocate(cd, cs1, rs2)) = { | ||
let cs1_val = C(cs1); | ||
let rs2_val = X(rs2); | ||
|
||
let cd1 = invalidateCap(cs1_val); | ||
let (_, cd2) = relocateCap(cd1, rs2_val); | ||
C(cd) = cd2; | ||
RETIRE_SUCCESS | ||
} | ||
|
||
union clause ast = CBuildCap : (regidx, regidx, regidx) | ||
/*! | ||
* Capability register *cd* is set equal to capability register *cs1* with its | ||
|
@@ -2421,6 +2454,7 @@ mapping clause encdec = CSetBoundsExact(cd, cs1, rs2) if (haveXcheri()) <-> 0b00 | |
mapping clause encdec = CBuildCap(cd, cs1, cs2) if (haveXcheri()) <-> 0b0011101 @ cs2 @ cs1 @ 0b000 @ cd @ 0b1011011 if (haveXcheri()) | ||
mapping clause encdec = CCopyType(cd, cs1, cs2) if (haveXcheri()) <-> 0b0011110 @ cs2 @ cs1 @ 0b000 @ cd @ 0b1011011 if (haveXcheri()) | ||
mapping clause encdec = CCSeal(cd, cs1, cs2) if (haveXcheri()) <-> 0b0011111 @ cs2 @ cs1 @ 0b000 @ cd @ 0b1011011 if (haveXcheri()) | ||
mapping clause encdec = CRelocate(cd, cs1, rs2) if (haveXcheri()) <-> 0b0010101 @ rs2 @ cs1 @ 0b000 @ cd @ 0b1011011 if (haveXcheri()) | ||
|
||
mapping clause encdec = CToPtr(rd, cs1, cs2) if (haveXcheri()) <-> 0b0010010 @ cs2 @ cs1 @ 0b000 @ rd @ 0b1011011 if (haveXcheri()) | ||
mapping clause encdec = CFromPtr(cd, cs1, rs2) if (haveXcheri()) <-> 0b0010011 @ rs2 @ cs1 @ 0b000 @ cd @ 0b1011011 if (haveXcheri()) | ||
|
@@ -2446,6 +2480,7 @@ mapping clause assembly = CSetBoundsExact(cd, cs1, rs2) <-> "csetboundsexact" ^ | |
mapping clause assembly = CBuildCap(cd, cs1, cs2) <-> "cbuildcap" ^ spc() ^ cap_reg_name(cd) ^ sep() ^ cap_reg_name(cs1) ^ sep() ^ cap_reg_name(cs2) | ||
mapping clause assembly = CCopyType(cd, cs1, cs2) <-> "ccopytype" ^ spc() ^ cap_reg_name(cd) ^ sep() ^ cap_reg_name(cs1) ^ sep() ^ cap_reg_name(cs2) | ||
mapping clause assembly = CCSeal(cd, cs1, cs2) <-> "ccseal" ^ spc() ^ cap_reg_name(cd) ^ sep() ^ cap_reg_name(cs1) ^ sep() ^ cap_reg_name(cs2) | ||
mapping clause assembly = CRelocate(cd, cs1, rs2) <-> "crelocate" ^ spc() ^ cap_reg_name(cd) ^ sep() ^ cap_reg_name(cs1) ^ sep() ^ reg_name(rs2) | ||
|
||
mapping clause assembly = CToPtr(rd, cs1, cs2) <-> "ctoptr" ^ spc() ^ reg_name(rd) ^ sep() ^ cap_reg_name(cs1) ^ sep() ^ cap_reg_name(cs2) | ||
mapping clause assembly = CFromPtr(cd, cs1, rs2) <-> "cfromptr" ^ spc() ^ cap_reg_name(cd) ^ sep() ^ cap_reg_name(cs1) ^ sep() ^ reg_name(rs2) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a rather large and complex piece of code that looks like a close duplicate of other decoding code. I think this could either do with comments and/or share more code with getCapBoundsBits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, parts of it do, but it's not clear how you'd really factor it out into a common function, I guess the only thing you could do is have an
(a, B, T) -> (correction_base, correction_top)
helper, if that's what you mean?