5 Commits

Author SHA1 Message Date
9d7de214d7 added add delta
Some checks failed
check properties / tests (push) Has been cancelled
2026-03-31 16:15:40 +01:00
6120b13246 pass through pointer works
Some checks failed
check properties / tests (push) Has been cancelled
2026-03-12 18:12:25 +00:00
3c6d203186 saving commented delta changes
Some checks failed
check properties / tests (push) Has been cancelled
2026-03-05 17:40:03 +00:00
6263041aa1 fixed removing areas where delta values were used
Some checks failed
check properties / tests (push) Has been cancelled
2026-02-23 12:26:03 +00:00
8f4feb2f1b removed delta values
Some checks failed
check properties / tests (push) Has been cancelled
2026-02-23 11:59:31 +00:00
2 changed files with 109 additions and 53 deletions

View File

@@ -37,11 +37,13 @@ export CapMem;
export CapReg;
export CapPipe;
export encodeDelta;
export addDelta;
export decodeDelta;
export CapFat;
export MW;
export OTypeW;
export Delta;
export setDeltaValue;
export FlagsW;
export Perms;
export ResW;
@@ -61,8 +63,8 @@ export Exp;
export MetaInfo;
export SetBoundsReturn;
export CapTrim;
// export trimCap;
// export untrimCap;
export trimCap;
export untrimCap;
export CapAddr;
export CapAddrPlus1;
@@ -86,20 +88,20 @@ typedef 0 UPermW;
typedef 8 MW;
typedef 6 ExpW;
typedef 4 OTypeW;
typedef 24 Delta;
// typedef 24 Delta;
typedef `FLAGSW FlagsW;
typedef 32 CapAddrW;
typedef 88 CapW;
typedef 64 CapW;
`else // CAP128 is default
typedef 4 UPermW;
typedef 14 MW;
typedef 6 ExpW;
typedef 18 OTypeW;
typedef 44 Delta;
// typedef 44 Delta;
typedef `FLAGSW FlagsW;
typedef 64 CapAddrW;
// The capability width changes
typedef 172 CapW;
typedef 128 CapW;
`endif
// The Address type is used to represent the full sized address returned to the
@@ -144,9 +146,8 @@ typedef SizeOf#(Perms) PermsW;
// The reserved bits
typedef TSub#(CapW, TAdd#( CapAddrW
, TAdd#( OTypeW
, TAdd#( Delta
, TAdd#( CBoundsW
, TAdd#(PermsW, FlagsW)))))) ResW;
, TAdd#(PermsW, FlagsW))))) ResW;
// The full capability structure, including the "tag" bit.
typedef struct {
Bool isCapability;
@@ -154,7 +155,7 @@ typedef struct {
Bit#(ResW) reserved;
Bit#(FlagsW) flags;
Bit#(OTypeW) otype;
Bit#(Delta) delta;
// Bit#(Delta) delta;
CBounds bounds;
CapAddr address;
} CapabilityInMemory deriving (Bits, Eq, FShow); // CapW + 1 (tag bit)
@@ -190,7 +191,7 @@ typedef struct {
Bit#(FlagsW) flags;
Bit#(ResW) reserved;
Bit#(OTypeW) otype;
Bit#(Delta) delta;
// Bit#(Delta) delta;
Format format;
Bounds bounds;
} CapFat deriving (Bits);
@@ -237,7 +238,7 @@ function CapFat unpackCap(Capability thin);
fat.flags = memCap.flags;
fat.reserved = memCap.reserved;
fat.otype = memCap.otype;
fat.delta = memCap.delta;
// fat.delta = memCap.delta;
match {.f, .b} = decBounds(memCap.bounds);
fat.format = f;
fat.bounds = b;
@@ -1054,7 +1055,7 @@ typedef struct {
// Note: commented out methods have a provided default implementation in the
// CHERICap typeclass definition
instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3), Delta);
instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3));
// capability validity
//////////////////////////////////////////////////////////////////////////////
@@ -1122,7 +1123,7 @@ instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3), Delta
, pack (cap.reserved)
, pack (cap.flags)
, pack (cap.otype)
, pack (cap.delta)
// , pack (cap.delta)
, pack (cap.bounds) };
endfunction
function getAddr (capMem);
@@ -1184,6 +1185,10 @@ instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3), Delta
//////////////////////////////////////////////////////////////////////////////
function isDerivable = error ("isDerivable not implemented for CapMem");
function encodeDelta (cap, delta) = error ("encode delta not implemented");
function addDelta (cap, delta) = error ("addDelta not implemented");
function decodeDelta (cap) = error ("decode delta not implemented");
endinstance
instance FShow #(CapPipe);
@@ -1213,7 +1218,7 @@ endinstance
// Note: commented out methods have a provided default implementation in the
// CHERICap typeclass definition
instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3), Delta);
instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3));
// capability validity
//////////////////////////////////////////////////////////////////////////////
@@ -1337,6 +1342,11 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3), Delta
// capability derivation (bounds set)
//////////////////////////////////////////////////////////////////////////////
function setBoundsCombined (cap, length) = error ("setBoundsCombined not implemented for CapReg");
function encodeDelta (cap, delta) = error ("encode delta not implemented");
function addDelta (cap, delta) = error ("addDelta not implemented");
function decodeDelta (cap) = error ("decode delta not implemented");
//function setBounds = error ("setBounds not implemented for CapReg");
//function roundLength = error ("roundLength not implemented for CapReg");
//function alignmentMask = error ("alignmentMask not implemented for CapReg");
@@ -1361,7 +1371,7 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3), Delta
endinstance
instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddrW, CapW, TSub#(MW, 3), Delta);
instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddrW, CapW, TSub#(MW, 3));
//Functions supported by CapReg are just passed through
@@ -1409,14 +1419,30 @@ instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddrW, CapW, TSub#(MW, 3), Delta
, mask: result.mask };
endfunction
// Create function to set delta value
function setDeltaValue (CapPipe cap, Bit#(Delta) delta);
// let result = setDelta(cap.capFat, delta);
cap.capFat.delta = delta;
// TODO: Similar to set bounds but sets the delta value between the 38th and 64th bit
// function setDeltaValue (cap, length);
// endfunction
function encodeDelta(cap, delta);
// Make a test case of adding 3
Bit#(25) d = truncate(delta);
// d = 15;
Bit#(39) va_bits = cap.capFat.address[38:0];
cap.capFat.address = {d, va_bits};
return cap;
endfunction
function addDelta(cap, delta);
Bit#(25) d = truncate(delta);
cap.capFat.address = cap.capFat.address + zeroExtend(delta);
return cap;
endfunction
// Extract the delta stored in bits 63:39 of the address
function decodeDelta(cap);
return cap.capFat.address[63:39];
endfunction
function nullWithAddr (addr);
CapReg res = nullWithAddr(addr);
@@ -1544,36 +1570,62 @@ typedef 48 VA_Width;
typedef struct {
Perms perms;
Bit#(FlagsW) flags;
Bit#(Delta) delta;
// Bit#(Delta) delta;
CBounds bounds;
Bit#(VA_Width) address;
Bool validAddress;
} CapTrim deriving(Bits, Eq, FShow);
// function CapTrim trimCap(CapMem cm);
// CapabilityInMemory cap = unpack(cm);
// Bit#(TSub#(CapAddrW,VA_Width)) addr_upper = truncateLSB(cap.address);
// return CapTrim{perms: cap.perms,
// flags: cap.flags,
// delta: cap.delta,
// bounds: cap.bounds,
// address: truncate(cap.address),
// validAddress: (addr_upper==signExtend(cap.address[valueOf(VA_Width)-1]))
// };
// endfunction
// function CapMem untrimCap(CapTrim ct);
// // Encode an invalid address as the bit above the last valid bit being different.
// Bit#(1) addressMsb = ct.address[valueOf(VA_Width)-1];
// if (!ct.validAddress) addressMsb = ^addressMsb;
// return pack(CapabilityInMemory{
// isCapability: True,
// perms: ct.perms,
// reserved: 0,
// flags: ct.flags,
// otype: otype_unsealed,
// delta: ct.delta,
// bounds: ct.bounds,
// address: signExtend({addressMsb,ct.address})
// });
// endfunction
function CapTrim trimCap(CapMem cm);
CapabilityInMemory cap = unpack(cm);
Bit#(TSub#(CapAddrW,VA_Width)) addr_upper = truncateLSB(cap.address);
return CapTrim{perms: cap.perms,
flags: cap.flags,
bounds: cap.bounds,
address: truncate(cap.address),
validAddress: (addr_upper==signExtend(cap.address[valueOf(VA_Width)-1]))
};
endfunction
function CapMem untrimCap(CapTrim ct);
// Encode an invalid address as the bit above the last valid bit being different.
Bit#(1) addressMsb = ct.address[valueOf(VA_Width)-1];
if (!ct.validAddress) addressMsb = ^addressMsb;
return pack(CapabilityInMemory{
isCapability: True,
perms: ct.perms,
reserved: 0,
flags: ct.flags,
otype: otype_unsealed,
bounds: ct.bounds,
address: signExtend({addressMsb,ct.address})
});
endfunction
// We do not implement the functions as interfaces
// because all them will have the same implementation/
// This negates the purpose of having type classes.
// Create function to set delta value
// function setDeltaValue (CapPipe cap, Bit#(Delta) delta);
// // let result = setDelta(cap.capFat, delta);
// cap.capFat.delta = delta;
// return cap;
// endfunction
// typedef struct {
// CapFat capFat;
// TempFields tempFields;
// } CapPipe deriving (Bits);
// typedef struct {
// Bool isCapability;
// Bit#(CapAddrW) address;
// Bit#(MW) addrBits;
// Perms perms;
// Bit#(FlagsW) flags;
// Bit#(ResW) reserved;
// Bit#(OTypeW) otype;
// // Bit#(Delta) delta;
// Format format;
// Bounds bounds;
// } CapFat deriving (Bits);
endpackage

View File

@@ -119,7 +119,7 @@ endfunction
// XXX TODO augment with all architectural bounds/ repbounds ?
function Fmt showCHERICap (capT cap)
provisos (CHERICap #(capT , otypeW, flgW, addrW, inMemW, maskableW, delta));
provisos (CHERICap #(capT , otypeW, flgW, addrW, inMemW, maskableW));
return $format( "Valid: 0x%0x", isValidCap(cap)) +
$format(" Perms: 0x%0x", getPerms(cap)) +
$format(" Kind: ", fshow(getKind(cap))) +
@@ -153,9 +153,8 @@ typeclass CHERICap #( type capT // type of the CHERICap capability
, numeric type addrW // width of the address
, numeric type inMemW // width of the capability in mem
, numeric type maskableW // width of maskable bits
, numeric type delta // size of delta (tlb bypass)
)
dependencies (capT determines (otypeW, flgW, addrW, inMemW, maskableW, delta));
dependencies (capT determines (otypeW, flgW, addrW, inMemW, maskableW));
// capability validity
//////////////////////////////////////////////////////////////////////////////
@@ -173,6 +172,11 @@ typeclass CHERICap #( type capT // type of the CHERICap capability
// Set the flags field
function capT setFlags (capT cap, Bit #(flgW) flags);
function capT encodeDelta(capT cap, Bit #(64) delta);
function capT addDelta(capT cap, Bit #(25) delta);
function Bit #(25) decodeDelta(capT cap);
// capability permissions
//////////////////////////////////////////////////////////////////////////////
@@ -321,8 +325,8 @@ typeclass CHERICap #( type capT // type of the CHERICap capability
// the null capability (requires a dummy proxy)
function capT nullCapFromDummy (capT dummy);
// define set delta function
function capT setDeltaValue (capT cap, Bit #(delta) length);
// define set delta function (Disabled when we will use the virtual addresses)
// function capT setDeltaValue (capT cap, Bit #(delta) length);
// Assert that the encoding is valid
//////////////////////////////////////////////////////////////////////////////