Revert "Provide combined set bound function"

This reverts commit 80ba19db9f.
This commit is contained in:
Peter Rugg
2020-04-23 10:35:14 +01:00
parent 490a10f18c
commit d24104fa3e
2 changed files with 34 additions and 25 deletions

View File

@@ -58,7 +58,6 @@ export HPerms;
export PermsW;
export Exp;
export MetaInfo;
export SetBoundsReturn;
// ===============================================================================
@@ -399,8 +398,15 @@ 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#(CapFat, CapAddressW) setBoundsFat(CapFat cap, Address lengthFull);
function SetBoundsReturn 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
@@ -901,7 +907,7 @@ instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3));
function getTop = error("feature not implemented for this cap type");
function getLength = error("feature not implemented for this cap type");
function isInBounds = error("feature not implemented for this cap type");
function setBoundsCombined = error("feature not implemented for this cap type");
function setBounds = error("feature not implemented for this cap type");
function nullWithAddr = error("feature not implemented for this cap type");
function almightyCap = error("feature not implemented for this cap type");
function nullCap = error("feature not implemented for this cap type");
@@ -910,6 +916,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");
function isDerivable = error("feature not implemented for this cap type");
endinstance
@@ -1019,7 +1027,10 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3));
function getLength = error("feature not implemented for this cap type");
function isInBounds = error("feature not implemented for this cap type");
function SetBoundsReturn#(CapReg, CapAddressW) setBoundsCombined(CapReg cap, Bit#(CapAddressW) length) = setBoundsFat(cap, length);
function Exact#(CapReg) setBounds (CapReg cap, Bit#(CapAddressW) length);
SetBoundsReturn sr = setBoundsFat(cap, length);
return Exact {exact: sr.exact, value: sr.cap};
endfunction
function CapReg nullWithAddr (Bit#(CapAddressW) addr);
CapReg res = nullCap;
@@ -1055,6 +1066,16 @@ 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)))
@@ -1100,9 +1121,9 @@ instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3));
//Functions supported by CapReg but which require TempFields to be changed
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};
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)}};
endfunction
function CapPipe nullWithAddr (Bit#(CapAddressW) addr);
@@ -1165,6 +1186,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);
function isDerivable (cap) = isDerivable(cap.capFat);
endinstance

View File

@@ -78,14 +78,6 @@ typedef enum {
SEALED_WITH_TYPE
} Kind 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));
@@ -161,11 +153,6 @@ 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);
@@ -194,14 +181,11 @@ 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) =
// setBoundsCombined(nullCap, length_request).mask;
function Bit#(n) getRepresentableAlignmentMask (t dummy, Bit#(n) length_request);
// Get representable length
// function Bit#(n) getRepresentableLength (t dummy, Bit#(n) length_request) =
// setBoundsCombined(nullCap, length_request).length;
function Bit#(n) getRepresentableLength (t dummy, Bit#(n) length_request);
// Assert that the encoding is valid
function Bool isDerivable (t cap);