From 0d7b3bb49f618978961f49f2d11a799545c1380e Mon Sep 17 00:00:00 2001 From: Peter Rugg Date: Wed, 5 Feb 2020 01:44:00 +0000 Subject: [PATCH] Add utilities for CRRL and CRAM --- CHERICC_Fat.bsv | 12 ++++++++++++ CHERICap.bsv | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/CHERICC_Fat.bsv b/CHERICC_Fat.bsv index 77c0854..f24acbb 100644 --- a/CHERICC_Fat.bsv +++ b/CHERICC_Fat.bsv @@ -885,6 +885,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"); endinstance instance FShow #(CapPipe); @@ -1031,6 +1033,12 @@ 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); + let setBoundsCap = nullWithAddr((~0) - length_request); + Exact#(CapFat) result = setBounds(setBoundsCap, length_request); + return (~0) << (result.value.bounds.exp == 0 ? 0 : result.value.bounds.exp + fromInteger(valueOf(HalfExpW))); + endfunction + endinstance instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); @@ -1128,6 +1136,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); + endinstance instance Cast#(CapMem, CapReg); diff --git a/CHERICap.bsv b/CHERICap.bsv index 442c97d..e2ed483 100644 --- a/CHERICap.bsv +++ b/CHERICap.bsv @@ -179,6 +179,15 @@ typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n, n // base. function Bit#(2) getBaseAlignment (t cap); + // Get representable alignment mask + function Bit#(n) getRepresentableAlignmentMask (t dummy, Bit#(n) length_request); + + // Get representable length + function Bit#(n) getRepresentableLength (t dummy, Bit#(n) length_request); + let mask = getRepresentableAlignmentMask(dummy, length_request); + return (length_request + ~mask) & mask; + endfunction + endtypeclass function Fmt showCHERICap(t cap) provisos (CHERICap#(t, ot, flg, n, mem_sz, maskable_bits));