Added toMem/fromMem class methods

This commit is contained in:
Alexandre Joannou
2019-05-22 14:52:06 +01:00
parent 5063a8d9e3
commit 4d4001af8d
2 changed files with 20 additions and 7 deletions

View File

@@ -838,7 +838,7 @@ endfunction
// ===============================================================================
// Typeclass instance for interface
typedef Bit#(129) CapMem;
typedef Bit#(TAdd#(1, CapW)) CapMem;
typedef CapFat CapReg;
@@ -847,7 +847,7 @@ typedef struct {
TempFields tempFields;
} CapPipe deriving (Bits, FShow);
instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddressW);
instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddressW, CapW);
function isValidCap (x);
CapabilityInMemory capMem = unpack(x);
return capMem.isCapability;
@@ -879,9 +879,11 @@ instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddressW);
function almightyCap = error("feature not implemented for this cap type");
function nullCap = error("feature not implemented for this cap type");
function validAsType = error("feature not implemented for this cap type");
function fromMem = error("feature not implemented for this cap type");
function toMem = error("feature not implemented for this cap type");
endinstance
instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddressW);
instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddressW, CapW);
function isValidCap = error("feature not implemented for this cap type");
function setValidCap = error("feature not implemented for this cap type");
function getFlags = error("feature not implemented for this cap type");
@@ -906,9 +908,11 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddressW);
function almightyCap = defaultCapFat;
function nullCap = null_cap;
function validAsType = error("feature not implemented for this cap type");
function fromMem = error("feature not implemented for this cap type");
function toMem = error("feature not implemented for this cap type");
endinstance
instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddressW);
instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddressW, CapW);
function isValidCap (x) = x.capFat.isCapability;
@@ -1041,6 +1045,11 @@ instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddressW);
UInt#(64) otypeMaxUnsigned = unpack(zeroExtend(otype_max));
return checkTypeUnsigned <= otypeMaxUnsigned;
endfunction
function fromMem (x) = cast(pack(x));
function toMem (x) = unpack(cast(x));
endinstance
instance Cast#(CapMem, CapReg);

View File

@@ -78,8 +78,8 @@ typedef enum {
SEALED_WITH_TYPE
} Kind deriving (Eq, FShow);
typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n)
dependencies (t determines (ot, flg, n));
typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n, numeric type mem_sz)
dependencies (t determines (ot, flg, n, mem_sz));
// Return whether the Capability is valid
function Bool isValidCap (t cap);
@@ -159,9 +159,13 @@ typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n)
// Check if a type is valid
function Bool validAsType (t dummy, Bit#(n) checkType);
// convert from and to bit memory representation
function t fromMem (Tuple2#(Bool, Bit#(mem_sz)) mem_cap);
function Tuple2#(Bool, Bit#(mem_sz)) toMem (t cap);
endtypeclass
function Fmt showCHERICap(t cap) provisos (CHERICap#(t, ot, flg, n));
function Fmt showCHERICap(t cap) provisos (CHERICap#(t, ot, flg, n, mem_sz));
return $format( "Valid: 0x%0x", isValidCap(cap)) +
$format(" Perms: 0x%0x", getPerms(cap)) +
$format(" Kind: ", fshow(getKind(cap))) +