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

Add svnapot extention support #510

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added c_emulator/riscv_rvfi_RV64
Binary file not shown.
23 changes: 23 additions & 0 deletions model/riscv_vmem.sail
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,30 @@ function pt_walk(sv_params,
}
}
else {
let mask_bits = level * sv_params.pte_PPN_j_size_bits;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I haven't gone through the logic properly but are you sure this is right? level is guaranteed to be 0 here.

let mask : bits(64) = ~ (ones() << mask_bits);
let ppn : bits(64) = ppns | (vpns_of_va(sv_params, va) & mask);
let napot_mask : bits(64) = ppn ^ (ppn - 1);
let napot_mask_not : bits(64) = ~ (napot_mask);
let ptshift_level = sv_params.levels - 1;
let ptshift = ptshift_level * sv_params.vpn_size_bits;

let page_base = (ppn & napot_mask_not) |
(vpns_of_va(sv_params, va) & napot_mask) |
(vpns_of_va(sv_params, va) & ((zero_extend(0b1) << ptshift) - zero_extend(0b1)));

let pa = (ppns << pagesize_bits) | zero_extend(offset_of_va(va));
let pa_napot = page_base << 12 | zero_extend(offset_of_va(va));

// For svnapot ext purpose.
if (pte & (zero_extend(0b1) << 63)) == (zero_extend(0b1) << 63) then {
if (napot_mask != zero_extend(0xf)) then {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Easier like this: napot_mask[3 .. 0] != ones()

return PTW_Failure(PTW_Invalid_PTE(), 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.

Did you mean PTW_Unsupported_Napot here?

I'd probably call it PTW_Reserved_Napot btw.

} else {
return PTW_Success(pa_napot, pte, pte_addr, level, global', ext_ptw)
}
};

PTW_Success(pa, pte, pte_addr, level, global', ext_ptw)
}
}
Expand Down
18 changes: 10 additions & 8 deletions model/riscv_vmem_ptw.sail
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
// Failure modes for address-translation/page-table-walks
// PRIVATE
union PTW_Error = {
PTW_Invalid_Addr : unit, // invalid source address
PTW_Access : unit, // physical memory access error for a PTE
PTW_Invalid_PTE : unit,
PTW_No_Permission : unit,
PTW_Misaligned : unit, // misaligned superpage
PTW_PTE_Update : unit, // PTE update needed but not enabled
PTW_Ext_Error : ext_ptw_error // parameterized for errors from extensions
PTW_Invalid_Addr : unit, // invalid source address
PTW_Access : unit, // physical memory access error for a PTE
PTW_Invalid_PTE : unit,
PTW_No_Permission : unit,
PTW_Misaligned : unit, // misaligned superpage
PTW_PTE_Update : unit, // PTE update needed but not enabled
PTW_Ext_Error : ext_ptw_error, // parameterized for errors from extensions
PTW_Unsupport_Napot : unit // Unsupport Napot bits
}

// PRIVATE: only 'to_str' overload is public
Expand All @@ -33,7 +34,8 @@ function ptw_error_to_str(e : PTW_Error) -> string = {
PTW_No_Permission() => "no-permission",
PTW_Misaligned() => "misaligned-superpage",
PTW_PTE_Update() => "pte-update-needed",
PTW_Ext_Error(e) => "extension-error"
PTW_Ext_Error(e) => "extension-error",
PTW_Unsupport_Napot()=> "unsupport napot bits"
}
}

Expand Down
Binary file added test/riscv-tests/rv64ssvnapot-p-napot
Binary file not shown.
Loading