Add utilities for CRRL and CRAM
This commit is contained in:
@@ -885,6 +885,8 @@ instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3));
|
||||
function toMem = error("feature not implemented for this cap type");
|
||||
function maskAddr = error("feature not implemented for this cap type");
|
||||
function getBaseAlignment = error("feature not implemented for this cap type");
|
||||
function getRepresentableAlignmentMask = error("feature not implemented for this cap type");
|
||||
function getRepresentableLength = error("feature not implemented for this cap type");
|
||||
endinstance
|
||||
|
||||
instance FShow #(CapPipe);
|
||||
@@ -1031,6 +1033,12 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3));
|
||||
else return 2'b0;
|
||||
endfunction
|
||||
|
||||
function Bit#(CapAddressW) getRepresentableAlignmentMask (CapReg dummy, Bit#(CapAddressW) length_request);
|
||||
let setBoundsCap = nullWithAddr((~0) - length_request);
|
||||
Exact#(CapFat) result = setBounds(setBoundsCap, length_request);
|
||||
return (~0) << (result.value.bounds.exp == 0 ? 0 : result.value.bounds.exp + fromInteger(valueOf(HalfExpW)));
|
||||
endfunction
|
||||
|
||||
endinstance
|
||||
|
||||
instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3));
|
||||
@@ -1128,6 +1136,10 @@ instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3));
|
||||
return capInBounds(cap.capFat, cap.tempFields, inclusive);
|
||||
endfunction
|
||||
|
||||
function getRepresentableAlignmentMask (dummy) = getRepresentableAlignmentMask(null_cap);
|
||||
|
||||
function getRepresentableLength (dummy) = getRepresentableLength(null_cap);
|
||||
|
||||
endinstance
|
||||
|
||||
instance Cast#(CapMem, CapReg);
|
||||
|
||||
@@ -179,6 +179,15 @@ typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n, n
|
||||
// base.
|
||||
function Bit#(2) getBaseAlignment (t cap);
|
||||
|
||||
// Get representable alignment mask
|
||||
function Bit#(n) getRepresentableAlignmentMask (t dummy, Bit#(n) length_request);
|
||||
|
||||
// Get representable length
|
||||
function Bit#(n) getRepresentableLength (t dummy, Bit#(n) length_request);
|
||||
let mask = getRepresentableAlignmentMask(dummy, length_request);
|
||||
return (length_request + ~mask) & mask;
|
||||
endfunction
|
||||
|
||||
endtypeclass
|
||||
|
||||
function Fmt showCHERICap(t cap) provisos (CHERICap#(t, ot, flg, n, mem_sz, maskable_bits));
|
||||
|
||||
Reference in New Issue
Block a user