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

Replace old virtual memory code with new (details follow) #365

Closed
wants to merge 0 commits into from

Conversation

rsnikhil
Copy link
Collaborator

@rsnikhil rsnikhil commented Dec 1, 2023

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)

riscv_vmem_tlb.sail

Added documentation on new vmem code: doc/notes_Virtual_Memory.adoc
Deleted older vmem files.

Copy link

github-actions bot commented Dec 1, 2023

Test Results

712 tests  ±0   712 ✅ ±0   0s ⏱️ ±0s
  6 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 53a116e. ± Comparison against base commit d7a3d80.

♻️ This comment has been updated with latest results.

Copy link
Collaborator

@Alasdair Alasdair left a 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.

model/riscv_vmem.sail Outdated Show resolved Hide resolved
model/riscv_vmem.sail Outdated Show resolved Hide resolved
model/riscv_vmem.sail Outdated Show resolved Hide resolved
model/riscv_vmem.sail Outdated Show resolved Hide resolved
model/riscv_vmem.sail Outdated Show resolved Hide resolved
model/riscv_vmem.sail Outdated Show resolved Hide resolved
model/riscv_vmem.sail Outdated Show resolved Hide resolved
model/riscv_vmem.sail Outdated Show resolved Hide resolved
model/riscv_vmem_tlb.sail Outdated Show resolved Hide resolved
model/riscv_vmem_tlb.sail Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
model/riscv_vmem_tlb.sail Outdated Show resolved Hide resolved
@rsnikhil
Copy link
Collaborator Author

rsnikhil commented Dec 4, 2023 via email

model/riscv_vmem.sail Outdated Show resolved Hide resolved
Copy link
Collaborator

@Timmmm Timmmm left a 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 Show resolved Hide resolved
model/riscv_vmem.sail Outdated Show resolved Hide resolved
model/riscv_vmem.sail Outdated Show resolved Hide resolved
}

// PRIVATE: extract LSBs (including permissions) of PTE
function D_of_PTE(pte : bits(64)) -> bit = pte[7]
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

/* 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 */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Whitespace seems wrong here.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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 to boundary in VSCode.

image

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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 to boundary 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.

Copy link
Collaborator

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.

Copy link
Collaborator

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.

@Alasdair
Copy link
Collaborator

Alasdair commented Dec 5, 2023

Sail really needs module support!

I have one now, and I recently made a modularised sail-riscv to test it. I could open a PR for discussion.

rsnikhil added a commit to rsnikhil/sail-riscv that referenced this pull request Dec 5, 2023
model/riscv_vmem.sail Outdated Show resolved Hide resolved
@Timmmm
Copy link
Collaborator

Timmmm commented Dec 6, 2023

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!

rsnikhil added a commit to rsnikhil/sail-riscv that referenced this pull request Dec 6, 2023
@Alasdair
Copy link
Collaborator

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.

@rsnikhil
Copy link
Collaborator Author

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.

@jrtc27
Copy link
Collaborator

jrtc27 commented Dec 12, 2023

CODE_STYLE.md clearly states a two space indent, because that was (and still is) the predominant style in the model.

@rsnikhil
Copy link
Collaborator Author

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.

@jrtc27
Copy link
Collaborator

jrtc27 commented Dec 12, 2023

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.

@Alasdair
Copy link
Collaborator

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.

@rsnikhil
Copy link
Collaborator Author

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.

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.

@rsnikhil
Copy link
Collaborator Author

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.

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.

@Alasdair
Copy link
Collaborator

I made a PR here #372

Copy link
Collaborator

@Timmmm Timmmm left a 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.

/* 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 */
Copy link
Collaborator

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.

// 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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing )!


// 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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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)

Copy link
Collaborator Author

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.

satp_ppn_lsb_index = 0,

// VA
va_size_bits = 32,
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.


// PRIVATE: Extract full VPN field from VA
function vpns_of_va(sv_params : SV_Params,
va : bits(64)) -> bits(64) = {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

}

// PRIVATE: Extract offset within page from VA
function offset_of_va(va : bits(64)) -> bits(64) = {
Copy link
Collaborator

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]

Copy link
Collaborator Author

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).

}

// 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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Extra spaces

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok; fixed.

let pte_R = pte_lsbs.R();
let pte_W = pte_lsbs.W();
let pte_X = pte_lsbs.X();
let b : bool =
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok; fixed.

// walks during address translation; it typically works in conjunction
// with any customization to check_PTE_permission().

// PRIVATE
Copy link
Collaborator

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).

Copy link
Collaborator Author

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.

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];
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

@@ -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)
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

Copy link
Collaborator

@Timmmm Timmmm left a 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.

}

// PRIVATE
function add_to_TLB(asid : bits(16),
Copy link
Collaborator

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)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok. Done.

global : bool,
levelBitSize : nat,
PAGESIZE_BITS : nat) -> unit = {
let shift : nat = PAGESIZE_BITS + (level * levelBitSize);
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok. Removed.

let shift : nat = PAGESIZE_BITS + (level * levelBitSize);
assert(shift <= 64);
let vAddrMask : bits(64) = zero_extend(ones(shift));
let vMatchMask : bits(64) = ~ (vAddrMask);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can remove : bits(64).

Copy link
Collaborator Author

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.

ReadWrite(_, _) => true
});
// Update 'accessed'-bit?
let update_a : bool = pte_lsbs.A() == 0b0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can remove : bool.

Copy link
Collaborator Author

@rsnikhil rsnikhil Jan 14, 2024

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.

let update_a : bool = pte_lsbs.A() == 0b0;

if update_d | update_a then {
let pte_lsbs1 = update_A (pte_lsbs, 0b1);
Copy link
Collaborator

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!)

Copy link
Collaborator Author

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.

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];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can delete the : xlenbits.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok. Fixed.

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];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Delete : xlenbits.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok. Fixed.

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);
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

if not(valid_va) then
TR_Failure(translationException(ac, PTW_Invalid_Addr()), ext_ptw)
else {
let mxr : bool = mstatus.MXR() == 0b1;
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

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;
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok. Fixed.

rsnikhil added a commit to rsnikhil/sail-riscv that referenced this pull request Jan 14, 2024
@Timmmm
Copy link
Collaborator

Timmmm commented Feb 2, 2024

Just wanted to say I haven't forgotten about this - I'm just working on testing it.

@Alasdair
Copy link
Collaborator

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

@rsnikhil
Copy link
Collaborator Author

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.

@Alasdair
Copy link
Collaborator

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.

@rsnikhil
Copy link
Collaborator Author

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.

@Timmmm
Copy link
Collaborator

Timmmm commented Feb 22, 2024

I haven't forgotten! Give me another week or so...

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.

7 participants