From bc7b518aaf2d683603a8856785438fe043816c41 Mon Sep 17 00:00:00 2001 From: Peter Rugg Date: Tue, 12 May 2020 20:10:09 +0100 Subject: [PATCH] Revert "Revert "Provide combined set bound function"" --- CHERICC_Fat.bsv | 37 +++++++------------------------------ CHERICap.bsv | 20 ++++++++++++++++++-- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/CHERICC_Fat.bsv b/CHERICC_Fat.bsv index 84a7c2d..e5efafa 100644 --- a/CHERICC_Fat.bsv +++ b/CHERICC_Fat.bsv @@ -58,6 +58,7 @@ export HPerms; export PermsW; export Exp; export MetaInfo; +export SetBoundsReturn; // =============================================================================== @@ -399,15 +400,8 @@ function Bit#(n) smearMSBRight(Bit#(n) x); return res; endfunction -typedef struct -{ - CapFat cap; - Bool exact; - CapAddress length; - CapAddress mask; -} SetBoundsReturn deriving (Bits, Eq, FShow); -function SetBoundsReturn setBoundsFat(CapFat cap, Address lengthFull); +function SetBoundsReturn#(CapFat, CapAddressW) setBoundsFat(CapFat cap, Address lengthFull); CapFat ret = cap; // Find new exponent by finding the index of the most significant bit of the // length, or counting leading zeros in the high bits of the length, and @@ -921,7 +915,7 @@ instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); function getTop = error("getTop not implemented for CapMem"); function getLength = error("getLength not implemented for CapMem"); function isInBounds = error("isInBounds not implemented for CapMem"); - function setBounds = error("setBounds not implemented for CapMem"); + function setBoundsCombined = error("setBoundsCombined not implemented for CapMem"); function nullWithAddr = error("nullWithAddr not implemented for CapMem"); function almightyCap; CapReg res = almightyCap; @@ -1058,10 +1052,7 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); function getLength = error("getLength not implemented for CapReg"); function isInBounds = error("isInBounds not implemented for CapReg"); - function Exact#(CapReg) setBounds (CapReg cap, Bit#(CapAddressW) length); - SetBoundsReturn sr = setBoundsFat(cap, length); - return Exact {exact: sr.exact, value: sr.cap}; - endfunction + function SetBoundsReturn#(CapReg, CapAddressW) setBoundsCombined(CapReg cap, Bit#(CapAddressW) length) = setBoundsFat(cap, length); function CapReg nullWithAddr (Bit#(CapAddressW) addr); CapReg res = nullCap; @@ -1096,16 +1087,6 @@ 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); - SetBoundsReturn sr = setBoundsFat(nullCap, length_request); - return sr.mask; - endfunction - - function Bit#(CapAddressW) getRepresentableLength (CapReg dummy, Bit#(CapAddressW) length_request); - SetBoundsReturn sr = setBoundsFat(nullCap, length_request); - return sr.length; - endfunction - function Bool isDerivable (CapReg cap); return cap.bounds.exp <= resetExp && !(cap.bounds.exp == resetExp && ((truncateLSB(cap.bounds.topBits) != 1'b0) || (truncateLSB(cap.bounds.baseBits) != 2'b0))) @@ -1148,9 +1129,9 @@ instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); //Functions supported by CapReg but which require TempFields to be changed - function Exact#(CapPipe) setBounds (CapPipe cap, Bit#(CapAddressW) length); - let result = setBounds(cap.capFat, length); - return Exact {exact: result.exact, value: CapPipe {capFat: result.value, tempFields: getTempFields(result.value)}}; + function SetBoundsReturn#(CapPipe, CapAddressW) setBoundsCombined(CapPipe cap, Bit#(CapAddressW) length); + let result = setBoundsCombined(cap.capFat, length); + return SetBoundsReturn {cap: CapPipe{capFat: result.cap, tempFields: getTempFields(result.cap)}, exact: result.exact, length: result.length, mask: result.mask}; endfunction function CapPipe nullWithAddr (Bit#(CapAddressW) addr); @@ -1213,10 +1194,6 @@ 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); - function isDerivable (cap) = isDerivable(cap.capFat); endinstance diff --git a/CHERICap.bsv b/CHERICap.bsv index 5dbbf35..37dba33 100644 --- a/CHERICap.bsv +++ b/CHERICap.bsv @@ -78,6 +78,14 @@ typedef union tagged { Bit#(ot) SEALED_WITH_TYPE; } Kind#(numeric type ot) deriving (Bits, Eq, FShow); +typedef struct +{ + t cap; + Bool exact; + Bit#(n) length; + Bit#(n) mask; +} SetBoundsReturn#(type t, numeric type n) deriving (Bits, Eq, FShow); + typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n, numeric type mem_sz, numeric type maskable_bits) dependencies (t determines (ot, flg, n, mem_sz, maskable_bits)); @@ -145,6 +153,11 @@ typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n, n // Set the length of the capability. Inexact: result length may be different to requested function Exact#(t) setBounds (t cap, Bit#(n) length); + let combinedResult = setBoundsCombined(cap, length); + return Exact {exact: combinedResult.exact, value: combinedResult.cap}; + endfunction + + function SetBoundsReturn#(t, n) setBoundsCombined (t cap, Bit#(n) length); // Returns a null cap with an address set to the argument function t nullWithAddr (Bit#(n) addr); @@ -176,11 +189,14 @@ typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n, n // base. function Bit#(2) getBaseAlignment (t cap); + // TODO the following do not compile due to "not enough explicit type information" // Get representable alignment mask - function Bit#(n) getRepresentableAlignmentMask (t dummy, Bit#(n) length_request); + // function Bit#(n) getRepresentableAlignmentMask (t dummy, Bit#(n) length_request) = + // setBoundsCombined(nullCap, length_request).mask; // Get representable length - function Bit#(n) getRepresentableLength (t dummy, Bit#(n) length_request); + // function Bit#(n) getRepresentableLength (t dummy, Bit#(n) length_request) = + // setBoundsCombined(nullCap, length_request).length; // Assert that the encoding is valid function Bool isDerivable (t cap);