From 4d4001af8dc1625a548c269dfd2b3f4d225b087a Mon Sep 17 00:00:00 2001 From: Alexandre Joannou Date: Wed, 22 May 2019 14:52:06 +0100 Subject: [PATCH] Added toMem/fromMem class methods --- CHERICC_Fat.bsv | 17 +++++++++++++---- CHERICap.bsv | 10 +++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CHERICC_Fat.bsv b/CHERICC_Fat.bsv index 80e84df..de6574e 100644 --- a/CHERICC_Fat.bsv +++ b/CHERICC_Fat.bsv @@ -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); diff --git a/CHERICap.bsv b/CHERICap.bsv index be18bf2..9d8ed5a 100644 --- a/CHERICap.bsv +++ b/CHERICap.bsv @@ -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))) +