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 2 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
30 changes: 30 additions & 0 deletions model/riscv_vmem.sail
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ function vpn_j_of_va(sv_params : SV_Params,
((va >> lsb) & mask)
}

// PRIVATE: Count trailing zeros
function LowestSetBit(x : 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.

Funnily enough I have a version of this already that I wrote to demonstrate Sail's fancy type checking:

val count_trailing_zeros : forall 'n, 'n >= 0 . (bits('n)) -> range(0, 'n)
function count_trailing_zeros(x) = {
    foreach (i from 0 to ('n - 1)) {
        if x[i] == bitone then return i
    };
    'n
}

However I'm not sure you need this at all - if you check the PMP code it does some clever bit manipulation instead.

var count : bits(64) = zeros();
let perfect_one : bits(64) = 0x0000_0000_0000_0001;
foreach (i from 0 to (sizeof(xlen) - 1) by 1 in inc)
if [x[i]] == 0b1 then return(count + perfect_one) else (count = count + perfect_one);
return count;
}

// PRIVATE: Extract offset within page from VA
function offset_of_va(va : bits(64)) -> bits(PAGESIZE_BITS) = va[pagesize_bits - 1 .. 0]

Expand Down Expand Up @@ -164,7 +173,28 @@ 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_bits = LowestSetBit(ppn);
let perfect_one : bits(64) = 0x0000_0000_0000_0001;
Yui5427 marked this conversation as resolved.
Show resolved Hide resolved
let napot_mask : bits(64) = (perfect_one << napot_bits) - perfect_one;
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) & ((perfect_one << ptshift) - perfect_one));

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 & (perfect_one << 63)) == (perfect_one << 63) then {
return PTW_Success(pa_napot, pte, pte_addr, level, global', ext_ptw)
};

PTW_Success(pa, pte, pte_addr, level, global', ext_ptw)
}
}
Expand Down
Binary file added test/riscv-tests/rv64ssvnapot-p-napot
Binary file not shown.
Loading