From 910c2154f100d243c13179c1c7407ee00dd0f62e Mon Sep 17 00:00:00 2001 From: Peter Rugg Date: Thu, 26 Mar 2020 14:25:59 +0000 Subject: [PATCH 1/2] Add isDerivable function for CBuildCap --- CHERICC_Fat.bsv | 9 +++++++++ CHERICap.bsv | 3 +++ 2 files changed, 12 insertions(+) diff --git a/CHERICC_Fat.bsv b/CHERICC_Fat.bsv index d150ab4..1470684 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 && (cap.bounds.topBits != 0) || (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)); From c51cd15a5dbc8d69994cd11b381455edccb5a649 Mon Sep 17 00:00:00 2001 From: Peter Rugg Date: Mon, 30 Mar 2020 03:40:28 +0100 Subject: [PATCH 2/2] Fix derivability check --- CHERICC_Fat.bsv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHERICC_Fat.bsv b/CHERICC_Fat.bsv index 1470684..7b25ecd 100644 --- a/CHERICC_Fat.bsv +++ b/CHERICC_Fat.bsv @@ -1078,7 +1078,7 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); function Bool isDerivable (CapReg cap); return cap.bounds.exp <= resetExp - && !(cap.bounds.exp == resetExp && (cap.bounds.topBits != 0) || (cap.bounds.baseBits[valueOf(TSub#(MW,1))] != 1'b0)) + && !(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