diff --git a/CHERICC_Fat.bsv b/CHERICC_Fat.bsv index 055b309..c940897 100644 --- a/CHERICC_Fat.bsv +++ b/CHERICC_Fat.bsv @@ -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 getRepresentableAlignmentMask = 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 instance FShow #(CapPipe); @@ -1075,6 +1076,13 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); return sr.length; 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 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 isDerivable (cap) = isDerivable(cap.capFat); endinstance instance Cast#(CapMem, CapReg); diff --git a/CHERICap.bsv b/CHERICap.bsv index 1e6c887..e1e7903 100644 --- a/CHERICap.bsv +++ b/CHERICap.bsv @@ -187,6 +187,9 @@ typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n, n // Get representable length function Bit#(n) getRepresentableLength (t dummy, Bit#(n) length_request); + // Assert that the encoding is valid + function Bool isDerivable (t cap); + endtypeclass function Fmt showCHERICap(t cap) provisos (CHERICap#(t, ot, flg, n, mem_sz, maskable_bits));