Skip to content

Commit efe2e87

Browse files
added a bounds valid / malformed check method
1 parent 0d01e3a commit efe2e87

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHERICC_Fat.bsv

+17-1
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,17 @@ function BoundsInfo#(CapAddrW) getBoundsInfoFat (CapFat cap, TempFields tf)
507507

508508
Bool repSplit = alwaysRep ? False : ! unpack (reduceOr (addrUpperHi));
509509

510+
// compute valid / malformed bounds
511+
//////////////////////////////////////////////////////////////////////////////
512+
513+
Bool malformedMSB = ((exp == resetExp) && (baseBits != 0))
514+
|| ((exp == resetExp - 1) && (msb(baseBits) != 0));
515+
Bool malformedLSB = (exp > resetExp);
516+
`ifdef CAP64
517+
malformedLSB = malformedLSB || (exp == 0);
518+
`endif
519+
Bool malformed = (cap.format != Exp0) && (malformedMSB || malformedLSB);
520+
510521
// return populated BoundsInfo structure
511522
//////////////////////////////////////////////////////////////////////////////
512523

@@ -516,7 +527,8 @@ function BoundsInfo#(CapAddrW) getBoundsInfoFat (CapFat cap, TempFields tf)
516527
, repBase: repBase
517528
, repTop: repTop
518529
, repLength: repLength
519-
, repSplit: repSplit };
530+
, repSplit: repSplit
531+
, malformed: malformed };
520532
endfunction
521533

522534
function CapAddr getBotFat(CapFat cap, TempFields tf);
@@ -1269,6 +1281,7 @@ instance CHERICap #(CapMem, 0, 0, CapAddrW, CapW, TSub#(MW, 2));
12691281

12701282
// capability architectural bounds queries
12711283
//////////////////////////////////////////////////////////////////////////////
1284+
function areCapBoundsValid = error ("areCapBoundsValid not implemented for CapMem");
12721285
function getBoundsInfo = error ("getBoundsInfo not implemented for CapMem");
12731286
//function getBase = error ("getBase not implemented for CapMem");
12741287
//function getTop = error ("getTop not implemented for CapMem");
@@ -1435,6 +1448,7 @@ instance CHERICap #(CapReg, 0, 0, CapAddrW, CapW, TSub#(MW, 2));
14351448

14361449
// capability architectural bounds queries
14371450
//////////////////////////////////////////////////////////////////////////////
1451+
function areCapBoundsValid = error ("areCapBoundsValid not implemented for CapReg");
14381452
function getBoundsInfo = error ("getBoundsInfo not implemented for CapReg");
14391453
//function getBase = error ("getBase not implemented for CapReg");
14401454
//function getTop = error ("getTop not implemented for CapReg");
@@ -1575,6 +1589,8 @@ instance CHERICap #(CapPipe, 0, 0, CapAddrW, CapW, TSub#(MW, 2));
15751589
return Exact { exact: result.v, value: cap };
15761590
endfunction
15771591

1592+
function areCapBoundsValid (cap) = !getBoundsInfoFat(cap.capFat, cap.tempFields).malformed;
1593+
15781594
function getBoundsInfo (cap) = getBoundsInfoFat (cap.capFat, cap.tempFields);
15791595

15801596
function getBase (cap) = getBotFat(cap.capFat, cap.tempFields);

CHERICap.bsv

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ typedef struct {
8282
Bit #(TAdd #(addrW, 1)) repTop;
8383
Bit #(TAdd #(addrW, 1)) repLength;
8484
Bool repSplit;
85+
Bool malformed;
8586
} BoundsInfo #(numeric type addrW) deriving (Bits, Eq, FShow);
8687

8788
// helper types and functions
@@ -244,6 +245,8 @@ typeclass CHERICap #( type capT // type of the CHERICap capability
244245
// getRepBase (cap) + getRepLength (cap) == getRepTop (cap)
245246
// isInBounds (cap) ==> isInRepBounds (cap)
246247

248+
// Return whether the Capability's bounds are valid or malformed
249+
function Bool areCapBoundsValid (capT cap);
247250
// Get all architectural bound information for a capability
248251
function BoundsInfo #(addrW) getBoundsInfo (capT cap);
249252
// Get the base

CHERICapWrap.bsv

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ function Exact#(`CAPTYPE) capExactRet(Exact#(CapPipe) e_cap) =
4848
(* noinline *)
4949
function Bool `W(isValidCap) (`CAPTYPE cap) = isValidCap(cap);
5050
(* noinline *)
51+
function Bool `W(areCapBoundsValid) (`CAPTYPE cap) = areCapBoundsValid(capArg(cap));
52+
(* noinline *)
5153
function `CAPTYPE `W(setValidCap) (`CAPTYPE cap, Bool valid) = setValidCap(cap, valid);
5254
(* noinline *)
5355
function Bool `W(getIntMode) (`CAPTYPE cap) = getIntMode(cap);

0 commit comments

Comments
 (0)