@@ -404,20 +404,21 @@ let null_cap_bits : CapBits = capToBits(null_cap)
404404/*!
405405 * Returns the decoded base and top of the given Capability.
406406 */
407- function getCapBoundsBits (c ) : Capability -> (CapAddrBits , CapLenBits ) = {
407+ function getCapBoundsBits (c ) : Capability -> (CapAddrBits , CapLenBits , CapLenBits ) = {
408408 let E = if c . E >= _u cap_max_E_bits then cap_max_E_bits else c . E ;
409409 let a : CapAddrBits = c . address ;
410410 let a_mid = truncate (a >> E , cap_B_width );
411411 let a_hi = if a_mid <_u c . B then 1 else 0 ;
412412 let a_top = a >> (E + cap_B_width );
413413 let base : CapAddrBits = truncate (((a_top - a_hi ) @ c . B ) << E , cap_addr_width );
414414 let length : CapLenBits = truncate ((zeros (24 ) @ c . M ) << E , cap_len_width );
415- (base , length )
415+ let top : CapLenBits = (0b0 @ base ) + length ;
416+ (base , length , top )
416417}
417418
418- function getCapBounds (cap ) : Capability -> (CapAddrInt , CapLen ) =
419- let (base : CapAddrBits , length : CapLenBits ) = getCapBoundsBits (cap ) in
420- (unsigned (base ), unsigned (length ))
419+ function getCapBounds (cap ) : Capability -> (CapAddrInt , CapLen , CapLen ) =
420+ let (base : CapAddrBits , length : CapLenBits , top : CapLenBits ) = getCapBoundsBits (cap ) in
421+ (unsigned (base ), unsigned (length ), unsigned ( top ) )
421422
422423val count_ones : forall 'ni 'no , 'no >= 1 . (int ('no ), bits ('ni )) -> bits ('no )
423424function count_ones (no , x ) = {
@@ -449,7 +450,7 @@ function setCapBounds(cap, b, l) : (Capability, CapAddrBits, CapAddrBits) -> (bo
449450 let lostSum = unsigned (sumMod2e & mask2e ) != 0 ;
450451 let i : bits (2 ) = iInit + (if lostSum then 0b01 else 0b00 );
451452 let m : bits (cap_B_width + 2 ) = d + zero_extend (i );
452- let m1 : bits (cap_B_width + 1 ) = if m [(cap_B_width + 1 ).. (cap_B_width + 1 )] == 0b1 then m [10 .. 1 ] + zero_extend (m [0 .. 0 ]) else truncate (m , cap_B_width + 1 );
453+ let m1 : bits (cap_B_width + 1 ) = if m [(cap_B_width + 1 ).. (cap_B_width + 1 )] == 0b1 then m [( cap_B_width + 1 ) .. 1 ] + zero_extend (m [0 .. 0 ]) else truncate (m , cap_B_width + 1 );
453454 let e1 : bits (cap_E_width ) = if m [(cap_B_width + 1 ).. (cap_B_width + 1 )] == 0b1 then e + 1 else e ;
454455 let m2 : bits (cap_B_width + 1 ) = if m1 [cap_B_width .. cap_B_width ] == 0b1 then zero_extend (m1 [cap_B_width .. 1 ]) + zero_extend (m1 [0 .. 0 ]) else truncate (m1 , cap_B_width + 1 );
455456 let e2 : bits (cap_E_width ) = if m1 [cap_B_width .. cap_B_width ] == 0b1 then e1 + 1 else e1 ;
@@ -565,15 +566,15 @@ function unsealCap(cap) : Capability -> Capability =
565566 {cap with otype = to_bits (cap_otype_width , otype_unsealed )}
566567
567568function getCapBaseBits (c ) : Capability -> CapAddrBits =
568- let (base , _ ) = getCapBoundsBits (c ) in
569+ let (base , _, _ ) = getCapBoundsBits (c ) in
569570 base
570571
571572function getCapBase (c ) : Capability -> CapAddrInt =
572573 unsigned (getCapBaseBits (c ))
573574
574575function getCapTopBits (c ) : Capability -> CapLenBits =
575- let (base , length ) = getCapBoundsBits (c ) in {
576- zero_extend ( base ) + length
576+ let (_, _, top ) = getCapBoundsBits (c ) in {
577+ top
577578 }
578579
579580function getCapTop (c ) : Capability -> CapLen =
@@ -587,7 +588,7 @@ function getCapOffset(c) : Capability -> CapAddrInt =
587588 unsigned (getCapOffsetBits (c ))
588589
589590function getCapLength (c ) : Capability -> CapLen =
590- let (base , length ) = getCapBoundsBits (c ) in
591+ let (_ , length , _ ) = getCapBoundsBits (c ) in
591592 unsigned (length )
592593
593594/*!
@@ -598,9 +599,9 @@ function getCapLength(c) : Capability -> CapLen =
598599 */
599600val inCapBounds : (Capability , CapAddrBits , CapLen ) -> bool
600601function inCapBounds (cap , addr , size ) = {
601- let (base , length ) = getCapBounds (cap );
602+ let (base , length , top ) = getCapBounds (cap );
602603 let a = unsigned (addr );
603- (a >= base ) & (size <= length )
604+ (a >= base ) & (a + size <= top )
604605}
605606
606607function int_to_cap (offset ) : CapAddrBits -> Capability =
@@ -630,8 +631,8 @@ function clearTag(cap) : Capability -> Capability =
630631 clearTagIf (cap , true )
631632
632633function capBoundsEqual (c1 , c2 ) : (Capability , Capability ) -> bool =
633- let (base1 , length1 ) = getCapBounds (c1 ) in
634- let (base2 , length2 ) = getCapBounds (c2 ) in
634+ let (base1 , length1 , _ ) = getCapBounds (c1 ) in
635+ let (base2 , length2 , _ ) = getCapBounds (c2 ) in
635636 (base1 == base2 ) & (length1 == length2 )
636637
637638/*!
@@ -688,9 +689,8 @@ function incCapAddr(c, delta) =
688689
689690val capToString : (Capability ) -> string
690691function capToString (cap ) = {
691- let top = getCapTop (cap );
692- let top_str = BitStr (to_bits (cap_len_width + 3 , top ));
693- let (base , length ) = getCapBoundsBits (cap );
692+ let (base , length , top ) = getCapBoundsBits (cap );
693+ let top_str = BitStr (0b000 @ top );
694694 let len_str = BitStr (0b000 @ length );
695695 BitStr (cap . address )
696696 ^ " (v:" ^ (if cap . tag then "1 " else "0 " )
0 commit comments