This commit is contained in:
Jonathan Woodruff
2020-03-31 15:42:33 +01:00
2 changed files with 12 additions and 0 deletions

View File

@@ -918,6 +918,7 @@ instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3));
function getBaseAlignment = 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 getRepresentableAlignmentMask = error("feature not implemented for this cap type");
function getRepresentableLength = error("feature not implemented for this cap type"); function getRepresentableLength = error("feature not implemented for this cap type");
function isDerivable = error("feature not implemented for this cap type");
endinstance endinstance
instance FShow #(CapPipe); instance FShow #(CapPipe);
@@ -1075,6 +1076,13 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3));
return sr.length; return sr.length;
endfunction endfunction
function Bool isDerivable (CapReg cap);
return cap.bounds.exp <= resetExp
&& !(cap.bounds.exp == resetExp && ((truncateLSB(cap.bounds.topBits) != 1'b0) || (cap.bounds.baseBits[valueOf(TSub#(MW,1))] != 1'b0)))
&& !(cap.bounds.exp == resetExp-1 && (cap.bounds.baseBits[valueOf(TSub#(MW,1)):valueOf(TSub#(MW,2))] != 2'b0))
&& (cap.reserved == 0);
endfunction
endinstance endinstance
instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3));
@@ -1182,6 +1190,7 @@ instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3));
function getRepresentableLength (dummy) = getRepresentableLength(null_cap); function getRepresentableLength (dummy) = getRepresentableLength(null_cap);
function isDerivable (cap) = isDerivable(cap.capFat);
endinstance endinstance
instance Cast#(CapMem, CapReg); instance Cast#(CapMem, CapReg);

View File

@@ -187,6 +187,9 @@ typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n, n
// Get representable length // Get representable length
function Bit#(n) getRepresentableLength (t dummy, Bit#(n) length_request); function Bit#(n) getRepresentableLength (t dummy, Bit#(n) length_request);
// Assert that the encoding is valid
function Bool isDerivable (t cap);
endtypeclass endtypeclass
function Fmt showCHERICap(t cap) provisos (CHERICap#(t, ot, flg, n, mem_sz, maskable_bits)); function Fmt showCHERICap(t cap) provisos (CHERICap#(t, ot, flg, n, mem_sz, maskable_bits));