diff --git a/CHERICC_Fat.bsv b/CHERICC_Fat.bsv index f140fd2..0323769 100644 --- a/CHERICC_Fat.bsv +++ b/CHERICC_Fat.bsv @@ -830,6 +830,7 @@ instance CHERICap #(CapMem, 18, 64); 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"); + function validAsType = error("feature not implemented for this cap type"); endinstance instance CHERICap #(CapReg, 18, 64); @@ -854,6 +855,7 @@ instance CHERICap #(CapReg, 18, 64); function nullWithAddr = error("feature not implemented for this cap type"); function almightyCap = defaultCapFat; function nullCap = null_cap; + function validAsType = error("feature not implemented for this cap type"); endinstance instance CHERICap #(CapPipe, 18, 64); @@ -978,6 +980,11 @@ instance CHERICap #(CapPipe, 18, 64); function nullCap = CapPipe { capFat: nullCap, tempFields: getTempFields(nullCap) }; + function Bool validAsType (CapPipe dummy, Bit#(64) checkType); + UInt#(64) checkTypeUnsigned = unpack(checkType); + UInt#(64) otypeMaxUnsigned = unpack(zeroExtend(otype_max)); + return checkTypeUnsigned <= otypeMaxUnsigned; + endfunction endinstance instance Cast#(CapMem, CapReg); diff --git a/CHERICap.bsv b/CHERICap.bsv index c156659..9ec5333 100644 --- a/CHERICap.bsv +++ b/CHERICap.bsv @@ -151,6 +151,9 @@ typeclass CHERICap#(type t, numeric type ot, numeric type n) // Return the null capability function t nullCap; + // Check if a type is valid + function Bool validAsType (t dummy, Bit#(n) checkType); + endtypeclass function Fmt showCHERICap(t cap) provisos (CHERICap#(t, ot, n));