-
Notifications
You must be signed in to change notification settings - Fork 169
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
Remove pc alignment mask #618
base: master
Are you sure you want to change the base?
Conversation
model/riscv_sys_control.sail
Outdated
@@ -293,7 +293,7 @@ function exception_handler(cur_priv : Privilege, ctl : ctl_result, | |||
if get_config_print_platform() | |||
then print_platform("ret-ing from " ^ to_str(prev_priv) ^ " to " ^ to_str(cur_privilege)); | |||
|
|||
prepare_xret_target(Machine) & pc_alignment_mask() | |||
legalize_xepc(prepare_xret_target(Machine)) |
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.
Since the value is already legalized in the write functions (set_xret_target
) you don't need to also legalize it on read, so you can remove the legalize_xepc
s here, and also for the read_CSR
clauses.
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.
As per comment below I think this was correct previously except for the calculation of pc_alignment_mask
which should be something like sign_extend(if misa.C then 0b110 else 0b100)
.
model/riscv_sys_exceptions.sail
Outdated
@@ -89,9 +89,9 @@ function clause is_CSR_defined(0x305) = true // mtvec | |||
function clause is_CSR_defined(0x341) = true // mepc | |||
|
|||
function clause read_CSR(0x105) = get_stvec() | |||
function clause read_CSR(0x141) = get_xret_target(Supervisor) & pc_alignment_mask() | |||
function clause read_CSR(0x141) = legalize_xepc(get_xret_target(Supervisor)) |
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.
I would maybe also rename get/set_xret_target
to get/set_xepc
. It's a bit clearer IMO.
There is a bear trap here. From the RISC-V privileged spec:
(emphasis mine) So the legalization that occurs on write is not necessarily the same as the one for the implicit read in MRET. Please check whether we're getting this right. |
model/riscv_sys_control.sail
Outdated
@@ -310,7 +310,7 @@ function exception_handler(cur_priv : Privilege, ctl : ctl_result, | |||
then print_platform("ret-ing from " ^ to_str(prev_priv) | |||
^ " to " ^ to_str(cur_privilege)); | |||
|
|||
prepare_xret_target(Supervisor) & pc_alignment_mask() | |||
prepare_xret_target(Supervisor) & sign_extend(if misa[C] then 0b110 else 0b100) |
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.
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.
Is there a reason one should not just reuse legalize_xepc? Perhaps because we want to capture the fact that the LSB isn't ever set in this case, it's only the second bit that needs handling specially?
@@ -89,11 +89,11 @@ function clause is_CSR_defined(0x305) = true // mtvec | |||
function clause is_CSR_defined(0x341) = true // mepc | |||
|
|||
function clause read_CSR(0x105) = get_stvec() | |||
function clause read_CSR(0x141) = get_xret_target(Supervisor) & pc_alignment_mask() | |||
function clause read_CSR(0x141) = get_xepc(Supervisor) |
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.
I think there should still be a mask here (e.g. using align_pc
). It's weird but the way I understand the spec if a CPU supports C but can disable it via misa.C
then you could have the following sequence:
write misa.C <- 0
write mepc <- 0b11
read mepc -> 0b00
write misa.C <- 1
read mepc -> 0b10
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.
I believe that's true, though the slightly less weird sequence that's definitely true is:
write mepc <- 0b11
read mepc -> 0b10
write misa.C <- 0
read mepc -> 0b00
write misa.C <- 1
read mepc -> 0b10
That alone requires masking on read, something which is explicitly mentioned in the privileged spec.
I don't know what you've done to cause it, but your commit history is an inscrutable mess. Please clean it up per the second paragraph in https://github.com/riscv/sail-riscv/blob/master/CONTRIBUTING.md (and just because it's the expectation for contributing to any project). |
val get_xret_target : Privilege -> xlenbits | ||
function get_xret_target(p) = | ||
val get_xepc : Privilege -> xlenbits | ||
function get_xepc(p) = |
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.
Should this just not legalise the result? Every use of get_xret_target (possibly indirectly via prepare_xret_target) previously masked with pc_alignment_mask, all of which were correct.
This is getting worse not better; you're piling on more commits to an already mess of a history, you're committing some random test log file, you're adding in debug prints and you're removing more code that needs to be there. |
sorry... I'm try to remove the mess commit.... but it didn't work Is there a way to remove these commit in a pushed pr. I've learn how to better commit, It won't happen again.. really sorry.. |
Look up how to use git rebase, e.g. https://about.gitlab.com/blog/2020/11/23/keep-git-history-clean-with-interactive-rebase/ looks like it could be a decent introduction |
Copy that Sir |
It's worth pointing out that after a rebase you will have to use |
e824e9e
to
0893def
Compare
0893def
to
a85c988
Compare
So I got permission to push most of our Sail code in one big go, to support some CHERI stuff (long story)... anyway the point is you can see what we've done here:
And elsewhere:
Ignore my earlier comment about removing Also it was maybe overkill having both |
I'm not sure. Is the new commit ok? |
Yes looks good to me with one change: move the
(Or you can put the |
model/riscv_sys_exceptions.sail
Outdated
@@ -89,11 +89,11 @@ function clause is_CSR_defined(0x305) = true // mtvec | |||
function clause is_CSR_defined(0x341) = true // mepc | |||
|
|||
function clause read_CSR(0x105) = get_stvec() | |||
function clause read_CSR(0x141) = get_xret_target(Supervisor) & pc_alignment_mask() | |||
function clause read_CSR(0x141) = align_pc(get_xepc(Supervisor)) |
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.
Oh sorry you also don't need align_pc
here, or on line 94.
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.
LGTM
Yes, I think it looks fine but the commit history is a bit messy still. Could use squash merge but would need to update PR with proper description first. |
Ok cool, I will merge this in a few days with a nice squashed commit if nobody objects. Thanks for reviewing! |
I'll take a look over the weekend |
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.
Minor comment otherwise I think the change is correct
* get_xepc: used to read the value of the xret target (no control flow transfer) | ||
* set_xepc: used to write a value of the xret target (no control flow transfer) | ||
* prepare_xret_target: used to get the value for control transfer to the xret target |
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.
* get_xepc: used to read the value of the xret target (no control flow transfer) | |
* set_xepc: used to write a value of the xret target (no control flow transfer) | |
* prepare_xret_target: used to get the value for control transfer to the xret target | |
* get_xepc: used to read the value of the xret target (no control flow transfer) | |
* set_xepc: used to write a value of the xret target (no control flow transfer) | |
* prepare_xret_target: used to get the value for control transfer to the xret target |
#593