2 Commits

Author SHA1 Message Date
ed366654f0 saved compile time errors
Some checks failed
check properties / tests (push) Has been cancelled
2026-02-17 15:34:56 +00:00
b8f7b51e8a added latest changes 2026-02-17 14:49:00 +00:00
3 changed files with 81 additions and 125 deletions

View File

@@ -37,13 +37,11 @@ export CapMem;
export CapReg; export CapReg;
export CapPipe; export CapPipe;
export encodeDelta;
export addDelta;
export decodeDelta;
export CapFat; export CapFat;
export MW; export MW;
export OTypeW; export OTypeW;
export Delta;
export setDeltaValue;
export FlagsW; export FlagsW;
export Perms; export Perms;
export ResW; export ResW;
@@ -63,8 +61,8 @@ export Exp;
export MetaInfo; export MetaInfo;
export SetBoundsReturn; export SetBoundsReturn;
export CapTrim; export CapTrim;
export trimCap; // export trimCap;
export untrimCap; // export untrimCap;
export CapAddr; export CapAddr;
export CapAddrPlus1; export CapAddrPlus1;
@@ -88,20 +86,20 @@ typedef 0 UPermW;
typedef 8 MW; typedef 8 MW;
typedef 6 ExpW; typedef 6 ExpW;
typedef 4 OTypeW; typedef 4 OTypeW;
// typedef 24 Delta; typedef 24 Delta;
typedef `FLAGSW FlagsW; typedef `FLAGSW FlagsW;
typedef 32 CapAddrW; typedef 32 CapAddrW;
typedef 64 CapW; typedef 88 CapW;
`else // CAP128 is default `else // CAP128 is default
typedef 4 UPermW; typedef 4 UPermW;
typedef 14 MW; typedef 14 MW;
typedef 6 ExpW; typedef 6 ExpW;
typedef 18 OTypeW; typedef 18 OTypeW;
// typedef 44 Delta; typedef 44 Delta;
typedef `FLAGSW FlagsW; typedef `FLAGSW FlagsW;
typedef 64 CapAddrW; typedef 64 CapAddrW;
// The capability width changes // The capability width changes
typedef 128 CapW; typedef 172 CapW;
`endif `endif
// The Address type is used to represent the full sized address returned to the // The Address type is used to represent the full sized address returned to the
@@ -146,8 +144,9 @@ typedef SizeOf#(Perms) PermsW;
// The reserved bits // The reserved bits
typedef TSub#(CapW, TAdd#( CapAddrW typedef TSub#(CapW, TAdd#( CapAddrW
, TAdd#( OTypeW , TAdd#( OTypeW
, TAdd#( Delta
, TAdd#( CBoundsW , TAdd#( CBoundsW
, TAdd#(PermsW, FlagsW))))) ResW; , TAdd#(PermsW, FlagsW)))))) ResW;
// The full capability structure, including the "tag" bit. // The full capability structure, including the "tag" bit.
typedef struct { typedef struct {
Bool isCapability; Bool isCapability;
@@ -155,7 +154,7 @@ typedef struct {
Bit#(ResW) reserved; Bit#(ResW) reserved;
Bit#(FlagsW) flags; Bit#(FlagsW) flags;
Bit#(OTypeW) otype; Bit#(OTypeW) otype;
// Bit#(Delta) delta; Bit#(Delta) delta;
CBounds bounds; CBounds bounds;
CapAddr address; CapAddr address;
} CapabilityInMemory deriving (Bits, Eq, FShow); // CapW + 1 (tag bit) } CapabilityInMemory deriving (Bits, Eq, FShow); // CapW + 1 (tag bit)
@@ -191,7 +190,7 @@ typedef struct {
Bit#(FlagsW) flags; Bit#(FlagsW) flags;
Bit#(ResW) reserved; Bit#(ResW) reserved;
Bit#(OTypeW) otype; Bit#(OTypeW) otype;
// Bit#(Delta) delta; Bit#(Delta) delta;
Format format; Format format;
Bounds bounds; Bounds bounds;
} CapFat deriving (Bits); } CapFat deriving (Bits);
@@ -238,7 +237,7 @@ function CapFat unpackCap(Capability thin);
fat.flags = memCap.flags; fat.flags = memCap.flags;
fat.reserved = memCap.reserved; fat.reserved = memCap.reserved;
fat.otype = memCap.otype; fat.otype = memCap.otype;
// fat.delta = memCap.delta; fat.delta = memCap.delta;
match {.f, .b} = decBounds(memCap.bounds); match {.f, .b} = decBounds(memCap.bounds);
fat.format = f; fat.format = f;
fat.bounds = b; fat.bounds = b;
@@ -262,6 +261,7 @@ function Capability packCap(CapFat fat);
, flags: fat.flags , flags: fat.flags
, reserved: fat.reserved , reserved: fat.reserved
, otype: fat.otype , otype: fat.otype
, delta: fat.delta
, bounds: encBounds(fat.format,fat.bounds) , bounds: encBounds(fat.format,fat.bounds)
, address: fat.address }; , address: fat.address };
return pack(thin); return pack(thin);
@@ -887,6 +887,7 @@ instance DefaultValue #(CapFat);
, flags : 0 , flags : 0
, reserved : 0 , reserved : 0
, otype : otype_unsealed , otype : otype_unsealed
, delta : 0
, format : EmbeddedExp , format : EmbeddedExp
, bounds : defaultValue , bounds : defaultValue
, address : 0 , address : 0
@@ -899,6 +900,7 @@ CapFat null_cap = CapFat {
, flags : 0 , flags : 0
, reserved : 0 , reserved : 0
, otype : otype_unsealed , otype : otype_unsealed
, delta : 0
, format : EmbeddedExp , format : EmbeddedExp
, bounds : defaultValue , bounds : defaultValue
, address : 0 , address : 0
@@ -1055,7 +1057,7 @@ typedef struct {
// Note: commented out methods have a provided default implementation in the // Note: commented out methods have a provided default implementation in the
// CHERICap typeclass definition // CHERICap typeclass definition
instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3)); instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3), Delta);
// capability validity // capability validity
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@@ -1123,7 +1125,7 @@ instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3));
, pack (cap.reserved) , pack (cap.reserved)
, pack (cap.flags) , pack (cap.flags)
, pack (cap.otype) , pack (cap.otype)
// , pack (cap.delta) , pack (cap.delta)
, pack (cap.bounds) }; , pack (cap.bounds) };
endfunction endfunction
function getAddr (capMem); function getAddr (capMem);
@@ -1167,6 +1169,10 @@ instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3));
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
function setBoundsCombined = function setBoundsCombined =
error ("setBoundsCombined not implemented for CapMem"); error ("setBoundsCombined not implemented for CapMem");
// Create function to set delta value
function setDeltaValue (CapPipe cap, Bit#(Delta) delta) = error ("setDeltaValue not implemented for CapReg");
//function setBounds = error ("setBounds not implemented for CapMem"); //function setBounds = error ("setBounds not implemented for CapMem");
//function roundLength = error ("roundLength not implemented for CapMem"); //function roundLength = error ("roundLength not implemented for CapMem");
//function alignmentMask = error ("alignmentMask not implemented for CapMem"); //function alignmentMask = error ("alignmentMask not implemented for CapMem");
@@ -1185,10 +1191,6 @@ instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3));
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
function isDerivable = error ("isDerivable not implemented for CapMem"); 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 endinstance
instance FShow #(CapPipe); instance FShow #(CapPipe);
@@ -1218,7 +1220,7 @@ endinstance
// Note: commented out methods have a provided default implementation in the // Note: commented out methods have a provided default implementation in the
// CHERICap typeclass definition // CHERICap typeclass definition
instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3)); instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3), Delta);
// capability validity // capability validity
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@@ -1343,9 +1345,8 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3));
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
function setBoundsCombined (cap, length) = error ("setBoundsCombined not implemented for CapReg"); function setBoundsCombined (cap, length) = error ("setBoundsCombined not implemented for CapReg");
function encodeDelta (cap, delta) = error ("encode delta not implemented"); // Create function to set delta value
function addDelta (cap, delta) = error ("addDelta not implemented"); function setDeltaValue (CapPipe cap, Bit#(Delta) delta) = error ("setDeltaValue not implemented for CapReg");
function decodeDelta (cap) = error ("decode delta not implemented");
//function setBounds = error ("setBounds not implemented for CapReg"); //function setBounds = error ("setBounds not implemented for CapReg");
//function roundLength = error ("roundLength not implemented for CapReg"); //function roundLength = error ("roundLength not implemented for CapReg");
@@ -1371,7 +1372,7 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddrW, CapW, TSub #(MW, 3));
endinstance endinstance
instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddrW, CapW, TSub#(MW, 3)); instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddrW, CapW, TSub#(MW, 3), Delta);
//Functions supported by CapReg are just passed through //Functions supported by CapReg are just passed through
@@ -1419,30 +1420,14 @@ instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddrW, CapW, TSub#(MW, 3));
, mask: result.mask }; , mask: result.mask };
endfunction endfunction
// TODO: Similar to set bounds but sets the delta value between the 38th and 64th bit // Create function to set delta value
// function setDeltaValue (cap, length); function setDeltaValue (CapPipe cap, Bit#(Delta) delta);
// endfunction // let result = setDelta(cap.capFat, delta);
cap.capFat.delta = delta;
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; return cap;
endfunction 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); function nullWithAddr (addr);
CapReg res = nullWithAddr(addr); CapReg res = nullWithAddr(addr);
@@ -1570,62 +1555,36 @@ typedef 48 VA_Width;
typedef struct { typedef struct {
Perms perms; Perms perms;
Bit#(FlagsW) flags; Bit#(FlagsW) flags;
// Bit#(Delta) delta; Bit#(Delta) delta;
CBounds bounds; CBounds bounds;
Bit#(VA_Width) address; Bit#(VA_Width) address;
Bool validAddress; Bool validAddress;
} CapTrim deriving(Bits, Eq, FShow); } CapTrim deriving(Bits, Eq, FShow);
function CapTrim trimCap(CapMem cm); // function CapTrim trimCap(CapMem cm);
CapabilityInMemory cap = unpack(cm); // CapabilityInMemory cap = unpack(cm);
Bit#(TSub#(CapAddrW,VA_Width)) addr_upper = truncateLSB(cap.address); // Bit#(TSub#(CapAddrW,VA_Width)) addr_upper = truncateLSB(cap.address);
return CapTrim{perms: cap.perms, // return CapTrim{perms: cap.perms,
flags: cap.flags, // flags: cap.flags,
bounds: cap.bounds, // delta: cap.delta,
address: truncate(cap.address), // bounds: cap.bounds,
validAddress: (addr_upper==signExtend(cap.address[valueOf(VA_Width)-1])) // address: truncate(cap.address),
}; // validAddress: (addr_upper==signExtend(cap.address[valueOf(VA_Width)-1]))
endfunction // };
function CapMem untrimCap(CapTrim ct); // endfunction
// Encode an invalid address as the bit above the last valid bit being different. // function CapMem untrimCap(CapTrim ct);
Bit#(1) addressMsb = ct.address[valueOf(VA_Width)-1]; // // Encode an invalid address as the bit above the last valid bit being different.
if (!ct.validAddress) addressMsb = ^addressMsb; // Bit#(1) addressMsb = ct.address[valueOf(VA_Width)-1];
return pack(CapabilityInMemory{ // if (!ct.validAddress) addressMsb = ^addressMsb;
isCapability: True, // return pack(CapabilityInMemory{
perms: ct.perms, // isCapability: True,
reserved: 0, // perms: ct.perms,
flags: ct.flags, // reserved: 0,
otype: otype_unsealed, // flags: ct.flags,
bounds: ct.bounds, // otype: otype_unsealed,
address: signExtend({addressMsb,ct.address}) // delta: ct.delta,
}); // bounds: ct.bounds,
endfunction // address: signExtend({addressMsb,ct.address})
// });
// We do not implement the functions as interfaces // endfunction
// 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 endpackage

View File

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

View File

@@ -1,23 +1,23 @@
module assert_prop_unique( // module assert_prop_unique(
input wire [63 : 0] prop_base, // input wire [63 : 0] prop_base,
input wire [63 : 0] prop_len, // input wire [63 : 0] prop_len,
input wire [63 : 0] prop_newBase, // input wire [63 : 0] prop_newBase,
input wire [63 : 0] prop_newLen // input wire [63 : 0] prop_newLen
); // );
wire prop_ok; // wire prop_ok;
module_prop_unique module_prop_unique_inst ( // module_prop_unique module_prop_unique_inst (
.prop_unique_base(prop_base), // .prop_unique_base(prop_base),
.prop_unique_len(prop_len), // .prop_unique_len(prop_len),
.prop_unique_newBase(prop_newBase), // .prop_unique_newBase(prop_newBase),
.prop_unique_newLen(prop_newLen), // .prop_unique_newLen(prop_newLen),
.prop_unique(prop_ok) // .prop_unique(prop_ok)
); // );
always @(*) begin // always @(*) begin
assert(prop_ok); // assert(prop_ok);
end // end
endmodule // endmodule
module assert_prop_exact( module assert_prop_exact(
input wire [63 : 0] prop_base, input wire [63 : 0] prop_base,
@@ -180,3 +180,4 @@ module assert_prop_setBounds(
always @(*) begin always @(*) begin
assert(prop_ok); assert(prop_ok);
end end
endmodule