-
Notifications
You must be signed in to change notification settings - Fork 164
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
Replace old virtual memory code with new (details follow) #365
Conversation
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've added a bunch of comments. Mostly smaller style related issues, I hope you don't mind the nitpicking!
For what I suggested in our meeting, I found there's a bug during the Sail->C path where Sail will try to create a function that can produce an undefined
element of any custom datatype, to allow you to write let x : custom_datatype = undefined
. That seems to be falling over for the numeric set types I wanted to use 😢
I'll fix that bug but in the mean time, there's an easy workaround where you can just add your own undefined_custom_datatype
function and it'll use it. Since we don't create any undefined SV_Params
it can just return some valid instance. I think it's probably still worth it because the Sail->C generation will be much more efficient it we use finite types rather than nat
.
I know you mostly generalized the existing code, but maybe it would be good to roll in some fixing of naming conventions. I'm not sure why we have translateAddr
rather than translate_addr
. Alternatively we could leave that out of this PR for a follow-up, I don't have a strong opinion either way, other than I would like it to eventually be more consistent.
My apologies. I've re-marked it 'unresolved'.
I also don't know who is supposed to mark it 'resolved' (me? or the
commenter?).
[ I'm new to multi-person/multi-org projects on GitHub, and am not
familiar with the flows and protocols. I was marking each comment
resolved as I dealt with it in my local clone, re-testing at each
step. I had not yet pushed it to my GitHub fork.]
I've just pushed a new commit (225b9cf) with my changes, to my fork
(https://github.com/rsnikhil/sail-riscv). This started a CI run on my
fork, which reported success.
In the PR in upstream repo (https://github.com/riscv/sail-riscv),
it reports this commit, and reran a CI, which reports success.
Nikhil
…On Mon, Dec 4, 2023 at 1:44 PM Alexander Richardson < ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In model/riscv_vmem.sail
<#365 (comment)>:
> + satp_ppn_size_b : nat, // 22 44 44
+ satp_ppn_lsb_index : nat, // 0 0 0
+
+ // VA // Sv32 Sv39 Sv48
+ va_size_b : nat, // 32 39 48
+ vpn_size_b : nat, // 10 9 9
+
+ // PTE // Sv32 Sv39 Sv48
+ levels : nat, // 2 3 4
+ log_pte_size_B : nat, // 2 3 3
+ pte_msbs_lsb_index : nat, // 32 54 54
+ pte_msbs_size_b : nat, // 0 10 10
+ pte_PPNs_lsb_index : nat, // 10 10 10
+ pte_PPNs_size_b : nat, // 22 44 44
+ pte_PPN_j_size_b : nat // 10 9 9
+}
Could you please upload the new version before marking comments as
resolved?
—
Reply to this email directly, view it on GitHub
<#365 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA5QDSP7XIOYB5SDTQAFC7LYHYKZDAVCNFSM6AAAAABADL3UHSVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTONRTGE2TCOJXHE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
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.
Sail really needs module support!
model/riscv_vmem.sail
Outdated
} | ||
|
||
// PRIVATE: extract LSBs (including permissions) of PTE | ||
function D_of_PTE(pte : bits(64)) -> bit = pte[7] |
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.
Probably makes sense to use a bitfield
for this?
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.
The original code had three separate bitfields for PTEs for Sv32, Sv39 and Sv48, much of the PTEs are different for each one. To unify these (since bitfields are not allowed to be polymorphic at the moment), I resorted to working at 64bits throughout and using selector functions, and using SV_Params to parameterize the differences.
Of course, the bottom 8 bits of PTEs are the same for Sv32, Sv39 and Sv48, and one could use a common bitfield for that part of the PTE, but I’m not sure it would clarify things much.
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 using a bitfield for the common bits would be slightly easier to read than these wrapper functions.
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.
Ok, I’ll defer to the majority here and do the common 8 LSBs with a bitfield, although IMHO while bitfields are a nice construct, I don’t think it improves readability in this particular situation, especially since other fields in the PTE are not done this way.
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.
Github won't let me actually resolve this for some reason but it's resolved.
model/riscv_vmem_tlb.sail
Outdated
/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */ | ||
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF */ | ||
/* SUCH DAMAGE. */ | ||
/* RISCV Sail Model */ |
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.
Whitespace seems wrong here.
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 don’t think I understand the display above. The above cited excerpt looks like this:
/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF */
/* SUCH DAMAGE. */
/*=======================================================================================*/
// Although a TLB is not part of the RISC-V Architecture
// specification, we model a simple TLB so that
The “RISCV Sail Model” line is on line 2, not after line 68.
The whitespace looks ok on my Emacs screen.
In VSCode, this whole header section initially looks messed up, because by default it has a “Spaces: 2” setting. On the bottom line, where it says “Spaces: 2”, this needs to be changed to “Indent using spaces” and setting the tab size to 8, to match the way Emacs displays it.
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 some spaces have been replaced with hard tabs.
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.
I think some spaces have been replaced with hard tabs.
Is that a problem? CODE_STYLE.md is silent on any policy regarding tabs vs. spaces.
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.
PS: I highly recommend setting
Render Whitespace
toboundary
in VSCode.
I rely on Emacs’ ’tabify’ and ‘untabify’ functions to do tabs/spaces properly for a selected region or buffer.
If Emacs and VSCode (and possibly vi) do it differently, I suggest not relying either one as a standard, as long as each tools is able to display it properly.
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 still needs to be fixed.
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.
Github won't let me actually resolve this for some reason but it's resolved.
I have one now, and I recently made a modularised sail-riscv to test it. I could open a PR for discussion. |
Great news - yes please! |
It looks like the current code has tabs as well as spaces, we should make sure all the tabs are gone before we merge. I thought we had a pre-commit hook to check for no tabs, but it looks like we don't. |
Yes it has tabs; I was unaware that no-tabs is the recommended style; CODE_STYLE.md is silent on this (perhaps someone should add this recommendation to CODE_STYLE.md?). I actually applied “tabify()” in Emacs to convert spaces to tabs, because that is my normal practice in my own projects. I will apply “untabify()” in Emacs to reverse that. |
CODE_STYLE.md clearly states a two space indent, because that was (and still is) the predominant style in the model. |
Yes, I read that, and am aware of that, but it does not rule out using tabs to reach the context indent before applying two more spaces. And there were tabs in other long white spaces (e.g., in the license text). In any case: I’ve applied ‘untabify()’ to the wholef file to remove all tabs. |
Tabs are not spaces, and don’t even have a fixed column width. If you convert spaces to tabs then you don’t have a 2 space per block indent, you have N tabs and M spaces. |
We have too much code that tries to align things in a pretty way to use tabs, as it'll just look broken in anyone else's editor if they don't have the same tab width. The error message formatting code in Sail also just assumes a tab width of 4, so error messages will look off to anyone who has set their tab width differently. |
Ok, that’s not how I (and possibly others) interpret the language. IMO, a phrase “don’t use tabs at all” would clarify it. It’s a moot point anyway, now, for the files in question, since I’ve converted everything to spaces. |
I agree, and I’m fine with a policy of “no-tabs”. I’m just asking that we state that explicitlyl in CODE_STYLE.md. For example, there could be wide spaces in comments (and there are wide spaces in the license text) which, if done with tabs, would also look wrong, even though they don’t have anything to do with code indentation policy. |
I made a PR here #372 |
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.
Some more review comments. Please can you fix the formatting? Then I will do some more reviewing.
model/riscv_vmem_tlb.sail
Outdated
/* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */ | ||
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF */ | ||
/* SUCH DAMAGE. */ | ||
/* RISCV Sail Model */ |
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 still needs to be fixed.
model/riscv_vmem_tlb.sail
Outdated
// specification, we model a simple TLB so that | ||
// (1) we can meaningfully test SFENCE.VMA which would be a no-op wihout a TLB; | ||
// (2) we can greatly speed up simulation speed (for Linux boot, can | ||
// reduce elapsed time from 10s of minutes to few minutes. |
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.
Missing )
!
model/riscv_vmem.sail
Outdated
|
||
// This two-line idiom constrains the value (2nd line) to be a singleton, | ||
// which helps in type-checking wherever it is used. | ||
type PAGESIZE_BITS : Int = 12 |
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.
The rest of the code uses lowercase for these. Also I think it's proabbly unwise to use the same name for both of these.
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.
The rest of the code uses lowercase for these. Also I think it's proabbly unwise to use the same name for both of these.
-
I’m not sure what you mean by “rest of the code uses lowercase for these”. grep shows no other use of PAGESIZE_BITS, upper or lower case, in any file other than my new files (riscv_vmem.sail, riscv_vmem_tlb.sail) where they are all uppercase. Are you perhaps referring to code in some other repo or branch (CHERI)?
-
I was following Jessica’s suggestion exactly: Replace old virtual memory code with new (details follow) #365 (comment) which has both the type and the value in upper case.
But, in any case, I take your point, and I will change the value-use to lowercase.
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.
By "these" I meant global type definitions. If you search for : Int =
in this repo or the CHERI one they are all lowercase. I think Jessica was just copying your style.
Though they do use exactly the same name for both definitions in the CHERI code, so maybe it is ok to just do this:
type pagesize_bits : Int = 12
let pagesize_bits = sizeof(pagesize_bits)
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’ve retained uppercase for the type def and changed the value def to lowercase (Haskell-like). Perhaps we should adopt a uniform convention across the whole repo.
model/riscv_vmem.sail
Outdated
satp_ppn_lsb_index = 0, | ||
|
||
// VA | ||
va_size_bits = 32, |
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.
Indentation of va_size_bits
and levels
is a bit wrong in all 4 of these.
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 this was just a tabs artefact. I’ve removed all tabs.
model/riscv_vmem.sail
Outdated
|
||
// PRIVATE: Extract full VPN field from VA | ||
function vpns_of_va(sv_params : SV_Params, | ||
va : bits(64)) -> bits(64) = { |
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.
Indentation. I think you just have a load of hard tabs that need to be replaced with spaces.
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’re removed all tabs, for spaces.
model/riscv_vmem.sail
Outdated
} | ||
|
||
// PRIVATE: Extract offset within page from VA | ||
function offset_of_va(va : bits(64)) -> bits(64) = { |
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.
function offset_of_va(va : bits(64)) -> bits(PAGESIZE_BITS) = va[PAGESIZE_BITS - 1 .. 0]
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.
Ok (shrinking output type from bits(64) to bits[PAGESIZE_BITS] needed a compensating zero_extend() in the two places where it was invoked).
model/riscv_vmem.sail
Outdated
} | ||
|
||
// PRIVATE: check if a PTE is a pointer to next level (non-leaf) | ||
function pte_is_ptr(pte_lsbs : PTE_LSBs) -> bool = ( pte_lsbs.X() == 0b0) |
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.
Extra spaces
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.
Ok; fixed.
model/riscv_vmem.sail
Outdated
let pte_R = pte_lsbs.R(); | ||
let pte_W = pte_lsbs.W(); | ||
let pte_X = pte_lsbs.X(); | ||
let b : bool = |
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.
b
is not a very descriptive name. How about success
?
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.
Ok; fixed.
model/riscv_vmem.sail
Outdated
// walks during address translation; it typically works in conjunction | ||
// with any customization to check_PTE_permission(). | ||
|
||
// PRIVATE |
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.
Btw I wonder if we should adopt the "leading underscore = private" convention, given that Sail doesn't support public/private natively yet.
Maybe after modules are added.
(No changes needed here; just a thought).
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.
Let’s wait for modules, which I believe will be available soon.
model/riscv_vmem.sail
Outdated
let vpn_j = vpn_j_of_va(sv_params, va, level); | ||
let pte_offset = vpn_j << sv_params.log_pte_size_bytes; | ||
let pte_addr = pt_base + pte_offset; | ||
let pte_phys_addr : xlenbits = pte_addr[(sizeof(xlen) - 1) .. 0]; |
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 this right? Physical addresses are 34 bits with SV32.
Maybe a bug in mem_read_priv()
I guess. Worth adding a TODO comment at least.
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.
Yes, Sv32 phys mem addrs are 34 bits, not 32 bits. But it is used in 'mem_read_priv()' [riscv_mem.sail, L180], where the address argument is declared as 'xlenbits', so until mem_read_priv() is changed, we have to use 32 bits.
I don't know if it's straightforward to fix 'mem_read_priv()'. As I understand it, in RV32, phys mem addrs are 32(34) bits when Sv32 is not (is) supported. Even if Sv32 is supported, what happens when we run with M privilege (are phys addrs 32 bits? Or extended to 34 bits)?
I've mentioned this several times in our meetings (perhaps I should add an "issue" so it doesn't slip thru the cracks), and I'll also add a local TODO comment here in the vmem code.
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.
Physical addresses at 34 bits if Sv32 is implemented, but Mmode cannot access beyond 32 bits
unless it sets (mstatus.MPRV==1) && (mstatus.MPP !=mmode) && (satp.mode!=0).
If those are set correctly, then it will use VM translation and use all 34 bits.
Otherwise, the upper 2 bits can't be used in Mmode, and they're set to zero.
model/riscv_vmem.sail
Outdated
@@ -120,6 +120,9 @@ struct SV_Params = { | |||
pte_PPN_j_size_bits : {10, 9} // 10 9 9 | |||
} | |||
|
|||
// Current level during a page-table walk (0 to SV_Params.levels - 1) | |||
type Level = range(0,3) // range(0,4) when add Sv57 (TODO) |
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.
Level is quite a generic name. Until there is a real way of declaring this file-local in sail, I think we have to use something like PTELevel here.
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.
Ok, changed name to PTW_Level
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.
Hey, sorry for the review delay - I missed that you replied.
Generally this looks good to me. Review summary:
- One bit definitely looks like a bug (in
update_PTE_Bits
). - Lots of unnecessary explicit type annotations. I think it's better to leave those out in almost all cases.
- Lots of unnecessary brackets around expressions. Sometimes it clarifies things, but I think if you have
let foo = (...);
then it just adds noise. - Probably the biggest thing that needs to change is to move functions back into
riscv_pte.sail
/riscv_ptw.sail
so that CHERI can override functions without having to completely copy & paste the page table walker. - Some other misc stuff.
For CHERI I don't think we need to maintain exactly the same function signatures - some small amount of updating work is acceptable there I think. But we should maintain roughly the same code structure so it's at least feasible. And yeah it is kind of annoying that there's no clear indication exactly what the "public overidable" interfaces are, but I guess we'll just have to put up with that for now.
model/riscv_vmem_tlb.sail
Outdated
} | ||
|
||
// PRIVATE | ||
function add_to_TLB(asid : bits(16), |
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.
Could be worth a typedef for this? type asidbits = bits(16)
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.
Ok. Done.
model/riscv_vmem_tlb.sail
Outdated
global : bool, | ||
levelBitSize : nat, | ||
PAGESIZE_BITS : nat) -> unit = { | ||
let shift : nat = PAGESIZE_BITS + (level * levelBitSize); |
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.
Don't think you need the : nat
here.
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.
Ok. Removed.
model/riscv_vmem_tlb.sail
Outdated
let shift : nat = PAGESIZE_BITS + (level * levelBitSize); | ||
assert(shift <= 64); | ||
let vAddrMask : bits(64) = zero_extend(ones(shift)); | ||
let vMatchMask : bits(64) = ~ (vAddrMask); |
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.
Can remove : bits(64)
.
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.
In this case I think it serves as useful documentation, since 'zero_extend (ones (shift))' is polymorphic and so the result width may not be obvious.
model/riscv_vmem.sail
Outdated
ReadWrite(_, _) => true | ||
}); | ||
// Update 'accessed'-bit? | ||
let update_a : bool = pte_lsbs.A() == 0b0; |
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.
Can remove : bool
.
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.
Ok. Removed. But I’ve added parens around the RHS because I’m nervous when ‘=‘ and ‘==‘ are on the same line, especially for someone coming from a C background.
model/riscv_vmem.sail
Outdated
let update_a : bool = pte_lsbs.A() == 0b0; | ||
|
||
if update_d | update_a then { | ||
let pte_lsbs1 = update_A (pte_lsbs, 0b1); |
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.
[pte_lsbs with A = 0b1]
(apparently the update_A
is old syntax and I definitely prefer the new syntax!)
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.
Ok, fixed. I was unaware of the new syntax.
model/riscv_vmem.sail
Outdated
n_ent : TLB_Entry = ent; | ||
n_ent.pte = pte'; | ||
write_TLB(tlb_index, n_ent); | ||
let pte_phys_addr : xlenbits = ent.pteAddr[(sizeof(xlen) - 1) .. 0]; |
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.
Can delete the : xlenbits
.
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.
Ok. Fixed.
model/riscv_vmem.sail
Outdated
TR_Failure(PTW_PTE_Update(), ext_ptw) | ||
else { | ||
// Writeback the PTE (which has new A/D bits) | ||
let pte_phys_addr : xlenbits = pteAddr[(sizeof(xlen) - 1) .. 0]; |
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.
Delete : xlenbits
.
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.
Ok. Fixed.
model/riscv_vmem.sail
Outdated
let vAddr_64b : bits(64) = zero_extend(vAddr); | ||
// Effective privilege takes into account mstatus.PRV, mstatus.MPP | ||
// See riscv_sys_regs.sail for effectivePrivilege() and cur_privilege | ||
let effPriv : Privilege = effectivePrivilege(ac, mstatus, cur_privilege); |
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.
Can delete : Privilege
and : SATPMode
and : ext_ptw
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.
Here I think the annotations serve a useful documentation purpose. The RHS functions are non-local and the type of their results may not be obvious. Personally I prefer more rather than less type annotations.
model/riscv_vmem.sail
Outdated
if not(valid_va) then | ||
TR_Failure(translationException(ac, PTW_Invalid_Addr()), ext_ptw) | ||
else { | ||
let mxr : bool = mstatus.MXR() == 0b1; |
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.
Delete all these type annotations.
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.
Ok (partial). I’ve deleted them for the obvious boolean exprs, but not for the others, where I think they serve as useful documentation.
model/riscv_vmem.sail
Outdated
let effPriv : Privilege = effectivePrivilege(ac, mstatus, cur_privilege); | ||
let mode : SATPMode = translationMode(effPriv); | ||
// PTW extensions (non-standard): initialize the PTW extension state | ||
let ext_ptw : ext_ptw = init_ext_ptw; |
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.
Why make this copy? Just use init_ext_ptw
directly.
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.
Ok. Fixed.
Just wanted to say I haven't forgotten about this - I'm just working on testing it. |
If you don't want to continue, would it be possible for me to take over this PR? At the very least I would like this on my own fork, even if nothing can be merged here |
Hi Alasdair, no I will see it through. This PR (#365) got marked as 'closed' because of my ham-handedness with GitHub/git. I updated my fork of sail-riscv on GitHub to sync up with the latest commits, then did 'git pull - rebase' to my clone on my laptop, and (a) it closed the PR and (b) threw out all my changes. Fortunately I had a backup of all my changes. I have re-incorporated my changes and re-tested, and it looks ok. I'll create a new PR shortly. Apologies for the confusion. |
Ah, no worries then. I misinterpreted you closing the PR. That said I remember you said you would be busy at some point soon, so if you do need someone to help drive this forwards please don't hesitate to ask me. |
I have just now created PR #408 for this (it is running CI tests, which already passed in my fork). I also separated out code into riscv_vmem_pte.sail and riscv_vmem_ptw.sail per @Timmmm ’s suggestion for convenience for CHERI project which, as I understand it, substitute these files with CHERI-specific files. It’s been ready for merge for some time now (all PR comments addressed). @Timmmm said he’d run it through some additional tests that are not part of the CI tests. |
I haven't forgotten! Give me another week or so... |
Old code had much 'cut-and-paste' replication for RV32 (Sv32) and
RV64 (Sv39, Sv48), and was scattered over several files.
New code unifies them into single set of parameterized functions
that works for RV32/RV64 and Sv32/Sv39/Sv48 (and is ready for Sv57).
Deleted old files:
riscv_vmem_common.sail riscv_pte.sail riscv_ptw.sail
riscv_vmem_rv32.sail riscv_vmem_rv64.sail
riscv_vmem_sv32.sail riscv_vmem_sv39.sail riscv_vmem_sv48.sail
Added 1 new file, where the main vmem code sits:
riscv_vmem.sail
Modified (to be compatible with new code, and to isolate TLB stuff
into one file, since TLBs are not part of RISC-V Architecture Spec)
Added documentation on new vmem code: doc/notes_Virtual_Memory.adoc
Deleted older vmem files.