From abfcb20d038c2bb4debebc562bb72453994b7917 Mon Sep 17 00:00:00 2001 From: jon Date: Fri, 10 Jul 2020 20:47:50 +0100 Subject: [PATCH 1/3] Add function needed in MemCap instance. --- CHERICC_Fat.bsv | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/CHERICC_Fat.bsv b/CHERICC_Fat.bsv index 0808fe0..fc5600b 100644 --- a/CHERICC_Fat.bsv +++ b/CHERICC_Fat.bsv @@ -935,7 +935,7 @@ instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); function getLength = error("getLength not implemented for CapMem"); function isInBounds = error("isInBounds not implemented for CapMem"); function setBoundsCombined = error("setBoundsCombined not implemented for CapMem"); - function nullWithAddr = error("nullWithAddr not implemented for CapMem"); + function nullWithAddr(Bit#(CapAddressW) addr) = setAddrUnsafe(packCap(null_cap), addr); function almightyCap; CapReg res = almightyCap; return cast(res); @@ -1071,12 +1071,7 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); function SetBoundsReturn#(CapReg, CapAddressW) setBoundsCombined(CapReg cap, Bit#(CapAddressW) length) = setBoundsFat(cap, length); - function CapReg nullWithAddr (Bit#(CapAddressW) addr); - CapReg res = nullCap; - res.address = zeroExtend(addr); - res.addrBits = {2'b0, truncateLSB(addr)}; - return res; - endfunction + function CapReg nullWithAddr (Bit#(CapAddressW) addr) = setAddrUnsafe(null_cap, addr); function almightyCap = defaultCapFat; From 356c7891eeb0df74e01d3d9b01dc82b216774ccc Mon Sep 17 00:00:00 2001 From: jon Date: Fri, 21 Aug 2020 15:31:31 +0100 Subject: [PATCH 2/3] New function for adding to the address unsafely. Would used an increment size based on mantissa width, but this is not available in the type class, so just use 1 byte. This function is currently used for adding small increments to the PC, so does not need support for larger offsets. --- CHERICC_Fat.bsv | 5 +++++ CHERICap.bsv | 2 ++ 2 files changed, 7 insertions(+) diff --git a/CHERICC_Fat.bsv b/CHERICC_Fat.bsv index fc5600b..5d69b6a 100644 --- a/CHERICC_Fat.bsv +++ b/CHERICC_Fat.bsv @@ -928,6 +928,7 @@ instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); capMem.address = address; return pack(capMem); endfunction + function addAddrUnsafe (cap, inc) = setAddrUnsafe(cap, getAddr(cap) + signExtend(inc)); function getOffset = error("getOffset not implemented for CapMem"); function modifyOffset = error("modifyOffset not implemented for CapMem"); function getBase = error("getBase not implemented for CapMem"); @@ -1062,6 +1063,8 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); return setCapPointer(cap, zeroExtend(address)); endfunction + function addAddrUnsafe (cap, inc) = setAddrUnsafe(cap, getAddr(cap) + signExtend(inc)); + function getOffset = error("getOffset not implemented for CapReg"); function modifyOffset = error("modifyOffset not implemented for CapReg"); function getBase = error("getBase not implemented for CapReg"); @@ -1181,6 +1184,8 @@ instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); return cap; endfunction + function addAddrUnsafe (cap, inc) = setAddrUnsafe(cap, getAddr(cap) + signExtend(inc)); + function getOffset (x) = getOffsetFat(x.capFat, x.tempFields); function Exact#(CapPipe) modifyOffset (CapPipe cap, Bit#(CapAddressW) offset, Bool doInc); diff --git a/CHERICap.bsv b/CHERICap.bsv index 37dba33..5b883d4 100644 --- a/CHERICap.bsv +++ b/CHERICap.bsv @@ -124,6 +124,8 @@ typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n, n function Exact#(t) setAddr (t cap, Bit#(n) addr); // Set the address of the capability. Result assumed to be representable function t setAddrUnsafe (t cap, Bit#(n) addr); + // Add to the address of the capability. Result assumed to be representable + function t addAddrUnsafe (t cap, Bit#(8) inc); // Get the offset of the capability function Bit#(n) getOffset (t cap) = getAddr(cap) - getBase(cap); From a6f5ca93eb8cb2ef7e5d34982cb3ae12b62b6dd0 Mon Sep 17 00:00:00 2001 From: jon Date: Fri, 21 Aug 2020 15:54:57 +0100 Subject: [PATCH 3/3] Use the handy MW-derived type for a handy safe-if-inbounds increment size limit. --- CHERICap.bsv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHERICap.bsv b/CHERICap.bsv index 5b883d4..ba6a420 100644 --- a/CHERICap.bsv +++ b/CHERICap.bsv @@ -125,7 +125,7 @@ typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n, n // Set the address of the capability. Result assumed to be representable function t setAddrUnsafe (t cap, Bit#(n) addr); // Add to the address of the capability. Result assumed to be representable - function t addAddrUnsafe (t cap, Bit#(8) inc); + function t addAddrUnsafe (t cap, Bit#(maskable_bits) inc); // Get the offset of the capability function Bit#(n) getOffset (t cap) = getAddr(cap) - getBase(cap);