summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Norton2018-04-09 15:50:28 +0100
committerRobert Norton2018-04-09 15:50:33 +0100
commit0d77821e3617c6d7591ba1d68ab0fe90f8cb3c9c (patch)
tree4a953566d9dc981c86515c92d377353540442281
parent85e8b28d088dd74cd401c84ea41a97a35f66ee06 (diff)
cheri: compute virtual address mod 2^64 when doing bounds check to avoid failures with negative (i.e. large positive) offsets.
-rw-r--r--cheri/cheri_insts.sail8
-rw-r--r--cheri/cheri_prelude_common.sail4
2 files changed, 6 insertions, 6 deletions
diff --git a/cheri/cheri_insts.sail b/cheri/cheri_insts.sail
index 92c56cc4..a1ddc8aa 100644
--- a/cheri/cheri_insts.sail
+++ b/cheri/cheri_insts.sail
@@ -1159,7 +1159,7 @@ function clause execute (CLoad(rd, cb, rt, offset, signext, width, linked)) =
{
let 'size = wordWidthBytes(width);
let cursor = getCapCursor(cb_val);
- let vAddr = cursor + unsigned(rGPR(rt)) + (size*signed(offset));
+ let vAddr = (cursor + unsigned(rGPR(rt)) + size*signed(offset)) % pow2(64);
let vAddr64 = to_bits(64, vAddr);
if ((vAddr + size) > getCapTop(cb_val)) then
raise_c2_exception(CapEx_LengthViolation, cb)
@@ -1203,7 +1203,7 @@ function clause execute (CStore(rs, cb, rt, rd, offset, width, conditional)) =
{
size = wordWidthBytes(width);
cursor = getCapCursor(cb_val);
- vAddr = cursor + unsigned(rGPR(rt)) + (size * signed(offset));
+ vAddr = (cursor + unsigned(rGPR(rt)) + size * signed(offset)) % pow2(64);
vAddr64= to_bits(64, vAddr);
if ((vAddr + size) > getCapTop(cb_val)) then
raise_c2_exception(CapEx_LengthViolation, cb)
@@ -1266,7 +1266,7 @@ function clause execute (CSC(cs, cb, rt, rd, offset, conditional)) =
else
{
cursor = getCapCursor(cb_val);
- vAddr = cursor + unsigned(rGPR(rt)) + (16 * signed(offset));
+ vAddr = (cursor + unsigned(rGPR(rt)) + 16 * signed(offset)) % pow2(64);
vAddr64= to_bits(64, vAddr);
if ((vAddr + cap_size) > getCapTop(cb_val)) then
raise_c2_exception(CapEx_LengthViolation, cb)
@@ -1313,7 +1313,7 @@ function clause execute (CLC(cd, cb, rt, offset, linked)) =
else
{
cursor = getCapCursor(cb_val);
- vAddr = cursor + unsigned(rGPR(rt)) + (16 * signed(offset));
+ vAddr = (cursor + unsigned(rGPR(rt)) + 16 * signed(offset)) % pow2(64);
vAddr64= to_bits(64, vAddr);
if ((vAddr + cap_size) > getCapTop(cb_val)) then
raise_c2_exception(CapEx_LengthViolation, cb)
diff --git a/cheri/cheri_prelude_common.sail b/cheri/cheri_prelude_common.sail
index 09e07f70..9c51966b 100644
--- a/cheri/cheri_prelude_common.sail
+++ b/cheri/cheri_prelude_common.sail
@@ -355,7 +355,7 @@ function addrWrapper(addr, accessType, width) =
StoreData => if (~(cap.permit_store)) then (raise_c2_exception(CapEx_PermitStoreViolation, capno))
};
cursor = getCapCursor(cap);
- vAddr = cursor + unsigned(addr);
+ vAddr = (cursor + unsigned(addr)) % pow2(64);
size = wordWidthBytes(width);
base = getCapBase(cap);
top = getCapTop(cap);
@@ -364,7 +364,7 @@ function addrWrapper(addr, accessType, width) =
else if (vAddr < base) then
(raise_c2_exception(CapEx_LengthViolation, capno))
else
- to_bits(64, vAddr); /* XXX vAddr not truncated because top <= 2^64 and size > 0 */
+ to_bits(64, vAddr);
}
$ifdef _MIPS_TLB_STUB