From 97ee2f262b1179ea9f48439f7146f324794dffe9 Mon Sep 17 00:00:00 2001 From: Alexandre Joannou Date: Tue, 22 Oct 2019 10:38:43 +0100 Subject: [PATCH] Update set/inc/modify offset API --- CHERICC_Fat.bsv | 8 ++++---- CHERICap.bsv | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHERICC_Fat.bsv b/CHERICC_Fat.bsv index 386736d..cc163cf 100644 --- a/CHERICC_Fat.bsv +++ b/CHERICC_Fat.bsv @@ -872,7 +872,7 @@ instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); function setAddr = error("feature not implemented for this cap type"); function maskAddr = error("feature not implemented for this cap type"); function getOffset = error("feature not implemented for this cap type"); - function setOffset = error("feature not implemented for this cap type"); + function modifyOffset = error("feature not implemented for this cap type"); function getBase = error("feature not implemented for this cap type"); function getTop = error("feature not implemented for this cap type"); function getLength = error("feature not implemented for this cap type"); @@ -902,7 +902,7 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); function setAddr = error("feature not implemented for this cap type"); function maskAddr = error("feature not implemented for this cap type"); function getOffset = error("feature not implemented for this cap type"); - function setOffset = error("feature not implemented for this cap type"); + function modifyOffset = error("feature not implemented for this cap type"); function getBase = error("feature not implemented for this cap type"); function getTop = error("feature not implemented for this cap type"); function getLength = error("feature not implemented for this cap type"); @@ -1013,8 +1013,8 @@ instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); function getOffset (x) = getOffsetFat(x.capFat, x.tempFields); - function Exact#(CapPipe) setOffset (CapPipe cap, Bit#(CapAddressW) offset, Bool increment); - let result = incOffset(cap.capFat, pack(cap.capFat.address) + zeroExtend(offset), zeroExtend(offset), cap.tempFields, !increment); + function Exact#(CapPipe) modifyOffset (CapPipe cap, Bit#(CapAddressW) offset, Bool doInc); + let result = incOffset(cap.capFat, pack(cap.capFat.address) + zeroExtend(offset), zeroExtend(offset), cap.tempFields, !doInc); cap.capFat = result.d; cap.tempFields = getTempFields(cap.capFat); return Exact {exact: result.v, value: cap}; diff --git a/CHERICap.bsv b/CHERICap.bsv index 0b17924..fb28892 100644 --- a/CHERICap.bsv +++ b/CHERICap.bsv @@ -130,8 +130,14 @@ typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n, n // Get the offset of the capability function Bit#(n) getOffset (t cap) = getAddr(cap) - getBase(cap); + // Modify the offset of the capability. Result invalid if not exact + function Exact#(t) modifyOffset (t cap, Bit#(n) offset, Bool doInc); // Set the offset of the capability. Result invalid if not exact - function Exact#(t) setOffset (t cap, Bit#(n) offset, Bool increment); + function Exact#(t) setOffset (t cap, Bit#(n) offset) = + modifyOffset(cap, offset, False); + // Set the offset of the capability. Result invalid if not exact + function Exact#(t) incOffset (t cap, Bit#(n) inc) = + modifyOffset(cap, inc, True); // Get the base function Bit#(n) getBase (t cap);